From 93f0acfb389afa796b22eed7fbf004a78136f4c0 Mon Sep 17 00:00:00 2001 From: Palak Bhojani Date: Fri, 15 Feb 2019 14:11:53 -0800 Subject: [PATCH] Add the ability to run a task manually Co-authoerd-by: Delmer Reed --- CHANGELOG.md | 1 + .../organizations/components/OrgTasksPage.tsx | 5 +++++ ui/src/shared/copy/v2/notifications.ts | 6 ++++++ ui/src/tasks/actions/v2/index.ts | 10 ++++++++++ ui/src/tasks/components/TaskRow.test.tsx | 1 + ui/src/tasks/components/TaskRow.tsx | 11 +++++++++++ ui/src/tasks/components/TasksList.tsx | 17 +++++++++++++++-- .../__snapshots__/TaskRow.test.tsx.snap | 10 ++++++++++ ui/src/tasks/containers/TasksPage.tsx | 5 +++++ 9 files changed, 64 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ab675f753..a38cafbb384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v2.0.0-alpha.4 [unreleased] ### Features +1. [11954](https://github.com/influxdata/influxdb/pull/11954): Add the ability to run a task manually from tasks page ### Bug Fixes diff --git a/ui/src/organizations/components/OrgTasksPage.tsx b/ui/src/organizations/components/OrgTasksPage.tsx index 765963e2048..8a6ce98268c 100644 --- a/ui/src/organizations/components/OrgTasksPage.tsx +++ b/ui/src/organizations/components/OrgTasksPage.tsx @@ -25,6 +25,7 @@ import { importScript, addTaskLabelsAsync, removeTaskLabelsAsync, + runTask, } from 'src/tasks/actions/v2' // Types @@ -51,6 +52,7 @@ interface ConnectedDispatchProps { importScript: typeof importScript onAddTaskLabels: typeof addTaskLabelsAsync onRemoveTaskLabels: typeof removeTaskLabelsAsync + onRunTask: typeof runTask } interface ConnectedStateProps { @@ -89,6 +91,7 @@ class OrgTasksPage extends PureComponent { searchTerm, onAddTaskLabels, onRemoveTaskLabels, + onRunTask, } = this.props return ( @@ -129,6 +132,7 @@ class OrgTasksPage extends PureComponent { onAddTaskLabels={onAddTaskLabels} onRemoveTaskLabels={onRemoveTaskLabels} onUpdate={this.handleUpdateTask} + onRunTask={onRunTask} /> )} @@ -245,6 +249,7 @@ const mdtp: ConnectedDispatchProps = { importScript, onRemoveTaskLabels: removeTaskLabelsAsync, onAddTaskLabels: addTaskLabelsAsync, + onRunTask: runTask, } export default connect< diff --git a/ui/src/shared/copy/v2/notifications.ts b/ui/src/shared/copy/v2/notifications.ts index 9df991708af..f7c4f879f69 100644 --- a/ui/src/shared/copy/v2/notifications.ts +++ b/ui/src/shared/copy/v2/notifications.ts @@ -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', diff --git a/ui/src/tasks/actions/v2/index.ts b/ui/src/tasks/actions/v2/index.ts index 9d498b02bce..62578d87b1a 100644 --- a/ui/src/tasks/actions/v2/index.ts +++ b/ui/src/tasks/actions/v2/index.ts @@ -19,6 +19,7 @@ import { taskDeleteSuccess, taskCloneSuccess, taskCloneFailed, + taskRunSuccess, } from 'src/shared/copy/v2/notifications' // Types @@ -482,3 +483,12 @@ export const getRuns = async (taskID: string): Promise => { 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) + } +} diff --git a/ui/src/tasks/components/TaskRow.test.tsx b/ui/src/tasks/components/TaskRow.test.tsx index 920ade56034..a1433283618 100644 --- a/ui/src/tasks/components/TaskRow.test.tsx +++ b/ui/src/tasks/components/TaskRow.test.tsx @@ -20,6 +20,7 @@ const setup = (override = {}) => { onClone: jest.fn(), onSelect: jest.fn(), onEditLabels: jest.fn(), + onRunTask: jest.fn(), ...override, } diff --git a/ui/src/tasks/components/TaskRow.tsx b/ui/src/tasks/components/TaskRow.tsx index 23f29e99413..e41dfeee657 100644 --- a/ui/src/tasks/components/TaskRow.tsx +++ b/ui/src/tasks/components/TaskRow.tsx @@ -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 } @@ -89,6 +90,12 @@ export class TaskRow extends PureComponent { icon={IconFont.Duplicate} onClick={this.handleClone} /> +