Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: always show upload and scratch in create template gallery #15

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
MockTemplateExample2,
} from "testHelpers/entities";
import { server } from "testHelpers/server";
import StarterTemplatesPage from "./CreateTemplatesGalleryPage";
import CreateTemplateGalleryPage from "./CreateTemplateGalleryPage";

test("does not display the scratch template", async () => {
server.use(
http.get("api/v2/organizations/:organizationId/templates/examples", () => {
http.get("api/v2/templates/examples", () => {
return HttpResponse.json([
MockTemplateExample,
MockTemplateExample2,
Expand All @@ -36,7 +36,7 @@ test("does not display the scratch template", async () => {
children: [
{
path: "/starter-templates",
element: <StarterTemplatesPage />,
element: <CreateTemplateGalleryPage />,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
import { templateExamples } from "api/queries/templates";
import type { TemplateExample } from "api/typesGenerated";
import { useDashboard } from "modules/dashboard/useDashboard";
import type { FC } from "react";
import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { pageTitle } from "utils/page";
import { getTemplatesByTag } from "utils/starterTemplates";
import { CreateTemplatesPageView } from "./CreateTemplatesPageView";
import { StarterTemplatesPageView } from "./StarterTemplatesPageView";
import { CreateTemplateGalleryPageView } from "./CreateTemplateGalleryPageView";

const CreateTemplatesGalleryPage: FC = () => {
const { experiments } = useDashboard();
const templateExamplesQuery = useQuery(templateExamples());
const starterTemplatesByTag = templateExamplesQuery.data
? // Currently, the scratch template should not be displayed on the starter templates page.
getTemplatesByTag(removeScratchExample(templateExamplesQuery.data))
: undefined;
const multiOrgExperimentEnabled = experiments.includes("multi-organization");

return (
<>
<Helmet>
<title>{pageTitle("Create a Template")}</title>
</Helmet>
{multiOrgExperimentEnabled ? (
<CreateTemplatesPageView
error={templateExamplesQuery.error}
starterTemplatesByTag={starterTemplatesByTag}
/>
) : (
<StarterTemplatesPageView
error={templateExamplesQuery.error}
starterTemplatesByTag={starterTemplatesByTag}
/>
)}
<CreateTemplateGalleryPageView
error={templateExamplesQuery.error}
starterTemplatesByTag={starterTemplatesByTag}
/>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import {
mockApiError,
} from "testHelpers/entities";
import { getTemplatesByTag } from "utils/starterTemplates";
import { StarterTemplatesPageView } from "./StarterTemplatesPageView";
import { CreateTemplateGalleryPageView } from "./CreateTemplateGalleryPageView";

const meta: Meta<typeof StarterTemplatesPageView> = {
title: "pages/StarterTemplatesPage",
const meta: Meta<typeof CreateTemplateGalleryPageView> = {
title: "pages/CreateTemplateGalleryPage",
parameters: { chromatic },
component: StarterTemplatesPageView,
component: CreateTemplateGalleryPageView,
};

export default meta;
type Story = StoryObj<typeof StarterTemplatesPageView>;
type Story = StoryObj<typeof CreateTemplateGalleryPageView>;

export const Example: Story = {
args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import { Link as RouterLink } from "react-router-dom";
import type { StarterTemplatesByTag } from "utils/starterTemplates";
import { StarterTemplates } from "./StarterTemplates";

export interface CreateTemplatePageViewProps {
export interface CreateTemplateGalleryPageViewProps {
starterTemplatesByTag?: StarterTemplatesByTag;
error?: unknown;
}

export const CreateTemplatesPageView: FC<CreateTemplatePageViewProps> = ({
starterTemplatesByTag,
error,
}) => {
export const CreateTemplateGalleryPageView: FC<
CreateTemplateGalleryPageViewProps
> = ({ starterTemplatesByTag, error }) => {
return (
<Margins>
<PageHeader>
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions site/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ const TemplateVersionPage = lazy(
const TemplateVersionEditorPage = lazy(
() => import("./pages/TemplateVersionEditorPage/TemplateVersionEditorPage"),
);
const CreateTemplatesGalleryPage = lazy(
() => import("./pages/CreateTemplatesGalleryPage/CreateTemplatesGalleryPage"),
const CreateTemplateGalleryPage = lazy(
() => import("./pages/CreateTemplateGalleryPage/CreateTemplateGalleryPage"),
);
const StarterTemplatePage = lazy(
() => import("pages/StarterTemplatePage/StarterTemplatePage"),
Expand Down Expand Up @@ -353,7 +353,7 @@ export const router = createBrowserRouter(
<Route path="/workspaces" element={<WorkspacesPage />} />

<Route path="/starter-templates">
<Route index element={<CreateTemplatesGalleryPage />} />
<Route index element={<CreateTemplateGalleryPage />} />
<Route path=":exampleId" element={<StarterTemplatePage />} />
</Route>

Expand Down