Skip to content
Snippets Groups Projects
Commit 930b8cb2 authored by Alexander Madsen's avatar Alexander Madsen
Browse files

Merge branch 'CE-2094-convert-useNamingNames' into 'develop'

CE-2094: Convert useNamingNames

See merge request !375
parents ae125d62 73e32bf3
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!375CE-2094: Convert useNamingNames
Pipeline #161448 passed
...@@ -301,24 +301,6 @@ export function useRenewToken() { ...@@ -301,24 +301,6 @@ export function useRenewToken() {
return [renewToken, loading]; return [renewToken, loading];
} }
export function unpackNaming(naming) {
return { ...naming };
}
export function unpackNamingList(naming) {
return naming.map((h) => unpackNaming(h));
}
export function useNamingNames() {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(iocName) => api.apis.Naming.fetchIOCByName({ ioc_name: iocName }),
unpackNamingList
);
return useAsync({ fcn: method, call: false, init: [] });
}
export function unpackGitReference(reference) { export function unpackGitReference(reference) {
return { ...reference }; return { ...reference };
} }
......
import React, { useEffect, useState, useContext } from "react"; import React, { useEffect, useState, useContext } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useAllowedGitProjects, useNamingNames } from "../../../api/SwaggerApi"; import { useAllowedGitProjects } 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 {
...@@ -30,7 +30,6 @@ const renderErrorMessage = (error) => { ...@@ -30,7 +30,6 @@ const renderErrorMessage = (error) => {
export function CreateIOC() { export function CreateIOC() {
const navigate = useNavigate(); const navigate = useNavigate();
const [names, getNames, , loadingNames] = useNamingNames();
const [name, setName] = useState(); const [name, setName] = useState();
const [gitId, setGitId] = useState(null); const [gitId, setGitId] = useState(null);
const [nameQuery, onNameKeyUp] = useTypingTimer({ interval: 500 }); const [nameQuery, onNameKeyUp] = useTypingTimer({ interval: 500 });
...@@ -52,13 +51,25 @@ export function CreateIOC() { ...@@ -52,13 +51,25 @@ export function CreateIOC() {
call: false call: false
}); });
const {
value: names,
wrapper: getNames,
loading: loadingNames,
dataReady
} = useAPIMethod({
fcn: client.apis.Naming.fetchIOCByName,
call: false
});
// Return home on cancel // Return home on cancel
const handleCancel = () => { const handleCancel = () => {
navigate("/"); navigate("/");
}; };
// fetch new names when name query changes // fetch new names when name query changes
useEffect(() => getNames(nameQuery), [nameQuery, getNames]); useEffect(() => {
getNames(nameQuery);
}, [nameQuery, getNames]);
// get the allowed git projects on initial load // get the allowed git projects on initial load
// TODO unnecessary! Update the hook... // TODO unnecessary! Update the hook...
...@@ -102,8 +113,8 @@ export function CreateIOC() { ...@@ -102,8 +113,8 @@ export function CreateIOC() {
<Autocomplete <Autocomplete
autoHighlight autoHighlight
id="nameAutocomplete" id="nameAutocomplete"
options={names} options={names ?? []}
loading={loadingNames} loading={loadingNames || !dataReady}
clearOnBlur={false} clearOnBlur={false}
getOptionLabel={(option) => { getOptionLabel={(option) => {
return option?.name; return option?.name;
...@@ -118,7 +129,7 @@ export function CreateIOC() { ...@@ -118,7 +129,7 @@ export function CreateIOC() {
...params.InputProps, ...params.InputProps,
endAdornment: ( endAdornment: (
<React.Fragment> <React.Fragment>
{loadingNames ? ( {loadingNames || !dataReady ? (
<CircularProgress <CircularProgress
color="inherit" color="inherit"
size={20} size={20}
......
import React, { useState, useEffect, useCallback } from "react"; import React, { useState, useEffect, useCallback, useContext } from "react";
import { SimpleAccordion, ConfirmationDialog } from "@ess-ics/ce-ui-common"; import {
SimpleAccordion,
ConfirmationDialog,
useAPIMethod
} from "@ess-ics/ce-ui-common";
import { import {
Button, Button,
CircularProgress, CircularProgress,
...@@ -9,13 +13,10 @@ import { ...@@ -9,13 +13,10 @@ import {
Autocomplete, Autocomplete,
Alert Alert
} from "@mui/material"; } from "@mui/material";
import { import { useAllowedGitProjects, useUpdateIoc } from "../../../api/SwaggerApi";
useAllowedGitProjects,
useNamingNames,
useUpdateIoc
} from "../../../api/SwaggerApi";
import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer"; import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer";
import AccessControl from "../../auth/AccessControl"; import AccessControl from "../../auth/AccessControl";
import { apiContext } from "../../../api/DeployApi";
export default function IOCDetailAdmin({ export default function IOCDetailAdmin({
ioc, ioc,
...@@ -31,7 +32,6 @@ export default function IOCDetailAdmin({ ...@@ -31,7 +32,6 @@ export default function IOCDetailAdmin({
loadingAllowedGitProjects loadingAllowedGitProjects
] = useAllowedGitProjects([]); ] = useAllowedGitProjects([]);
const [nameQuery, onNameKeyUp] = useTypingTimer({ interval: 500 }); const [nameQuery, onNameKeyUp] = useTypingTimer({ interval: 500 });
const [names, getNames, , loadingNames] = useNamingNames();
const [name, setName] = useState({ const [name, setName] = useState({
uuid: ioc.namingUuid, uuid: ioc.namingUuid,
description: ioc.description, description: ioc.description,
...@@ -46,6 +46,17 @@ export default function IOCDetailAdmin({ ...@@ -46,6 +46,17 @@ export default function IOCDetailAdmin({
setError(message); setError(message);
} }
const client = useContext(apiContext);
const {
value: names,
wrapper: getNames,
loading: loadingNames,
dataReady
} = useAPIMethod({
fcn: client.apis.Naming.fetchIOCByName,
call: false
});
const requiredDataMissing = useCallback(() => !gitId || !name, [gitId, name]); const requiredDataMissing = useCallback(() => !gitId || !name, [gitId, name]);
const noModification = useCallback( const noModification = useCallback(
...@@ -63,7 +74,9 @@ export default function IOCDetailAdmin({ ...@@ -63,7 +74,9 @@ export default function IOCDetailAdmin({
getAllowedGitProjects(); getAllowedGitProjects();
}, [getAllowedGitProjects]); }, [getAllowedGitProjects]);
useEffect(() => getNames(nameQuery), [nameQuery, getNames]); useEffect(() => {
getNames(nameQuery);
}, [nameQuery, getNames]);
// when user clicks Submit button a dialog should open // when user clicks Submit button a dialog should open
const onSubmit = (event) => { const onSubmit = (event) => {
...@@ -99,13 +112,13 @@ export default function IOCDetailAdmin({ ...@@ -99,13 +112,13 @@ export default function IOCDetailAdmin({
function nameAutocomplete(disabled) { function nameAutocomplete(disabled) {
const isDisabled = disabled || iocIsDeployed; const isDisabled = disabled || iocIsDeployed;
const loading = loadingNames && !isDisabled; const loading = (loadingNames || !dataReady) && !isDisabled;
return ( return (
<Tooltip title={nameDisabledTitle}> <Tooltip title={nameDisabledTitle}>
<Autocomplete <Autocomplete
autoHighlight autoHighlight
id="namingName" id="namingName"
options={names} options={names ?? []}
loading={loading} loading={loading}
clearOnBlur={false} clearOnBlur={false}
defaultValue={name} defaultValue={name}
......
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