Skip to content
Snippets Groups Projects
Commit 67ca81d8 authored by Max Frederiksen's avatar Max Frederiksen
Browse files

Reset host field, Fix bad loading behaviour, implement RTK Hooks

parent f726b0c1
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!543CE-3152: Reset host field, Fix bad loading behaviour, implement RTK Hooks
Pipeline #197644 passed
import { useCallback, useContext, useEffect, useState, useMemo } from "react"; import { useCallback, useEffect, useState, useMemo } from "react";
import { import {
Button, Button,
TextField, TextField,
...@@ -8,12 +8,11 @@ import { ...@@ -8,12 +8,11 @@ import {
Alert, Alert,
Stack Stack
} from "@mui/material"; } from "@mui/material";
import { apiContext } from "../../../api/DeployApi"; import { Dialog, GitRefAutocomplete } from "@ess-ics/ce-ui-common";
import { import {
useAPIMethod, useLazyListHostsQuery,
Dialog, useLazyListTagsAndCommitIdsQuery
GitRefAutocomplete } from "../../../store/deployApi";
} from "@ess-ics/ce-ui-common";
export function IOCDeployDialog({ export function IOCDeployDialog({
open, open,
...@@ -27,35 +26,23 @@ export function IOCDeployDialog({ ...@@ -27,35 +26,23 @@ export function IOCDeployDialog({
buttonDisabled, buttonDisabled,
setButtonDisabled setButtonDisabled
}) { }) {
const client = useContext(apiContext); const [getHosts, { data: hosts, isFetching: loadingHosts }] =
useLazyListHostsQuery();
const { const [
value: hosts, callGetTagOrCommitId,
wrapper: getHosts, {
loading: loadingHosts data: tagOrCommitId = [],
} = useAPIMethod({ isFetching: loadingTagsAndCommitIds,
fcn: client.apis.Hosts.listHosts, error: tagOrCommitIdError
call: false }
}); ] = useLazyListTagsAndCommitIdsQuery();
const {
value: tagOrCommitId,
wrapper: callGetTagOrCommitId,
loading: loadingTagsAndCommitIds,
error: tagOrCommitIdError
} = useAPIMethod({
fcn: client.apis.Git.listTagsAndCommitIds,
call: false,
init: []
});
const getTagOrCommitId = useCallback( const getTagOrCommitId = useCallback(
(gitProjectId, reference, includeAllReference, searchMethod) => { (gitProjectId, reference, searchMethod) => {
callGetTagOrCommitId({ callGetTagOrCommitId({
project_id: gitProjectId, projectId: gitProjectId,
reference: reference, reference,
include_all_reference: includeAllReference, searchMethod
search_method: searchMethod
}); });
}, },
[callGetTagOrCommitId] [callGetTagOrCommitId]
...@@ -74,20 +61,22 @@ export function IOCDeployDialog({ ...@@ -74,20 +61,22 @@ export function IOCDeployDialog({
const [gitRepo, setGitRepo] = useState(deployIocFormDefaults.git || ""); const [gitRepo, setGitRepo] = useState(deployIocFormDefaults.git || "");
const [revision, setRevision] = useState(deployIocFormDefaults); const [revision, setRevision] = useState(deployIocFormDefaults);
const gitProjectId = deployIocFormDefaults.gitProjectId; const gitProjectId = deployIocFormDefaults.gitProjectId;
const hasHostData = host?.id || host?.hostId || host?.fqdn;
const handleClose = () => { const handleClose = () => {
setOpen(false); setOpen(false);
setHost(null);
resetError(); resetError();
}; };
useEffect(() => { useEffect(() => {
if (query && query.length > 2) { if (!hasHostData && query && query.length > 2) {
getHosts({ text: `${query}` }); getHosts({ text: `${query}` });
} }
}, [query, getHosts]); }, [query, getHosts]);
useEffect(() => { useEffect(() => {
getTagOrCommitId(gitProjectId, "", false, "CONTAINS"); getTagOrCommitId(gitProjectId, "", "CONTAINS");
}, [gitProjectId, getTagOrCommitId]); }, [gitProjectId, getTagOrCommitId]);
const onSubmit = (event) => { const onSubmit = (event) => {
......
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