- Notifications
You must be signed in to change notification settings - Fork907
feat: add opt-out option to new parameters form#17456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
9491b23
pls hold
aslilac84f8785
Merge branch 'main' into lilac/parameters-opt-out
aslilac063538a
not now pls
aslilacc8fcb77
Merge branch 'main' into lilac/parameters-opt-out
aslilac7efa2b0
yay
aslilacd09fdb9
Merge branch 'main' into lilac/parameters-opt-out
aslilacf7cc333
Merge branch 'main' into lilac/parameters-opt-out
aslilac210f80c
:)
aslilace910eb3
sort
aslilaca9badc9
clean up design
aslilacb60b3da
rename context
aslilacFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
64 changes: 61 additions & 3 deletionssite/src/pages/CreateWorkspacePage/CreateWorkspaceExperimentRouter.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,76 @@ | ||
import { templateByName } from "api/queries/templates"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { useDashboard } from "modules/dashboard/useDashboard"; | ||
import { type FC, createContext } from "react"; | ||
import { useQuery } from "react-query"; | ||
import { useParams } from "react-router-dom"; | ||
import CreateWorkspacePage from "./CreateWorkspacePage"; | ||
import CreateWorkspacePageExperimental from "./CreateWorkspacePageExperimental"; | ||
const CreateWorkspaceExperimentRouter: FC = () => { | ||
const { experiments } = useDashboard(); | ||
const dynamicParametersEnabled = experiments.includes("dynamic-parameters"); | ||
const { organization: organizationName = "default", template: templateName } = | ||
useParams() as { organization?: string; template: string }; | ||
const templateQuery = useQuery( | ||
dynamicParametersEnabled | ||
? templateByName(organizationName, templateName) | ||
: { enabled: false }, | ||
); | ||
const optOutQuery = useQuery( | ||
templateQuery.data | ||
? { | ||
queryKey: [ | ||
organizationName, | ||
"template", | ||
templateQuery.data.id, | ||
"optOut", | ||
], | ||
queryFn: () => ({ | ||
templateId: templateQuery.data.id, | ||
optedOut: | ||
localStorage.getItem(optOutKey(templateQuery.data.id)) === "true", | ||
}), | ||
} | ||
: { enabled: false }, | ||
); | ||
if (dynamicParametersEnabled) { | ||
if (optOutQuery.isLoading) { | ||
return <Loader />; | ||
} | ||
if (!optOutQuery.data) { | ||
return <ErrorAlert error={optOutQuery.error} />; | ||
} | ||
const toggleOptedOut = () => { | ||
const key = optOutKey(optOutQuery.data.templateId); | ||
const current = localStorage.getItem(key) === "true"; | ||
localStorage.setItem(key, (!current).toString()); | ||
optOutQuery.refetch(); | ||
}; | ||
return ( | ||
<ExperimentalFormContext.Provider value={{ toggleOptedOut }}> | ||
{optOutQuery.data.optedOut ? ( | ||
<CreateWorkspacePage /> | ||
) : ( | ||
<CreateWorkspacePageExperimental /> | ||
)} | ||
</ExperimentalFormContext.Provider> | ||
); | ||
} | ||
return <CreateWorkspacePage />; | ||
}; | ||
export default CreateWorkspaceExperimentRouter; | ||
const optOutKey = (id: string) => `parameters.${id}.optOut`; | ||
export const ExperimentalFormContext = createContext< | ||
{ toggleOptedOut: () => void } | undefined | ||
>(undefined); |
9 changes: 5 additions & 4 deletionssite/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
30 changes: 25 additions & 5 deletionssite/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletionssite/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.