Skip to content

Commit 30b578a

Browse files
authored
feat(Tasks): create new Task scheduler form (#6265)
* feat(TaskPage): add TaskScheduler to TaskPage * feat(Tasks): create new task scheduler component * feat: add script selector component * feat: add task interval form component * fix: prettier * chore: clean up * fix: update form input styles * chore: clean up * fix: fix positioning of tooltips * fix: use taskOption.name for task name input * fix(taskPage): update showControlBar prop * chore: updating wording
1 parent d27d4aa commit 30b578a

File tree

6 files changed

+414
-49
lines changed

6 files changed

+414
-49
lines changed

src/tasks/components/TaskHeader.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,40 @@ import {
1010
} from '@influxdata/clockface'
1111

1212
interface Props {
13-
title: string
1413
canSubmit: boolean
1514
onCancel: () => void
1615
onSave: () => void
16+
showControlBar?: boolean
17+
title: string
1718
}
1819

1920
export default class TaskHeader extends PureComponent<Props> {
2021
public render() {
21-
const {onCancel, onSave, title} = this.props
22+
const {onCancel, onSave, showControlBar = true, title} = this.props
2223
return (
2324
<>
2425
<Page.Header fullWidth={true}>
2526
<Page.Title title={title} />
2627
</Page.Header>
27-
<Page.ControlBar fullWidth={true}>
28-
<Page.ControlBarRight>
29-
<Button
30-
color={ComponentColor.Tertiary}
31-
text="Cancel"
32-
onClick={onCancel}
33-
testID="task-cancel-btn"
34-
/>
35-
<Button
36-
color={ComponentColor.Success}
37-
text="Save"
38-
status={this.status}
39-
onClick={onSave}
40-
testID="task-save-btn"
41-
/>
42-
</Page.ControlBarRight>
43-
</Page.ControlBar>
28+
{showControlBar && (
29+
<Page.ControlBar fullWidth={true}>
30+
<Page.ControlBarRight>
31+
<Button
32+
color={ComponentColor.Tertiary}
33+
text="Cancel"
34+
onClick={onCancel}
35+
testID="task-cancel-btn"
36+
/>
37+
<Button
38+
color={ComponentColor.Success}
39+
text="Save"
40+
status={this.status}
41+
onClick={onSave}
42+
testID="task-save-btn"
43+
/>
44+
</Page.ControlBarRight>
45+
</Page.ControlBar>
46+
)}
4447
</>
4548
)
4649
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, {FC} from 'react'
2+
import {useHistory, useParams} from 'react-router-dom'
3+
import {
4+
ComponentSize,
5+
Dropdown,
6+
Form,
7+
IconFont,
8+
Input,
9+
} from '@influxdata/clockface'
10+
11+
// Utils
12+
import {SafeBlankLink} from 'src/utils/SafeBlankLink'
13+
14+
export const ScriptSelector: FC = () => {
15+
const {orgID} = useParams<{orgID: string}>()
16+
const history = useHistory()
17+
const fluxScriptEditorLink = `/orgs/${orgID}/data-explorer?fluxScriptEditor`
18+
19+
const openScriptEditor = () => {
20+
history.push(`/orgs/${orgID}/data-explorer?fluxScriptEditor`)
21+
}
22+
23+
const createScriptInEditor = (
24+
<Dropdown.Item onClick={openScriptEditor}>
25+
+ Create Script in Editor
26+
</Dropdown.Item>
27+
)
28+
29+
const dropdownButtonText = 'Select a Script'
30+
31+
return (
32+
<div className="select-script">
33+
<div className="create-task-titles script">Select a Script</div>
34+
<Form.Element label="Script" required={true} className="script-dropdown">
35+
<Dropdown
36+
button={(active, onClick) => (
37+
<Dropdown.Button
38+
active={active}
39+
onClick={onClick}
40+
testID="variable-type-dropdown--button"
41+
>
42+
{dropdownButtonText}
43+
</Dropdown.Button>
44+
)}
45+
menu={onCollapse => (
46+
<>
47+
<Input
48+
size={ComponentSize.Small}
49+
icon={IconFont.Search_New}
50+
value=""
51+
placeholder="Search Scripts..."
52+
onChange={() => {}}
53+
/>
54+
<Dropdown.Menu onCollapse={onCollapse}>
55+
{createScriptInEditor}
56+
</Dropdown.Menu>
57+
</>
58+
)}
59+
/>
60+
</Form.Element>
61+
<p>
62+
You can create or edit Scripts in the{' '}
63+
<SafeBlankLink href={fluxScriptEditorLink}>
64+
Script Editor.
65+
</SafeBlankLink>
66+
</p>
67+
</div>
68+
)
69+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React, {FC, ChangeEvent} from 'react'
2+
import {
3+
Columns,
4+
ComponentColor,
5+
Grid,
6+
Input,
7+
InputType,
8+
Form,
9+
QuestionMarkTooltip,
10+
} from '@influxdata/clockface'
11+
12+
// Types
13+
import {TaskSchedule, TaskOptions} from 'src/types'
14+
15+
interface Props {
16+
taskOptions: TaskOptions
17+
updateInput: (event: ChangeEvent<HTMLInputElement>) => void
18+
}
19+
20+
const tooltipContents = {
21+
interval:
22+
'This is the interval at which the task runs. It also determines when the task first starts to run, depending on the specified time (in duration literal)',
23+
offset:
24+
'Offset delays the execution of the task but preserves the original time range',
25+
cron: 'Cron is an expression that defines the schedule on which the task runs. Cron scheduling is based on system time',
26+
}
27+
28+
export const TaskIntervalForm: FC<Props> = props => {
29+
const {
30+
taskOptions: {taskScheduleType, cron, offset, interval},
31+
updateInput,
32+
} = props
33+
34+
return (
35+
<div className="task-form-field">
36+
<Grid.Column widthXS={Columns.Six}>
37+
<Form.Element
38+
label={taskScheduleType === TaskSchedule.interval ? 'Every' : 'Cron'}
39+
required={true}
40+
className="task-form-labels"
41+
>
42+
<div className="schedule-tooltip interval">
43+
<QuestionMarkTooltip
44+
diameter={15}
45+
color={ComponentColor.Primary}
46+
tooltipContents={tooltipContents[taskScheduleType]}
47+
/>
48+
</div>
49+
<Input
50+
name={taskScheduleType}
51+
type={InputType.Text}
52+
value={taskScheduleType === TaskSchedule.interval ? interval : cron}
53+
placeholder={
54+
taskScheduleType === TaskSchedule.interval ? '3h30s' : '02***'
55+
}
56+
onChange={updateInput}
57+
testID="task-form-every-input"
58+
/>
59+
</Form.Element>
60+
</Grid.Column>
61+
<Grid.Column widthXS={Columns.Six}>
62+
<Form.Element
63+
label="Offset"
64+
required={true}
65+
className="task-form-labels"
66+
>
67+
<div className="schedule-tooltip offset">
68+
<QuestionMarkTooltip
69+
diameter={15}
70+
color={ComponentColor.Primary}
71+
tooltipContents={tooltipContents['offset']}
72+
/>
73+
</div>
74+
<Input
75+
name="offset"
76+
type={InputType.Text}
77+
value={offset}
78+
placeholder="20m"
79+
onChange={updateInput}
80+
testID="task-form-offset-input"
81+
/>
82+
</Form.Element>
83+
</Grid.Column>
84+
</div>
85+
)
86+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.cf-form--footer {
2+
position: relative;
3+
margin-top: 20%;
4+
justify-content: end;
5+
}
6+
7+
.cf-page-contents__fluid {
8+
position: absolute;
9+
}
10+
11+
.create-task-titles {
12+
font-size: 20px;
13+
font-weight: bold;
14+
opacity: 0.9;
15+
}
16+
17+
.cf-form--footer > * {
18+
margin: 0px;
19+
}
20+
21+
.schedule-task,
22+
.name-task,
23+
.select-script {
24+
margin-top: 35px;
25+
}
26+
27+
.schedule-task p {
28+
margin-top: 5px;
29+
}
30+
31+
.task-name-input,
32+
.script-dropdown,
33+
.task-form-field {
34+
margin-top: 15px;
35+
}
36+
37+
.task-form-labels {
38+
position: relative;
39+
}
40+
41+
.schedule-tooltip {
42+
position: absolute;
43+
}
44+
45+
.interval {
46+
left: 51px;
47+
}
48+
49+
.offset {
50+
left: 55px;
51+
}
52+
53+
.cf-input-field:focus,
54+
.cf-input-field:hover {
55+
background-color: rgb(0, 0, 0);
56+
}
57+
58+
.cf-form--label-text {
59+
font-weight: 600;
60+
font-size: 15px;
61+
}

0 commit comments

Comments
 (0)