diff --git a/src/reducer/TermItReducers.ts b/src/reducer/TermItReducers.ts index 6c51b0cc..baebede5 100644 --- a/src/reducer/TermItReducers.ts +++ b/src/reducer/TermItReducers.ts @@ -41,10 +41,7 @@ import VocabularyUtils, { IRIImpl } from "../util/VocabularyUtils"; import TermOccurrence from "../model/TermOccurrence"; import { Breadcrumb } from "../model/Breadcrumb"; import AnnotatorLegendFilter from "../model/AnnotatorLegendFilter"; -import { - LongRunningTask, - LongRunningTaskState, -} from "../model/LongRunningTask"; +import { LongRunningTask } from "../model/LongRunningTask"; function isAsyncSuccess(action: AsyncAction) { return action.status === AsyncActionStatus.SUCCESS; @@ -707,20 +704,14 @@ function accessLevels( } function runningTasks( - state: { [key: string]: LongRunningTask } = {}, - action: AsyncActionSuccess + state: { [uuid: string]: LongRunningTask } = {}, + action: AsyncActionSuccess<{ [uuid: string]: LongRunningTask }> ) { if (action.type === ActionType.LONG_RUNNING_TASKS_UPDATE) { if (!action.payload) { return {}; } - const newState = Object.assign({}, state, { - [action.payload.uuid]: action.payload, - }); - if (action.payload.state === LongRunningTaskState.DONE) { - delete newState[action.payload.uuid]; - } - return newState; + return Object.assign({}, action.payload); } return state; } diff --git a/src/reducer/WebSocketUtilityDispatchers.ts b/src/reducer/WebSocketUtilityDispatchers.ts index 1792ae9f..cf96e65c 100644 --- a/src/reducer/WebSocketUtilityDispatchers.ts +++ b/src/reducer/WebSocketUtilityDispatchers.ts @@ -1,11 +1,7 @@ import { IMessage } from "react-stomp-hooks"; import { Action } from "redux"; import { ThunkDispatch } from "../util/Types"; -import { - LongRunningTask, - LongRunningTaskState, -} from "../model/LongRunningTask"; -import { isNumber, isString } from "lodash"; +import { LongRunningTask } from "../model/LongRunningTask"; import { asyncActionSuccess, asyncActionSuccessWithPayload, @@ -18,28 +14,20 @@ export function updateLongRunningTasks(message: IMessage, action: Action) { return; } - const task: LongRunningTask = JSON.parse(message.body); + const tasks: { [uuid: string]: LongRunningTask } = JSON.parse(message.body); - if ( - !( - task && - task.state && - isString(task.uuid) && - isString(task.name) && - LongRunningTaskState[task.state] && - (isNumber(task.startedAt) || !task.startedAt) - ) || - task.name.trim() === "" - ) { - return; - } - - if (task.startedAt) { - task.startedAt = new Date(task.startedAt * 1000); - } + const mapped = Object.keys(tasks).map((uuid) => { + const task = tasks[uuid]; + if (task.startedAt) { + // @ts-ignore + task.startedAt = new Date(task.startedAt * 1000); + task.startedAt.setMilliseconds(0); // round to second + } - task.name = "longrunningtasks.name." + task.name; + task.name = "longrunningtasks.name." + task.name; + return task; + }); - dispatch(asyncActionSuccessWithPayload(action, task)); + dispatch(asyncActionSuccessWithPayload(action, mapped)); }; }