Fix health check form to properly sync test commands with form state

Co-authored-by: Siumauricio <[email protected]>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-31 09:14:40 +00:00
co-authored by Siumauricio
parent f450b13dc5
commit 9e8dacfe06
2 changed files with 16 additions and 13 deletions
@@ -31,7 +31,6 @@ interface HealthCheckFormProps {
export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => { export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [testCommands, setTestCommands] = useState<string[]>([]);
const queryMap = { const queryMap = {
postgres: () => postgres: () =>
@@ -72,6 +71,8 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
}, },
}); });
const testCommands = form.watch("Test") || [];
useEffect(() => { useEffect(() => {
if (data?.healthCheckSwarm) { if (data?.healthCheckSwarm) {
const hc = data.healthCheckSwarm; const hc = data.healthCheckSwarm;
@@ -82,7 +83,6 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
StartPeriod: hc.StartPeriod, StartPeriod: hc.StartPeriod,
Retries: hc.Retries, Retries: hc.Retries,
}); });
setTestCommands(hc.Test || []);
} }
}, [data, form]); }, [data, form]);
@@ -117,17 +117,20 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
}; };
const addTestCommand = () => { const addTestCommand = () => {
setTestCommands([...testCommands, ""]); form.setValue("Test", [...testCommands, ""]);
}; };
const updateTestCommand = (index: number, value: string) => { const updateTestCommand = (index: number, value: string) => {
const newCommands = [...testCommands]; const newCommands = [...testCommands];
newCommands[index] = value; newCommands[index] = value;
setTestCommands(newCommands); form.setValue("Test", newCommands);
}; };
const removeTestCommand = (index: number) => { const removeTestCommand = (index: number) => {
setTestCommands(testCommands.filter((_, i) => i !== index)); form.setValue(
"Test",
testCommands.filter((_, i) => i !== index),
);
}; };
return ( return (
@@ -1,10 +1,10 @@
export { HealthCheckForm } from "./health-check-form";
export { RestartPolicyForm } from "./restart-policy-form";
export { PlacementForm } from "./placement-form";
export { UpdateConfigForm } from "./update-config-form";
export { RollbackConfigForm } from "./rollback-config-form";
export { ModeForm } from "./mode-form";
export { LabelsForm } from "./labels-form";
export { StopGracePeriodForm } from "./stop-grace-period-form";
export { EndpointSpecForm } from "./endpoint-spec-form"; export { EndpointSpecForm } from "./endpoint-spec-form";
export { HealthCheckForm } from "./health-check-form";
export { LabelsForm } from "./labels-form";
export { ModeForm } from "./mode-form";
export { PlacementForm } from "./placement-form";
export { RestartPolicyForm } from "./restart-policy-form";
export { RollbackConfigForm } from "./rollback-config-form";
export { StopGracePeriodForm } from "./stop-grace-period-form";
export { UpdateConfigForm } from "./update-config-form";
export { filterEmptyValues, hasValues } from "./utils"; export { filterEmptyValues, hasValues } from "./utils";