From 7e9ed7c6f964a1e4dc039989e1b0eccc7e520efd Mon Sep 17 00:00:00 2001 From: Zoltan Runyo <zoltan.runyo@ess.eu> Date: Tue, 21 Feb 2023 10:20:27 +0100 Subject: [PATCH] ICSHWI-11790: Get ongoing command using 'Operation list' endpoint --- src/api/SwaggerApi.js | 26 +++++++++++-------- src/components/common/notification/Storage.js | 18 +++++++------ src/views/IOC/IOCDetailsView.js | 4 +-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index 4b37f919..dc90c28b 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -344,23 +344,27 @@ export function unpackDeployment(deployment) { return d; } -export function unpackOngoingCommand(command) { - if (command) { - return { ...command }; - } - return null; +export function unpackOngoingOperations(input) { + const { operations: operationsList, ...rest } = input; + const output = { ...rest, operationsList }; + return output.totalCount > 0 ? output.operationsList[0] : null; } export function useOngoingCommand(iocId) { const api = useContext(apiContext); const method = useCallAndUnpack( - api.apis.Deployments.ongoingCommandByIoc, - unpackOngoingCommand + api.apis.Deployments.listOperations, + unpackOngoingOperations ); - const boundMethod = useCallback(method.bind(null, { ioc_id: iocId }), [ - iocId - ]); - return useAsync({ fcn: boundMethod, call: false }); + const boundMethod = useCallback( + method.bind(null, { ioc_id: iocId, type: "COMMAND", status: "ONGOING" }), + [iocId] + ); + return useAsync({ + fcn: boundMethod, + call: false, + init: emptyOperationsListResponse + }); } const emptyOperationsListResponse = { diff --git a/src/components/common/notification/Storage.js b/src/components/common/notification/Storage.js index 8cb4884b..6395a95a 100644 --- a/src/components/common/notification/Storage.js +++ b/src/components/common/notification/Storage.js @@ -8,15 +8,17 @@ export const TYPE_COMMAND = "command"; function watchId(watchedId, storageKey) { let watchedIds = JSON.parse(localStorage.getItem(storageKey)); - if (watchedIds) { - if (!watchedIds.includes(watchedId)) { - localStorage.setItem( - storageKey, - JSON.stringify([watchedId].concat(watchedIds)) - ); + if (watchedId) { + if (watchedIds) { + if (!watchedIds.includes(watchedId)) { + localStorage.setItem( + storageKey, + JSON.stringify([watchedId].concat(watchedIds)) + ); + } + } else { + localStorage.setItem(storageKey, JSON.stringify([watchedId])); } - } else { - localStorage.setItem(storageKey, JSON.stringify([watchedId])); } } diff --git a/src/views/IOC/IOCDetailsView.js b/src/views/IOC/IOCDetailsView.js index 7561f4fd..eae883e0 100644 --- a/src/views/IOC/IOCDetailsView.js +++ b/src/views/IOC/IOCDetailsView.js @@ -37,9 +37,9 @@ export function IOCDetailsView({ ioc, getIOC, loading }) { useOperationsSearch(); const [ ongoingCommand, - getOngoingCommand /* reset*/, + getOngoingCommand, , - ongoingCommandLoading + /* reset*/ ongoingCommandLoading ] = useOngoingCommand(ioc.id); const jobLazyParams = useCallback(() => { -- GitLab