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

Merge branch 'CE-2074-useCreateUndeployment' into 'develop'

CE-2074: convert useUpdateAndDeployIoc and useCreateUndeployment to common

See merge request !368
parents e0028f4e 38b338c6
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!368CE-2074: convert useUpdateAndDeployIoc and useCreateUndeployment to common
Pipeline #161024 passed
......@@ -21,7 +21,19 @@ export const apiContext = createContext(null);
const apiOptions = {
url: `${window.API_BASE_ENDPOINT}`,
server: `${window.SERVER_ADDRESS}`
server: `${window.SERVER_ADDRESS}`,
// Workaround for https://github.com/swagger-api/swagger-js/issues/1022
// Empty body POST requests are sent with Content-Type text/plaintext
// instead of no content type, or application/json
requestInterceptor: (req) => {
req.headers["Content-Type"] = "application/json";
req.headers.accept = "application/json";
window.req = req;
return req;
},
responseInterceptor: (res) => {
return res;
}
};
export function DeployAPIProvider({ children }) {
......
......@@ -241,26 +241,6 @@ export function useJobLogById() {
return useAsync({ fcn: method, call: false, init: null });
}
export function useUpdateAndDeployIoc(id, onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(body) =>
api.apis.IOCs.updateAndDeployIoc({ ioc_id: id }, { requestBody: body }),
unpackDeployment
);
return useAsync({ fcn: method, call: false, onError: onError });
}
export function useCreateUndeployment(id, onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(body) =>
api.apis.IOCs.createUndeployment({ ioc_id: id }, { requestBody: body }),
unpackDeployment
);
return useAsync({ fcn: method, call: false, onError: onError });
}
export function unpackHost(host) {
return { ...host };
}
......
import React, { useContext, useState } from "react";
import React, { useContext, useState, useEffect } from "react";
import { Navigate } from "react-router-dom";
import { IOCDeployDialog } from "../IOCDeployDialog";
import { notificationContext } from "../../common/notification/Notifications";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
// Process component
export function DeployIOC({
open,
setOpen,
submitCallback,
hook,
iocId,
hasActiveDeployment,
init = {}
}) {
function onError(message) {
setError(message);
}
const [deployment, action] = hook(onError);
const [error, setError] = useState();
const client = useContext(apiContext);
const {
value: deployment,
wrapper: action,
error: deployError
} = useAPIMethod({
fcn: client.apis.IOCs.updateAndDeployIoc,
call: false
});
useEffect(() => {
if (deployError) {
setError(deployError?.message);
}
}, [deployError]);
const { watchDeployment } = useContext(notificationContext);
if (!deployment) {
......@@ -25,6 +38,7 @@ export function DeployIOC({
<IOCDeployDialog
open={open}
setOpen={setOpen}
iocId={iocId}
submitCallback={action}
init={init}
hasActiveDeployment={hasActiveDeployment}
......
......@@ -19,6 +19,7 @@ import { formatDate, transformHostQuery } from "../../common/Helper";
export function IOCDeployDialog({
open,
setOpen,
iocId,
submitCallback,
hasActiveDeployment,
init = {},
......@@ -58,15 +59,22 @@ export function IOCDeployDialog({
const { git: gitText } = event.currentTarget.elements;
const git = gitText.value;
submitCallback({
sourceUrl: git,
sourceVersion: gitVersion,
hostCSEntryId: host
? Number(host.csEntryHost.id)
: init.csEntryHost
? init.csEntryHost.id
: undefined
});
submitCallback(
{
ioc_id: iocId
},
{
requestBody: {
sourceUrl: git,
sourceVersion: gitVersion,
hostCSEntryId: host
? Number(host.csEntryHost.id)
: init.csEntryHost
? init.csEntryHost.id
: undefined
}
}
);
};
// Creates, and formats tags/commitIds with dates into a table-format for using it in autocomplete
......
......@@ -9,10 +9,6 @@ import React, {
import { IOCDetails } from "../IOCDetails";
import { DeployIOC } from "../DeployIOC";
import { UndeployIOC } from "../UndeployIOC";
import {
useUpdateAndDeployIoc,
useCreateUndeployment
} from "../../../api/SwaggerApi";
import {
userContext,
SimpleAccordion,
......@@ -247,7 +243,7 @@ export function IOCManage({
setOpen={setDeployDialogOpen}
submitCallback={closeDeployModal}
init={formInit}
hook={useUpdateAndDeployIoc.bind(null, ioc.id)}
iocId={ioc.id}
hasActiveDeployment={ioc.activeDeployment}
/>
<UndeployIOC
......@@ -255,7 +251,6 @@ export function IOCManage({
setOpen={setUndeployDialogOpen}
submitCallback={closeUndeployModal}
ioc={ioc}
hook={useCreateUndeployment.bind(null, ioc.id)}
/>
</AccessControl>
</>
......
......@@ -23,7 +23,9 @@ export function IOCUndeployDialog({
const onSubmit = (event) => {
event.preventDefault();
submitCallback();
submitCallback({
ioc_id: ioc.id
});
};
return (
......
import React, { useContext, useState } from "react";
import React, { useContext, useState, useEffect } from "react";
import { Navigate } from "react-router-dom";
import { IOCUndeployDialog } from "../IOCUndeployDialog";
import { notificationContext } from "../../common/notification/Notifications";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
// Process component
export function UndeployIOC({ open, setOpen, submitCallback, hook, ioc }) {
function onError(message) {
setError(message);
}
const [deployment, action] = hook(onError);
export function UndeployIOC({ open, setOpen, submitCallback, ioc }) {
const [error, setError] = useState();
const client = useContext(apiContext);
const {
value: deployment,
wrapper: action,
error: deploymentError
} = useAPIMethod({
fcn: client.apis.IOCs.createUndeployment,
call: false
});
useEffect(() => {
if (deploymentError) {
setError(deploymentError?.message);
}
}, [deploymentError]);
const { watchDeployment } = useContext(notificationContext);
if (!deployment) {
......
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