Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[Fleet] Fix add fleet server host from advanced tab (elastic#145622)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Nov 18, 2022
1 parent beeea7d commit 904fc21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useComboInput,
useInput,
useSwitchInput,
validateInputs,
} from '../../../hooks';
import type { FleetServerHost } from '../../../types';

Expand Down Expand Up @@ -44,11 +45,17 @@ export const useFleetServerHost = (): FleetServerHostForm => {
const isDefaultInput = useSwitchInput(false, isPreconfigured || fleetServerHost?.is_default);
const hostUrlsInput = useComboInput('hostUrls', [], validateFleetServerHosts, isPreconfigured);

const validate = useCallback(
() => hostUrlsInput.validate() && nameInput.validate(),
[hostUrlsInput, nameInput]
const inputs = useMemo(
() => ({
nameInput,
isDefaultInput,
hostUrlsInput,
}),
[nameInput, isDefaultInput, hostUrlsInput]
);

const validate = useCallback(() => validateInputs(inputs), [inputs]);

const { data, resendRequest: refreshGetFleetServerHosts } = useGetFleetServerHosts();

const fleetServerHosts = useMemo(() => data?.items ?? [], [data?.items]);
Expand Down Expand Up @@ -97,10 +104,6 @@ export const useFleetServerHost = (): FleetServerHostForm => {
isFleetServerHostSubmitted,
setFleetServerHost,
validate,
inputs: {
hostUrlsInput,
nameInput,
isDefaultInput,
},
inputs,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export const AddFleetServerHostStepContent = ({
id: 'fleet-server-host',
is_preconfigured: false,
};
setFleetServerHost(newFleetServerHost);

if (validate()) {
setSubmittedFleetServerHost(newFleetServerHost);
setFleetServerHost(await saveFleetServerHost(newFleetServerHost));
setSubmittedFleetServerHost(newFleetServerHost);
}
} catch (err) {
notifications.toasts.addError(err, {
Expand Down

0 comments on commit 904fc21

Please sign in to comment.