From 01f4c507f0c7efbf5b1d4760bc9cffc7ecd59957 Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Fri, 5 Apr 2019 16:08:24 -0700 Subject: [PATCH] Move Create Org near Switch Org and alphabetize orgs Co-authored-by: Alirie Gray --- .../components/AccountNavSubItem.tsx | 118 ++++++++++++------ ui/src/pageLayout/containers/Nav.tsx | 118 ++++++++++++------ 2 files changed, 155 insertions(+), 81 deletions(-) diff --git a/ui/src/pageLayout/components/AccountNavSubItem.tsx b/ui/src/pageLayout/components/AccountNavSubItem.tsx index f02b0ce915..69a10dded6 100644 --- a/ui/src/pageLayout/components/AccountNavSubItem.tsx +++ b/ui/src/pageLayout/components/AccountNavSubItem.tsx @@ -1,76 +1,112 @@ // Libraries -import React, {SFC} from 'react' +import React, {PureComponent} from 'react' +import {Link} from 'react-router' // Components -import NavMenu from 'src/pageLayout/components/NavMenu' +import {NavMenu} from '@influxdata/clockface' import {Organization} from '@influxdata/influx' -import {NavMenuType} from 'src/clockface' import CloudFeatureFlag from 'src/shared/components/CloudFeatureFlag' +import DapperScrollbars from 'src/shared/components/dapperScrollbars/DapperScrollbars' +import SortingHat from 'src/shared/components/sorting_hat/SortingHat' interface Props { orgs: Organization[] - showOrganizations: boolean - toggleOrganizationsView: () => void + isShowingOrganizations: boolean + showOrganizationsView: () => void + closeOrganizationsView: () => void } -const AccountNavSubItem: SFC = ({ - orgs, - showOrganizations, - toggleOrganizationsView, -}) => { - if (showOrganizations) { +class AccountNavSubItem extends PureComponent { + render() { + const {orgs, isShowingOrganizations, showOrganizationsView} = this.props + + if (isShowingOrganizations) { + return ( + + {this.orgs} + + ) + } + return ( <> + + {orgs.length > 1 && ( + ( +
+ Switch Organizations +
+ )} + active={false} + key="switch-orgs" + /> + )} + + ( + + Create Organization + + )} + active={false} + /> +
+ + ( + + Logout + + )} + active={false} + key="logout" + /> + + ) + } + + private orgs = (orgs: Organization[]): JSX.Element => { + const {closeOrganizationsView} = this.props + + return ( + {orgs.reduce( (acc, org) => { acc.push( ( + + {org.name} + + )} key={org.id} - type={NavMenuType.RouterLink} active={false} /> ) return acc }, + [ ( +
+ {'< Back'} +
+ )} active={false} key="back-button" className="back-button" />, ] )} - +
) } - - return ( - <> - - {orgs.length > 1 && ( - - )} - - - - - ) } export default AccountNavSubItem diff --git a/ui/src/pageLayout/containers/Nav.tsx b/ui/src/pageLayout/containers/Nav.tsx index 5dd2d4eaae..e6a5263194 100644 --- a/ui/src/pageLayout/containers/Nav.tsx +++ b/ui/src/pageLayout/containers/Nav.tsx @@ -1,13 +1,12 @@ // Libraries import React, {PureComponent} from 'react' -import {withRouter, WithRouterProps} from 'react-router' +import {withRouter, WithRouterProps, Link} from 'react-router' import {connect} from 'react-redux' import _ from 'lodash' // Components -import NavMenu from 'src/pageLayout/components/NavMenu' +import {NavMenu, Icon} from '@influxdata/clockface' import CloudNav from 'src/pageLayout/components/CloudNav' -import CloudExclude from 'src/shared/components/cloud/CloudExclude' import AccountNavSubItem from 'src/pageLayout/components/AccountNavSubItem' // Utils @@ -29,7 +28,7 @@ interface StateProps { } interface State { - showOrganizations: boolean + isShowingOrganizations: boolean } type Props = StateProps & WithRouterProps @@ -40,7 +39,7 @@ class SideNav extends PureComponent { super(props) this.state = { - showOrganizations: false, + isShowingOrganizations: false, } } @@ -52,65 +51,104 @@ class SideNav extends PureComponent { orgs, orgName, } = this.props + if (isHidden) { return null } const orgPrefix = `/orgs/${orgID}` + const dashboardsLink = `${orgPrefix}/dashboards` + const dataExplorerLink = `${orgPrefix}/data-explorer` + const tasksLink = `${orgPrefix}/tasks` + const settingsLink = `${orgPrefix}/settings` return ( +
+ ( + + {`${me.name} (${orgName})`} + + )} + iconLink={className => ( + + + + )} + active={getNavItemActivation(['me', 'account'], location.pathname)} + > + + +
- - - ( + + Data Explorer + + )} + iconLink={className => ( + + + + )} active={getNavItemActivation(['data-explorer'], location.pathname)} /> ( + + Dashboards + + )} + iconLink={className => ( + + + + )} active={getNavItemActivation(['dashboards'], location.pathname)} /> ( + + Tasks + + )} + iconLink={className => ( + + + + )} active={getNavItemActivation(['tasks'], location.pathname)} /> ( + + Settings + + )} + iconLink={className => ( + + + + )} active={getNavItemActivation(['settings'], location.pathname)} - > - - - - + />
) } - private toggleOrganizationsView = (): void => { - this.setState({showOrganizations: !this.state.showOrganizations}) + private showOrganizationsView = (): void => { + this.setState({isShowingOrganizations: true}) + } + + private closeOrganizationsView = (): void => { + this.setState({isShowingOrganizations: false}) } }