From 985b7359bbb5d604ffb112459c85069a0dd3136a Mon Sep 17 00:00:00 2001 From: Grace <145345672+microbit-grace@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:27:45 +0000 Subject: [PATCH] Parameterise Sanity config (#1158) Retain the current default. The intent is to allow folks to provide alternative content. See https://github.com/microbit-foundation/python-editor-v3/issues/1148 --- .env | 3 +++ src/common/sanity.ts | 6 ++++-- src/documentation/common/DocumentationContent.test.tsx | 2 +- src/documentation/ideas/content.ts | 9 +-------- src/setupTests.ts | 3 +++ src/vite.d.ts | 3 +++ 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.env b/.env index e10a70f1c..f60921e48 100644 --- a/.env +++ b/.env @@ -1,3 +1,6 @@ VITE_VERSION=$npm_package_version VITE_NAME=$npm_package_name VITE_FULL_URL=/ +VITE_SANITY_PROJECT=ajwvhvgo +VITE_SANITY_DATASET=apps +VITE_SANITY_PREVIEW_DATASET=apps-preview \ No newline at end of file diff --git a/src/common/sanity.ts b/src/common/sanity.ts index 99f7b3330..c8edad7eb 100644 --- a/src/common/sanity.ts +++ b/src/common/sanity.ts @@ -87,8 +87,10 @@ export const sanityLanguageId = (locale: string): string => { return `${parts[0]}-${parts[1].toUpperCase()}`; }; -export const project = "ajwvhvgo"; -export const dataset = flags.cmsPreview ? "apps-preview" : "apps"; +export const project = import.meta.env.VITE_SANITY_PROJECT; +export const dataset = flags.cmsPreview + ? import.meta.env.VITE_SANITY_PREVIEW_DATASET + : import.meta.env.VITE_SANITY_DATASET; const queryUrl = (query: string): string => { return `https://${project}.apicdn.sanity.io/v1/data/query/${dataset}?query=${encodeURIComponent( diff --git a/src/documentation/common/DocumentationContent.test.tsx b/src/documentation/common/DocumentationContent.test.tsx index cbacaf281..9bbf2c87e 100644 --- a/src/documentation/common/DocumentationContent.test.tsx +++ b/src/documentation/common/DocumentationContent.test.tsx @@ -67,7 +67,7 @@ describe("DocumentationContent", () => { const view = render(); // This relies on the mock above because Chakra UI's images have the src added later. expect(view.container.innerHTML).toMatchInlineSnapshot( - `"
"` + `"
"` ); }); }); diff --git a/src/documentation/ideas/content.ts b/src/documentation/ideas/content.ts index 6721735c1..0eab70e1a 100644 --- a/src/documentation/ideas/content.ts +++ b/src/documentation/ideas/content.ts @@ -29,12 +29,5 @@ const ideasQuery = (languageId: string): string => { }; const adaptContent = (result: any): Idea[] | undefined => { - const ideas = result?.pythonIdeasOrder as Idea[]; - if (!ideas) { - return undefined; - } - if (ideas.length === 0) { - return undefined; - } - return ideas; + return result?.pythonIdeasOrder ?? []; }; diff --git a/src/setupTests.ts b/src/setupTests.ts index 65e7faa14..6715d3b62 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -13,6 +13,9 @@ afterEach(() => { cleanup(); }); +vi.stubEnv("VITE_SANITY_PROJECT", "project"); +vi.stubEnv("VITE_SANITY_DATASET", "dataset"); + global.matchMedia = global.matchMedia || function () { diff --git a/src/vite.d.ts b/src/vite.d.ts index 91d3b1708..6295d64a2 100644 --- a/src/vite.d.ts +++ b/src/vite.d.ts @@ -4,6 +4,9 @@ interface ImportMetaEnv { readonly VITE_VERSION: string; readonly VITE_STAGE: string; + readonly VITE_SANITY_PROJECT: string; + readonly VITE_SANITY_DATASET: string; + readonly VITE_SANITY_PREVIEW_DATASET: string; } interface ImportMeta {