-
+const AdminChronografPage = ({me}) =>
+
+
+
+
+
Chronograf Admin
-
- {users.length && organizations.length
- ?
- : }
-
- )
- }
-}
+
+
+
+
+
-const {arrayOf, func, shape, string} = PropTypes
+const {shape, string} = PropTypes
AdminChronografPage.propTypes = {
- links: shape({
- users: string.isRequired,
- }),
- users: arrayOf(shape),
- organizations: arrayOf(shape),
- meCurrentOrganization: shape({
- id: string.isRequired,
- name: string.isRequired,
- }).isRequired,
- meRole: string.isRequired,
me: shape({
- name: string.isRequired,
id: string.isRequired,
+ role: string.isRequired,
+ currentOrganization: shape({
+ name: string.isRequired,
+ id: string.isRequired,
+ }),
}).isRequired,
- meID: string.isRequired,
- actions: shape({
- loadUsersAsync: func.isRequired,
- loadOrganizationsAsync: func.isRequired,
- createUserAsync: func.isRequired,
- updateUserAsync: func.isRequired,
- deleteUserAsync: func.isRequired,
- }),
- notify: func.isRequired,
}
-const mapStateToProps = ({
- links,
- adminChronograf: {users, organizations},
- auth: {
- me,
- me: {currentOrganization: meCurrentOrganization, role: meRole, id: meID},
- },
-}) => ({
+const mapStateToProps = ({auth: {me}}) => ({
me,
- meID,
- links,
- users,
- meRole,
- organizations,
- meCurrentOrganization,
})
-const mapDispatchToProps = dispatch => ({
- actions: bindActionCreators(adminChronografActionCreators, dispatch),
- notify: bindActionCreators(publishAutoDismissingNotification, dispatch),
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(AdminChronografPage)
+export default connect(mapStateToProps, null)(AdminChronografPage)
diff --git a/ui/src/admin/containers/OrganizationsPage.js b/ui/src/admin/containers/chronograf/OrganizationsPage.js
similarity index 82%
rename from ui/src/admin/containers/OrganizationsPage.js
rename to ui/src/admin/containers/chronograf/OrganizationsPage.js
index 4c57c88fb6..630357de3d 100644
--- a/ui/src/admin/containers/OrganizationsPage.js
+++ b/ui/src/admin/containers/chronograf/OrganizationsPage.js
@@ -71,21 +71,25 @@ class OrganizationsPage extends Component {
}
render() {
- const {organizations, currentOrganization, authConfig} = this.props
+ const {meCurrentOrganization, organizations, authConfig} = this.props
- return (
-
+ const organization = organizations.find(
+ o => o.id === meCurrentOrganization.id
)
+
+ return organizations.length
+ ?
+ :
}
}
@@ -116,7 +120,7 @@ OrganizationsPage.propTypes = {
updateAuthConfigAsync: func.isRequired,
}),
getMe: func.isRequired,
- currentOrganization: shape({
+ meCurrentOrganization: shape({
name: string.isRequired,
id: string.isRequired,
}),
diff --git a/ui/src/admin/containers/chronograf/UsersPage.js b/ui/src/admin/containers/chronograf/UsersPage.js
new file mode 100644
index 0000000000..46cb87cb04
--- /dev/null
+++ b/ui/src/admin/containers/chronograf/UsersPage.js
@@ -0,0 +1,143 @@
+import React, {Component, PropTypes} from 'react'
+import {connect} from 'react-redux'
+import {bindActionCreators} from 'redux'
+
+import * as adminChronografActionCreators from 'src/admin/actions/chronograf'
+import {publishAutoDismissingNotification} from 'shared/dispatchers'
+
+import UsersTable from 'src/admin/components/chronograf/UsersTable'
+
+class UsersPage extends Component {
+ constructor(props) {
+ super(props)
+
+ this.state = {
+ isLoading: true,
+ }
+ }
+
+ // // TODO: revisit this, possibly don't call setState if both are deep equal
+ // componentWillReceiveProps(nextProps) {
+ // const {meCurrentOrganization} = nextProps
+ //
+ // const hasChangedCurrentOrganization =
+ // meCurrentOrganization.id !== this.props.meCurrentOrganization.id
+ //
+ // if (hasChangedCurrentOrganization) {
+ // this.setState({isLoading: true})
+ // this.loadUsers()
+ // }
+ // }
+
+ // loadUsers = () => {
+ // // this.setState({isLoading: true})
+ // return loadUsersAsync(links.users)
+ // }
+
+ handleCreateUser = user => {
+ const {links, actions: {createUserAsync}} = this.props
+ createUserAsync(links.users, user)
+ }
+
+ handleUpdateUserRole = (user, currentRole, {name}) => {
+ const {actions: {updateUserAsync}} = this.props
+ const updatedRole = {...currentRole, name}
+ const newRoles = user.roles.map(
+ r => (r.organization === currentRole.organization ? updatedRole : r)
+ )
+ updateUserAsync(user, {...user, roles: newRoles})
+ }
+
+ handleUpdateUserSuperAdmin = (user, superAdmin) => {
+ const {actions: {updateUserAsync}} = this.props
+ const updatedUser = {...user, superAdmin}
+ updateUserAsync(user, updatedUser)
+ }
+
+ handleDeleteUser = user => {
+ const {actions: {deleteUserAsync}} = this.props
+ deleteUserAsync(user)
+ }
+
+ async componentWillMount() {
+ const {
+ links,
+ actions: {loadOrganizationsAsync, loadUsersAsync},
+ } = this.props
+
+ this.setState({isLoading: true})
+
+ loadOrganizationsAsync(links.organizations)
+ await loadUsersAsync(links.users)
+
+ this.setState({isLoading: false})
+ }
+
+ render() {
+ const {
+ meCurrentOrganization,
+ organizations,
+ meID,
+ users,
+ notify,
+ } = this.props
+ const {isLoading} = this.state
+
+ if (isLoading || !(organizations.length && users.length)) {
+ return
Loading...
+ }
+
+ const organization = organizations.find(
+ o => o.id === meCurrentOrganization.id
+ )
+
+ return (
+
+ )
+ }
+}
+
+const {arrayOf, func, shape, string} = PropTypes
+
+UsersPage.propTypes = {
+ links: shape({
+ users: string.isRequired,
+ }),
+ meID: string.isRequired,
+ meCurrentOrganization: shape({
+ id: string.isRequired,
+ name: string.isRequired,
+ }).isRequired,
+ users: arrayOf(shape),
+ organizations: arrayOf(shape),
+ actions: shape({
+ loadUsersAsync: func.isRequired,
+ loadOrganizationsAsync: func.isRequired,
+ createUserAsync: func.isRequired,
+ updateUserAsync: func.isRequired,
+ deleteUserAsync: func.isRequired,
+ }),
+ notify: func.isRequired,
+}
+
+const mapStateToProps = ({links, adminChronograf: {organizations, users}}) => ({
+ links,
+ organizations,
+ users,
+})
+
+const mapDispatchToProps = dispatch => ({
+ actions: bindActionCreators(adminChronografActionCreators, dispatch),
+ notify: bindActionCreators(publishAutoDismissingNotification, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(UsersPage)
diff --git a/ui/src/admin/index.js b/ui/src/admin/index.js
index 5663e7aeb3..a985904015 100644
--- a/ui/src/admin/index.js
+++ b/ui/src/admin/index.js
@@ -1,5 +1,4 @@
import AdminInfluxDBPage from './containers/AdminInfluxDBPage'
import AdminChronografPage from './containers/AdminChronografPage'
-import OrganizationsPage from './containers/OrganizationsPage'
-export {AdminChronografPage, AdminInfluxDBPage, OrganizationsPage}
+export {AdminChronografPage, AdminInfluxDBPage}