refactor: simplify sourcing of challenge nodes into gatsby (#63697)

This commit is contained in:
Oliver Eyton-Williams
2025-11-11 09:34:24 +01:00
committed by GitHub
parent 6fe97d3105
commit ee911d7eac
18 changed files with 2778 additions and 5531 deletions

View File

@@ -470,8 +470,6 @@ exports.createSchemaCustomization = ({ actions }) => {
}
type ChallengeFields {
slug: String
blockName: String
tests: [Test]
}
type Nodule {
type: String

View File

@@ -91,10 +91,7 @@ function formatChallengeData({
...baseChallengeProps,
helpCategory: 'JavaScript',
challengeType: 28,
fields: {
blockName: 'daily-coding-challenge',
tests: javascript.tests
},
tests: javascript.tests,
challengeFiles: [
{
name: 'script',
@@ -119,10 +116,7 @@ function formatChallengeData({
...baseChallengeProps,
helpCategory: 'Python',
challengeType: 29,
fields: {
blockName: 'daily-coding-challenge',
tests: python.tests
},
tests: python.tests,
challengeFiles: [
{
fileKey: 'mainpy',

View File

@@ -254,9 +254,9 @@ function useIdToNameMap(t: TFunction): Map<string, NameMap> {
edges {
node {
challenge {
block
fields {
slug
blockName
}
id
superBlock
@@ -281,6 +281,8 @@ function useIdToNameMap(t: TFunction): Map<string, NameMap> {
({
node: {
challenge: {
// @ts-expect-error Graphql needs typing
block,
// @ts-expect-error Graphql needs typing
id,
// @ts-expect-error Graphql needs typing
@@ -288,13 +290,13 @@ function useIdToNameMap(t: TFunction): Map<string, NameMap> {
// @ts-expect-error Graphql needs typing
title,
// @ts-expect-error Graphql needs typing
fields: { slug, blockName },
fields: { slug },
// @ts-expect-error Graphql needs typing
hasEditableBoundaries
}
}
}) => {
const blockNameTitle = t(`intro:${superBlock}.blocks.${blockName}.title`);
const blockNameTitle = t(`intro:${superBlock}.blocks.${block}.title`);
const shouldAppendBlockNameToTitle =
hasEditableBoundaries || superBlock === SuperBlocks.A2English;
idToNameMap.set(id, {

View File

@@ -54,8 +54,6 @@ export type FillInTheBlank = {
export type Fields = {
slug: string;
blockHashSlug: string;
blockName: string;
tests: Test[];
};
type Required = {
link: string;
@@ -293,10 +291,7 @@ export type DailyCodingChallengeNode = {
helpCategory: 'JavaScript' | 'Python';
challengeType: 28 | 29;
fields: {
blockName: 'daily-coding-challenge';
tests: Test[];
};
tests: Test[];
challengeFiles: ChallengeFiles;
// props to satisfy the show classic component

View File

@@ -203,7 +203,7 @@ function ShowClassic({
description,
instructions,
hooks,
fields: { tests, blockName },
tests,
challengeType,
hasEditableBoundaries = false,
superBlock,
@@ -317,7 +317,7 @@ function ShowClassic({
// Independent lower jaw is only enabled for the urriculum outline workshop
const showIndependentLowerJaw =
blockName === 'workshop-curriculum-outline' &&
block === 'workshop-curriculum-outline' &&
isIndependentLowerJawEnabled &&
!isMobile;
@@ -547,7 +547,7 @@ function ShowClassic({
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
<VideoModal videoUrl={videoUrl} />
@@ -596,12 +596,7 @@ export const query = graphql`
afterAll
}
fields {
blockName
slug
tests {
text
testString
}
}
required {
link
@@ -618,6 +613,10 @@ export const query = graphql`
editableRegionBoundaries
history
}
tests {
text
testString
}
}
}
}

View File

@@ -137,7 +137,7 @@ function ShowCodeAlly({
challenge: {
block,
challengeType,
fields: { tests },
tests,
description,
helpCategory,
id: challengeId,
@@ -385,12 +385,6 @@ export const query = graphql`
challengeNode(id: { eq: $id }) {
challenge {
block
fields {
tests {
text
testString
}
}
challengeType
description
helpCategory
@@ -398,6 +392,10 @@ export const query = graphql`
instructions
notes
superBlock
tests {
text
testString
}
title
translationPending
url

View File

@@ -149,7 +149,6 @@ function ShowExam(props: ShowExamProps) {
block,
dashedName,
description,
fields: { blockName },
instructions,
prerequisites,
superBlock,
@@ -186,12 +185,7 @@ function ShowExam(props: ShowExamProps) {
challengeMounted,
data: {
challengeNode: {
challenge: {
fields: { tests },
challengeType,
helpCategory,
title
}
challenge: { tests, challengeType, helpCategory, title }
}
},
pageContext: { challengeMeta },
@@ -530,7 +524,7 @@ function ShowExam(props: ShowExamProps) {
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
</Row>
@@ -558,11 +552,6 @@ export const query = graphql`
description
fields {
blockHashSlug
blockName
tests {
text
testString
}
}
helpCategory
id
@@ -572,6 +561,10 @@ export const query = graphql`
title
}
superBlock
tests {
text
testString
}
title
translationPending
}

View File

@@ -86,11 +86,11 @@ const ShowFillInTheBlank = ({
superBlock,
block,
translationPending,
fields: { blockName, tests },
challengeType,
fillInTheBlank,
helpCategory,
scene
scene,
tests
}
}
},
@@ -260,7 +260,7 @@ const ShowFillInTheBlank = ({
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
</Row>
@@ -288,12 +288,7 @@ export const query = graphql`
superBlock
block
fields {
blockName
slug
tests {
text
testString
}
}
fillInTheBlank {
sentence
@@ -302,6 +297,10 @@ export const query = graphql`
feedback
}
}
tests {
text
testString
}
transcript
scene {
setup {

View File

@@ -104,10 +104,10 @@ const ShowGeneric = ({
nodules,
explanation,
challengeType,
fields: { blockName, tests },
helpCategory,
instructions,
questions,
tests,
title,
transcript,
translationPending,
@@ -358,7 +358,7 @@ const ShowGeneric = ({
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
</Row>
@@ -394,12 +394,7 @@ export const query = graphql`
helpCategory
instructions
fields {
blockName
slug
tests {
text
testString
}
}
questions {
text
@@ -448,6 +443,10 @@ export const query = graphql`
}
}
superBlock
tests {
text
testString
}
title
transcript
translationPending

View File

@@ -97,12 +97,7 @@ function MsTrophy(props: MsTrophyProps) {
challengeMounted,
data: {
challengeNode: {
challenge: {
fields: { tests },
title,
challengeType,
helpCategory
}
challenge: { tests, title, challengeType, helpCategory }
}
},
pageContext: { challengeMeta },
@@ -141,8 +136,7 @@ function MsTrophy(props: MsTrophyProps) {
instructions,
superBlock,
block,
translationPending,
fields: { blockName }
translationPending
}
}
},
@@ -204,7 +198,7 @@ function MsTrophy(props: MsTrophyProps) {
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
</Row>
@@ -231,12 +225,9 @@ export const query = graphql`
superBlock
block
translationPending
fields {
blockName
tests {
text
testString
}
tests {
text
testString
}
}
}

View File

@@ -112,12 +112,7 @@ const ShowBackEnd = (props: BackEndProps) => {
updateChallengeMeta,
data: {
challengeNode: {
challenge: {
fields: { tests },
title,
challengeType,
helpCategory
}
challenge: { challengeType, helpCategory, tests, title }
}
},
pageContext: { challengeMeta }
@@ -143,7 +138,6 @@ const ShowBackEnd = (props: BackEndProps) => {
data: {
challengeNode: {
challenge: {
fields: { blockName },
challengeType,
forumTopicId,
title,
@@ -212,7 +206,7 @@ const ShowBackEnd = (props: BackEndProps) => {
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
</Row>
@@ -241,12 +235,11 @@ export const query = graphql`
block
translationPending
fields {
blockName
slug
tests {
text
testString
}
}
tests {
text
testString
}
}
}

View File

@@ -86,14 +86,14 @@ const ShowFrontEndProject = (props: ProjectProps) => {
challengeMounted,
data: {
challengeNode: {
challenge: { fields, title, challengeType, helpCategory }
challenge: { tests, title, challengeType, helpCategory }
}
},
pageContext: { challengeMeta },
initTests,
updateChallengeMeta
} = props;
initTests(fields.tests);
initTests(tests);
const challengePaths = getChallengePaths({
currentCurriculumPaths: challengeMeta
});
@@ -115,7 +115,6 @@ const ShowFrontEndProject = (props: ProjectProps) => {
challengeNode: {
challenge: {
challengeType,
fields: { blockName },
forumTopicId,
title,
description,
@@ -172,7 +171,7 @@ const ShowFrontEndProject = (props: ProjectProps) => {
<CompletionModal />
<HelpModal
challengeTitle={title}
challengeBlock={blockName}
challengeBlock={block}
superBlock={superBlock}
/>
</Row>
@@ -201,12 +200,11 @@ export const query = graphql`
block
translationPending
fields {
blockName
slug
tests {
text
testString
}
}
tests {
text
testString
}
}
}

View File

@@ -92,13 +92,14 @@ const ShowQuiz = ({
data: {
challengeNode: {
challenge: {
fields: { tests, blockHashSlug },
fields: { blockHashSlug },
title,
description,
challengeType,
helpCategory,
superBlock,
block,
tests,
translationPending,
quizzes
}
@@ -396,12 +397,7 @@ export const query = graphql`
block
fields {
blockHashSlug
blockName
slug
tests {
text
testString
}
}
quizzes {
questions {
@@ -410,6 +406,10 @@ export const query = graphql`
answer
}
}
tests {
text
testString
}
translationPending
}
}

View File

@@ -57,7 +57,7 @@ type FetchState = {
type ChallengeNode = {
challenge: {
fields: { slug: string; blockName: string };
fields: { slug: string };
id: string;
block: string;
blockLabel: BlockLabel;
@@ -371,7 +371,6 @@ export const query = graphql`
challenge {
fields {
slug
blockName
}
id
block

View File

@@ -17,14 +17,12 @@ function createChallengeNode(
};
if (internal.type === 'ChallengeNode') {
const { tests = [], block, dashedName, superBlock } = challenge;
const { block, dashedName, superBlock } = challenge;
const slug = `/learn/${superBlock}/${block}/${dashedName}`;
const blockHashSlug = `/learn/${superBlock}/#${block}`;
challenge.fields = {
slug,
blockName: block,
tests,
blockHashSlug
};
}

View File

@@ -37,11 +37,9 @@ query {
id
title
description
fields {
tests {
tests {
testString
text
}
}
challengeFiles {
contents
@@ -78,14 +76,14 @@ export function combineChallenges({
id: jsId,
title: jsTitle,
description: jsDescription,
fields: { tests: jsTests },
tests: jsTests,
challengeFiles: jsChallengeFiles
} = jsChallenge;
const {
title: pyTitle,
description: pyDescription,
fields: { tests: pyTests },
tests: pyTests,
challengeFiles: pyChallengeFiles
} = pyChallenge;

View File

@@ -15,12 +15,10 @@ export type Challenge = {
title: string;
date: Date;
description: string;
fields: {
tests: {
testString: string;
text: string;
}[];
};
tests: {
testString: string;
text: string;
}[];
challengeFiles: {
contents: string;
filekey: string;