-
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 #11739 from influxdata/fix/route-tasks-adminui
Update routes to create, update and select task from org page
- Loading branch information
Showing
9 changed files
with
436 additions
and
35 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,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) |
Oops, something went wrong.