Skip to content

Commit

Permalink
Merge pull request #13161 from influxdata/feat/labels-variables
Browse files Browse the repository at this point in the history
Add the ability to add labels on variables
  • Loading branch information
Palakp41 authored Apr 4, 2019
2 parents 2909927 + dbfe926 commit 8254149
Show file tree
Hide file tree
Showing 29 changed files with 235 additions and 75 deletions.
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. [13024](https://github.com/influxdata/influxdb/pull/13024): Add the ability to edit token's description
1. [13078](https://github.com/influxdata/influxdb/pull/13078): Add the option to create a Dashboard from a Template.
1. [13161](https://github.com/influxdata/influxdb/pull/13161): Add the ability to add labels on variables

### Bug Fixes

Expand Down
6 changes: 3 additions & 3 deletions ui/package-lock.json

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

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
},
"dependencies": {
"@influxdata/clockface": "0.0.8",
"@influxdata/influx": "0.2.59",
"@influxdata/influx": "0.2.61",
"@influxdata/react-custom-scrollbars": "4.3.8",
"@influxdata/vis": "^0.2.3",
"axios": "^0.18.0",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/configuration/components/CreateVariableOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Overlay} from 'src/clockface'
import VariableForm from 'src/organizations/components/VariableForm'

// Types
import {Variable, Organization} from '@influxdata/influx'
import {IVariable as Variable, Organization} from '@influxdata/influx'

interface Props {
onCreateVariable: (variable: Variable) => void
Expand Down
47 changes: 28 additions & 19 deletions ui/src/configuration/components/Variables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import CreateVariableOverlay from 'src/configuration/components/CreateVariableOv
import VariableList from 'src/organizations/components/VariableList'
import FilterList from 'src/shared/components/Filter'
import AddResourceDropdown from 'src/shared/components/AddResourceDropdown'
import GetLabels from 'src/configuration/components/GetLabels'

// Types
import {OverlayState} from 'src/types'
import {AppState} from 'src/types'
import {Variable, Organization} from '@influxdata/influx'
import {IVariable as Variable, Organization} from '@influxdata/influx'
import {IconFont, ComponentSize, RemoteDataState} from '@influxdata/clockface'
import {VariablesState} from 'src/variables/reducers'

Expand Down Expand Up @@ -75,21 +76,24 @@ class Variables extends PureComponent<Props, State> {
onSelectNew={this.handleOpenCreateOverlay}
/>
</TabbedPageHeader>
<FilterList<Variable>
searchTerm={searchTerm}
searchKeys={['name']}
list={this.variableList(variables)}
sortByKey="name"
>
{v => (
<VariableList
variables={v}
emptyState={this.emptyState}
onDeleteVariable={this.handleDeleteVariable}
onUpdateVariable={this.handleUpdateVariable}
/>
)}
</FilterList>
<GetLabels>
<FilterList<Variable>
searchTerm={searchTerm}
searchKeys={['name']}
list={this.variableList(variables)}
sortByKey="name"
>
{v => (
<VariableList
variables={v}
emptyState={this.emptyState}
onDeleteVariable={this.handleDeleteVariable}
onUpdateVariable={this.handleUpdateVariable}
onFilterChange={this.handleFilterUpdate}
/>
)}
</FilterList>
</GetLabels>
<CreateVariableOverlay
onCreateVariable={this.handleCreateVariable}
onHideOverlay={this.handleCloseCreateOverlay}
Expand Down Expand Up @@ -136,11 +140,16 @@ class Variables extends PureComponent<Props, State> {
}

private handleFilterChange = (e: ChangeEvent<HTMLInputElement>) => {
const {value} = e.target
this.setState({searchTerm: value})
this.handleFilterUpdate(e.target.value)
}

private handleFilterBlur() {}
private handleFilterBlur(e: ChangeEvent<HTMLInputElement>) {
this.setState({searchTerm: e.target.value})
}

private handleFilterUpdate = (searchTerm: string) => {
this.setState({searchTerm})
}

private handleOpenImportOverlay = (): void => {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {moveVariable} from 'src/variables/actions'

// Types
import {AppState} from 'src/types'
import {Variable} from '@influxdata/influx'
import {IVariable as Variable} from '@influxdata/influx'
import {ComponentSize} from '@influxdata/clockface'

// Decorators
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dataExplorer/components/SaveAsVariable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {createVariable} from 'src/variables/actions'

// Types
import {AppState} from 'src/types'
import {Variable} from '@influxdata/influx'
import {IVariable as Variable} from '@influxdata/influx'
import {getActiveQuery} from 'src/timeMachine/selectors'

interface OwnProps {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/organizations/components/CreateVariableOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Overlay} from 'src/clockface'
import VariableForm from 'src/organizations/components/VariableForm'

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

interface Props {
onCreateVariable: (variable: Variable) => void
Expand Down
2 changes: 1 addition & 1 deletion ui/src/organizations/components/UpdateVariableOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Overlay} from 'src/clockface'
import FluxEditor from 'src/shared/components/FluxEditor'

// Types
import {Variable} from '@influxdata/influx'
import {IVariable as Variable} from '@influxdata/influx'
import {
ButtonType,
ComponentColor,
Expand Down
5 changes: 4 additions & 1 deletion ui/src/organizations/components/VariableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import VariableRow from 'src/organizations/components/VariableRow'
import UpdateVariableOverlay from 'src/organizations/components/UpdateVariableOverlay'

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

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

interface State {
Expand All @@ -38,6 +39,7 @@ class VariableList extends PureComponent<Props, State> {
variables,
onDeleteVariable,
onUpdateVariable,
onFilterChange,
} = this.props

return (
Expand All @@ -55,6 +57,7 @@ class VariableList extends PureComponent<Props, State> {
onDeleteVariable={onDeleteVariable}
onUpdateVariableName={onUpdateVariable}
onEditVariable={this.handleStartEdit}
onFilterChange={onFilterChange}
/>
))}
</IndexList.Body>
Expand Down
114 changes: 102 additions & 12 deletions ui/src/organizations/components/VariableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
// Libraries
import React, {PureComponent} from 'react'
import {connect} from 'react-redux'
import {withRouter, WithRouterProps} from 'react-router'

// Components
import {IndexList, Alignment, Context, IconFont} from 'src/clockface'
import {
IndexList,
Alignment,
Context,
IconFont,
Stack,
ComponentSpacer,
} from 'src/clockface'
import {ComponentColor} from '@influxdata/clockface'
import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels'

// Types
import {Variable} from '@influxdata/influx'
import {IVariable as Variable, ILabel} from '@influxdata/influx'
import EditableName from 'src/shared/components/EditableName'
import {AppState} from 'src/types'

// Selectors
import {viewableLabels} from 'src/labels/selectors'

// Actions
import {
addVariableLabelsAsync,
removeVariableLabelsAsync,
} from 'src/variables/actions'
import {createLabel as createLabelAsync} from 'src/labels/actions'

interface OwnProps {
variable: Variable
onDeleteVariable: (variable: Variable) => void
onUpdateVariableName: (variable: Partial<Variable>) => void
onEditVariable: (variable: Variable) => void
onFilterChange: (searchTerm: string) => void
}

type Props = OwnProps & WithRouterProps
interface StateProps {
labels: ILabel[]
}

class VariableRow extends PureComponent<Props> {
interface DispatchProps {
onAddVariableLabels: typeof addVariableLabelsAsync
onRemoveVariableLabels: typeof removeVariableLabelsAsync
onCreateLabel: typeof createLabelAsync
}

type Props = OwnProps & DispatchProps & StateProps

class VariableRow extends PureComponent<Props & WithRouterProps> {
public render() {
const {variable, onDeleteVariable} = this.props

return (
<IndexList.Row testID="variable-row">
<IndexList.Cell alignment={Alignment.Left}>
<EditableName
onUpdate={this.handleUpdateVariableName}
name={variable.name}
noNameString="NAME THIS VARIABLE"
onEditName={this.handleEditVariable}
<ComponentSpacer
stackChildren={Stack.Rows}
align={Alignment.Left}
stretchToFitWidth={true}
>
{variable.name}
</EditableName>
<EditableName
onUpdate={this.handleUpdateVariableName}
name={variable.name}
noNameString="NAME THIS VARIABLE"
onEditName={this.handleEditVariable}
>
{variable.name}
</EditableName>
{this.labels}
</ComponentSpacer>
</IndexList.Cell>
<IndexList.Cell alignment={Alignment.Left}>Query</IndexList.Cell>
<IndexList.Cell revealOnHover={true} alignment={Alignment.Right}>
Expand All @@ -59,6 +97,43 @@ class VariableRow extends PureComponent<Props> {
)
}

private get labels(): JSX.Element {
const {variable, labels, onFilterChange} = this.props
const collectorLabels = viewableLabels(variable.labels)

return (
<InlineLabels
selectedLabels={collectorLabels}
labels={labels}
onFilterChange={onFilterChange}
onAddLabel={this.handleAddLabel}
onRemoveLabel={this.handleRemoveLabel}
onCreateLabel={this.handleCreateLabel}
/>
)
}

private handleAddLabel = (label: ILabel): void => {
const {variable, onAddVariableLabels} = this.props

onAddVariableLabels(variable.id, [label])
}

private handleRemoveLabel = (label: ILabel): void => {
const {variable, onRemoveVariableLabels} = this.props

onRemoveVariableLabels(variable.id, [label])
}

private handleCreateLabel = async (label: ILabel): Promise<void> => {
try {
const {name, properties} = label
await this.props.onCreateLabel(name, properties)
} catch (err) {
throw err
}
}

private handleExport = () => {
const {
router,
Expand All @@ -79,4 +154,19 @@ class VariableRow extends PureComponent<Props> {
}
}

export default withRouter<OwnProps>(VariableRow)
const mstp = ({labels}: AppState): StateProps => {
return {
labels: viewableLabels(labels.list),
}
}

const mdtp: DispatchProps = {
onCreateLabel: createLabelAsync,
onAddVariableLabels: addVariableLabelsAsync,
onRemoveVariableLabels: removeVariableLabelsAsync,
}

export default connect<StateProps, DispatchProps, OwnProps>(
mstp,
mdtp
)(withRouter<Props>(VariableRow))
Loading

0 comments on commit 8254149

Please sign in to comment.