- Notifications
You must be signed in to change notification settings - Fork909
feat: create experimental template embed page for dynamic params#17999
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
Draft
jaaydenh wants to merge7 commits intomainChoose a base branch fromjaaydenh/template-embed-page
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+484 −51
Draft
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
18a81ae
fix: prevent layout shift when Select component dropdown appears
jaaydenh9548678
feat: update template embed page for dynamic params
jaaydenh5a30f45
fix: fix types
jaaydenh44e1e26
fix: cleanup
jaaydenh5eae893
chore: cleanup
jaaydenhafb5361
fix: fix commits
jaaydenh7c28011
chore: cleanup
jaaydenhFile 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
51 changes: 49 additions & 2 deletionssite/src/modules/workspaces/DynamicParameter/DynamicParameter.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
44 changes: 2 additions & 42 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
92 changes: 92 additions & 0 deletionssite/src/pages/TemplatePage/TemplateEmbedPage/TemplateEmbedExperimentRouter.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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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 { ExperimentalFormContext } from "pages/CreateWorkspacePage/ExperimentalFormContext"; | ||
import type { FC } from "react"; | ||
import { useQuery } from "react-query"; | ||
import { useParams } from "react-router-dom"; | ||
import TemplateEmbedPage from "./TemplateEmbedPage"; | ||
import TemplateEmbedPageExperimental from "./TemplateEmbedPageExperimental"; | ||
const TemplateEmbedExperimentRouter: 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: () => { | ||
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 }, | ||
); | ||
if (dynamicParametersEnabled) { | ||
if (optOutQuery.isLoading) { | ||
return <Loader />; | ||
} | ||
if (!optOutQuery.data) { | ||
return <ErrorAlert error={optOutQuery.error} />; | ||
} | ||
const toggleOptedOut = () => { | ||
const key = optOutKey(optOutQuery.data.templateId); | ||
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 ( | ||
<ExperimentalFormContext.Provider value={{ toggleOptedOut }}> | ||
{optOutQuery.data.optedOut ? ( | ||
<TemplateEmbedPage /> | ||
) : ( | ||
<TemplateEmbedPageExperimental /> | ||
)} | ||
</ExperimentalFormContext.Provider> | ||
); | ||
} | ||
return <TemplateEmbedPage />; | ||
}; | ||
export default TemplateEmbedExperimentRouter; | ||
const optOutKey = (id: string) => `parameters.${id}.optOut`; |
20 changes: 17 additions & 3 deletionssite/src/pages/TemplatePage/TemplateEmbedPage/TemplateEmbedPage.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.
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.