Skip to content
Snippets Groups Projects
Commit e0028f4e authored by Christina Jenks's avatar Christina Jenks
Browse files

Merge branch 'CE-2105-replace-useUndeployInDb' into 'develop'

CE-2105: convert useUndeployInDb to common

See merge request !366
parents 515f18b8 ca92fc2e
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!366CE-2105: convert useUndeployInDb to common
Pipeline #160937 passed
...@@ -520,20 +520,6 @@ export function unpackUpdateIoc(updateIoc) { ...@@ -520,20 +520,6 @@ export function unpackUpdateIoc(updateIoc) {
return d; return d;
} }
export function unpackUndeployInDb(deployment) {
return { ...deployment };
}
export function useUndeployInDb(id, onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
api.apis.Deployments.unDeployInDb,
unpackUndeployInDb
);
const boundMethod = useCallback(method.bind(null, { ioc_id: id }), [id]);
return useAsync({ fcn: boundMethod, call: false, onError: onError });
}
export function unpackUpdateActiveDeploymentHost(ioc) { export function unpackUpdateActiveDeploymentHost(ioc) {
return { ...ioc }; return { ...ioc };
} }
......
import React, { useState, useEffect, useCallback } from "react"; import React, {
useState,
useEffect,
useCallback,
useContext,
useMemo
} from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Button, Typography, Grid, Tooltip } from "@mui/material"; import {
import { useUndeployInDb } from "../../../api/SwaggerApi"; Button,
Typography,
Grid,
Tooltip,
LinearProgress
} from "@mui/material";
import { SimpleAccordion, ConfirmationDialog } from "@ess-ics/ce-ui-common"; import { SimpleAccordion, ConfirmationDialog } from "@ess-ics/ce-ui-common";
import Alert from "@mui/material/Alert"; import Alert from "@mui/material/Alert";
import AccessControl from "../../auth/AccessControl"; import AccessControl from "../../auth/AccessControl";
import { IocActiveDeployment } from "../../../api/DataTypes"; import { IocActiveDeployment } from "../../../api/DataTypes";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common/dist/hooks/API";
export default function AdministerUndeployment({ ioc, buttonDisabled }) { export default function AdministerUndeployment({ ioc, buttonDisabled }) {
const navigate = useNavigate(); const navigate = useNavigate();
function onError(message) {
setError(message);
}
// for the dialog // for the dialog
const [error, setError] = useState(); const [error, setError] = useState();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [response, undeployIOC] = useUndeployInDb(ioc.id, onError); const client = useContext(apiContext);
const params = useMemo(
() => ({
ioc_id: ioc?.id
}),
[ioc]
);
const {
value: response,
wrapper: undeployIOC,
loading,
error: errorResponse
} = useAPIMethod({
fcn: client.apis.IOCs.unDeployInDb,
call: false,
params
});
useEffect(() => {
setError(errorResponse?.message);
}, [errorResponse]);
const onClose = useCallback(() => { const onClose = useCallback(() => {
setOpen(false); setOpen(false);
...@@ -30,22 +61,22 @@ export default function AdministerUndeployment({ ioc, buttonDisabled }) { ...@@ -30,22 +61,22 @@ export default function AdministerUndeployment({ ioc, buttonDisabled }) {
useEffect(() => { useEffect(() => {
if (response) { if (response) {
setOpen(false);
navigate(-1); navigate(-1);
} }
}, [response, navigate]); }, [response, navigate]);
const failedDeployment = new IocActiveDeployment( const hasDeployment = new IocActiveDeployment(
ioc.activeDeployment ioc.activeDeployment
).failedDeployment(); ).hasDeployment();
let disabledButtonTitle = ""; let disabledButtonTitle = "";
if (buttonDisabled || ioc.operationInProgress) { if (buttonDisabled || ioc.operationInProgress) {
disabledButtonTitle = disabledButtonTitle =
"There is an ongoing operation, you cannot 'undeploy' the IOC right now"; "There is an ongoing operation, you cannot 'undeploy' the IOC right now";
} else { } else {
if (!failedDeployment) { if (!hasDeployment) {
disabledButtonTitle = disabledButtonTitle = "IOC is not deployed";
"IOC doesn't have failed (un)deployment, you cannot 'undeploy' it";
} }
} }
...@@ -70,6 +101,7 @@ export default function AdministerUndeployment({ ioc, buttonDisabled }) { ...@@ -70,6 +101,7 @@ export default function AdministerUndeployment({ ioc, buttonDisabled }) {
</Typography>{" "} </Typography>{" "}
? ?
</Typography> </Typography>
{loading ? <LinearProgress /> : null}
</> </>
} }
confirmText="Undeploy IOC" confirmText="Undeploy IOC"
...@@ -108,7 +140,8 @@ export default function AdministerUndeployment({ ioc, buttonDisabled }) { ...@@ -108,7 +140,8 @@ export default function AdministerUndeployment({ ioc, buttonDisabled }) {
disabled={ disabled={
buttonDisabled || buttonDisabled ||
ioc.operationInProgress || ioc.operationInProgress ||
!failedDeployment !hasDeployment ||
loading
} }
color="error" color="error"
variant="contained" variant="contained"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment