Skip to content
Snippets Groups Projects
Commit 38b338c6 authored by cjenkscybercom's avatar cjenkscybercom
Browse files

CE-2074: convert useUpdateAndDeployIoc and useCreateUndeployment to common

parent 74b9abc0
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 #160819 passed
...@@ -21,7 +21,19 @@ export const apiContext = createContext(null); ...@@ -21,7 +21,19 @@ export const apiContext = createContext(null);
const apiOptions = { const apiOptions = {
url: `${window.API_BASE_ENDPOINT}`, 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 }) { export function DeployAPIProvider({ children }) {
......
...@@ -258,26 +258,6 @@ export function useJobLogById() { ...@@ -258,26 +258,6 @@ export function useJobLogById() {
return useAsync({ fcn: method, call: false, init: null }); 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) { export function unpackHost(host) {
return { ...host }; return { ...host };
} }
......
import React, { useContext, useState } from "react"; import React, { useContext, useState, useEffect } from "react";
import { Navigate } from "react-router-dom"; import { Navigate } from "react-router-dom";
import { IOCDeployDialog } from "../IOCDeployDialog"; import { IOCDeployDialog } from "../IOCDeployDialog";
import { notificationContext } from "../../common/notification/Notifications"; import { notificationContext } from "../../common/notification/Notifications";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
// Process component // Process component
export function DeployIOC({ export function DeployIOC({
open, open,
setOpen, setOpen,
submitCallback, submitCallback,
hook, iocId,
hasActiveDeployment, hasActiveDeployment,
init = {} init = {}
}) { }) {
function onError(message) {
setError(message);
}
const [deployment, action] = hook(onError);
const [error, setError] = useState(); 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); const { watchDeployment } = useContext(notificationContext);
if (!deployment) { if (!deployment) {
...@@ -25,6 +38,7 @@ export function DeployIOC({ ...@@ -25,6 +38,7 @@ export function DeployIOC({
<IOCDeployDialog <IOCDeployDialog
open={open} open={open}
setOpen={setOpen} setOpen={setOpen}
iocId={iocId}
submitCallback={action} submitCallback={action}
init={init} init={init}
hasActiveDeployment={hasActiveDeployment} hasActiveDeployment={hasActiveDeployment}
......
...@@ -19,6 +19,7 @@ import { formatDate, transformHostQuery } from "../../common/Helper"; ...@@ -19,6 +19,7 @@ import { formatDate, transformHostQuery } from "../../common/Helper";
export function IOCDeployDialog({ export function IOCDeployDialog({
open, open,
setOpen, setOpen,
iocId,
submitCallback, submitCallback,
hasActiveDeployment, hasActiveDeployment,
init = {}, init = {},
...@@ -58,15 +59,22 @@ export function IOCDeployDialog({ ...@@ -58,15 +59,22 @@ export function IOCDeployDialog({
const { git: gitText } = event.currentTarget.elements; const { git: gitText } = event.currentTarget.elements;
const git = gitText.value; const git = gitText.value;
submitCallback({ submitCallback(
sourceUrl: git, {
sourceVersion: gitVersion, ioc_id: iocId
hostCSEntryId: host },
? Number(host.csEntryHost.id) {
: init.csEntryHost requestBody: {
? init.csEntryHost.id sourceUrl: git,
: undefined 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 // Creates, and formats tags/commitIds with dates into a table-format for using it in autocomplete
......
...@@ -9,10 +9,6 @@ import React, { ...@@ -9,10 +9,6 @@ import React, {
import { IOCDetails } from "../IOCDetails"; import { IOCDetails } from "../IOCDetails";
import { DeployIOC } from "../DeployIOC"; import { DeployIOC } from "../DeployIOC";
import { UndeployIOC } from "../UndeployIOC"; import { UndeployIOC } from "../UndeployIOC";
import {
useUpdateAndDeployIoc,
useCreateUndeployment
} from "../../../api/SwaggerApi";
import { import {
userContext, userContext,
SimpleAccordion, SimpleAccordion,
...@@ -247,7 +243,7 @@ export function IOCManage({ ...@@ -247,7 +243,7 @@ export function IOCManage({
setOpen={setDeployDialogOpen} setOpen={setDeployDialogOpen}
submitCallback={closeDeployModal} submitCallback={closeDeployModal}
init={formInit} init={formInit}
hook={useUpdateAndDeployIoc.bind(null, ioc.id)} iocId={ioc.id}
hasActiveDeployment={ioc.activeDeployment} hasActiveDeployment={ioc.activeDeployment}
/> />
<UndeployIOC <UndeployIOC
...@@ -255,7 +251,6 @@ export function IOCManage({ ...@@ -255,7 +251,6 @@ export function IOCManage({
setOpen={setUndeployDialogOpen} setOpen={setUndeployDialogOpen}
submitCallback={closeUndeployModal} submitCallback={closeUndeployModal}
ioc={ioc} ioc={ioc}
hook={useCreateUndeployment.bind(null, ioc.id)}
/> />
</AccessControl> </AccessControl>
</> </>
......
...@@ -23,7 +23,9 @@ export function IOCUndeployDialog({ ...@@ -23,7 +23,9 @@ export function IOCUndeployDialog({
const onSubmit = (event) => { const onSubmit = (event) => {
event.preventDefault(); event.preventDefault();
submitCallback(); submitCallback({
ioc_id: ioc.id
});
}; };
return ( return (
......
import React, { useContext, useState } from "react"; import React, { useContext, useState, useEffect } from "react";
import { Navigate } from "react-router-dom"; import { Navigate } from "react-router-dom";
import { IOCUndeployDialog } from "../IOCUndeployDialog"; import { IOCUndeployDialog } from "../IOCUndeployDialog";
import { notificationContext } from "../../common/notification/Notifications"; import { notificationContext } from "../../common/notification/Notifications";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
// Process component // Process component
export function UndeployIOC({ open, setOpen, submitCallback, hook, ioc }) { export function UndeployIOC({ open, setOpen, submitCallback, ioc }) {
function onError(message) {
setError(message);
}
const [deployment, action] = hook(onError);
const [error, setError] = useState(); 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); const { watchDeployment } = useContext(notificationContext);
if (!deployment) { 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