Skip to content

Commit 3c2c1e1

Browse files
gnimnixjloh02
andauthored
Enable CPEx on non-production environments (#4063)
* renamed feature flag to fit context * added CPEx to config while checking type of environment * updated source for show CPEx config * Change condition for enableCPEx to allow all non-production This makes the variable for enableCPExforProd clearer, as well as to allow easy UI testing. Nonetheless, backend testing with API is still not possible other than on prod and cpex-staging * Update maintenance docs for CPEx --------- Co-authored-by: Jonathan Loh <[email protected]>
1 parent bb4516f commit 3c2c1e1

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

MAINTENANCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Reference PRs: [PR #3286](https://github.com/nusmodifications/nusmods/pull/3286)
3030
- [ ] Update `TERM` in `scrapers/cpex-scraper/src/index.ts` and `MPE_SEMESTER` in `website/src/views/mpe/constants.ts` to be the semester you're configuring CPEx for (usually the next semester)
3131
- [ ] Update the displayed dates in `website/src/views/mpe/MpeContainer.tsx` and any new requirements/descriptions
3232
- [ ] Update dates in the ModReg schedule in `website/src/data/modreg-schedule.json`
33-
- [ ] Enable the `enabledCPEx` and `showCPExTab` flags in `website/src/featureFlags.ts`
33+
- [ ] Enable the `enableCPExforProd` and `showCPExTab` flags in `website/src/featureFlags.ts`
3434
- [ ] Push onto `cpex-staging` branch (Ensure synced with `master` branch first), then visit https://cpex-staging.nusmods.com/cpex and verify that NUS authentication is working
3535
- During
3636
- [ ] Merge `cpex-staging` into `master`
3737
- [ ] Deploy latest `master` to `production`
3838
- After
39-
- [ ] Disable the `enabledCPEx` and `showCPExTab` flags in `website/src/featureFlags.ts`
39+
- [ ] Disable the `enableCPExforProd` and `showCPExTab` flags in `website/src/featureFlags.ts`
4040
- [ ] Merge into `master`
4141
- [ ] Deploy latest `master` to `production`

website/src/config/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AcadYear, Semester } from 'types/modules';
66
import holidays from 'data/holidays.json';
77
import modRegData from 'data/modreg-schedule.json';
88
import appConfig from './app-config.json';
9+
import { enableCPExforProd } from '../featureFlags';
910

1011
export const regPeriods = [
1112
'Select Courses',
@@ -70,6 +71,8 @@ export type Config = {
7071
holidays: Date[];
7172

7273
modRegSchedule: { [type in ScheduleType]: RegPeriod[] };
74+
75+
enableCPEx: boolean;
7376
};
7477

7578
export function convertModRegDates(roundData: (typeof modRegData)[ScheduleType]): RegPeriod[] {
@@ -97,6 +100,8 @@ const augmentedConfig: Config = {
97100
*/
98101
getSemesterKey: (): string =>
99102
`${augmentedConfig.academicYear} ${augmentedConfig.semesterNames[augmentedConfig.semester]}`,
103+
104+
enableCPEx: enableCPExforProd || NUSMODS_ENV !== 'production',
100105
};
101106

102107
export default augmentedConfig;

website/src/featureFlags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable import/prefer-default-export */
22

33
/** Enable Course Planning Exercise */
4-
export const enableCPEx = false;
4+
export const enableCPExforProd = false;
55

66
export const showCPExTab = false;

website/src/serverless/mpe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios, { AxiosHeaders } from 'axios';
2-
import { enableCPEx } from '../featureFlags';
32
import { MpeSubmission, MpePreference, MODULE_TYPES } from '../types/mpe';
43
import type { Handler } from './handler';
4+
import config from '../config';
55

66
const vfsEndpoint = process.env.NUS_VFS_MPE_ENDPOINT;
77
const defaultHeaders = new AxiosHeaders({
@@ -104,7 +104,7 @@ const validatePreferences = (preferences: MpePreference[]): boolean =>
104104
export const featureFlagEnablerMiddleware =
105105
(next: Handler): Handler =>
106106
async (req, res): Promise<void> => {
107-
if (!enableCPEx) {
107+
if (!config.enableCPEx) {
108108
res.status(404).end();
109109
return;
110110
}

website/src/views/mpe/MpeContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useCallback, useState } from 'react';
22
import { useLocation, useHistory } from 'react-router-dom';
33
import classnames from 'classnames';
4-
import { enableCPEx } from 'featureFlags';
54
import Modal from 'views/components/Modal';
65
import type { MpeSubmission } from 'types/mpe';
76
import ExternalLink from 'views/components/ExternalLink';
@@ -31,6 +30,7 @@ const MpeContainer: React.FC = () => {
3130
);
3231
const hasCPEx = ugCPEx && gdCPEx;
3332
const sameTime = hasCPEx && ugCPEx.startDate.getTime() === gdCPEx.startDate.getTime();
33+
const { enableCPEx } = config;
3434

3535
const onLogin = useCallback(() => {
3636
setIsGettingSSOLink(true);

0 commit comments

Comments
 (0)