Skip to content

Commit

Permalink
Merge pull request #11739 from influxdata/fix/route-tasks-adminui
Browse files Browse the repository at this point in the history
Update routes to create, update and select task from org page
  • Loading branch information
Palakp41 authored Feb 7, 2019
2 parents 625d7f4 + 078ff6d commit e835033
Show file tree
Hide file tree
Showing 9 changed files with 436 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Features
1. [11677](https://github.com/influxdata/influxdb/pull/11677): Add instructions button to view `$INFLUX_TOKEN` setup for telegraf configs
1. [11693](https://github.com/influxdata/influxdb/pull/11693): Save the $INFLUX_TOKEN environmental variable in telegraf configs
1. [11700](https://github.com/influxdata/influxdb/pull/11700): Update Tasks tab on Org page to look like Tasks Page

## Bug Fixes
1. [11678](https://github.com/influxdata/influxdb/pull/11678): Update the System Telegraf Plugin bundle to include the swap plugin
Expand Down
20 changes: 16 additions & 4 deletions ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import TaskPage from 'src/tasks/containers/TaskPage'
import TasksPage from 'src/tasks/containers/TasksPage'
import OrganizationsIndex from 'src/organizations/containers/OrganizationsIndex'
import OrganizationView from 'src/organizations/containers/OrganizationView'
import OrgTaskPage from 'src/organizations/components/OrgTaskPage'
import OrgTaskEditPage from 'src/organizations/components/OrgTaskEditPage'
import TaskEditPage from 'src/tasks/containers/TaskEditPage'
import DashboardPage from 'src/dashboards/components/DashboardPage'
import DashboardsIndex from 'src/dashboards/components/dashboard_index/DashboardsIndex'
Expand Down Expand Up @@ -101,10 +103,20 @@ class Root extends PureComponent {
<IndexRoute component={MePage} />
<Route path="organizations">
<IndexRoute component={OrganizationsIndex} />
<Route
path=":orgID/:tab"
component={OrganizationView}
/>
<Route path=":orgID">
<Route
path="tasks_tab/new"
component={OrgTaskPage}
/>
<Route
path="tasks_tab/:id"
component={OrgTaskEditPage}
/>
<Route
path=":tab"
component={OrganizationView}
/>
</Route>
</Route>
<Route path="tasks">
<IndexRoute component={TasksPage} />
Expand Down
189 changes: 189 additions & 0 deletions ui/src/organizations/components/OrgTaskEditPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Libraries
import _ from 'lodash'
import React, {PureComponent, ChangeEvent} from 'react'
import {InjectedRouter} from 'react-router'
import {connect} from 'react-redux'

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

// Actions
import {
updateScript,
selectTaskByID,
setCurrentScript,
cancel,
setTaskOption,
clearTask,
setAllTaskOptions,
} from 'src/tasks/actions/v2'

// Types
import {Organization} from '@influxdata/influx'
import {Links} from 'src/types/v2/links'
import {State as TasksState} from 'src/tasks/reducers/v2'
import {
TaskOptions,
TaskOptionKeys,
TaskSchedule,
} from 'src/utils/taskOptionsToFluxScript'
import {Task} from 'src/tasks/containers/TasksPage'

interface PassedInProps {
router: InjectedRouter
params: {id: string; orgID: string}
}

interface ConnectStateProps {
orgs: Organization[]
taskOptions: TaskOptions
currentTask: Task
currentScript: string
tasksLink: string
}

interface ConnectDispatchProps {
setTaskOption: typeof setTaskOption
setCurrentScript: typeof setCurrentScript
updateScript: typeof updateScript
cancel: typeof cancel
selectTaskByID: typeof selectTaskByID
clearTask: typeof clearTask
setAllTaskOptions: typeof setAllTaskOptions
}

class OrgTaskEditPage extends PureComponent<
PassedInProps & ConnectStateProps & ConnectDispatchProps
> {
constructor(props) {
super(props)
}

public async componentDidMount() {
const {
params: {id, orgID},
} = this.props
await this.props.selectTaskByID(id, `organizations/${orgID}/tasks_tab/`)

const {currentTask} = this.props

this.props.setAllTaskOptions(currentTask)
}

public componentWillUnmount() {
this.props.clearTask()
}

public render(): JSX.Element {
const {currentScript, taskOptions, orgs} = this.props

return (
<Page titleTag={`Edit ${taskOptions.name}`}>
<TaskHeader
title="Update Task"
canSubmit={this.isFormValid}
onCancel={this.handleCancel}
onSave={this.handleSave}
/>
<Page.Contents fullWidth={true} scrollable={false}>
<div className="task-form">
<div className="task-form--options">
<TaskForm
orgs={orgs}
canSubmit={this.isFormValid}
taskOptions={taskOptions}
onChangeInput={this.handleChangeInput}
onChangeScheduleType={this.handleChangeScheduleType}
onChangeTaskOrgID={this.handleChangeTaskOrgID}
/>
</div>
<div className="task-form--editor">
<FluxEditor
script={currentScript}
onChangeScript={this.handleChangeScript}
visibility="visible"
status={{text: '', type: ''}}
suggestions={[]}
/>
</div>
</div>
</Page.Contents>
</Page>
)
}

private get isFormValid(): boolean {
const {
taskOptions: {name, cron, interval},
currentScript,
} = this.props

const hasSchedule = !!cron || !!interval
return hasSchedule && !!name && !!currentScript
}

private handleChangeScript = (script: string) => {
this.props.setCurrentScript(script)
}

private handleChangeScheduleType = (schedule: TaskSchedule) => {
this.props.setTaskOption({key: 'taskScheduleType', value: schedule})
}

private handleSave = () => {
const {params} = this.props

this.props.updateScript(`organizations/${params.orgID}/tasks_tab/`)
}

private handleCancel = () => {
this.props.cancel()
}

private handleChangeInput = (e: ChangeEvent<HTMLInputElement>) => {
const {name, value} = e.target
const key = name as TaskOptionKeys

this.props.setTaskOption({key, value})
}

private handleChangeTaskOrgID = (orgID: string) => {
this.props.setTaskOption({key: 'orgID', value: orgID})
}
}

const mstp = ({
tasks,
links,
orgs,
}: {
tasks: TasksState
links: Links
orgs: Organization[]
}): ConnectStateProps => {
return {
orgs,
taskOptions: tasks.taskOptions,
currentScript: tasks.currentScript,
tasksLink: links.tasks,
currentTask: tasks.currentTask,
}
}

const mdtp: ConnectDispatchProps = {
setTaskOption,
setCurrentScript,
updateScript,
cancel,
selectTaskByID,
setAllTaskOptions,
clearTask,
}

export default connect<ConnectStateProps, ConnectDispatchProps, {}>(
mstp,
mdtp
)(OrgTaskEditPage)
Loading

0 comments on commit e835033

Please sign in to comment.