fix(site/src): gate TemplateExampleCard Use template link on builder state (#28035)

This commit is contained in:
Jeremy Ruppel
2026-08-11 14:30:37 -04:00
committed by GitHub
parent b721935fc1
commit e9ee83af69
7 changed files with 37 additions and 6 deletions
@@ -10,6 +10,7 @@ const meta: Meta<typeof TemplateExampleCard> = {
component: TemplateExampleCard, component: TemplateExampleCard,
args: { args: {
example: MockTemplateExample, example: MockTemplateExample,
templateBuilderEnabled: true,
}, },
}; };
@@ -32,3 +33,9 @@ export const LotsOfTags: Story = {
}, },
}, },
}; };
export const TemplateBuilderDisabled: Story = {
args: {
templateBuilderEnabled: false,
},
};
@@ -10,14 +10,20 @@ import { cn } from "#/utils/cn";
type TemplateExampleCardProps = HTMLAttributes<HTMLDivElement> & { type TemplateExampleCardProps = HTMLAttributes<HTMLDivElement> & {
example: TemplateExample; example: TemplateExample;
activeTag?: string; activeTag?: string;
templateBuilderEnabled?: boolean;
}; };
export const TemplateExampleCard: FC<TemplateExampleCardProps> = ({ export const TemplateExampleCard: FC<TemplateExampleCardProps> = ({
example, example,
activeTag, activeTag,
templateBuilderEnabled,
className, className,
...divProps ...divProps
}) => { }) => {
const useTemplateLink = templateBuilderEnabled
? `/templates/new/builder?base=${example.id}`
: `/templates/new?exampleId=${example.id}`;
return ( return (
<div <div
className={cn( className={cn(
@@ -66,9 +72,7 @@ export const TemplateExampleCard: FC<TemplateExampleCardProps> = ({
<div className="mt-auto flex flex-col items-center gap-3 pt-6"> <div className="mt-auto flex flex-col items-center gap-3 pt-6">
<Button asChild className="w-full"> <Button asChild className="w-full">
<RouterLink to={`/templates/new/builder?base=${example.id}`}> <RouterLink to={useTemplateLink}>Use template</RouterLink>
Use template
</RouterLink>
</Button> </Button>
</div> </div>
</div> </div>
@@ -1,5 +1,6 @@
import type { FC } from "react"; import type { FC } from "react";
import { useQuery } from "react-query"; import { useQuery } from "react-query";
import { deploymentConfig } from "#/api/queries/deployment";
import { templateExamples } from "#/api/queries/templates"; import { templateExamples } from "#/api/queries/templates";
import { pageTitle } from "#/utils/page"; import { pageTitle } from "#/utils/page";
import { getTemplatesByTag } from "#/utils/starterTemplates"; import { getTemplatesByTag } from "#/utils/starterTemplates";
@@ -11,6 +12,10 @@ const CreateTemplatesGalleryPage: FC = () => {
? getTemplatesByTag(templateExamplesQuery.data) ? getTemplatesByTag(templateExamplesQuery.data)
: undefined; : undefined;
const { data: deploymentConfigData } = useQuery(deploymentConfig());
const builderDisabled =
deploymentConfigData?.config?.template_builder?.disabled ?? false;
return ( return (
<> <>
<title>{pageTitle("Create a Template")}</title> <title>{pageTitle("Create a Template")}</title>
@@ -18,6 +23,7 @@ const CreateTemplatesGalleryPage: FC = () => {
<CreateTemplateGalleryPageView <CreateTemplateGalleryPageView
error={templateExamplesQuery.error} error={templateExamplesQuery.error}
starterTemplatesByTag={starterTemplatesByTag} starterTemplatesByTag={starterTemplatesByTag}
templateBuilderEnabled={!builderDisabled}
/> />
</> </>
); );
@@ -10,6 +10,9 @@ import { CreateTemplateGalleryPageView } from "./CreateTemplateGalleryPageView";
const meta: Meta<typeof CreateTemplateGalleryPageView> = { const meta: Meta<typeof CreateTemplateGalleryPageView> = {
title: "pages/CreateTemplateGalleryPage", title: "pages/CreateTemplateGalleryPage",
component: CreateTemplateGalleryPageView, component: CreateTemplateGalleryPageView,
args: {
templateBuilderEnabled: true,
},
}; };
export default meta; export default meta;
@@ -15,12 +15,13 @@ import { StarterTemplates } from "./StarterTemplates";
interface CreateTemplateGalleryPageViewProps { interface CreateTemplateGalleryPageViewProps {
starterTemplatesByTag?: StarterTemplatesByTag; starterTemplatesByTag?: StarterTemplatesByTag;
templateBuilderEnabled: boolean;
error?: unknown; error?: unknown;
} }
export const CreateTemplateGalleryPageView: FC< export const CreateTemplateGalleryPageView: FC<
CreateTemplateGalleryPageViewProps CreateTemplateGalleryPageViewProps
> = ({ starterTemplatesByTag, error }) => { > = ({ starterTemplatesByTag, templateBuilderEnabled, error }) => {
return ( return (
<Margins className="pb-12"> <Margins className="pb-12">
<PageHeader <PageHeader
@@ -87,7 +88,10 @@ export const CreateTemplateGalleryPageView: FC<
{Boolean(!starterTemplatesByTag) && <Loader />} {Boolean(!starterTemplatesByTag) && <Loader />}
<StarterTemplates starterTemplatesByTag={starterTemplatesByTag} /> <StarterTemplates
starterTemplatesByTag={starterTemplatesByTag}
templateBuilderEnabled={templateBuilderEnabled}
/>
</div> </div>
</Margins> </Margins>
); );
@@ -48,10 +48,12 @@ const sortVisibleTemplates = (templates: TemplateExample[]) => {
interface StarterTemplatesProps { interface StarterTemplatesProps {
starterTemplatesByTag?: StarterTemplatesByTag; starterTemplatesByTag?: StarterTemplatesByTag;
templateBuilderEnabled: boolean;
} }
export const StarterTemplates: FC<StarterTemplatesProps> = ({ export const StarterTemplates: FC<StarterTemplatesProps> = ({
starterTemplatesByTag, starterTemplatesByTag,
templateBuilderEnabled,
}) => { }) => {
const [urlParams] = useSearchParams(); const [urlParams] = useSearchParams();
const tags = starterTemplatesByTag const tags = starterTemplatesByTag
@@ -95,6 +97,7 @@ export const StarterTemplates: FC<StarterTemplatesProps> = ({
example={example} example={example}
key={example.id} key={example.id}
activeTag={activeTag} activeTag={activeTag}
templateBuilderEnabled={templateBuilderEnabled}
className="bg-surface-primary" className="bg-surface-primary"
/> />
))} ))}
@@ -76,7 +76,11 @@ export const EmptyTemplates: FC<EmptyTemplatesProps> = ({
<div className="flex flex-col gap-8 items-center"> <div className="flex flex-col gap-8 items-center">
<div className="flex flex-wrap justify-center gap-4"> <div className="flex flex-wrap justify-center gap-4">
{featuredExamples.map((example) => ( {featuredExamples.map((example) => (
<TemplateExampleCard example={example} key={example.id} /> <TemplateExampleCard
example={example}
key={example.id}
templateBuilderEnabled={templateBuilderEnabled}
/>
))} ))}
</div> </div>
<Button size="sm" asChild className="rounded-full"> <Button size="sm" asChild className="rounded-full">