From c98cc411b73c2f97f93b45331533b306560059fc Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Fri, 1 Apr 2022 15:34:10 -0700 Subject: [PATCH] (ui): Make list tasks action generic --- ui/src/actions/tasksActions.ts | 233 +++++--------- ui/src/reducers/groupsReducer.ts | 9 +- ui/src/reducers/queuesReducer.ts | 14 +- ui/src/reducers/tasksReducer.ts | 506 +++++++++++++++---------------- 4 files changed, 326 insertions(+), 436 deletions(-) diff --git a/ui/src/actions/tasksActions.ts b/ui/src/actions/tasksActions.ts index 51d771b..46d9ba5 100644 --- a/ui/src/actions/tasksActions.ts +++ b/ui/src/actions/tasksActions.ts @@ -68,27 +68,6 @@ import { toErrorString, toErrorStringWithHttpStatus } from "../utils"; export const GET_TASK_INFO_BEGIN = "GET_TASK_INFO_BEGIN"; export const GET_TASK_INFO_SUCCESS = "GET_TASK_INFO_SUCCESS"; export const GET_TASK_INFO_ERROR = "GET_TASK_INFO_ERROR"; -export const LIST_ACTIVE_TASKS_BEGIN = "LIST_ACTIVE_TASKS_BEGIN"; -export const LIST_ACTIVE_TASKS_SUCCESS = "LIST_ACTIVE_TASKS_SUCCESS"; -export const LIST_ACTIVE_TASKS_ERROR = "LIST_ACTIVE_TASKS_ERROR"; -export const LIST_PENDING_TASKS_BEGIN = "LIST_PENDING_TASKS_BEGIN"; -export const LIST_PENDING_TASKS_SUCCESS = "LIST_PENDING_TASKS_SUCCESS"; -export const LIST_PENDING_TASKS_ERROR = "LIST_PENDING_TASKS_ERROR"; -export const LIST_SCHEDULED_TASKS_BEGIN = "LIST_SCHEDULED_TASKS_BEGIN"; -export const LIST_SCHEDULED_TASKS_SUCCESS = "LIST_SCHEDULED_TASKS_SUCCESS"; -export const LIST_SCHEDULED_TASKS_ERROR = "LIST_SCHEDULED_TASKS_ERROR"; -export const LIST_RETRY_TASKS_BEGIN = "LIST_RETRY_TASKS_BEGIN"; -export const LIST_RETRY_TASKS_SUCCESS = "LIST_RETRY_TASKS_SUCCESS"; -export const LIST_RETRY_TASKS_ERROR = "LIST_RETRY_TASKS_ERROR"; -export const LIST_ARCHIVED_TASKS_BEGIN = "LIST_ARCHIVED_TASKS_BEGIN"; -export const LIST_ARCHIVED_TASKS_SUCCESS = "LIST_ARCHIVED_TASKS_SUCCESS"; -export const LIST_ARCHIVED_TASKS_ERROR = "LIST_ARCHIVED_TASKS_ERROR"; -export const LIST_COMPLETED_TASKS_BEGIN = "LIST_COMPLETED_TASKS_BEGIN"; -export const LIST_COMPLETED_TASKS_SUCCESS = "LIST_COMPLETED_TASKS_SUCCESS"; -export const LIST_COMPLETED_TASKS_ERROR = "LIST_COMPLETED_TASKS_ERROR"; -export const LIST_AGGREGATING_TASKS_BEGIN = "LIST_AGGREGATING_TASKS_BEGIN"; -export const LIST_AGGREGATING_TASKS_SUCCESS = "LIST_AGGREGATING_TASKS_SUCCESS"; -export const LIST_AGGREGATING_TASKS_ERROR = "LIST_AGGREGATING_TASKS_ERROR"; export const CANCEL_ACTIVE_TASK_BEGIN = "CANCEL_ACTIVE_TASK_BEGIN"; export const CANCEL_ACTIVE_TASK_SUCCESS = "CANCEL_ACTIVE_TASK_SUCCESS"; export const CANCEL_ACTIVE_TASK_ERROR = "CANCEL_ACTIVE_TASK_ERROR"; @@ -293,6 +272,10 @@ export const DELETE_ALL_AGGREGATING_TASKS_SUCCESS = export const DELETE_ALL_AGGREGATING_TASKS_ERROR = "DELETE_ALL_AGGREGATING_TASKS_ERROR"; +export const LIST_TASKS_BEGIN = "LIST_TASKS_BEGIN"; +export const LIST_TASKS_ERROR = "LIST_TASKS_ERROR"; +export const LIST_TASKS_SUCCESS = "LIST_TASKS_SUCCESS"; + interface GetTaskInfoBeginAction { type: typeof GET_TASK_INFO_BEGIN; } @@ -307,126 +290,50 @@ interface GetTaskInfoSuccessAction { payload: TaskInfo; } -interface ListActiveTasksBeginAction { - type: typeof LIST_ACTIVE_TASKS_BEGIN; +type TaskState = + | "active" + | "pending" + | "aggregating" + | "scheduled" + | "retry" + | "archived" + | "completed"; + +interface ListTasksBeginAction { + type: typeof LIST_TASKS_BEGIN; + taskState: TaskState; queue: string; } -interface ListActiveTasksSuccessAction { - type: typeof LIST_ACTIVE_TASKS_SUCCESS; - queue: string; - payload: ListTasksResponse; -} - -interface ListActiveTasksErrorAction { - type: typeof LIST_ACTIVE_TASKS_ERROR; +interface ListTasksErrorAction { + type: typeof LIST_TASKS_ERROR; + taskState: TaskState; queue: string; error: string; // error description } -interface ListPendingTasksBeginAction { - type: typeof LIST_PENDING_TASKS_BEGIN; - queue: string; -} - -interface ListPendingTasksSuccessAction { - type: typeof LIST_PENDING_TASKS_SUCCESS; +interface ListTasksSuccessAction { + type: typeof LIST_TASKS_SUCCESS; + taskState: TaskState; queue: string; payload: ListTasksResponse; } -interface ListPendingTasksErrorAction { - type: typeof LIST_PENDING_TASKS_ERROR; - queue: string; - error: string; // error description -} - -interface ListScheduledTasksBeginAction { - type: typeof LIST_SCHEDULED_TASKS_BEGIN; - queue: string; -} - -interface ListScheduledTasksSuccessAction { - type: typeof LIST_SCHEDULED_TASKS_SUCCESS; - queue: string; - payload: ListTasksResponse; -} - -interface ListScheduledTasksErrorAction { - type: typeof LIST_SCHEDULED_TASKS_ERROR; - queue: string; - error: string; // error description -} - -interface ListRetryTasksBeginAction { - type: typeof LIST_RETRY_TASKS_BEGIN; - queue: string; -} - -interface ListRetryTasksSuccessAction { - type: typeof LIST_RETRY_TASKS_SUCCESS; - queue: string; - payload: ListTasksResponse; -} - -interface ListRetryTasksErrorAction { - type: typeof LIST_RETRY_TASKS_ERROR; - queue: string; - error: string; // error description -} - -interface ListArchivedTasksBeginAction { - type: typeof LIST_ARCHIVED_TASKS_BEGIN; - queue: string; -} - -interface ListArchivedTasksSuccessAction { - type: typeof LIST_ARCHIVED_TASKS_SUCCESS; - queue: string; - payload: ListTasksResponse; -} - -interface ListArchivedTasksErrorAction { - type: typeof LIST_ARCHIVED_TASKS_ERROR; - queue: string; - error: string; // error description -} - -interface ListCompletedTasksBeginAction { - type: typeof LIST_COMPLETED_TASKS_BEGIN; - queue: string; -} - -interface ListCompletedTasksSuccessAction { - type: typeof LIST_COMPLETED_TASKS_SUCCESS; - queue: string; - payload: ListTasksResponse; -} - -interface ListCompletedTasksErrorAction { - type: typeof LIST_COMPLETED_TASKS_ERROR; - queue: string; - error: string; // error description -} - -interface ListAggregatingTasksBeginAction { - type: typeof LIST_AGGREGATING_TASKS_BEGIN; - queue: string; +export interface ListAggregatingTasksBeginAction extends ListTasksBeginAction { + taskState: "aggregating"; group: string; } -interface ListAggregatingTasksSuccessAction { - type: typeof LIST_AGGREGATING_TASKS_SUCCESS; - queue: string; +export interface ListAggregatingTasksSuccessAction + extends ListTasksSuccessAction { + taskState: "aggregating"; group: string; payload: ListAggregatingTasksResponse; } -interface ListAggregatingTasksErrorAction { - type: typeof LIST_AGGREGATING_TASKS_ERROR; - queue: string; +export interface ListAggregatingTasksErrorAction extends ListTasksErrorAction { + taskState: "aggregating"; group: string; - error: string; // error description } interface CancelActiveTaskBeginAction { @@ -1270,24 +1177,9 @@ export type TasksActionTypes = | GetTaskInfoBeginAction | GetTaskInfoErrorAction | GetTaskInfoSuccessAction - | ListActiveTasksBeginAction - | ListActiveTasksSuccessAction - | ListActiveTasksErrorAction - | ListPendingTasksBeginAction - | ListPendingTasksSuccessAction - | ListPendingTasksErrorAction - | ListScheduledTasksBeginAction - | ListScheduledTasksSuccessAction - | ListScheduledTasksErrorAction - | ListRetryTasksBeginAction - | ListRetryTasksSuccessAction - | ListRetryTasksErrorAction - | ListArchivedTasksBeginAction - | ListArchivedTasksSuccessAction - | ListArchivedTasksErrorAction - | ListCompletedTasksBeginAction - | ListCompletedTasksSuccessAction - | ListCompletedTasksErrorAction + | ListTasksBeginAction + | ListTasksErrorAction + | ListTasksSuccessAction | ListAggregatingTasksBeginAction | ListAggregatingTasksSuccessAction | ListAggregatingTasksErrorAction @@ -1451,11 +1343,12 @@ export function listActiveTasksAsync( pageOpts?: PaginationOptions ) { return async (dispatch: Dispatch) => { - dispatch({ type: LIST_ACTIVE_TASKS_BEGIN, queue: qname }); + dispatch({ type: LIST_TASKS_BEGIN, taskState: "active", queue: qname }); try { const response = await listActiveTasks(qname, pageOpts); dispatch({ - type: LIST_ACTIVE_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "active", queue: qname, payload: response, }); @@ -1465,7 +1358,8 @@ export function listActiveTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_ACTIVE_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "active", queue: qname, error: toErrorString(error), }); @@ -1478,11 +1372,12 @@ export function listPendingTasksAsync( pageOpts?: PaginationOptions ) { return async (dispatch: Dispatch) => { - dispatch({ type: LIST_PENDING_TASKS_BEGIN, queue: qname }); + dispatch({ type: LIST_TASKS_BEGIN, taskState: "pending", queue: qname }); try { const response = await listPendingTasks(qname, pageOpts); dispatch({ - type: LIST_PENDING_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "pending", queue: qname, payload: response, }); @@ -1492,7 +1387,8 @@ export function listPendingTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_PENDING_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "pending", queue: qname, error: toErrorString(error), }); @@ -1505,11 +1401,12 @@ export function listScheduledTasksAsync( pageOpts?: PaginationOptions ) { return async (dispatch: Dispatch) => { - dispatch({ type: LIST_SCHEDULED_TASKS_BEGIN, queue: qname }); + dispatch({ type: LIST_TASKS_BEGIN, taskState: "scheduled", queue: qname }); try { const response = await listScheduledTasks(qname, pageOpts); dispatch({ - type: LIST_SCHEDULED_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "scheduled", queue: qname, payload: response, }); @@ -1519,7 +1416,8 @@ export function listScheduledTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_SCHEDULED_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "scheduled", queue: qname, error: toErrorString(error), }); @@ -1532,11 +1430,12 @@ export function listRetryTasksAsync( pageOpts?: PaginationOptions ) { return async (dispatch: Dispatch) => { - dispatch({ type: LIST_RETRY_TASKS_BEGIN, queue: qname }); + dispatch({ type: LIST_TASKS_BEGIN, taskState: "retry", queue: qname }); try { const response = await listRetryTasks(qname, pageOpts); dispatch({ - type: LIST_RETRY_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "retry", queue: qname, payload: response, }); @@ -1546,7 +1445,8 @@ export function listRetryTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_RETRY_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "retry", queue: qname, error: toErrorString(error), }); @@ -1559,11 +1459,12 @@ export function listArchivedTasksAsync( pageOpts?: PaginationOptions ) { return async (dispatch: Dispatch) => { - dispatch({ type: LIST_ARCHIVED_TASKS_BEGIN, queue: qname }); + dispatch({ type: LIST_TASKS_BEGIN, taskState: "archived", queue: qname }); try { const response = await listArchivedTasks(qname, pageOpts); dispatch({ - type: LIST_ARCHIVED_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "archived", queue: qname, payload: response, }); @@ -1573,7 +1474,8 @@ export function listArchivedTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_ARCHIVED_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "archived", queue: qname, error: toErrorString(error), }); @@ -1587,10 +1489,15 @@ export function listCompletedTasksAsync( ) { return async (dispatch: Dispatch) => { try { - dispatch({ type: LIST_COMPLETED_TASKS_BEGIN, queue: qname }); + dispatch({ + type: LIST_TASKS_BEGIN, + taskState: "completed", + queue: qname, + }); const response = await listCompletedTasks(qname, pageOpts); dispatch({ - type: LIST_COMPLETED_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "completed", queue: qname, payload: response, }); @@ -1600,7 +1507,8 @@ export function listCompletedTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_COMPLETED_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "completed", queue: qname, error: toErrorString(error), }); @@ -1616,13 +1524,15 @@ export function listAggregatingTasksAsync( return async (dispatch: Dispatch) => { try { dispatch({ - type: LIST_AGGREGATING_TASKS_BEGIN, + type: LIST_TASKS_BEGIN, + taskState: "aggregating", queue: qname, group: gname, }); const response = await listAggregatingTasks(qname, gname, pageOpts); dispatch({ - type: LIST_AGGREGATING_TASKS_SUCCESS, + type: LIST_TASKS_SUCCESS, + taskState: "aggregating", queue: qname, group: gname, payload: response, @@ -1633,7 +1543,8 @@ export function listAggregatingTasksAsync( toErrorStringWithHttpStatus(error) ); dispatch({ - type: LIST_AGGREGATING_TASKS_ERROR, + type: LIST_TASKS_ERROR, + taskState: "aggregating", queue: qname, group: gname, error: toErrorString(error), diff --git a/ui/src/reducers/groupsReducer.ts b/ui/src/reducers/groupsReducer.ts index 417bb0b..e90ba68 100644 --- a/ui/src/reducers/groupsReducer.ts +++ b/ui/src/reducers/groupsReducer.ts @@ -5,7 +5,8 @@ import { LIST_GROUPS_SUCCESS, } from "../actions/groupsActions"; import { - LIST_AGGREGATING_TASKS_SUCCESS, + ListAggregatingTasksSuccessAction, + LIST_TASKS_SUCCESS, TasksActionTypes, } from "../actions/tasksActions"; import { GroupInfo } from "../api"; @@ -41,10 +42,12 @@ function groupsReducer( data: action.payload.groups, }; - case LIST_AGGREGATING_TASKS_SUCCESS: + case LIST_TASKS_SUCCESS: + if (action.taskState !== "aggregating") return state; + let act = action as ListAggregatingTasksSuccessAction; return { ...state, - data: action.payload.groups, + data: act.payload.groups, }; default: diff --git a/ui/src/reducers/queuesReducer.ts b/ui/src/reducers/queuesReducer.ts index ce71a07..def5d05 100644 --- a/ui/src/reducers/queuesReducer.ts +++ b/ui/src/reducers/queuesReducer.ts @@ -36,11 +36,6 @@ import { ARCHIVE_ALL_SCHEDULED_TASKS_SUCCESS, ARCHIVE_RETRY_TASK_SUCCESS, ARCHIVE_SCHEDULED_TASK_SUCCESS, - LIST_ACTIVE_TASKS_SUCCESS, - LIST_ARCHIVED_TASKS_SUCCESS, - LIST_PENDING_TASKS_SUCCESS, - LIST_RETRY_TASKS_SUCCESS, - LIST_SCHEDULED_TASKS_SUCCESS, RUN_ALL_ARCHIVED_TASKS_SUCCESS, RUN_ALL_RETRY_TASKS_SUCCESS, RUN_ALL_SCHEDULED_TASKS_SUCCESS, @@ -66,7 +61,7 @@ import { DELETE_AGGREGATING_TASK_SUCCESS, RUN_AGGREGATING_TASK_SUCCESS, ARCHIVE_AGGREGATING_TASK_SUCCESS, - LIST_AGGREGATING_TASKS_SUCCESS, + LIST_TASKS_SUCCESS, } from "../actions/tasksActions"; import { Queue } from "../api"; @@ -174,12 +169,7 @@ function queuesReducer( return { ...state, data: newData }; } - case LIST_ACTIVE_TASKS_SUCCESS: - case LIST_PENDING_TASKS_SUCCESS: - case LIST_AGGREGATING_TASKS_SUCCESS: - case LIST_SCHEDULED_TASKS_SUCCESS: - case LIST_RETRY_TASKS_SUCCESS: - case LIST_ARCHIVED_TASKS_SUCCESS: { + case LIST_TASKS_SUCCESS: { const newData = state.data .filter((queueInfo) => queueInfo.name !== action.queue) .concat({ diff --git a/ui/src/reducers/tasksReducer.ts b/ui/src/reducers/tasksReducer.ts index 801ad55..f31dd63 100644 --- a/ui/src/reducers/tasksReducer.ts +++ b/ui/src/reducers/tasksReducer.ts @@ -1,23 +1,5 @@ import { - LIST_ACTIVE_TASKS_BEGIN, - LIST_ACTIVE_TASKS_SUCCESS, - LIST_ACTIVE_TASKS_ERROR, TasksActionTypes, - LIST_PENDING_TASKS_BEGIN, - LIST_PENDING_TASKS_SUCCESS, - LIST_PENDING_TASKS_ERROR, - LIST_SCHEDULED_TASKS_BEGIN, - LIST_SCHEDULED_TASKS_SUCCESS, - LIST_SCHEDULED_TASKS_ERROR, - LIST_RETRY_TASKS_BEGIN, - LIST_RETRY_TASKS_SUCCESS, - LIST_RETRY_TASKS_ERROR, - LIST_ARCHIVED_TASKS_BEGIN, - LIST_ARCHIVED_TASKS_SUCCESS, - LIST_ARCHIVED_TASKS_ERROR, - LIST_COMPLETED_TASKS_BEGIN, - LIST_COMPLETED_TASKS_SUCCESS, - LIST_COMPLETED_TASKS_ERROR, CANCEL_ACTIVE_TASK_BEGIN, CANCEL_ACTIVE_TASK_SUCCESS, CANCEL_ACTIVE_TASK_ERROR, @@ -129,9 +111,6 @@ import { BATCH_DELETE_COMPLETED_TASKS_BEGIN, BATCH_DELETE_COMPLETED_TASKS_ERROR, BATCH_DELETE_COMPLETED_TASKS_SUCCESS, - LIST_AGGREGATING_TASKS_BEGIN, - LIST_AGGREGATING_TASKS_SUCCESS, - LIST_AGGREGATING_TASKS_ERROR, DELETE_ALL_AGGREGATING_TASKS_BEGIN, DELETE_ALL_AGGREGATING_TASKS_SUCCESS, DELETE_ALL_AGGREGATING_TASKS_ERROR, @@ -159,6 +138,12 @@ import { RUN_AGGREGATING_TASK_SUCCESS, ARCHIVE_AGGREGATING_TASK_SUCCESS, DELETE_AGGREGATING_TASK_SUCCESS, + LIST_TASKS_BEGIN, + LIST_TASKS_SUCCESS, + LIST_TASKS_ERROR, + ListAggregatingTasksBeginAction, + ListAggregatingTasksErrorAction, + ListAggregatingTasksSuccessAction, } from "../actions/tasksActions"; import { TaskInfo } from "../api"; @@ -326,247 +311,248 @@ function tasksReducer( }, }; - case LIST_ACTIVE_TASKS_BEGIN: - return { - ...state, - activeTasks: { - ...state.activeTasks, - loading: true, - }, - }; + case LIST_TASKS_BEGIN: + switch (action.taskState) { + case "active": + return { + ...state, + activeTasks: { + ...state.activeTasks, + loading: true, + }, + }; + case "pending": + return { + ...state, + pendingTasks: { + ...state.pendingTasks, + loading: true, + }, + }; + case "aggregating": { + let act = action as ListAggregatingTasksBeginAction; + return { + ...state, + aggregatingTasks: { + ...state.aggregatingTasks, + group: act.group, + loading: true, + }, + }; + } + case "scheduled": + return { + ...state, + scheduledTasks: { + ...state.scheduledTasks, + loading: true, + }, + }; + case "retry": + return { + ...state, + retryTasks: { + ...state.retryTasks, + loading: true, + }, + }; + case "archived": + return { + ...state, + archivedTasks: { + ...state.archivedTasks, + loading: true, + }, + }; + case "completed": + return { + ...state, + completedTasks: { + ...state.completedTasks, + loading: true, + }, + }; + default: + return state; + } - case LIST_ACTIVE_TASKS_SUCCESS: - return { - ...state, - activeTasks: { - ...state.activeTasks, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - canceling: false, - requestPending: false, - })), - }, - }; + case LIST_TASKS_ERROR: + switch (action.taskState) { + case "active": + return { + ...state, + activeTasks: { + ...state.activeTasks, + loading: false, + error: action.error, + data: [], + }, + }; + case "pending": + return { + ...state, + pendingTasks: { + ...state.pendingTasks, + loading: false, + error: action.error, + data: [], + }, + }; + case "aggregating": + let act = action as ListAggregatingTasksErrorAction; + return { + ...state, + aggregatingTasks: { + ...state.aggregatingTasks, + group: act.group, + loading: false, + error: action.error, + data: [], + }, + }; + case "scheduled": + return { + ...state, + scheduledTasks: { + ...state.scheduledTasks, + loading: false, + error: action.error, + data: [], + }, + }; + case "retry": + return { + ...state, + retryTasks: { + ...state.retryTasks, + loading: false, + error: action.error, + data: [], + }, + }; + case "archived": + return { + ...state, + archivedTasks: { + ...state.archivedTasks, + loading: false, + error: action.error, + data: [], + }, + }; + case "completed": + return { + ...state, + completedTasks: { + ...state.completedTasks, + loading: false, + error: action.error, + data: [], + }, + }; + default: + return state; + } - case LIST_ACTIVE_TASKS_ERROR: - return { - ...state, - activeTasks: { - ...state.activeTasks, - loading: false, - error: action.error, - data: [], - }, - }; - - case LIST_PENDING_TASKS_BEGIN: - return { - ...state, - pendingTasks: { - ...state.pendingTasks, - loading: true, - }, - }; - - case LIST_PENDING_TASKS_SUCCESS: - return { - ...state, - pendingTasks: { - ...state.pendingTasks, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - requestPending: false, - })), - }, - }; - - case LIST_PENDING_TASKS_ERROR: - return { - ...state, - pendingTasks: { - ...state.pendingTasks, - loading: false, - error: action.error, - data: [], - }, - }; - - case LIST_SCHEDULED_TASKS_BEGIN: - return { - ...state, - scheduledTasks: { - ...state.scheduledTasks, - loading: true, - }, - }; - - case LIST_SCHEDULED_TASKS_SUCCESS: - return { - ...state, - scheduledTasks: { - ...state.scheduledTasks, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - requestPending: false, - })), - }, - }; - - case LIST_SCHEDULED_TASKS_ERROR: - return { - ...state, - scheduledTasks: { - ...state.scheduledTasks, - loading: false, - error: action.error, - data: [], - }, - }; - - case LIST_RETRY_TASKS_BEGIN: - return { - ...state, - retryTasks: { - ...state.retryTasks, - loading: true, - }, - }; - - case LIST_RETRY_TASKS_SUCCESS: - return { - ...state, - retryTasks: { - ...state.retryTasks, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - requestPending: false, - })), - }, - }; - - case LIST_RETRY_TASKS_ERROR: - return { - ...state, - retryTasks: { - ...state.retryTasks, - loading: false, - error: action.error, - data: [], - }, - }; - - case LIST_ARCHIVED_TASKS_BEGIN: - return { - ...state, - archivedTasks: { - ...state.archivedTasks, - loading: true, - }, - }; - - case LIST_ARCHIVED_TASKS_SUCCESS: - return { - ...state, - archivedTasks: { - ...state.archivedTasks, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - requestPending: false, - })), - }, - }; - - case LIST_ARCHIVED_TASKS_ERROR: - return { - ...state, - archivedTasks: { - ...state.archivedTasks, - loading: false, - error: action.error, - data: [], - }, - }; - - case LIST_COMPLETED_TASKS_BEGIN: - return { - ...state, - completedTasks: { - ...state.completedTasks, - loading: true, - }, - }; - - case LIST_COMPLETED_TASKS_SUCCESS: - return { - ...state, - completedTasks: { - ...state.completedTasks, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - requestPending: false, - })), - }, - }; - - case LIST_COMPLETED_TASKS_ERROR: - return { - ...state, - completedTasks: { - ...state.completedTasks, - loading: false, - error: action.error, - data: [], - }, - }; - - case LIST_AGGREGATING_TASKS_BEGIN: - return { - ...state, - aggregatingTasks: { - ...state.aggregatingTasks, - group: action.group, - loading: true, - }, - }; - - case LIST_AGGREGATING_TASKS_SUCCESS: - return { - ...state, - aggregatingTasks: { - ...state.aggregatingTasks, - group: action.group, - loading: false, - error: "", - data: action.payload.tasks.map((task) => ({ - ...task, - requestPending: false, - })), - }, - }; - - case LIST_AGGREGATING_TASKS_ERROR: - return { - ...state, - aggregatingTasks: { - ...state.aggregatingTasks, - group: action.group, - loading: false, - error: action.error, - data: [], - }, - }; + case LIST_TASKS_SUCCESS: + switch (action.taskState) { + case "active": + return { + ...state, + activeTasks: { + ...state.activeTasks, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + canceling: false, + requestPending: false, + })), + }, + }; + case "pending": + return { + ...state, + pendingTasks: { + ...state.pendingTasks, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + requestPending: false, + })), + }, + }; + case "aggregating": + let act = action as ListAggregatingTasksSuccessAction; + return { + ...state, + aggregatingTasks: { + ...state.aggregatingTasks, + group: act.group, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + requestPending: false, + })), + }, + }; + case "scheduled": + return { + ...state, + scheduledTasks: { + ...state.scheduledTasks, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + requestPending: false, + })), + }, + }; + case "retry": + return { + ...state, + retryTasks: { + ...state.retryTasks, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + requestPending: false, + })), + }, + }; + case "archived": + return { + ...state, + archivedTasks: { + ...state.archivedTasks, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + requestPending: false, + })), + }, + }; + case "completed": + return { + ...state, + completedTasks: { + ...state.completedTasks, + loading: false, + error: "", + data: action.payload.tasks.map((task) => ({ + ...task, + requestPending: false, + })), + }, + }; + default: + return state; + } case DELETE_COMPLETED_TASK_BEGIN: return {