Skip to content

Add a cmsPreview flag to use alternative CMS dataset #1135

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

Merged
merged 4 commits into from
Oct 18, 2023
Merged
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
5 changes: 3 additions & 2 deletions src/common/imageUrlBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
*/

import unconfiguredImageUrlBuilder from "@sanity/image-url";
import { dataset, project } from "./sanity";

export const defaultQuality = 80;

export const imageUrlBuilder = unconfiguredImageUrlBuilder()
// Hardcoded for now as there's no practical alternative.
.projectId("ajwvhvgo")
.dataset("apps")
.projectId(project)
.dataset(dataset)
.auto("format")
.dpr(window.devicePixelRatio ?? 1)
.quality(defaultQuality);
Expand Down
12 changes: 8 additions & 4 deletions src/common/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Common sanity types.
*/

import { flags } from "../flags";

export interface PortableTextBlock {
_type: "block";
_key: string;
Expand Down Expand Up @@ -85,9 +87,11 @@ export const sanityLanguageId = (locale: string): string => {
return `${parts[0]}-${parts[1].toUpperCase()}`;
};

export const project = "ajwvhvgo";
export const dataset = flags.cmsPreview ? "apps-preview" : "apps";

const queryUrl = (query: string): string => {
return (
"https://ajwvhvgo.apicdn.sanity.io/v1/data/query/apps?query=" +
encodeURIComponent(query)
);
return `https://${project}.apicdn.sanity.io/v1/data/query/${dataset}?query=${encodeURIComponent(
query
)}`;
};
4 changes: 2 additions & 2 deletions src/documentation/reference/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const getTopicAndEntry = (
return [entry.parent, entry];
};

// For now we just slurp the whole toolkit at once.
// Might revisit depending on eventual size.
// We just slurp the whole toolkit at once.
// This is necessary for the client-side search index.
const toolkitQuery = (languageId: string): string => {
return `
*[_type == "toolkit" && language == "${languageId}" && (slug.current == "explore" || slug.current == "reference") && !(_id in path("drafts.**"))]{
Expand Down
31 changes: 17 additions & 14 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,32 @@ import { Stage, stage as stageFromEnvironment } from "./environment";
* A union of the flag names (alphabetical order).
*/
export type Flag =
/**
* Enables verbose debug logging to the console of drag events.
*/
| "dndDebug"

/**
* Flag to add a beta notice. Enabled for staging site but not production stages.
*/
| "betaNotice"

/**
* Disables the pop-up welcome dialog.
*
* Added to support user-testing and has the nice side-effect of disabling
* the dialog for local development so is worth keeping for that use alone.
* Uses CMS content from an alternative preview dataset.
*/
| "cmsPreview"
/**
* Enables verbose debug logging to the console of drag events.
*/
| "noWelcome"
| "dndDebug"
/**
* Disables language selection from the settings menu.
*
* Added so we can embed the editor in micro:bit classroom without competing language
* options. The language selected in classroom is passed through via query param.
*/
| "noLang";
| "noLang"
/**
* Disables the pop-up welcome dialog.
*
* Added to support user-testing and has the nice side-effect of disabling
* the dialog for local development so is worth keeping for that use alone.
*/
| "noWelcome";

interface FlagMetadata {
defaultOnStages: Stage[];
Expand All @@ -48,10 +50,11 @@ interface FlagMetadata {

const allFlags: FlagMetadata[] = [
// Alphabetical order.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so not so much before 😄

{ name: "dndDebug", defaultOnStages: [] },
{ name: "betaNotice", defaultOnStages: ["local", "REVIEW", "STAGING"] },
{ name: "noWelcome", defaultOnStages: ["local", "REVIEW"] },
{ name: "cmsPreview", defaultOnStages: [] },
{ name: "dndDebug", defaultOnStages: [] },
{ name: "noLang", defaultOnStages: [] },
{ name: "noWelcome", defaultOnStages: ["local", "REVIEW"] },
];

type Flags = Record<Flag, boolean>;
Expand Down