From f8f4dc6875414917b8b4c27125cc03c6727681e7 Mon Sep 17 00:00:00 2001 From: Jaayden Halko Date: Fri, 16 May 2025 18:40:59 +0100 Subject: [PATCH] feat: check for classic flow on the create workspace page (#17852) the local storage key is only set when a user presses the opt-in or opt-out buttons Overall, this feels less annoying for users to have to opt-in/opt-out on every visit to the create workspace page. Maybe less of a concern for end users but more of a concern while dogfooding. Pros: - User gets the admin setting value for the template as long as they didn't opt-in or opt-out - User can choose to opt-in/out-out at will and their preference is saved --- .../CreateWorkspaceExperimentRouter.tsx | 33 +++++++++++++++---- .../TemplateSettingsForm.tsx | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/site/src/pages/CreateWorkspacePage/CreateWorkspaceExperimentRouter.tsx b/site/src/pages/CreateWorkspacePage/CreateWorkspaceExperimentRouter.tsx index 3ebc194cc6..1652fb6521 100644 --- a/site/src/pages/CreateWorkspacePage/CreateWorkspaceExperimentRouter.tsx +++ b/site/src/pages/CreateWorkspacePage/CreateWorkspaceExperimentRouter.tsx @@ -30,11 +30,26 @@ const CreateWorkspaceExperimentRouter: FC = () => { templateQuery.data.id, "optOut", ], - queryFn: () => ({ - templateId: templateQuery.data.id, - optedOut: - localStorage.getItem(optOutKey(templateQuery.data.id)) === "true", - }), + queryFn: () => { + const templateId = templateQuery.data.id; + const localStorageKey = optOutKey(templateId); + const storedOptOutString = localStorage.getItem(localStorageKey); + + let optOutResult: boolean; + + if (storedOptOutString !== null) { + optOutResult = storedOptOutString === "true"; + } else { + optOutResult = Boolean( + templateQuery.data.use_classic_parameter_flow, + ); + } + + return { + templateId: templateId, + optedOut: optOutResult, + }; + }, } : { enabled: false }, ); @@ -49,11 +64,15 @@ const CreateWorkspaceExperimentRouter: FC = () => { const toggleOptedOut = () => { const key = optOutKey(optOutQuery.data.templateId); - const current = localStorage.getItem(key) === "true"; + const storedValue = localStorage.getItem(key); + + const current = storedValue + ? storedValue === "true" + : Boolean(templateQuery.data?.use_classic_parameter_flow); + localStorage.setItem(key, (!current).toString()); optOutQuery.refetch(); }; - return ( {optOutQuery.data.optedOut ? ( diff --git a/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx b/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx index cd01421b64..71adb89e14 100644 --- a/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx +++ b/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx @@ -242,7 +242,7 @@ export const TemplateSettingsForm: FC = ({ Show the original workspace creation form without dynamic parameters or live updates. Recommended if your provisioners - aren't updated or the new form causes issues. + aren't updated or the new form causes issues.{" "} Users can always manually switch experiences in the workspace creation form.