From 274f79f401690cb7af3798ba98663fc4f5ce1b64 Mon Sep 17 00:00:00 2001 From: Palak Bhojani Date: Mon, 25 Feb 2019 11:34:02 -0800 Subject: [PATCH] Update tasks runs to use the api instead of dummy data --- ui/src/tasks/actions/v2/index.ts | 24 +++++- ui/src/tasks/components/TaskRow.tsx | 14 ++-- ui/src/tasks/components/TaskRunsList.tsx | 15 +++- ui/src/tasks/components/TaskRunsPage.tsx | 83 ++++++++++++++++--- ui/src/tasks/components/TaskRunsRow.tsx | 8 +- .../__snapshots__/TaskRow.test.tsx.snap | 24 +++--- ui/src/tasks/reducers/v2/index.ts | 7 +- 7 files changed, 136 insertions(+), 39 deletions(-) diff --git a/ui/src/tasks/actions/v2/index.ts b/ui/src/tasks/actions/v2/index.ts index 8bfd97d1b2..0da13a0368 100644 --- a/ui/src/tasks/actions/v2/index.ts +++ b/ui/src/tasks/actions/v2/index.ts @@ -50,6 +50,7 @@ export type Action = | SetAllTaskOptions | AddTaskLabels | RemoveTaskLabels + | SetRuns type GetStateFunc = () => AppState interface Task extends TaskAPI { @@ -148,6 +149,13 @@ export interface RemoveTaskLabels { } } +export interface SetRuns { + type: 'SET_RUNS' + payload: { + runs: Run[] + } +} + export const setTaskOption = (taskOption: { key: TaskOptionKeys value: string @@ -200,6 +208,11 @@ export const setDropdownOrgID = (dropdownOrgID: string): SetDropdownOrgID => ({ payload: {dropdownOrgID}, }) +export const setRuns = (runs: Run[]): SetRuns => ({ + type: 'SET_RUNS', + payload: {runs}, +}) + const addTaskLabels = (taskID: string, labels: Label[]): AddTaskLabels => ({ type: 'ADD_TASK_LABELS', payload: { @@ -468,9 +481,14 @@ export const getErrorMessage = (e: any) => { return message } -export const getRuns = async (taskID: string): Promise => { - const runs = await client.tasks.getRunsByTaskID(taskID) - return runs +export const getRuns = (taskID: string) => async (dispatch): Promise => { + try { + const runs = await client.tasks.getRunsByTaskID(taskID) + + dispatch(setRuns(runs)) + } catch (error) { + console.error(error) + } } export const runTask = (taskID: string) => async dispatch => { diff --git a/ui/src/tasks/components/TaskRow.tsx b/ui/src/tasks/components/TaskRow.tsx index 62a52ca858..0fffbe3279 100644 --- a/ui/src/tasks/components/TaskRow.tsx +++ b/ui/src/tasks/components/TaskRow.tsx @@ -70,14 +70,12 @@ export class TaskRow extends PureComponent { {task.latestCompleted} - -