Skip to content

Commit

Permalink
Add the ability to run a task manually
Browse files Browse the repository at this point in the history
Co-authoerd-by: Delmer Reed <[email protected]>
  • Loading branch information
Palakp41 committed Feb 15, 2019
1 parent 12292a4 commit 9ded305
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ui/src/organizations/components/OrgTasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
importScript,
addTaskLabelsAsync,
removeTaskLabelsAsync,
runTask,
} from 'src/tasks/actions/v2'

// Types
Expand All @@ -51,6 +52,7 @@ interface ConnectedDispatchProps {
importScript: typeof importScript
onAddTaskLabels: typeof addTaskLabelsAsync
onRemoveTaskLabels: typeof removeTaskLabelsAsync
onRunTask: typeof runTask
}

interface ConnectedStateProps {
Expand Down Expand Up @@ -89,6 +91,7 @@ class OrgTasksPage extends PureComponent<Props, State> {
searchTerm,
onAddTaskLabels,
onRemoveTaskLabels,
onRunTask,
} = this.props

return (
Expand Down Expand Up @@ -129,6 +132,7 @@ class OrgTasksPage extends PureComponent<Props, State> {
onAddTaskLabels={onAddTaskLabels}
onRemoveTaskLabels={onRemoveTaskLabels}
onUpdate={this.handleUpdateTask}
onRunTask={onRunTask}
/>
)}
</FilterList>
Expand Down Expand Up @@ -245,6 +249,7 @@ const mdtp: ConnectedDispatchProps = {
importScript,
onRemoveTaskLabels: removeTaskLabelsAsync,
onAddTaskLabels: addTaskLabelsAsync,
onRunTask: runTask,
}

export default connect<
Expand Down
6 changes: 6 additions & 0 deletions ui/src/shared/copy/v2/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export const taskImportSuccess = (fileName: string): Notification => ({
message: `Successfully imported file ${fileName}.`,
})

export const taskRunSuccess = (): Notification => ({
...defaultSuccessNotification,
duration: FIVE_SECONDS,
message: 'Task ran successfully',
})

export const getTelegrafConfigFailed = (): Notification => ({
...defaultErrorNotification,
message: 'Failed to get telegraf config',
Expand Down
10 changes: 10 additions & 0 deletions ui/src/tasks/actions/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
taskDeleteSuccess,
taskCloneSuccess,
taskCloneFailed,
taskRunSuccess,
} from 'src/shared/copy/v2/notifications'

// Types
Expand Down Expand Up @@ -482,3 +483,12 @@ export const getRuns = async (taskID: string): Promise<Run[]> => {
const runs = await client.tasks.getRunsByTaskID(taskID)
return runs
}

export const runTask = (taskID: string) => async dispatch => {
try {
await client.tasks.startRunByTaskID(taskID)
dispatch(notify(taskRunSuccess()))
} catch (e) {
console.error(e)
}
}
1 change: 1 addition & 0 deletions ui/src/tasks/components/TaskRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const setup = (override = {}) => {
onClone: jest.fn(),
onSelect: jest.fn(),
onEditLabels: jest.fn(),
onRunTask: jest.fn(),
...override,
}

Expand Down
11 changes: 11 additions & 0 deletions ui/src/tasks/components/TaskRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface Props {
onSelect: (task: Task) => void
onClone: (task: Task) => void
onEditLabels: (task: Task) => void
onRunTask: (taskID: string) => void
onUpdate?: (task: Task) => void
}

Expand Down Expand Up @@ -89,6 +90,12 @@ export class TaskRow extends PureComponent<Props & WithRouterProps> {
icon={IconFont.Duplicate}
onClick={this.handleClone}
/>
<Button
size={ComponentSize.ExtraSmall}
color={ComponentColor.Primary}
text="RunTask"
onClick={this.handleRunTask}
/>
<ConfirmationButton
size={ComponentSize.ExtraSmall}
text="Delete"
Expand Down Expand Up @@ -125,6 +132,10 @@ export class TaskRow extends PureComponent<Props & WithRouterProps> {
)
}

private handleRunTask = () => {
this.props.onRunTask(this.props.task.id)
}

// private handleViewRuns = () => {
// const {router, task} = this.props
// router.push(`tasks/${task.id}/runs`)
Expand Down
17 changes: 15 additions & 2 deletions ui/src/tasks/components/TasksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ interface Task extends TaskAPI {
}

import {Sort} from 'src/clockface'
import {addTaskLabelsAsync, removeTaskLabelsAsync} from 'src/tasks/actions/v2'
import {
addTaskLabelsAsync,
removeTaskLabelsAsync,
runTask,
} from 'src/tasks/actions/v2'

interface Props {
tasks: Task[]
Expand All @@ -32,6 +36,7 @@ interface Props {
totalCount: number
onRemoveTaskLabels: typeof removeTaskLabelsAsync
onAddTaskLabels: typeof addTaskLabelsAsync
onRunTask: typeof runTask
onUpdate?: (task: Task) => void
}

Expand Down Expand Up @@ -131,7 +136,14 @@ export default class TasksList extends PureComponent<Props, State> {
}

private rows = (tasks: Task[]): JSX.Element => {
const {onActivate, onDelete, onSelect, onClone, onUpdate} = this.props
const {
onActivate,
onDelete,
onSelect,
onClone,
onUpdate,
onRunTask,
} = this.props
const taskrows = (
<>
{tasks.map(t => (
Expand All @@ -144,6 +156,7 @@ export default class TasksList extends PureComponent<Props, State> {
onSelect={onSelect}
onEditLabels={this.handleStartEditingLabels}
onUpdate={onUpdate}
onRunTask={onRunTask}
/>
))}
</>
Expand Down
10 changes: 10 additions & 0 deletions ui/src/tasks/components/__snapshots__/TaskRow.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ exports[`Tasks.Components.TaskRow renders 1`] = `
text="Clone"
type="button"
/>
<t
active={false}
color="primary"
onClick={[Function]}
shape="none"
size="xs"
status="default"
text="RunTask"
type="button"
/>
<ConfirmationButton
confirmText="Confirm"
onConfirm={[MockFunction]}
Expand Down
5 changes: 5 additions & 0 deletions ui/src/tasks/containers/TasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
importScript,
addTaskLabelsAsync,
removeTaskLabelsAsync,
runTask,
} from 'src/tasks/actions/v2'

// Constants
Expand Down Expand Up @@ -55,6 +56,7 @@ interface ConnectedDispatchProps {
importScript: typeof importScript
onAddTaskLabels: typeof addTaskLabelsAsync
onRemoveTaskLabels: typeof removeTaskLabelsAsync
onRunTask: typeof runTask
}

interface ConnectedStateProps {
Expand Down Expand Up @@ -97,6 +99,7 @@ class TasksPage extends PureComponent<Props, State> {
showInactive,
onAddTaskLabels,
onRemoveTaskLabels,
onRunTask,
} = this.props

return (
Expand All @@ -122,6 +125,7 @@ class TasksPage extends PureComponent<Props, State> {
onSelect={this.props.selectTask}
onAddTaskLabels={onAddTaskLabels}
onRemoveTaskLabels={onRemoveTaskLabels}
onRunTask={onRunTask}
/>
{this.hiddenTaskAlert}
</div>
Expand Down Expand Up @@ -249,6 +253,7 @@ const mdtp: ConnectedDispatchProps = {
importScript,
onRemoveTaskLabels: removeTaskLabelsAsync,
onAddTaskLabels: addTaskLabelsAsync,
onRunTask: runTask,
}

export default connect<
Expand Down

0 comments on commit 9ded305

Please sign in to comment.