diff --git a/ui/src/admin/containers/AdminChronografPage.js b/ui/src/admin/containers/AdminChronografPage.js index 12e87e3ac9..10e443a583 100644 --- a/ui/src/admin/containers/AdminChronografPage.js +++ b/ui/src/admin/containers/AdminChronografPage.js @@ -4,6 +4,8 @@ import {bindActionCreators} from 'redux' import {loadUsersAsync} from 'src/admin/actions/chronograf' +import Authorized, {SUPERADMIN_ROLE} from 'src/auth/Authorized' + import PageHeader from 'src/admin/components/chronograf/PageHeader' import UsersTableHeader from 'src/admin/components/chronograf/UsersTableHeader' import UsersTable from 'src/admin/components/chronograf/UsersTable' @@ -20,18 +22,20 @@ class AdminChronografPage extends Component { this.state = { // TODO: pass around organization object instead of just name - organizationName: DEFAULT_ORG, // // TODO: make sure that we take org from server if not superadmin + organizationName: this.props.currentOrganization, selectedUsers: [], filteredUsers: this.props.users, showCreateOverlay: false, } } - // TODO: revisit this, possibly for deep equal comparison on just users + // TODO: revisit this, possibly don't call setState if both are deep equal componentWillReceiveProps(nextProps) { + const {users, currentOrganization} = nextProps + this.handleFilterUsers({ - name: this.state.organizationName, - users: nextProps.users, + name: currentOrganization, + users, }) } @@ -51,22 +55,26 @@ class AdminChronografPage extends Component { ) } - handleFilterUsers = ({name, users}) => { + handleFilterUsers = ({users, name}) => { const nextUsers = users || this.props.users + const nextOrganizationName = name || this.props.currentOrganization const filteredUsers = - name === DEFAULT_ORG + nextOrganizationName === DEFAULT_ORG ? nextUsers : nextUsers.filter( user => - name === NO_ORG + nextOrganizationName === NO_ORG ? user.roles.length === 1 // Filter out if user is only part of Default Org - : user.roles.find(role => role.organizationName === name) + : user.roles.find( + role => role.organizationName === nextOrganizationName + ) ) this.setState({ filteredUsers, - organizationName: name, - selectedUsers: name === DEFAULT_ORG ? this.state.selectedUsers : [], + organizationName: nextOrganizationName, + selectedUsers: + nextOrganizationName === DEFAULT_ORG ? this.state.selectedUsers : [], }) } @@ -125,6 +133,7 @@ class AdminChronografPage extends Component { return (