diff --git a/client/gatsby-node.js b/client/gatsby-node.js index b7d96010ef..6fa003143a 100644 --- a/client/gatsby-node.js +++ b/client/gatsby-node.js @@ -20,13 +20,6 @@ const createByIdentityMap = { exports.onCreateNode = function onCreateNode({ node, actions, getNode }) { const { createNodeField } = actions; - if (node.internal.type === 'ChallengeNode') { - const { tests = [], block, dashedName, superBlock } = node; - const slug = `/learn/${superBlock}/${block}/${dashedName}`; - createNodeField({ node, name: 'slug', value: slug }); - createNodeField({ node, name: 'blockName', value: blockNameify(block) }); - createNodeField({ node, name: 'tests', value: tests }); - } if (node.internal.type === 'MarkdownRemark') { const slug = createFilePath({ node, getNode }); @@ -71,37 +64,45 @@ exports.createPages = function createPages({ graphql, actions, reporter }) { graphql(` { allChallengeNode( - sort: { fields: [superOrder, order, challengeOrder] } + sort: { + fields: [ + challenge___superOrder + challenge___order + challenge___challengeOrder + ] + } ) { edges { node { - block - challengeType - fields { - slug + challenge { + block + challengeType + fields { + slug + } + id + order + required { + link + src + } + challengeOrder + challengeFiles { + name + ext + contents + head + tail + } + solutions { + contents + ext + } + superBlock + superOrder + template + usesMultifileEditor } - id - order - required { - link - src - } - challengeOrder - challengeFiles { - name - ext - contents - head - tail - } - solutions { - contents - ext - } - superBlock - superOrder - template - usesMultifileEditor } } } @@ -137,12 +138,22 @@ exports.createPages = function createPages({ graphql, actions, reporter }) { ); const blocks = uniq( - result.data.allChallengeNode.edges.map(({ node: { block } }) => block) + result.data.allChallengeNode.edges.map( + ({ + node: { + challenge: { block } + } + }) => block + ) ).map(block => blockNameify(block)); const superBlocks = uniq( result.data.allChallengeNode.edges.map( - ({ node: { superBlock } }) => superBlock + ({ + node: { + challenge: { superBlock } + } + }) => superBlock ) ); @@ -256,6 +267,9 @@ exports.createSchemaCustomization = ({ actions }) => { const { createTypes } = actions; const typeDefs = ` type ChallengeNode implements Node { + challenge: Challenge + } + type Challenge { challengeFiles: [FileContents] notes: String url: String diff --git a/client/plugins/fcc-source-challenges/create-challenge-nodes.js b/client/plugins/fcc-source-challenges/create-challenge-nodes.js index 394364f033..7e5e80b27b 100644 --- a/client/plugins/fcc-source-challenges/create-challenge-nodes.js +++ b/client/plugins/fcc-source-challenges/create-challenge-nodes.js @@ -1,4 +1,5 @@ const crypto = require('crypto'); +const { blockNameify } = require('../../../utils/block-nameify'); function createChallengeNode(challenge, reporter) { // challengeType 11 is for video challenges (they only have instructions) @@ -31,6 +32,17 @@ function createChallengeNode(challenge, reporter) { type: challenge.challengeType === 7 ? 'CertificateNode' : 'ChallengeNode' }; + if (internal.type === 'ChallengeNode') { + const { tests = [], block, dashedName, superBlock } = challenge; + const slug = `/learn/${superBlock}/${block}/${dashedName}`; + + challenge.fields = { + slug, + blockName: blockNameify(block), + tests + }; + } + return JSON.parse( JSON.stringify( Object.assign( @@ -41,7 +53,8 @@ function createChallengeNode(challenge, reporter) { internal, sourceInstanceName: 'challenge' }, - challenge + { challenge }, + { id: crypto.randomUUID() } ) ) ); diff --git a/client/src/__mocks__/challenge-nodes.js b/client/src/__mocks__/challenge-nodes.js index 87f4ef28ed..6a4ce63b0e 100644 --- a/client/src/__mocks__/challenge-nodes.js +++ b/client/src/__mocks__/challenge-nodes.js @@ -1,136 +1,158 @@ const mockChallengeNodes = [ { - fields: { - slug: '/super-block-one/block-a/challenge-one', - blockName: 'Block A' - }, - id: 'a', - block: 'block-a', - title: 'Challenge One', - isPrivate: false, - superBlock: 'super-block-one', - dashedName: 'challenge-one' + challenge: { + fields: { + slug: '/super-block-one/block-a/challenge-one', + blockName: 'Block A' + }, + id: 'a', + block: 'block-a', + title: 'Challenge One', + isPrivate: false, + superBlock: 'super-block-one', + dashedName: 'challenge-one' + } }, { - fields: { - slug: '/super-block-one/block-a/challenge-two', - blockName: 'Block A' - }, - id: 'b', - block: 'block-a', - title: 'Challenge Two', - isPrivate: false, - superBlock: 'super-block-one', - dashedName: 'challenge-two' + challenge: { + fields: { + slug: '/super-block-one/block-a/challenge-two', + blockName: 'Block A' + }, + id: 'b', + block: 'block-a', + title: 'Challenge Two', + isPrivate: false, + superBlock: 'super-block-one', + dashedName: 'challenge-two' + } }, { - fields: { - slug: '/super-block-one/block-b/challenge-one', - blockName: 'Block B' - }, - id: 'c', - block: 'block-b', - title: 'Challenge One', - isPrivate: false, - superBlock: 'super-block-one', - dashedName: 'challenge-one' + challenge: { + fields: { + slug: '/super-block-one/block-b/challenge-one', + blockName: 'Block B' + }, + id: 'c', + block: 'block-b', + title: 'Challenge One', + isPrivate: false, + superBlock: 'super-block-one', + dashedName: 'challenge-one' + } }, { - fields: { - slug: '/super-block-one/block-b/challenge-two', - blockName: 'Block B' - }, + challenge: { + fields: { + slug: '/super-block-one/block-b/challenge-two', + blockName: 'Block B' + }, - id: 'd', - block: 'block-b', - title: 'Challenge Two', - isPrivate: false, - superBlock: 'super-block-one', - dashedName: 'challenge-two' + id: 'd', + block: 'block-b', + title: 'Challenge Two', + isPrivate: false, + superBlock: 'super-block-one', + dashedName: 'challenge-two' + } }, { - fields: { - slug: '/super-block-one/block-c/challenge-one', - blockName: 'Block C' - }, - id: 'e', - block: 'block-c', - title: 'Challenge One', - isPrivate: true, - superBlock: 'super-block-one', - dashedName: 'challenge-one' + challenge: { + fields: { + slug: '/super-block-one/block-c/challenge-one', + blockName: 'Block C' + }, + id: 'e', + block: 'block-c', + title: 'Challenge One', + isPrivate: true, + superBlock: 'super-block-one', + dashedName: 'challenge-one' + } }, { - fields: { - slug: '/super-block-two/block-a/challenge-one', - blockName: 'Block A' - }, - id: 'f', - block: 'block-a', - title: 'Challenge One', - isPrivate: false, - superBlock: 'super-block-two', - dashedName: 'challenge-one' + challenge: { + fields: { + slug: '/super-block-two/block-a/challenge-one', + blockName: 'Block A' + }, + id: 'f', + block: 'block-a', + title: 'Challenge One', + isPrivate: false, + superBlock: 'super-block-two', + dashedName: 'challenge-one' + } }, { - fields: { - slug: '/super-block-two/block-a/challenge-two', - blockName: 'Block A' - }, - id: 'g', - block: 'block-a', - title: 'Challenge Two', - isPrivate: false, - superBlock: 'super-block-two', - dashedName: 'challenge-two' + challenge: { + fields: { + slug: '/super-block-two/block-a/challenge-two', + blockName: 'Block A' + }, + id: 'g', + block: 'block-a', + title: 'Challenge Two', + isPrivate: false, + superBlock: 'super-block-two', + dashedName: 'challenge-two' + } }, { - fields: { - slug: '/super-block-two/block-b/challenge-one', - blockName: 'Block B' - }, - id: 'h', - block: 'block-b', - title: 'Challenge One', - isPrivate: false, - superBlock: 'super-block-two', - dashedName: 'challenge-one' + challenge: { + fields: { + slug: '/super-block-two/block-b/challenge-one', + blockName: 'Block B' + }, + id: 'h', + block: 'block-b', + title: 'Challenge One', + isPrivate: false, + superBlock: 'super-block-two', + dashedName: 'challenge-one' + } }, { - fields: { - slug: '/super-block-two/block-b/challenge-two', - blockName: 'Block B' - }, - id: 'i', - block: 'block-b', - title: 'Challenge Two', - isPrivate: false, - superBlock: 'super-block-two', - dashedName: 'challenge-two' + challenge: { + fields: { + slug: '/super-block-two/block-b/challenge-two', + blockName: 'Block B' + }, + id: 'i', + block: 'block-b', + title: 'Challenge Two', + isPrivate: false, + superBlock: 'super-block-two', + dashedName: 'challenge-two' + } }, { - fields: { - slug: '/super-block-three/block-a/challenge-one', - blockName: 'Block A' - }, - id: 'j', - block: 'block-a', - title: 'Challenge One', - isPrivate: false, - superBlock: 'super-block-three', - dashedName: 'challenge-one' + challenge: { + fields: { + slug: '/super-block-three/block-a/challenge-one', + blockName: 'Block A' + }, + id: 'j', + block: 'block-a', + title: 'Challenge One', + isPrivate: false, + superBlock: 'super-block-three', + dashedName: 'challenge-one' + } }, { - fields: { - slug: '/super-block-three/block-c/challenge-two', - blockName: 'Block C' - }, - id: 'k', - block: 'block-c', - title: 'Challenge Two', - isPrivate: false, - superBlock: 'super-block-three', - dashedName: 'challenge-two' + challenge: { + fields: { + slug: '/super-block-three/block-c/challenge-two', + blockName: 'Block C' + }, + id: 'k', + block: 'block-c', + title: 'Challenge Two', + isPrivate: false, + superBlock: 'super-block-three', + dashedName: 'challenge-two' + } } ]; diff --git a/client/src/components/Map/index.tsx b/client/src/components/Map/index.tsx index 024a739156..6988f52487 100644 --- a/client/src/components/Map/index.tsx +++ b/client/src/components/Map/index.tsx @@ -42,19 +42,19 @@ const linkSpacingStyle = { function renderLandingMap(nodes: ChallengeNode[]) { nodes = nodes.filter( - node => node.superBlock !== SuperBlocks.CodingInterviewPrep + ({ challenge }) => challenge.superBlock !== SuperBlocks.CodingInterviewPrep ); return (