diff --git a/src/components/IOC/DeployIOC/DeployIOC.jsx b/src/components/IOC/DeployIOC/DeployIOC.jsx index 0fdafd258de779b9f20ec345b23e672b47623e3e..8b8f50f015b019923a1db1775579a70f67f2bccc 100644 --- a/src/components/IOC/DeployIOC/DeployIOC.jsx +++ b/src/components/IOC/DeployIOC/DeployIOC.jsx @@ -1,52 +1,38 @@ -import { useContext, useState, useEffect } from "react"; +import { useState, useEffect } from "react"; import { Navigate } from "react-router-dom"; -import { useAPIMethod } from "@ess-ics/ce-ui-common"; import { IOCDeployDialog } from "../IOCDeployDialog"; -import { apiContext } from "../../../api/DeployApi"; -import { getErrorMessage } from "../../common/Helper"; +import { useStartJobMutation } from "../../../store/deployApi"; -// Process component export function DeployIOC({ open, setOpen, submitCallback, - iocId, + ioc, hasActiveDeployment, - deployIocFormDefaults = {}, - buttonDisabled, - setButtonDisabled + deployIocFormDefaults = {} }) { - const [error, setError] = useState(); - const client = useContext(apiContext); - const { - value: deployment, - wrapper: action, - error: deployError - } = useAPIMethod({ - fcn: client.apis.Jobs.startJob, - call: false - }); + const [error, setError] = useState(null); + const [deploy, { data: deployment, error: deployError, isLoading }] = + useStartJobMutation(); useEffect(() => { if (deployError) { - setButtonDisabled(false); - setError(getErrorMessage(deployError)); + setError(deployError); } - }, [deployError, setButtonDisabled]); + }, [deployError]); if (!deployment) { return ( <IOCDeployDialog open={open} setOpen={setOpen} - iocId={iocId} - submitCallback={action} + iocId={ioc.id} + submitCallback={deploy} deployIocFormDefaults={deployIocFormDefaults} hasActiveDeployment={hasActiveDeployment} error={error} resetError={() => setError(null)} - buttonDisabled={buttonDisabled} - setButtonDisabled={setButtonDisabled} + buttonDisabled={ioc.operationInProgress || isLoading} /> ); } else { diff --git a/src/components/IOC/IOCDeployDialog/IOCDeployDialog.tsx b/src/components/IOC/IOCDeployDialog/IOCDeployDialog.tsx index 3e01e168559b2dc2c699a0e617f2057bb1696490..e010c963fccc3f79f1bcf0cd65b71cb20e6bf91f 100644 --- a/src/components/IOC/IOCDeployDialog/IOCDeployDialog.tsx +++ b/src/components/IOC/IOCDeployDialog/IOCDeployDialog.tsx @@ -12,7 +12,6 @@ import { Typography, CircularProgress, Autocomplete, - Alert, Stack } from "@mui/material"; import { Dialog, GitRefAutocomplete } from "@ess-ics/ce-ui-common"; @@ -23,7 +22,8 @@ import { useLazyListTagsAndCommitIdsQuery } from "../../../store/deployApi"; import { getErrorMessage } from "../../common/Helper"; -import { FormElements } from "../../../types/common"; +import { ApiError } from "../../../types/common"; +import { ApiAlertError } from "../../common/Alerts/ApiAlertError"; interface DeployIocFormDefaults { name: string; @@ -42,13 +42,12 @@ interface IOCDeployDialogProps { open: boolean; setOpen: (open: boolean) => void; iocId: string; - submitCallback: (arg0: object, arg1: object) => void; + submitCallback: (arg: object) => void; hasActiveDeployment: boolean; deployIocFormDefaults: DeployIocFormDefaults; - error: string; + error: ApiError; resetError: () => void; buttonDisabled: boolean; - setButtonDisabled: (buttonDisabled: boolean) => void; } type SearchMethodConstants = "EQUALS" | "CONTAINS"; @@ -62,8 +61,7 @@ export function IOCDeployDialog({ deployIocFormDefaults, error, resetError, - buttonDisabled, - setButtonDisabled + buttonDisabled }: IOCDeployDialogProps) { const [getHosts, { data: hosts, isFetching: loadingHosts }] = useLazyListHostsQuery(); @@ -124,24 +122,15 @@ export function IOCDeployDialog({ const onSubmit = (event: FormEvent<HTMLFormElement>) => { event.preventDefault(); - setButtonDisabled(true); - const { git: gitText } = event.currentTarget - .elements as FormElements<"git">; - const git = gitText.value; - submitCallback( - { - ioc_id: iocId - }, - { - requestBody: { - sourceUrl: git, - sourceVersion: revision, - hostId: host.hostId, - type: "DEPLOY" - } + submitCallback({ + iocId: iocId, + createJobRequest: { + sourceVersion: revision, + hostId: host.hostId, + type: "DEPLOY" } - ); + }); }; return ( @@ -252,7 +241,7 @@ export function IOCDeployDialog({ <></> )} - {error ? <Alert severity="error">{error}</Alert> : <></>} + {error && <ApiAlertError error={error} />} <Stack flexDirection="row" justifyContent="flex-end" diff --git a/src/components/IOC/IOCManage/IOCManage.jsx b/src/components/IOC/IOCManage/IOCManage.jsx index 446f3a043e6bd0cce137ea9df83d12be4a617ed9..5a4a8bfc8006ec905b992ad05fa04d05851453f1 100644 --- a/src/components/IOC/IOCManage/IOCManage.jsx +++ b/src/components/IOC/IOCManage/IOCManage.jsx @@ -18,7 +18,6 @@ import env from "../../../config/env"; export function IOCManage({ ioc, - getIOC, buttonDisabled, currentCommand, getJobs, @@ -50,7 +49,6 @@ export function IOCManage({ const closeDeployModal = () => { setDeployDialogOpen(false); - getIOC(); }; const closeUndeployModal = () => { @@ -211,7 +209,7 @@ export function IOCManage({ setOpen={setDeployDialogOpen} submitCallback={closeDeployModal} deployIocFormDefaults={deployIocFormDefaults} - iocId={ioc.id} + ioc={ioc} hasActiveDeployment={Boolean(ioc.activeDeployment)} buttonDisabled={buttonDisabled} setButtonDisabled={setButtonDisabled} diff --git a/src/views/IOC/IOCDetailsView.jsx b/src/views/IOC/IOCDetailsView.jsx index 4ff34f23133e4d20f63b2dd6bc8ca572a1e4a26f..695b8472c2b05d198b0a14c7bb469e6a21dd40fe 100644 --- a/src/views/IOC/IOCDetailsView.jsx +++ b/src/views/IOC/IOCDetailsView.jsx @@ -113,7 +113,6 @@ export function IOCDetailsView({ ioc, getIOC, abortGetIOC, loading }) { content: ( <IOCManage ioc={ioc} - getIOC={getIOC} buttonDisabled={buttonDisabled} currentCommand={ ongoingCommand?.jobs?.length > 0 ? ongoingCommand.jobs[0] : null