-
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.
Merge pull request #12523 from influxdata/explorer/save-as-variable
feat(explorer): add save as variable overlay
- Loading branch information
Showing
7 changed files
with
231 additions
and
103 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
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
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,64 @@ | ||
// Libraries | ||
import React, {PureComponent} from 'react' | ||
import {connect} from 'react-redux' | ||
|
||
// Components | ||
import VariableForm from 'src/organizations/components/VariableForm' | ||
|
||
// Utils | ||
import {getActiveOrg} from 'src/organizations/selectors' | ||
import {createVariable} from 'src/variables/actions' | ||
|
||
// Types | ||
import {AppState} from 'src/types/v2' | ||
import {Variable} from '@influxdata/influx' | ||
import {getActiveQuery} from 'src/timeMachine/selectors' | ||
|
||
interface OwnProps { | ||
onHideOverlay: () => void | ||
} | ||
|
||
interface DispatchProps { | ||
onCreateVariable: (variable: Variable) => void | ||
} | ||
|
||
interface StateProps { | ||
initialScript?: string | ||
orgID: string | ||
} | ||
|
||
type Props = StateProps & DispatchProps & OwnProps | ||
|
||
class SaveAsVariable extends PureComponent<Props> { | ||
render() { | ||
const {orgID, onHideOverlay, onCreateVariable, initialScript} = this.props | ||
|
||
return ( | ||
<VariableForm | ||
orgID={orgID} | ||
onHideOverlay={onHideOverlay} | ||
onCreateVariable={onCreateVariable} | ||
initialScript={initialScript} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
const mstp = (state: AppState): StateProps => { | ||
const activeQuery = getActiveQuery(state) | ||
const activeOrgID = getActiveOrg(state).id | ||
|
||
return { | ||
orgID: activeOrgID, | ||
initialScript: activeQuery.text, | ||
} | ||
} | ||
|
||
const mdtp = { | ||
onCreateVariable: createVariable, | ||
} | ||
|
||
export default connect<StateProps, DispatchProps, OwnProps>( | ||
mstp, | ||
mdtp | ||
)(SaveAsVariable) |
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
118 changes: 16 additions & 102 deletions
118
ui/src/organizations/components/CreateVariableOverlay.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 |
---|---|---|
@@ -1,125 +1,39 @@ | ||
// Libraries | ||
import React, {PureComponent, ChangeEvent} from 'react' | ||
import React, {PureComponent} from 'react' | ||
|
||
// Styles | ||
import 'src/organizations/components/CreateVariableOverlay.scss' | ||
|
||
// Components | ||
import {Form, Input, Overlay} from 'src/clockface' | ||
import {Button} from '@influxdata/clockface' | ||
import FluxEditor from 'src/shared/components/FluxEditor' | ||
import {Overlay} from 'src/clockface' | ||
import VariableForm from 'src/organizations/components/VariableForm' | ||
|
||
// Types | ||
import {Variable} from '@influxdata/influx' | ||
import { | ||
ComponentColor, | ||
ComponentStatus, | ||
ButtonType, | ||
} from '@influxdata/clockface' | ||
|
||
interface Props { | ||
onCreateVariable: (variable: Variable) => void | ||
onCloseModal: () => void | ||
onHideOverlay: () => void | ||
orgID: string | ||
initialScript?: string | ||
} | ||
|
||
interface State { | ||
name: string | ||
script: string | ||
nameInputStatus: ComponentStatus | ||
errorMessage: string | ||
} | ||
|
||
export default class CreateOrgOverlay extends PureComponent<Props, State> { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
name: '', | ||
script: '', | ||
nameInputStatus: ComponentStatus.Default, | ||
errorMessage: '', | ||
} | ||
} | ||
|
||
export default class CreateVariableOverlay extends PureComponent<Props> { | ||
public render() { | ||
const {onCloseModal} = this.props | ||
const {nameInputStatus, name, script} = this.state | ||
const {onHideOverlay, onCreateVariable, orgID, initialScript} = this.props | ||
|
||
return ( | ||
<Overlay.Container maxWidth={1000}> | ||
<Overlay.Heading | ||
title="Create Variable" | ||
onDismiss={this.props.onCloseModal} | ||
/> | ||
|
||
<Form onSubmit={this.handleSubmit}> | ||
<Overlay.Body> | ||
<div className="overlay-flux-editor--spacing"> | ||
<Form.Element label="Name"> | ||
<Input | ||
placeholder="Give your variable a name" | ||
name="name" | ||
autoFocus={true} | ||
value={name} | ||
onChange={this.handleChangeInput} | ||
status={nameInputStatus} | ||
/> | ||
</Form.Element> | ||
</div> | ||
|
||
<Form.Element label="Value"> | ||
<div className="overlay-flux-editor"> | ||
<FluxEditor | ||
script={script} | ||
onChangeScript={this.handleChangeScript} | ||
visibility="visible" | ||
suggestions={[]} | ||
/> | ||
</div> | ||
</Form.Element> | ||
|
||
<Overlay.Footer> | ||
<Button | ||
text="Cancel" | ||
color={ComponentColor.Danger} | ||
onClick={onCloseModal} | ||
/> | ||
<Button | ||
text="Create" | ||
type={ButtonType.Submit} | ||
color={ComponentColor.Primary} | ||
/> | ||
</Overlay.Footer> | ||
</Overlay.Body> | ||
</Form> | ||
<Overlay.Heading title="Create Variable" onDismiss={onHideOverlay} /> | ||
<Overlay.Body> | ||
<VariableForm | ||
onCreateVariable={onCreateVariable} | ||
onHideOverlay={onHideOverlay} | ||
orgID={orgID} | ||
initialScript={initialScript} | ||
/> | ||
</Overlay.Body> | ||
</Overlay.Container> | ||
) | ||
} | ||
|
||
private handleSubmit = (): void => { | ||
const {onCreateVariable, orgID, onCloseModal} = this.props | ||
|
||
onCreateVariable({ | ||
name: this.state.name, | ||
orgID, | ||
arguments: { | ||
type: 'query', | ||
values: {query: this.state.script, language: 'flux'}, | ||
}, | ||
}) | ||
|
||
onCloseModal() | ||
} | ||
|
||
private handleChangeInput = (e: ChangeEvent<HTMLInputElement>) => { | ||
const {value, name} = e.target | ||
|
||
const newState = {...this.state} | ||
newState[name] = value | ||
this.setState(newState) | ||
} | ||
|
||
private handleChangeScript = (script: string): void => { | ||
this.setState({script}) | ||
} | ||
} |
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,125 @@ | ||
// Libraries | ||
import React, {PureComponent, ChangeEvent} from 'react' | ||
|
||
// Styles | ||
import 'src/organizations/components/CreateVariableOverlay.scss' | ||
|
||
// Components | ||
import {Form, Input, Grid} from 'src/clockface' | ||
import {Button} from '@influxdata/clockface' | ||
import FluxEditor from 'src/shared/components/FluxEditor' | ||
|
||
// Types | ||
import {Variable} from '@influxdata/influx' | ||
import { | ||
ComponentColor, | ||
ComponentStatus, | ||
ButtonType, | ||
} from '@influxdata/clockface' | ||
|
||
interface Props { | ||
onCreateVariable: (variable: Variable) => void | ||
onHideOverlay?: () => void | ||
orgID: string | ||
initialScript?: string | ||
} | ||
|
||
interface State { | ||
name: string | ||
script: string | ||
nameInputStatus: ComponentStatus | ||
errorMessage: string | ||
} | ||
|
||
export default class CreateOrgOverlay extends PureComponent<Props, State> { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
name: '', | ||
script: this.props.initialScript || '', | ||
nameInputStatus: ComponentStatus.Default, | ||
errorMessage: '', | ||
} | ||
} | ||
|
||
public render() { | ||
const {onHideOverlay} = this.props | ||
const {nameInputStatus, name, script} = this.state | ||
|
||
return ( | ||
<Form onSubmit={this.handleSubmit}> | ||
<Grid> | ||
<Grid.Row> | ||
<Grid.Column> | ||
<div className="overlay-flux-editor--spacing"> | ||
<Form.Element label="Name"> | ||
<Input | ||
placeholder="Give your variable a name" | ||
name="name" | ||
autoFocus={true} | ||
value={name} | ||
onChange={this.handleChangeInput} | ||
status={nameInputStatus} | ||
/> | ||
</Form.Element> | ||
</div> | ||
</Grid.Column> | ||
<Grid.Column> | ||
<Form.Element label="Value"> | ||
<div className="overlay-flux-editor"> | ||
<FluxEditor | ||
script={script} | ||
onChangeScript={this.handleChangeScript} | ||
visibility="visible" | ||
suggestions={[]} | ||
/> | ||
</div> | ||
</Form.Element> | ||
</Grid.Column> | ||
<Grid.Column> | ||
<Form.Footer> | ||
<Button | ||
text="Cancel" | ||
color={ComponentColor.Danger} | ||
onClick={onHideOverlay} | ||
/> | ||
<Button | ||
text="Create" | ||
type={ButtonType.Submit} | ||
color={ComponentColor.Primary} | ||
/> | ||
</Form.Footer> | ||
</Grid.Column> | ||
</Grid.Row> | ||
</Grid> | ||
</Form> | ||
) | ||
} | ||
|
||
private handleSubmit = (): void => { | ||
const {onCreateVariable, orgID, onHideOverlay} = this.props | ||
|
||
onCreateVariable({ | ||
name: this.state.name, | ||
orgID, | ||
arguments: { | ||
type: 'query', | ||
values: {query: this.state.script, language: 'flux'}, | ||
}, | ||
}) | ||
|
||
onHideOverlay() | ||
} | ||
|
||
private handleChangeInput = (e: ChangeEvent<HTMLInputElement>) => { | ||
const {value, name} = e.target | ||
|
||
const newState = {...this.state} | ||
newState[name] = value | ||
this.setState(newState) | ||
} | ||
|
||
private handleChangeScript = (script: string): void => { | ||
this.setState({script}) | ||
} | ||
} |
Oops, something went wrong.