diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index ecc874924496c42fa42e036e16606bfca90c65d4..dc90c28b85f4813178077574e91c6814db9145ec 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -344,107 +344,24 @@ export function unpackDeployment(deployment) { return d; } -export function unpackDeploymentList(deployments) { - let deploymentArr = deployments.operations.map((d) => unpackDeployment(d)); - - let unpackedDeploymentList = { - totalCount: deployments.totalCount, - pageNumber: deployments.pageNumber, - limit: deployments.limit, - operationsList: deploymentArr - }; - - return unpackedDeploymentList; -} - -export function useDeploymentListForIOC() { - const api = useContext(apiContext); - const method = useCallAndUnpack( - (iocId, page, limit) => - api.apis.Deployments.listDeployments({ - ioc_id: iocId, - page: page, - limit: limit - }), - unpackOperationsList - ); - return useAsync({ - fcn: method, - call: false, - init: emptyOperationsListResponse - }); -} - -export function unpackCommand(command) { - const c = { ...command }; - return c; -} - -export function unpackCommandList(commandList) { - let commandArr = commandList.commands.map((c) => unpackCommand(c)); - - let unpackedCommandList = { - totalCount: commandList.totalCount, - pageNumber: commandList.pageNumber, - limit: commandList.limit, - commandList: commandArr - }; - - return unpackedCommandList; -} - -export function unpackAllCommandList(input) { - const { commands: operationsList, ...rest } = input; +export function unpackOngoingOperations(input) { + const { operations: operationsList, ...rest } = input; const output = { ...rest, operationsList }; - return output; -} - -export function useCommandList() { - const api = useContext(apiContext); - const method = useCallAndUnpack( - (iocId, deploymentId, page, limit) => - api.apis.Deployments.listCommands({ - ioc_id: iocId, - deployment_id: deploymentId, - page: page, - limit: limit - }), - unpackAllCommandList - ); - return useAsync({ - fcn: method, - call: false, - init: emptyOperationsListResponse - }); -} - -export function unpackOngoingCommand(command) { - if (command) { - return { ...command }; - } - return null; + 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 }); -} - -export function useDeploymentSearch() { - const api = useContext(apiContext); - const method = useCallAndUnpack( - (params) => api.apis.Deployments.listDeployments(params), - unpackDeploymentList + const boundMethod = useCallback( + method.bind(null, { ioc_id: iocId, type: "COMMAND", status: "ONGOING" }), + [iocId] ); return useAsync({ - fcn: method, + fcn: boundMethod, call: false, init: emptyOperationsListResponse }); @@ -515,15 +432,6 @@ export function useDeploymentById() { return useAsync({ fcn: method, call: false, init: null }); } -export function useCommandById() { - const api = useContext(apiContext); - const method = useCallAndUnpack( - (commandId) => api.apis.Deployments.fetchCommand({ command_id: commandId }), - unpackCommand - ); - return useAsync({ fcn: method, call: false, init: null }); -} - export function unpackJob(job) { return { ...job }; } diff --git a/src/components/common/notification/Storage.js b/src/components/common/notification/Storage.js index 8cb4884b6746343cd38506cef7b63ded2524f9d9..6395a95af0b42f6506db45ef60909380e4626448 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/components/common/notification/Watchers.js b/src/components/common/notification/Watchers.js index c9767b768594dfcf5cfa930fa547ef7eefd3c690..902427b4d92c7bd7867827ae120fe3d81c2350aa 100644 --- a/src/components/common/notification/Watchers.js +++ b/src/components/common/notification/Watchers.js @@ -1,7 +1,7 @@ import { useCallback, useEffect, useMemo } from "react"; import { AdHocCommand, DeploymentStatus } from "../../../api/DataTypes"; import { - useCommandById, + useOperation, useDeployment, useJobById } from "../../../api/SwaggerApi"; @@ -65,7 +65,7 @@ export function DeploymentWatcher({ } export function CommandWatcher({ commandId, addNotification, stopWatching }) { - const [command, getCommand /* reset*/, , loading] = useCommandById(); + const [command, getCommand /* reset*/, , loading] = useOperation(commandId); const poll = useCallback( () => getCommand(commandId), [commandId, getCommand] diff --git a/src/views/IOC/IOCDetailsView.js b/src/views/IOC/IOCDetailsView.js index 7561f4fdd06881c2df3a7bb62c5fe487196d76d0..eae883e030caec2a32db0ce76ab9dbfdf1bda11b 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(() => {