From f7ef728a3b249d5b014b4a1336fb81a66135c33e Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 13 Dec 2017 14:09:13 -0800 Subject: [PATCH] Fix organization default role being stale on chrono users page The 'currentOrganization' namespaced in the auth reducer does not get updated when chronograf organizations reducer gets updated. This results in temporary stale state until `/me` is hit and the 'me auth' state trickles through the application. --- .../admin/components/chronograf/UsersTable.js | 17 ++++++++++++++++- .../components/chronograf/UsersTableRowNew.js | 3 +-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/src/admin/components/chronograf/UsersTable.js b/ui/src/admin/components/chronograf/UsersTable.js index 60ced87ec7..467a85dbf8 100644 --- a/ui/src/admin/components/chronograf/UsersTable.js +++ b/ui/src/admin/components/chronograf/UsersTable.js @@ -1,8 +1,11 @@ import React, {Component, PropTypes} from 'react' +import {connect} from 'react-redux' +import {bindActionCreators} from 'redux' import uuid from 'node-uuid' import Authorized, {SUPERADMIN_ROLE} from 'src/auth/Authorized' +import {getMeAsync} from 'shared/actions/auth' import UsersTableHeader from 'src/admin/components/chronograf/UsersTableHeader' import UsersTableRowNew from 'src/admin/components/chronograf/UsersTableRowNew' @@ -19,6 +22,12 @@ class UsersTable extends Component { } } + componentDidMount() { + // TODO: update the {me: currentOrganization} and {organizations: []} at the same time + // updates the current organization. + this.props.getMe({shouldResetMe: false}) + } + handleChangeUserRole = (user, currentRole) => newRole => { this.props.onUpdateUserRole(user, currentRole, newRole) } @@ -134,5 +143,11 @@ UsersTable.propTypes = { onDeleteUser: func.isRequired, meID: string.isRequired, notify: func.isRequired, + getMe: func.isRequired, } -export default UsersTable + +const mapDispatchToProps = dispatch => ({ + getMe: bindActionCreators(getMeAsync, dispatch), +}) + +export default connect(null, mapDispatchToProps)(UsersTable) diff --git a/ui/src/admin/components/chronograf/UsersTableRowNew.js b/ui/src/admin/components/chronograf/UsersTableRowNew.js index 60aef76926..d084dd2865 100644 --- a/ui/src/admin/components/chronograf/UsersTableRowNew.js +++ b/ui/src/admin/components/chronograf/UsersTableRowNew.js @@ -7,7 +7,6 @@ import SlideToggle from 'shared/components/SlideToggle' import {USERS_TABLE} from 'src/admin/constants/chronografTableSizing' import {USER_ROLES} from 'src/admin/constants/chronografAdmin' -import {MEMBER_ROLE} from 'src/auth/Authorized' class UsersTableRowNew extends Component { constructor(props) { @@ -17,7 +16,7 @@ class UsersTableRowNew extends Component { name: '', provider: '', scheme: 'oauth2', - role: MEMBER_ROLE, + role: this.props.organization.defaultRole, superAdmin: false, } }