Skip to content

Commit

Permalink
Add UI for creating a template variable
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirieGray committed Feb 12, 2019
1 parent 2a45302 commit 31b3ab5
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ui/src/configuration/components/LabelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {validateLabelName} from 'src/configuration/utils/labels'

// Types
import {LabelType} from 'src/clockface'
import {OverlayState} from 'src/types/v2'
import {OverlayState} from 'src/types'

// Decorators
import {ErrorHandling} from 'src/shared/decorators/errors'
Expand Down
2 changes: 1 addition & 1 deletion ui/src/organizations/components/BucketList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DataLoaderSwitcher from 'src/dataLoaders/components/DataLoaderSwitcher'
import {setBucketInfo} from 'src/dataLoaders/actions/steps'

// Types
import {OverlayState} from 'src/types/v2'
import {OverlayState} from 'src/types'
import {Substep, DataLoaderStep, DataLoaderType} from 'src/types/v2/dataLoaders'
import {setDataLoadersType} from 'src/dataLoaders/actions/dataLoaders'
import {AppState} from 'src/types/v2'
Expand Down
2 changes: 1 addition & 1 deletion ui/src/organizations/components/Buckets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {ruleToString} from 'src/utils/formatting'
import {client} from 'src/utils/api'

// Types
import {OverlayState} from 'src/types/v2'
import {OverlayState} from 'src/types'

import {Bucket, Organization, BucketRetentionRules} from '@influxdata/influx'

Expand Down
2 changes: 1 addition & 1 deletion ui/src/organizations/components/Collectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {ErrorHandling} from 'src/shared/decorators/errors'

// Types
import {Telegraf, Bucket} from '@influxdata/influx'
import {OverlayState} from 'src/types/v2'
import {OverlayState} from 'src/types'
import {
setDataLoadersType,
setTelegrafConfigID,
Expand Down
15 changes: 15 additions & 0 deletions ui/src/organizations/components/CreateVariableOverlay.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Create Variable Overlay Styles
-----------------------------------------------------------------------------
*/

@import 'src/style/modules';

.overlay-flux-editor {
position: relative;
height: 300px;
}

.overlay-flux-editor--spacing {
margin-bottom: $ix-marg-c;
}
116 changes: 116 additions & 0 deletions ui/src/organizations/components/CreateVariableOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Libraries
import React, {PureComponent, ChangeEvent} from 'react'

// Styles
import 'src/organizations/components/CreateVariableOverlay.scss'

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

interface Props {
onCreateVariable: () => void
onCloseModal: () => void
}

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: '',
}
}

public render() {
const {onCloseModal} = this.props
const {nameInputStatus, name, script} = this.state

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

<Form>
<OverlayBody>
<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>

<OverlayFooter>
<Button
text="Cancel"
color={ComponentColor.Danger}
onClick={onCloseModal}
/>
<Button
text="Create"
type={ButtonType.Submit}
onClick={this.handleCreateVariable}
color={ComponentColor.Primary}
/>
</OverlayFooter>
</OverlayBody>
</Form>
</OverlayContainer>
)
}

private handleCreateVariable = () => {
this.props.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})
}
}
1 change: 0 additions & 1 deletion ui/src/organizations/components/OrgTaskEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class OrgTaskEditPage extends PureComponent<
script={currentScript}
onChangeScript={this.handleChangeScript}
visibility="visible"
status={{text: '', type: ''}}
suggestions={[]}
/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/organizations/components/OrgTaskPage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Libraries
import _ from 'lodash'
import React, {PureComponent, ChangeEvent} from 'react'
import {InjectedRouter} from 'react-router'
import {connect} from 'react-redux'

// components
// Components
import TaskForm from 'src/tasks/components/TaskForm'
import TaskHeader from 'src/tasks/components/TaskHeader'
import FluxEditor from 'src/shared/components/FluxEditor'
import {Page} from 'src/pageLayout'

// actions
// Actions
import {State as TasksState} from 'src/tasks/reducers/v2'
import {
setNewScript,
Expand Down Expand Up @@ -96,7 +97,6 @@ class OrgTaskPage extends PureComponent<
script={newScript}
onChangeScript={this.handleChangeScript}
visibility="visible"
status={{text: '', type: ''}}
suggestions={[]}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/organizations/components/Scrapers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {ErrorHandling} from 'src/shared/decorators/errors'

// Types
import {ScraperTargetResponse, Bucket} from '@influxdata/influx'
import {OverlayState} from 'src/types/v2'
import {OverlayState} from 'src/types'
import {DataLoaderType, DataLoaderStep} from 'src/types/v2/dataLoaders'

interface Props {
Expand Down
79 changes: 79 additions & 0 deletions ui/src/organizations/components/Variables.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Libraries
import React, {PureComponent} from 'react'
import _ from 'lodash'

// Components
import TabbedPageHeader from 'src/shared/components/tabbed_page/TabbedPageHeader'
import CreateVariableOverlay from 'src/organizations/components/CreateVariableOverlay'
import {
Input,
Button,
ComponentColor,
IconFont,
OverlayTechnology,
} from 'src/clockface'

// Types
import {OverlayState} from 'src/types'

interface Props {}

interface State {
searchTerm: string
overlayState: OverlayState
}

export default class Variables extends PureComponent<Props, State> {
constructor(props: Props) {
super(props)
this.state = {
searchTerm: '',
overlayState: OverlayState.Closed,
}
}

public render() {
const {searchTerm, overlayState} = this.state

return (
<>
<TabbedPageHeader>
<Input
icon={IconFont.Search}
placeholder="Filter variables..."
widthPixels={290}
value={searchTerm}
onChange={this.handleFilterChange}
onBlur={this.handleFilterBlur}
/>
<Button
text="Create Variable"
icon={IconFont.Plus}
color={ComponentColor.Primary}
onClick={this.handleOpenModal}
/>
</TabbedPageHeader>
<OverlayTechnology visible={overlayState === OverlayState.Open}>
<CreateVariableOverlay
onCreateVariable={this.handleCreateVariable}
onCloseModal={this.handleCloseModal}
/>
</OverlayTechnology>
</>
)
}

private handleFilterChange() {}

private handleFilterBlur() {}

private handleOpenModal = (): void => {
this.setState({overlayState: OverlayState.Open})
}

private handleCloseModal = (): void => {
this.setState({overlayState: OverlayState.Closed})
}

private handleCreateVariable() {}
}
8 changes: 8 additions & 0 deletions ui/src/organizations/containers/OrganizationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {Page} from 'src/pageLayout'
import {SpinnerContainer, TechnoSpinner} from 'src/clockface'
import TabbedPageSection from 'src/shared/components/tabbed_page/TabbedPageSection'
import Members from 'src/organizations/components/Members'
import Variables from 'src/organizations/components/Variables'
import Buckets from 'src/organizations/components/Buckets'
import OrgTasksPage from 'src/organizations/components/OrgTasksPage'
import Collectors from 'src/organizations/components/Collectors'
Expand Down Expand Up @@ -265,6 +266,13 @@ class OrganizationView extends PureComponent<Props> {
}}
</GetOrgResources>
</TabbedPageSection>
<TabbedPageSection
id="org-view-tab--variables"
url="variables_tab"
title="Variables"
>
<Variables />
</TabbedPageSection>
</OrganizationTabs>
</div>
</Page.Contents>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/shared/components/FluxEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface Status {

interface Props {
script: string
status: Status
status?: Status
onChangeScript: OnChangeScript
onSubmitScript?: () => void
suggestions: Suggestion[]
Expand All @@ -52,6 +52,7 @@ interface EditorInstance extends IInstance {
class FluxEditor extends PureComponent<Props, State> {
public static defaultProps = {
visibility: 'visible',
status: {text: '', type: ''},
}

private editor: EditorInstance
Expand Down
1 change: 0 additions & 1 deletion ui/src/tasks/containers/TaskEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class TaskEditPage extends PureComponent<
script={currentScript}
onChangeScript={this.handleChangeScript}
visibility="visible"
status={{text: '', type: ''}}
suggestions={[]}
/>
</div>
Expand Down
9 changes: 5 additions & 4 deletions ui/src/tasks/containers/TaskPage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Libraries
import _ from 'lodash'
import React, {PureComponent, ChangeEvent} from 'react'
import {InjectedRouter} from 'react-router'
import {connect} from 'react-redux'

// components
// Components
import TaskForm from 'src/tasks/components/TaskForm'
import TaskHeader from 'src/tasks/components/TaskHeader'
import FluxEditor from 'src/shared/components/FluxEditor'
import {Page} from 'src/pageLayout'

// actions
// Actions
import {State as TasksState} from 'src/tasks/reducers/v2'
import {
setNewScript,
Expand All @@ -18,7 +19,8 @@ import {
clearTask,
cancel,
} from 'src/tasks/actions/v2'
// types

// Types
import {Links} from 'src/types/v2/links'
import {Organization} from 'src/types/v2'
import {
Expand Down Expand Up @@ -95,7 +97,6 @@ class TaskPage extends PureComponent<
script={newScript}
onChangeScript={this.handleChangeScript}
visibility="visible"
status={{text: '', type: ''}}
suggestions={[]}
/>
</div>
Expand Down
2 changes: 2 additions & 0 deletions ui/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ import {
} from 'src/types/tempVars'
import {FluxTable, ScriptStatus, SchemaFilter, RemoteDataState} from './flux'
import {WriteDataMode} from './dataExplorer'
import {OverlayState} from 'src/types/overlay'

export {
TemplateType,
TemplateValue,
TemplateValueType,
Template,
OverlayState,
Cell,
DashboardQuery,
Legend,
Expand Down
File renamed without changes.
Loading

0 comments on commit 31b3ab5

Please sign in to comment.