Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to update a variable #12011

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
1. [11954](https://github.com/influxdata/influxdb/pull/11954): Add the ability to run a task manually from tasks page
1. [11990](https://github.com/influxdata/influxdb/pull/11990): Add the ability to select a custom time range in explorer and dashboard
1. [12009](https://github.com/influxdata/influxdb/pull/12009): Display the version information on the login page
1. [12011](https://github.com/influxdata/influxdb/pull/12011): Add the ability to update a Variable's name and query.

### Bug Fixes
1. [11997](https://github.com/influxdata/influxdb/pull/11997): Update the bucket retention policy to update the time in seconds
Expand Down
30 changes: 15 additions & 15 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
},
"dependencies": {
"@influxdata/clockface": "0.0.4",
"@influxdata/influx": "^0.2.10",
"@influxdata/influx": "^0.2.11",
"@influxdata/react-custom-scrollbars": "4.3.8",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
Expand All @@ -158,14 +158,14 @@
"papaparse": "^4.4.0",
"prop-types": "^15.6.1",
"qs": "^6.5.2",
"react": "^16.8.0",
"react": "^16.8.2",
"react-codemirror2": "^4.2.1",
"react-copy-to-clipboard": "^5.0.1",
"react-datepicker": "^2.1.0",
"react-dimensions": "^1.2.0",
"react-dnd": "^2.6.0",
"react-dnd-html5-backend": "^2.6.0",
"react-dom": "^16.8.0",
"react-dom": "^16.8.2",
"react-grid-layout": "^0.16.6",
"react-markdown": "^4.0.3",
"react-redux": "^5.0.7",
Expand Down
145 changes: 145 additions & 0 deletions ui/src/organizations/components/UpdateVariableOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Libraries
import React, {PureComponent, ChangeEvent, FormEvent} from 'react'
import _ from 'lodash'

// Components
import {
OverlayBody,
OverlayHeading,
OverlayFooter,
ComponentStatus,
OverlayContainer,
Form,
Input,
} from 'src/clockface'
import {Button, ButtonType, ComponentColor} from '@influxdata/clockface'
import FluxEditor from 'src/shared/components/FluxEditor'

// Types
import {Variable} from '@influxdata/influx'

interface Props {
variable: Variable
onCloseOverlay: () => void
onUpdateVariable: (variable: Variable) => Promise<void>
}

interface State {
variable: Variable
script: string
nameErrorMessage: string
nameInputStatus: ComponentStatus
}

export default class UpdateVariableOverlay extends PureComponent<Props, State> {
constructor(props) {
super(props)

const {variable} = this.props
const script = _.get(variable, 'arguments.values.query', '')

this.state = {
variable,
script,
nameInputStatus: ComponentStatus.Default,
nameErrorMessage: '',
}
}

public render() {
const {onCloseOverlay} = this.props
const {variable, nameInputStatus, nameErrorMessage, script} = this.state

return (
<OverlayContainer maxWidth={1000}>
<OverlayHeading
title="Edit Variable"
onDismiss={this.props.onCloseOverlay}
/>

<Form onSubmit={this.handleSubmit}>
<OverlayBody>
<div className="overlay-flux-editor--spacing">
<Form.Element label="Name" errorMessage={nameErrorMessage}>
<Input
placeholder="Give your variable a name"
name="name"
autoFocus={true}
value={variable.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>

<OverlayFooter>
<Button
text="Cancel"
color={ComponentColor.Danger}
onClick={onCloseOverlay}
/>
<Button
text="Submit"
type={ButtonType.Submit}
color={ComponentColor.Primary}
status={
this.isVariableValid
? ComponentStatus.Default
: ComponentStatus.Disabled
}
/>
</OverlayFooter>
</OverlayBody>
</Form>
</OverlayContainer>
)
}

private get isVariableValid(): boolean {
const {variable, script} = this.state

return !!variable.name && !!script
}

private handleSubmit = (e: FormEvent): void => {
e.preventDefault()

this.props.onUpdateVariable(this.state.variable)
this.props.onCloseOverlay()
}

private handleChangeScript = (script: string): void => {
this.setState({script})
}

private handleChangeInput = (e: ChangeEvent<HTMLInputElement>) => {
const value = e.target.value
const key = e.target.name
const variable = {...this.state.variable, [key]: value}

if (!value) {
return this.setState({
variable,
nameInputStatus: ComponentStatus.Error,
nameErrorMessage: `Variable ${key} cannot be empty`,
})
}

this.setState({
variable,
nameInputStatus: ComponentStatus.Valid,
nameErrorMessage: '',
})
}
}
56 changes: 53 additions & 3 deletions ui/src/organizations/components/VariableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@
import React, {PureComponent} from 'react'

// Components
import {IndexList} from 'src/clockface'
import {IndexList, OverlayTechnology} from 'src/clockface'
import VariableRow from 'src/organizations/components/VariableRow'
import UpdateVariableOverlay from 'src/organizations/components/UpdateVariableOverlay'

// Types
import {Variable} from '@influxdata/influx'
import {OverlayState} from 'src/types'

interface Props {
variables: Variable[]
emptyState: JSX.Element
onDeleteVariable: (variable: Variable) => void
onUpdateVariable: (variable: Variable) => void
}

class VariableList extends PureComponent<Props> {
interface State {
variableID: string
variableOverlayState: OverlayState
}

class VariableList extends PureComponent<Props, State> {
constructor(props) {
super(props)

this.state = {
variableID: null,
variableOverlayState: OverlayState.Closed,
}
}

public render() {
const {emptyState, variables, onDeleteVariable} = this.props
const {
emptyState,
variables,
onDeleteVariable,
onUpdateVariable,
} = this.props

return (
<>
Expand All @@ -35,13 +53,45 @@ class VariableList extends PureComponent<Props> {
key={`variable-${variable.id}`}
variable={variable}
onDeleteVariable={onDeleteVariable}
onUpdateVariableName={onUpdateVariable}
onEditVariable={this.handleStartEdit}
/>
))}
</IndexList.Body>
</IndexList>
<OverlayTechnology visible={this.isVariableOverlayVisible}>
<UpdateVariableOverlay
variable={this.variable}
onCloseOverlay={this.handleCloseOverlay}
onUpdateVariable={this.handleUpdateVariable}
/>
</OverlayTechnology>
</>
)
}

private get variable(): Variable {
return this.props.variables.find(v => v.id === this.state.variableID)
}

private get isVariableOverlayVisible(): boolean {
return this.state.variableOverlayState === OverlayState.Open
}

private handleCloseOverlay = () => {
this.setState({variableOverlayState: OverlayState.Closed, variableID: null})
}

private handleStartEdit = (variable: Variable) => {
this.setState({
variableID: variable.id,
variableOverlayState: OverlayState.Open,
})
}

private handleUpdateVariable = async (variable: Variable): Promise<void> => {
this.props.onUpdateVariable(variable)
}
}

export default VariableList
22 changes: 21 additions & 1 deletion ui/src/organizations/components/VariableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import {

// Types
import {Variable} from '@influxdata/influx'
import EditableName from 'src/shared/components/EditableName'

interface Props {
variable: Variable
onDeleteVariable: (variable: Variable) => void
onUpdateVariableName: (variable: Partial<Variable>) => void
onEditVariable: (variable: Variable) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps there is a better name distinction between these two props? both of those names seem like they would do the same thing.

}

export default class VariableRow extends PureComponent<Props> {
Expand All @@ -24,7 +27,14 @@ export default class VariableRow extends PureComponent<Props> {
return (
<IndexList.Row>
<IndexList.Cell alignment={Alignment.Left}>
{variable.name}
<EditableName
onUpdate={this.handleUpdateVariableName}
name={variable.name}
noNameString={'NAME THIS VARIABLE'}
onEditName={this.handleEditVariable}
>
{variable.name}
</EditableName>
</IndexList.Cell>
<IndexList.Cell alignment={Alignment.Left}>{'Query'}</IndexList.Cell>
<IndexList.Cell revealOnHover={true} alignment={Alignment.Right}>
Expand All @@ -39,4 +49,14 @@ export default class VariableRow extends PureComponent<Props> {
</IndexList.Row>
)
}

private handleUpdateVariableName = (name: string) => {
const {onUpdateVariableName, variable} = this.props

onUpdateVariableName({id: variable.id, name})
}

private handleEditVariable = (): void => {
this.props.onEditVariable(this.props.variable)
}
}
Loading