Skip to content

Commit

Permalink
Merge pull request #13173 from influxdata/feat/create-org-nav
Browse files Browse the repository at this point in the history
feat(ui): Add create org to side nav
  • Loading branch information
ischolten authored Apr 5, 2019
2 parents c0bda59 + 05df47d commit f15dea3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ui/cypress/e2e/buckets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Buckets', () => {
const newBucket = '🅱️ucket'
cy.getByTestID('table-row').should('have.length', 1)

cy.contains('Create').click()
cy.getByTestID('Create Bucket').click()
cy.getByTestID('overlay--container').within(() => {
cy.getByInputName('name').type(newBucket)
cy.get('.button')
Expand Down
1 change: 1 addition & 0 deletions ui/src/buckets/components/BucketsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BucketsTab extends PureComponent<Props, State> {
icon={IconFont.Plus}
color={ComponentColor.Primary}
onClick={this.handleOpenModal}
testID="Create Bucket"
/>
</Tabs.TabContentsHeader>
<FilterList<PrettyBucket>
Expand Down
7 changes: 4 additions & 3 deletions ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import VariableImportOverlay from 'src/variables/components/VariableImportOverla
import OrgVariableExportOverlay from 'src/organizations/components/OrgVariableExportOverlay'
import SetOrg from 'src/shared/containers/SetOrg'
import RouteToOrg from 'src/shared/containers/RouteToOrg'

import CreateOrgOverlay from 'src/organizations/components/CreateOrgOverlay'
import TokensIndex from 'src/authorizations/containers/TokensIndex'

// Actions
Expand Down Expand Up @@ -117,8 +117,9 @@ class Root extends PureComponent {
<Route component={GetOrganizations}>
<Route path="/">
<IndexRoute component={RouteToOrg} />
<Route path="orgs/:orgID" component={App}>
<Route component={SetOrg}>
<Route path="orgs" component={App}>
<Route path="new" component={CreateOrgOverlay} />
<Route path=":orgID" component={SetOrg}>
<IndexRoute component={MePage} />
<Route path="tasks" component={TasksPage}>
<Route
Expand Down
21 changes: 18 additions & 3 deletions ui/src/organizations/actions/orgs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Libraries
import {Dispatch} from 'redux'
import {push, RouterAction} from 'react-router-redux'

// APIs
import {client} from 'src/utils/api'

// Types
import {Organization, RemoteDataState} from 'src/types'
// Actions
import {notify} from 'src/shared/actions/notifications'

// Constants
import {defaultTemplates} from 'src/templates/constants/'
import {
orgCreateSuccess,
orgCreateFailed,
} from 'src/shared/copy/v2/notifications'

// Types
import {Organization, RemoteDataState} from 'src/types'
import {PublishNotificationAction} from 'src/types/actions/notifications'

export enum ActionTypes {
SetOrgs = 'SET_ORGS',
Expand Down Expand Up @@ -126,17 +136,22 @@ export const getOrganizations = () => async (
}

export const createOrg = (org: Organization) => async (
dispatch: Dispatch<AddOrg>
dispatch: Dispatch<Actions | RouterAction | PublishNotificationAction>
): Promise<void> => {
try {
const createdOrg = await client.organizations.create(org)
await client.templates.create({
...defaultTemplates.systemTemplate(),
orgID: createdOrg.id,
})

dispatch(addOrg(createdOrg))
dispatch(push(`/orgs/${createdOrg.id}`))

dispatch(notify(orgCreateSuccess()))
} catch (e) {
console.error(e)
dispatch(notify(orgCreateFailed()))
}
}

Expand Down
1 change: 0 additions & 1 deletion ui/src/organizations/components/CreateOrgOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class CreateOrgOverlay extends PureComponent<Props, State> {
const {createOrg} = this.props

await createOrg(org)
this.closeModal()
}

private closeModal = () => {
Expand Down
38 changes: 22 additions & 16 deletions ui/src/pageLayout/containers/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import _ from 'lodash'
// Components
import NavMenu from 'src/pageLayout/components/NavMenu'
import CloudNav from 'src/pageLayout/components/CloudNav'
import CloudExclude from 'src/shared/components/cloud/CloudExclude'
import AccountNavSubItem from 'src/pageLayout/components/AccountNavSubItem'

// Utils
import {getNavItemActivation} from 'src/pageLayout/utils'
Expand All @@ -16,13 +18,14 @@ import {AppState} from 'src/types'
import {IconFont} from 'src/clockface'
import {Organization} from '@influxdata/influx'

// Decorators
import {ErrorHandling} from 'src/shared/decorators/errors'
import AccountNavSubItem from 'src/pageLayout/components/AccountNavSubItem'

interface StateProps {
isHidden: boolean
me: AppState['me']
orgs: Organization[]
orgName: string
}

interface State {
Expand All @@ -47,6 +50,7 @@ class SideNav extends PureComponent<Props, State> {
me,
params: {orgID},
orgs,
orgName,
} = this.props
if (isHidden) {
return null
Expand All @@ -57,7 +61,7 @@ class SideNav extends PureComponent<Props, State> {
return (
<NavMenu>
<NavMenu.Item
title={`${me.name} (${this.orgName})`}
title={`${me.name} (${orgName})`}
path={`${orgPrefix}`}
icon={IconFont.CuboNav}
active={getNavItemActivation(['me', 'account'], location.pathname)}
Expand Down Expand Up @@ -87,36 +91,38 @@ class SideNav extends PureComponent<Props, State> {
active={getNavItemActivation(['tasks'], location.pathname)}
/>
<NavMenu.Item
title="Settings"
title={`${orgName} Settings`}
path={`${orgPrefix}/settings`}
icon={IconFont.Wrench}
active={getNavItemActivation(['settings'], location.pathname)}
/>
>
<CloudExclude>
<NavMenu.SubItem
title="Create Organization"
path="/orgs/new"
active={false}
/>
</CloudExclude>
</NavMenu.Item>
<CloudNav />
</NavMenu>
)
}

private get orgName(): string {
const {
params: {orgID},
orgs,
} = this.props
return orgs.find(org => {
return org.id === orgID
}).name
}

private toggleOrganizationsView = (): void => {
this.setState({showOrganizations: !this.state.showOrganizations})
}
}

const mstp = (state: AppState): StateProps => {
const isHidden = state.app.ephemeral.inPresentationMode
const {me, orgs} = state
const {
me,
orgs,
orgs: {org},
} = state

return {isHidden, me, orgs: orgs.items}
return {isHidden, me, orgs: orgs.items, orgName: _.get(org, 'name', '')}
}

export default connect<StateProps>(mstp)(withRouter(SideNav))
10 changes: 10 additions & 0 deletions ui/src/shared/copy/v2/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ export const bucketUpdateFailed = (bucketName: string): Notification => ({
message: `Failed to update bucket: "${bucketName}"`,
})

export const orgCreateSuccess = (): Notification => ({
...defaultSuccessNotification,
message: 'Organization was successfully created',
})

export const orgCreateFailed = (): Notification => ({
...defaultErrorNotification,
message: 'Failed to create organization',
})

export const scraperDeleteSuccess = (scraperName: string): Notification => ({
...defaultSuccessNotification,
message: `Scraper "${scraperName}" was successfully deleted`,
Expand Down

0 comments on commit f15dea3

Please sign in to comment.