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

Merge branch 'CE-2102-convert-useAllowedGitProjects' into 'develop'

CE-2102: convert useAllowedGitProjects

See merge request !380
parents fe890536 de4dae11
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!380CE-2102: convert useAllowedGitProjects
Pipeline #161778 passed
...@@ -283,19 +283,6 @@ export function unpackGitProject(project) { ...@@ -283,19 +283,6 @@ export function unpackGitProject(project) {
return { ...project }; return { ...project };
} }
export function unpackAllowedGitProjects(projectList) {
return projectList.map((p) => unpackGitProject(p));
}
export function useAllowedGitProjects() {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(repoUrl) => api.apis.Git.listProjects(),
unpackAllowedGitProjects
);
return useAsync({ fcn: method, call: false, init: [] });
}
export function useUpdateIoc(id, onError) { export function useUpdateIoc(id, onError) {
const api = useContext(apiContext); const api = useContext(apiContext);
const method = useCallAndUnpack( const method = useCallAndUnpack(
......
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 } 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 {
...@@ -33,14 +32,19 @@ export function CreateIOC() { ...@@ -33,14 +32,19 @@ export function CreateIOC() {
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 });
const [
allowedGitProjects,
getAllowedGitProjects,
,
loadingAllowedGitProjects
] = useAllowedGitProjects([]);
const client = useContext(apiContext); const client = useContext(apiContext);
const {
value: allowedGitProjects,
wrapper: getAllowedGitProjects,
loading: loadingAllowedGitProjects,
dataReady: dataReadyAllowedGitProjects
} = useAPIMethod({
fcn: client.apis.Git.listProjects,
call: false
});
const { const {
value: ioc, value: ioc,
wrapper: createIoc, wrapper: createIoc,
...@@ -155,8 +159,8 @@ export function CreateIOC() { ...@@ -155,8 +159,8 @@ export function CreateIOC() {
<Autocomplete <Autocomplete
autoHighlight autoHighlight
id="gitId" id="gitId"
options={allowedGitProjects} options={allowedGitProjects ?? []}
loading={loadingAllowedGitProjects} loading={loadingAllowedGitProjects || !dataReadyAllowedGitProjects}
clearOnBlur={false} clearOnBlur={false}
defaultValue={{ defaultValue={{
id: null, id: null,
...@@ -179,7 +183,8 @@ export function CreateIOC() { ...@@ -179,7 +183,8 @@ export function CreateIOC() {
...params.InputProps, ...params.InputProps,
endAdornment: ( endAdornment: (
<React.Fragment> <React.Fragment>
{loadingAllowedGitProjects ? ( {loadingAllowedGitProjects ||
!dataReadyAllowedGitProjects ? (
<CircularProgress <CircularProgress
color="inherit" color="inherit"
size={20} size={20}
......
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
Autocomplete, Autocomplete,
Alert Alert
} from "@mui/material"; } from "@mui/material";
import { useAllowedGitProjects, useUpdateIoc } from "../../../api/SwaggerApi"; import { 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"; import { apiContext } from "../../../api/DeployApi";
...@@ -25,12 +25,7 @@ export default function IOCDetailAdmin({ ...@@ -25,12 +25,7 @@ export default function IOCDetailAdmin({
buttonDisabled buttonDisabled
}) { }) {
const [gitId, setGitId] = useState(ioc.gitProjectId); const [gitId, setGitId] = useState(ioc.gitProjectId);
const [
allowedGitProjects,
getAllowedGitProjects,
,
loadingAllowedGitProjects
] = useAllowedGitProjects([]);
const [nameQuery, onNameKeyUp] = useTypingTimer({ interval: 500 }); const [nameQuery, onNameKeyUp] = useTypingTimer({ interval: 500 });
const [name, setName] = useState({ const [name, setName] = useState({
uuid: ioc.namingUuid, uuid: ioc.namingUuid,
...@@ -47,6 +42,17 @@ export default function IOCDetailAdmin({ ...@@ -47,6 +42,17 @@ export default function IOCDetailAdmin({
} }
const client = useContext(apiContext); const client = useContext(apiContext);
const {
value: allowedGitProjects,
wrapper: getAllowedGitProjects,
loading: loadingAllowedGitProjects,
dataReady: dataReadyAllowedGitProjects
} = useAPIMethod({
fcn: client.apis.Git.listProjects,
call: false
});
const { const {
value: names, value: names,
wrapper: getNames, wrapper: getNames,
...@@ -163,12 +169,14 @@ export default function IOCDetailAdmin({ ...@@ -163,12 +169,14 @@ export default function IOCDetailAdmin({
function gitRepoAutocomplete(disabled) { function gitRepoAutocomplete(disabled) {
const isDisabled = disabled || iocIsDeployed; const isDisabled = disabled || iocIsDeployed;
const loading = loadingAllowedGitProjects && !isDisabled; const loading =
(loadingAllowedGitProjects || !dataReadyAllowedGitProjects) &&
!isDisabled;
return ( return (
<Autocomplete <Autocomplete
autoHighlight autoHighlight
id="gitId" id="gitId"
options={allowedGitProjects} options={allowedGitProjects ?? []}
loading={loading} loading={loading}
clearOnBlur={false} clearOnBlur={false}
defaultValue={{ defaultValue={{
......
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