mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: always show upload and scratch in create template gallery (#14327)
This commit is contained in:
+3
-3
@@ -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,
|
||||
@@ -36,7 +36,7 @@ test("does not display the scratch template", async () => {
|
||||
children: [
|
||||
{
|
||||
path: "/starter-templates",
|
||||
element: <StarterTemplatesPage />,
|
||||
element: <CreateTemplateGalleryPage />,
|
||||
},
|
||||
],
|
||||
},
|
||||
+5
-15
@@ -1,16 +1,13 @@
|
||||
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 { showOrganizations } = useDashboard();
|
||||
const templateExamplesQuery = useQuery(templateExamples());
|
||||
const starterTemplatesByTag = templateExamplesQuery.data
|
||||
? // Currently, the scratch template should not be displayed on the starter templates page.
|
||||
@@ -22,17 +19,10 @@ const CreateTemplatesGalleryPage: FC = () => {
|
||||
<Helmet>
|
||||
<title>{pageTitle("Create a Template")}</title>
|
||||
</Helmet>
|
||||
{showOrganizations ? (
|
||||
<CreateTemplatesPageView
|
||||
error={templateExamplesQuery.error}
|
||||
starterTemplatesByTag={starterTemplatesByTag}
|
||||
/>
|
||||
) : (
|
||||
<StarterTemplatesPageView
|
||||
error={templateExamplesQuery.error}
|
||||
starterTemplatesByTag={starterTemplatesByTag}
|
||||
/>
|
||||
)}
|
||||
<CreateTemplateGalleryPageView
|
||||
error={templateExamplesQuery.error}
|
||||
starterTemplatesByTag={starterTemplatesByTag}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
+5
-5
@@ -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: {
|
||||
+4
-5
@@ -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>
|
||||
@@ -1,38 +0,0 @@
|
||||
import { ErrorAlert } from "components/Alert/ErrorAlert";
|
||||
import { Loader } from "components/Loader/Loader";
|
||||
import { Margins } from "components/Margins/Margins";
|
||||
import {
|
||||
PageHeader,
|
||||
PageHeaderSubtitle,
|
||||
PageHeaderTitle,
|
||||
} from "components/PageHeader/PageHeader";
|
||||
import type { FC } from "react";
|
||||
import type { StarterTemplatesByTag } from "utils/starterTemplates";
|
||||
import { StarterTemplates } from "./StarterTemplates";
|
||||
|
||||
export interface StarterTemplatesPageViewProps {
|
||||
starterTemplatesByTag?: StarterTemplatesByTag;
|
||||
error?: unknown;
|
||||
}
|
||||
|
||||
export const StarterTemplatesPageView: FC<StarterTemplatesPageViewProps> = ({
|
||||
starterTemplatesByTag,
|
||||
error,
|
||||
}) => {
|
||||
return (
|
||||
<Margins>
|
||||
<PageHeader>
|
||||
<PageHeaderTitle>Starter Templates</PageHeaderTitle>
|
||||
<PageHeaderSubtitle>
|
||||
Import a built-in template to start developing in the cloud
|
||||
</PageHeaderSubtitle>
|
||||
</PageHeader>
|
||||
|
||||
{Boolean(error) && <ErrorAlert error={error} />}
|
||||
|
||||
{Boolean(!starterTemplatesByTag) && <Loader />}
|
||||
|
||||
<StarterTemplates starterTemplatesByTag={starterTemplatesByTag} />
|
||||
</Margins>
|
||||
);
|
||||
};
|
||||
+3
-3
@@ -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"),
|
||||
@@ -359,7 +359,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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user