Skip to content

Commit

Permalink
Switch approach: use an alternative dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed Oct 18, 2023
1 parent a3d9adf commit 6ac8350
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
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
)}`;
};
7 changes: 1 addition & 6 deletions src/documentation/reference/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: MIT
*/
import { fetchContent } from "../../common/sanity";
import { flags } from "../../flags";
import { Toolkit, ToolkitTopic, ToolkitTopicEntry } from "./model";

export const fetchReferenceToolkit = async (
Expand Down Expand Up @@ -33,12 +32,8 @@ export const getTopicAndEntry = (
// We just slurp the whole toolkit at once.
// This is necessary for the client-side search index.
const toolkitQuery = (languageId: string): string => {
// The flag applies to the top-level document so for now there's no support for viewing drafts further down.
const noDraftsConstraint = flags.drafts
? ""
: `&& (_id in path("drafts.**"))`;
return `
*[_type == "toolkit" && language == "${languageId}" && (slug.current == "explore" || slug.current == "reference") ${noDraftsConstraint}]{
*[_type == "toolkit" && language == "${languageId}" && (slug.current == "explore" || slug.current == "reference") && !(_id in path("drafts.**"))]{
_id, id, name, description, language,
contents[]->{
name, slug, compatibility, subtitle, image,
Expand Down
16 changes: 7 additions & 9 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ export type Flag =
*/
| "betaNotice"
/**
* Enables verbose debug logging to the console of drag events.
* Uses CMS content from an alternative preview dataset.
*/
| "dndDebug"
| "cmsPreview"
/**
* Shows CMS drafts in preference to live content.
*
* Currently only supported for the reference content.
* Enables verbose debug logging to the console of drag events.
*/
| "drafts"
| "dndDebug"
/**
* Disables language selection from the settings menu.
*
Expand All @@ -52,11 +50,11 @@ interface FlagMetadata {

const allFlags: FlagMetadata[] = [
// Alphabetical order.
{ name: "dndDebug", defaultOnStages: [] },
{ name: "drafts", defaultOnStages: ["local", "REVIEW"] },
{ 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

0 comments on commit 6ac8350

Please sign in to comment.