Skip to content

Commit 1f1e6ff

Browse files
refactor(client, curriculum): consolidate is-FSD checks (freeCodeCamp#59598)
1 parent 17800ef commit 1f1e6ff

8 files changed

Lines changed: 37 additions & 23 deletions

File tree

client/src/redux/donation-saga.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { stringifyDonationEvents } from '../utils/analytics-strings';
1919
import { stripe } from '../utils/stripe';
2020
import { PaymentProvider } from '../../../shared/config/donation-settings';
21+
import { chapterBasedSuperBlocks } from '../../../shared/config/curriculum';
2122
import {
2223
getSessionChallengeData,
2324
saveCurrentCount
@@ -52,7 +53,7 @@ function* showDonateModalSaga() {
5253
if (
5354
shouldRequestDonation &&
5455
recentlyClaimedBlock &&
55-
recentlyClaimedBlock.superBlock === 'full-stack-developer'
56+
chapterBasedSuperBlocks.includes(recentlyClaimedBlock.superBlock)
5657
) {
5758
yield put(preventBlockDonationRequests());
5859
} else if (shouldRequestDonation || isModalRecentlyShown) {

client/src/templates/Introduction/components/block.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { createSelector } from 'reselect';
88
import { Spacer } from '@freecodecamp/ui';
99

1010
import { challengeTypes } from '../../../../../shared/config/challenge-types';
11-
import { SuperBlocks } from '../../../../../shared/config/curriculum';
11+
import {
12+
chapterBasedSuperBlocks,
13+
SuperBlocks
14+
} from '../../../../../shared/config/curriculum';
1215
import envData from '../../../../config/env.json';
1316
import { isAuditedSuperBlock } from '../../../../../shared/utils/is-audited';
1417
import Caret from '../../../assets/icons/caret';
@@ -407,7 +410,7 @@ class Block extends Component<BlockProps> {
407410
!isEmptyBlock && (
408411
<>
409412
{layoutToComponent[blockLayout]}
410-
{superBlock !== SuperBlocks.FullStackDeveloper && (
413+
{!chapterBasedSuperBlocks.includes(superBlock) && (
411414
<Spacer size='xs' />
412415
)}
413416
</>

client/src/templates/Introduction/super-block-intro.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { bindActionCreators, Dispatch } from 'redux';
1111
import { createSelector } from 'reselect';
1212
import { Container, Col, Row, Spacer } from '@freecodecamp/ui';
1313

14-
import { SuperBlocks } from '../../../../shared/config/curriculum';
14+
import {
15+
chapterBasedSuperBlocks,
16+
SuperBlocks
17+
} from '../../../../shared/config/curriculum';
1518
import DonateModal from '../../components/Donation/donation-modal';
1619
import Login from '../../components/Header/components/login';
1720
import Map from '../../components/Map';
@@ -172,8 +175,6 @@ const SuperBlockIntroductionPage = (props: SuperBlockProps) => {
172175
cert => superBlockToCertMap[superBlock] === cert.certSlug
173176
);
174177

175-
const superBlockWithAccordionView = [SuperBlocks.FullStackDeveloper];
176-
177178
const getInitiallyExpandedBlock = (): string => {
178179
// if coming from breadcrumb click
179180
if (
@@ -258,7 +259,7 @@ const SuperBlockIntroductionPage = (props: SuperBlockProps) => {
258259
{t(`intro:misc-text.courses`)}
259260
</h2>
260261
<Spacer size='m' />
261-
{superBlockWithAccordionView.includes(superBlock) ? (
262+
{chapterBasedSuperBlocks.includes(superBlock) ? (
262263
<SuperBlockAccordion
263264
challenges={superBlockChallenges}
264265
superBlock={superBlock}

curriculum/get-challenges.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {
1515

1616
const { isAuditedSuperBlock } = require('../shared/utils/is-audited');
1717
const { createPoly } = require('../shared/utils/polyvinyl');
18+
const { chapterBasedSuperBlocks } = require('../shared/config/curriculum');
1819
const {
1920
getSuperOrder,
2021
getSuperBlockFromDir,
@@ -287,16 +288,12 @@ async function buildChallenges({ path: filePath }, curriculum, lang) {
287288
challengeBlock.challenges = [...challengeBlock.challenges, challenge];
288289
}
289290

290-
function isSuperBlockWithChapters(superBlock) {
291-
return superBlock === 'full-stack-developer';
292-
}
293-
294291
// This is a slightly weird abstraction, but it lets us define helper functions
295292
// without passing around a ton of arguments.
296293
function generateChallengeCreator(lang, englishPath, i18nPath) {
297294
function addMetaToChallenge(challenge, meta) {
298295
function addChapterAndModuleToChallenge(challenge) {
299-
if (isSuperBlockWithChapters(challenge.superBlock)) {
296+
if (chapterBasedSuperBlocks.includes(challenge.superBlock)) {
300297
challenge.chapter = getChapterFromBlock(
301298
challenge.block,
302299
fullStackSuperBlockStructure
@@ -329,7 +326,7 @@ function generateChallengeCreator(lang, englishPath, i18nPath) {
329326
challenge.blockType = meta.blockType;
330327
challenge.blockLayout = meta.blockLayout;
331328
challenge.hasEditableBoundaries = !!meta.hasEditableBoundaries;
332-
challenge.order = isSuperBlockWithChapters(meta.superBlock)
329+
challenge.order = chapterBasedSuperBlocks.includes(meta.superBlock)
333330
? getBlockOrder(meta.dashedName, fullStackSuperBlockStructure)
334331
: meta.order;
335332

curriculum/schema/challenge-schema.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const Joi = require('joi');
22
Joi.objectId = require('joi-objectid')(Joi);
33

44
const { challengeTypes } = require('../../shared/config/challenge-types');
5-
const { SuperBlocks } = require('../../shared/config/curriculum');
5+
const {
6+
SuperBlocks,
7+
chapterBasedSuperBlocks
8+
} = require('../../shared/config/curriculum');
69
const {
710
availableCharacters,
811
availableBackgrounds,
@@ -128,7 +131,7 @@ const schema = Joi.object()
128131
block: Joi.string().regex(slugRE).required(),
129132
blockId: Joi.objectId(),
130133
blockType: Joi.when('superBlock', {
131-
is: [SuperBlocks.FullStackDeveloper],
134+
is: chapterBasedSuperBlocks,
132135
then: Joi.valid(
133136
'workshop',
134137
'lab',
@@ -151,7 +154,7 @@ const schema = Joi.object()
151154
).required(),
152155
challengeOrder: Joi.number(),
153156
chapter: Joi.string().when('superBlock', {
154-
is: 'full-stack-developer',
157+
is: chapterBasedSuperBlocks,
155158
then: Joi.required(),
156159
otherwise: Joi.optional()
157160
}),
@@ -211,7 +214,7 @@ const schema = Joi.object()
211214
isLocked: Joi.bool(),
212215
isPrivate: Joi.bool(),
213216
module: Joi.string().when('superBlock', {
214-
is: 'full-stack-developer',
217+
is: chapterBasedSuperBlocks,
215218
then: Joi.required(),
216219
otherwise: Joi.optional()
217220
}),

curriculum/schema/meta-schema.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const Joi = require('joi');
22

3-
const { SuperBlocks } = require('../../shared/config/curriculum');
3+
const {
4+
SuperBlocks,
5+
chapterBasedSuperBlocks
6+
} = require('../../shared/config/curriculum');
47

58
const slugRE = new RegExp('^[a-z0-9-]+$');
69
const slugWithSlashRE = new RegExp('^[a-z0-9-/]+$');
@@ -33,7 +36,7 @@ const schema = Joi.object()
3336
.valid(...Object.values(SuperBlocks))
3437
.required(),
3538
order: Joi.number().when('superBlock', {
36-
is: 'full-stack-developer',
39+
is: chapterBasedSuperBlocks,
3740
then: Joi.forbidden(),
3841
otherwise: Joi.required()
3942
}),

curriculum/test/test-challenges.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const {
5151
createContent,
5252
testId
5353
} = require('../../client/src/templates/Challenges/utils/frame');
54-
const { SuperBlocks } = require('../../shared/config/curriculum');
54+
const {
55+
SuperBlocks,
56+
chapterBasedSuperBlocks
57+
} = require('../../shared/config/curriculum');
5558
const ChallengeTitles = require('./utils/challenge-titles');
5659
const MongoIds = require('./utils/mongo-ids');
5760
const createPseudoWorker = require('./utils/pseudo-worker');
@@ -313,11 +316,11 @@ function populateTestsForLang({ lang, challenges, meta, superBlocks }) {
313316
);
314317
});
315318
filteredMeta.forEach((meta, index) => {
316-
// Upcoming changes are in developmen so are not required to be in
317-
// order. FullStackDeveloper does not use the meta for order.
319+
// Upcoming changes are in development so are not required to be in
320+
// order. Chapter-based super blocks do not use the meta for order.
318321
if (
319322
!meta.isUpcomingChange &&
320-
meta.superBlock !== SuperBlocks.FullStackDeveloper
323+
!chapterBasedSuperBlocks.includes(meta.superBlock)
321324
) {
322325
it(`${meta.superBlock} ${meta.name} must be in order`, function () {
323326
assert.equal(meta.order, index);

shared/config/curriculum.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ export const notAuditedSuperBlocks: NotAuditedSuperBlocks = {
240240

241241
Object.freeze(notAuditedSuperBlocks);
242242

243+
export const chapterBasedSuperBlocks = [SuperBlocks.FullStackDeveloper];
244+
Object.freeze(chapterBasedSuperBlocks);
245+
243246
type Config = {
244247
showUpcomingChanges: boolean;
245248
};

0 commit comments

Comments
 (0)