Skip to content

Commit 9d10195

Browse files
committed
feat: set initial param values from autofill
1 parent 1d798ea commit 9d10195

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ export const CreateWorkspacePageViewExperimental: FC<
142142
},
143143
});
144144

145+
// On component mount, sends all initial parameter values to the websocket
146+
// (including defaults and autofilled from the url)
147+
// This ensures the backend has the complete initial state of the form,
148+
// which is vital for correctly rendering dynamic UI elements where parameter visibility
149+
// or options might depend on the initial values of other parameters.
150+
const hasInitializedWebsocket = useRef(false);
151+
useEffect(() => {
152+
if (hasInitializedWebsocket.current) return;
153+
154+
const formValues = form.values.rich_parameter_values;
155+
if (parameters.length > 0 && formValues && formValues.length > 0) {
156+
const initialParams: { [k: string]: string } = {};
157+
for (const param of formValues) {
158+
if (param.name && param.value) {
159+
initialParams[param.name] = param.value;
160+
}
161+
}
162+
if (Object.keys(initialParams).length > 0) {
163+
sendMessage(initialParams);
164+
hasInitializedWebsocket.current = true;
165+
}
166+
}
167+
}, [parameters, form.values.rich_parameter_values, sendMessage]);
168+
145169
const autofillByName = useMemo(
146170
() =>
147171
Object.fromEntries(

0 commit comments

Comments
 (0)