-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Add option to generate an all access token
- Loading branch information
Showing
11 changed files
with
390 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
ui/src/authorizations/components/AllAccessTokenOverlay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import React, {PureComponent, ChangeEvent} from 'react' | ||
import {connect} from 'react-redux' | ||
|
||
// Components | ||
import {Overlay, Input, Form} from 'src/clockface' | ||
import { | ||
Alert, | ||
IconFont, | ||
ComponentColor, | ||
ComponentSpacer, | ||
AlignItems, | ||
FlexDirection, | ||
ComponentSize, | ||
Button, | ||
ButtonType, | ||
} from '@influxdata/clockface' | ||
import {withRouter, WithRouterProps} from 'react-router' | ||
|
||
// Actions | ||
import {createAuthorization} from 'src/authorizations/actions' | ||
|
||
// Utils | ||
import {allAccessPermissions} from 'src/authorizations/utils/permissions' | ||
|
||
// Decorators | ||
import {ErrorHandling} from 'src/shared/decorators/errors' | ||
import {Authorization} from '@influxdata/influx' | ||
|
||
interface DispatchProps { | ||
onCreateAuthorization: typeof createAuthorization | ||
} | ||
|
||
interface State { | ||
description: string | ||
} | ||
|
||
type Props = WithRouterProps & DispatchProps | ||
|
||
@ErrorHandling | ||
class AllAccessTokenOverlay extends PureComponent<Props, State> { | ||
public state = {description: ''} | ||
|
||
render() { | ||
const {description} = this.state | ||
|
||
return ( | ||
<Overlay visible={true}> | ||
<Overlay.Container> | ||
<Overlay.Heading | ||
title="Generate All Access Token" | ||
onDismiss={this.handleDismiss} | ||
/> | ||
<Overlay.Body> | ||
<Form onSubmit={this.handleSave}> | ||
<ComponentSpacer | ||
alignItems={AlignItems.Center} | ||
direction={FlexDirection.Column} | ||
margin={ComponentSize.Large} | ||
> | ||
<Form.Element label="Description"> | ||
<Input | ||
placeholder="Describe this new token" | ||
value={description} | ||
onChange={this.handleInputChange} | ||
/> | ||
</Form.Element> | ||
<Alert | ||
icon={IconFont.AlertTriangle} | ||
color={ComponentColor.Warning} | ||
> | ||
This token will be able to create, update, delete, read, and | ||
write to anything in this organization | ||
</Alert> | ||
|
||
<ComponentSpacer | ||
alignItems={AlignItems.Center} | ||
direction={FlexDirection.Row} | ||
margin={ComponentSize.Small} | ||
> | ||
<Button | ||
text="Cancel" | ||
icon={IconFont.Remove} | ||
onClick={this.handleDismiss} | ||
/> | ||
|
||
<Button | ||
text="Save" | ||
icon={IconFont.Checkmark} | ||
color={ComponentColor.Success} | ||
type={ButtonType.Submit} | ||
/> | ||
</ComponentSpacer> | ||
</ComponentSpacer> | ||
</Form> | ||
</Overlay.Body> | ||
</Overlay.Container> | ||
</Overlay> | ||
) | ||
} | ||
|
||
private handleSave = async () => { | ||
const { | ||
params: {orgID}, | ||
onCreateAuthorization, | ||
} = this.props | ||
|
||
const token: Authorization = { | ||
orgID, | ||
description: this.state.description, | ||
permissions: allAccessPermissions(orgID), | ||
} | ||
|
||
await onCreateAuthorization(token) | ||
|
||
this.handleDismiss() | ||
} | ||
|
||
private handleInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
const {value} = e.target | ||
|
||
this.setState({description: value}) | ||
} | ||
|
||
private handleDismiss = () => { | ||
const { | ||
router, | ||
params: {orgID}, | ||
} = this.props | ||
|
||
router.push(`/orgs/${orgID}/tokens`) | ||
} | ||
} | ||
|
||
const mdtp: DispatchProps = { | ||
onCreateAuthorization: createAuthorization, | ||
} | ||
|
||
export default connect<{}, DispatchProps, {}>( | ||
null, | ||
mdtp | ||
)(withRouter(AllAccessTokenOverlay)) |
55 changes: 55 additions & 0 deletions
55
ui/src/authorizations/components/GenerateTokenDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Libraries | ||
import React, {PureComponent} from 'react' | ||
import _ from 'lodash' | ||
|
||
// Components | ||
import {Dropdown, DropdownMode} from 'src/clockface' | ||
|
||
// Types | ||
import {IconFont, ComponentColor, ComponentSize} from '@influxdata/clockface' | ||
|
||
interface OwnProps { | ||
onSelectAllAccess: () => void | ||
} | ||
|
||
type Props = OwnProps | ||
|
||
export default class GenerateTokenDropdown extends PureComponent<Props> { | ||
public render() { | ||
return ( | ||
<Dropdown | ||
mode={DropdownMode.ActionList} | ||
titleText="Generate" | ||
icon={IconFont.Plus} | ||
buttonColor={ComponentColor.Primary} | ||
buttonSize={ComponentSize.Small} | ||
widthPixels={160} | ||
onChange={this.handleSelect} | ||
> | ||
{this.optionItems} | ||
</Dropdown> | ||
) | ||
} | ||
|
||
private get optionItems(): JSX.Element[] { | ||
return [ | ||
<Dropdown.Item | ||
id={this.allAccessOption} | ||
key={this.allAccessOption} | ||
value={this.allAccessOption} | ||
> | ||
{this.allAccessOption} | ||
</Dropdown.Item>, | ||
] | ||
} | ||
|
||
private get allAccessOption(): string { | ||
return 'All Access Token' | ||
} | ||
|
||
private handleSelect = (selection: string): void => { | ||
if (selection === this.allAccessOption) { | ||
this.props.onSelectAllAccess() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.