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

Merge branch 'CE-2066-convert-useCreateIoc' into 'develop'

CE-2066: replace useCreateIoc with common api

See merge request !348
parents 374b4101 47b311b9
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!348CE-2066: replace useCreateIoc with common api
Pipeline #160130 passed
...@@ -218,15 +218,6 @@ export function unpackIOCList(iocs) { ...@@ -218,15 +218,6 @@ export function unpackIOCList(iocs) {
return unpackedIOCList; return unpackedIOCList;
} }
export function useCreateIOC(onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(body) => api.apis.IOCs.createIoc({}, { requestBody: body }),
unpackIOC
);
return useAsync({ fcn: method, call: false, onError: onError });
}
export function unpackDeployment(deployment) { export function unpackDeployment(deployment) {
const d = { ...deployment }; const d = { ...deployment };
return d; return d;
......
import React, { useEffect, useState } from "react"; import React, { useEffect, useState, useContext } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { import { useAllowedGitProjects, useNamingNames } from "../../../api/SwaggerApi";
useAllowedGitProjects,
useCreateIOC,
useNamingNames
} from "../../../api/SwaggerApi";
import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer"; import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer";
import { RootPaper } from "@ess-ics/ce-ui-common/dist/components/common/container/RootPaper"; import { RootPaper } from "@ess-ics/ce-ui-common/dist/components/common/container/RootPaper";
import { import {
...@@ -17,6 +13,20 @@ import { ...@@ -17,6 +13,20 @@ import {
TextField, TextField,
Typography Typography
} from "@mui/material"; } from "@mui/material";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { apiContext } from "../../../api/DeployApi";
const renderErrorMessage = (error) => {
const { response, status: requestStatus, message: requestMessage } = error;
const {
body: { description },
status: httpStatus
} = response;
return `${httpStatus ?? requestStatus ?? "unknown"}: ${
description ?? requestMessage ?? "An unknown error has occurred"
}`;
};
export function CreateIOC() { export function CreateIOC() {
const navigate = useNavigate(); const navigate = useNavigate();
...@@ -30,11 +40,17 @@ export function CreateIOC() { ...@@ -30,11 +40,17 @@ export function CreateIOC() {
, ,
loadingAllowedGitProjects loadingAllowedGitProjects
] = useAllowedGitProjects([]); ] = useAllowedGitProjects([]);
const [error, setError] = useState();
const onError = (error) => { const client = useContext(apiContext);
setError(error); const {
}; value: ioc,
const [ioc, createIoc, , loading] = useCreateIOC(onError); wrapper: createIoc,
loading,
error
} = useAPIMethod({
fcn: client.apis.IOCs.createIoc,
call: false
});
// Return home on cancel // Return home on cancel
const handleCancel = () => { const handleCancel = () => {
...@@ -53,10 +69,15 @@ export function CreateIOC() { ...@@ -53,10 +69,15 @@ export function CreateIOC() {
// create the ioc on form submit // create the ioc on form submit
const onSubmit = (event) => { const onSubmit = (event) => {
event.preventDefault(); event.preventDefault();
createIoc({ createIoc(
gitProjectId: gitId, {},
namingUuid: name ? name.uuid : undefined {
}); requestBody: {
gitProjectId: gitId,
namingUuid: name ? name.uuid : undefined
}
}
);
}; };
// navigate home once ioc created // navigate home once ioc created
...@@ -113,7 +134,6 @@ export function CreateIOC() { ...@@ -113,7 +134,6 @@ export function CreateIOC() {
)} )}
onChange={(event, value, reason) => { onChange={(event, value, reason) => {
setName(value); setName(value);
setError(null);
}} }}
onInputChange={(event, value, reason) => { onInputChange={(event, value, reason) => {
event && onNameKeyUp(event.nativeEvent); event && onNameKeyUp(event.nativeEvent);
...@@ -136,7 +156,6 @@ export function CreateIOC() { ...@@ -136,7 +156,6 @@ export function CreateIOC() {
}} }}
onChange={(event, value, reason) => { onChange={(event, value, reason) => {
setGitId(value?.id); setGitId(value?.id);
setError(null);
}} }}
renderInput={(params) => ( renderInput={(params) => (
<TextField <TextField
...@@ -164,8 +183,11 @@ export function CreateIOC() { ...@@ -164,8 +183,11 @@ export function CreateIOC() {
)} )}
autoSelect autoSelect
/> />
{error ? (
{error ? <Alert severity="error">{error}</Alert> : <></>} <Alert severity="error">{renderErrorMessage(error)}</Alert>
) : (
<></>
)}
<Stack <Stack
direction="row" direction="row"
justifyContent="flex-end" justifyContent="flex-end"
......
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