From 4ec96c1a0cec3e3e59a37f26ca6b47cf3ef5d465 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 10 Nov 2025 12:29:21 +0100 Subject: [PATCH] feat: allow filtering by block and challengeId (#63640) --- client/gatsby-node.js | 7 ++++++- curriculum/src/build-curriculum.ts | 12 +++++------- curriculum/src/config.ts | 15 ++++++++++----- curriculum/src/get-challenges.ts | 8 +++----- tools/scripts/build/build-curriculum.ts | 5 ++++- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/client/gatsby-node.js b/client/gatsby-node.js index fcabe9f49a6..40c24d3c77c 100644 --- a/client/gatsby-node.js +++ b/client/gatsby-node.js @@ -341,6 +341,7 @@ exports.createSchemaCustomization = ({ actions }) => { superOrder: Int template: String tests: [Test] + fields: ChallengeFields title: String transcript: String translationPending: Boolean @@ -467,7 +468,11 @@ exports.createSchemaCustomization = ({ actions }) => { beforeAll: String afterAll: String } - + type ChallengeFields { + slug: String + blockName: String + tests: [Test] + } type Nodule { type: String data: JSON diff --git a/curriculum/src/build-curriculum.ts b/curriculum/src/build-curriculum.ts index 96b26a62b38..7c152458b4e 100644 --- a/curriculum/src/build-curriculum.ts +++ b/curriculum/src/build-curriculum.ts @@ -334,19 +334,17 @@ export async function parseCurriculumStructure(filter?: Filter) { } export async function buildCurriculum(lang: string, filters?: Filter) { + // Block validation assumes the entire block is being built, if that's not the + // case, skip validation + const skipBlockValidation = filters?.challengeId !== undefined; const contentDir = getContentDir(lang); - const fccSuperblock = process.env.FCC_SUPERBLOCK; - - const combinedFilters: Filter | undefined = fccSuperblock - ? { ...filters, superBlock: fccSuperblock } - : filters; const builder = new SuperblockCreator( - getBlockCreator(lang, !isEmpty(combinedFilters)) + getBlockCreator(lang, skipBlockValidation) ); const { fullSuperblockList, certifications } = - await parseCurriculumStructure(combinedFilters); + await parseCurriculumStructure(filters); const fullCurriculum: { [key: string]: unknown; diff --git a/curriculum/src/config.ts b/curriculum/src/config.ts index e4e9218a92b..48f48efd8ec 100644 --- a/curriculum/src/config.ts +++ b/curriculum/src/config.ts @@ -28,10 +28,15 @@ export const FCC_CHALLENGE_ID = process.env.FCC_CHALLENGE_ID ? process.env.FCC_CHALLENGE_ID.trim() : undefined; +const FCC_BLOCK = process.env.FCC_BLOCK + ? process.env.FCC_BLOCK.trim() + : undefined; +const FCC_SUPERBLOCK = process.env.FCC_SUPERBLOCK + ? process.env.FCC_SUPERBLOCK.trim() + : undefined; + export const curriculumFilter = { - block: process.env.FCC_BLOCK ? process.env.FCC_BLOCK.trim() : undefined, - challengeId: FCC_CHALLENGE_ID, - superBlock: process.env.FCC_SUPERBLOCK - ? process.env.FCC_SUPERBLOCK.trim() - : undefined + ...(FCC_CHALLENGE_ID && { challengeId: FCC_CHALLENGE_ID }), + ...(FCC_BLOCK && { block: FCC_BLOCK }), + ...(FCC_SUPERBLOCK && { superBlock: FCC_SUPERBLOCK }) }; diff --git a/curriculum/src/get-challenges.ts b/curriculum/src/get-challenges.ts index e2d3c8452cb..48acdf74cef 100644 --- a/curriculum/src/get-challenges.ts +++ b/curriculum/src/get-challenges.ts @@ -4,6 +4,8 @@ import { promisify } from 'util'; import { availableLangs } from '../../shared-dist/config/i18n.js'; import { buildCurriculum } from './build-curriculum.js'; +import { curriculumFilter } from './config.js'; +import type { Filter } from './filter.js'; const { curriculum: curriculumLangs } = availableLangs; @@ -11,11 +13,7 @@ const access = promisify(_access); export async function getChallengesForLang( lang: string, - filters?: { - superBlock?: string; - block?: string; - challengeId?: string; - } + filters: Filter = curriculumFilter // default to global curriculum filter, but allow override (e.g. when testing specific blocks) ) { const invalidLang = !curriculumLangs.includes(lang); if (invalidLang) diff --git a/tools/scripts/build/build-curriculum.ts b/tools/scripts/build/build-curriculum.ts index 34c1f1a1bea..72a2fa2218f 100644 --- a/tools/scripts/build/build-curriculum.ts +++ b/tools/scripts/build/build-curriculum.ts @@ -15,7 +15,10 @@ import { const globalConfigPath = path.resolve(__dirname, '../../../shared-dist/config'); -const isSelectiveBuild = !!process.env.FCC_SUPERBLOCK; +const isSelectiveBuild = + process.env.FCC_SUPERBLOCK || + process.env.FCC_BLOCK || + process.env.FCC_CHALLENGE_ID; void getChallengesForLang('english') .then(result => {