Skip to content

Commit d1b8330

Browse files
woojiahaokokrui
andauthored
feat(cpex): implement separate flags for CPEx (#3669)
* Fix formatting issues * Enable CPEx flag --------- Co-authored-by: Kok Rui Wong <[email protected]>
1 parent 5945799 commit d1b8330

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

website/src/featureFlags.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export const enableShortUrl = false;
99

1010
/** Enable Course Planning Exercise */
1111
export const enableCPEx = true;
12+
13+
export const showCPExTab = true;

website/src/views/layout/Navtabs.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import produce from 'immer';
33
import React from 'react';
44
import { Provider } from 'react-redux';
55
import { MemoryRouter } from 'react-router-dom';
6-
import { enableCPEx } from 'featureFlags';
6+
import { showCPExTab } from 'featureFlags';
77
import configureStore from 'bootstrapping/configure-store';
88
import reducers from 'reducers';
99
import { initAction } from 'test-utils/redux';
@@ -37,7 +37,7 @@ function make(storeOverrides: Partial<typeof relevantStoreContents> = {}) {
3737
describe(Navtabs, () => {
3838
test('should render into nav element', () => {
3939
make();
40-
if (enableCPEx) {
40+
if (showCPExTab) {
4141
expect(screen.getAllByRole('link').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
4242
[
4343
"Today",
@@ -67,7 +67,7 @@ describe(Navtabs, () => {
6767

6868
test('should show beta tabs if beta is true', () => {
6969
make({ settings: { beta: true } });
70-
if (enableCPEx) {
70+
if (showCPExTab) {
7171
expect(screen.getAllByRole('link').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
7272
[
7373
"Today",

website/src/views/layout/Navtabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
Trello,
1515
} from 'react-feather';
1616

17-
import { enableCPEx } from 'featureFlags';
17+
import { showCPExTab } from 'featureFlags';
1818
import ExternalLink from 'views/components/ExternalLink';
1919
import { timetablePage } from 'views/routes/paths';
2020
import { preload as preloadToday } from 'views/today/TodayContainer';
@@ -52,7 +52,7 @@ const Navtabs: FC = () => {
5252
<BookOpen />
5353
<span className={styles.title}>Courses</span>
5454
</NavLink>
55-
{enableCPEx && (
55+
{showCPExTab && (
5656
<NavLink {...tabProps} to="/cpex">
5757
<Target />
5858
<span className={styles.title}>CPEx</span>

website/src/views/mpe/MpeContainer.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { enableCPEx } from 'featureFlags';
55
import Modal from 'views/components/Modal';
66
import type { MpeSubmission } from 'types/mpe';
77
import ExternalLink from 'views/components/ExternalLink';
8+
import config from 'config';
89
import {
910
getLoginState,
1011
getSSOLink,
@@ -22,6 +23,15 @@ const MpeContainer: React.FC = () => {
2223
const [isModalOpen, setIsModalOpen] = useState(false);
2324
const [isLoggedIn, setIsLoggedIn] = useState(getLoginState(useLocation(), useHistory()));
2425

26+
const ugCPEx = config.modRegSchedule.Undergraduate.find(
27+
({ type: t }) => t === 'Course Planning Exercise (CPEx)',
28+
);
29+
const gdCPEx = config.modRegSchedule.Graduate.find(
30+
({ type: t }) => t === 'Course Planning Exercise (CPEx)',
31+
);
32+
const hasCPEx = ugCPEx && gdCPEx;
33+
const sameTime = hasCPEx && ugCPEx.startDate.getTime() === gdCPEx.startDate.getTime();
34+
2535
const onLogin = useCallback(() => {
2636
setIsGettingSSOLink(true);
2737
return getSSOLink()
@@ -119,7 +129,21 @@ const MpeContainer: React.FC = () => {
119129
) : (
120130
<>
121131
<hr />
122-
<div>CPEx is not open.</div>
132+
{hasCPEx &&
133+
(sameTime ? (
134+
<p>
135+
<strong>CPEx will open on:</strong> {ugCPEx.start}
136+
</p>
137+
) : (
138+
<div>
139+
<p>
140+
<strong>Undergraduate CPEx will open on:</strong> {ugCPEx.start}
141+
</p>
142+
<p>
143+
<strong>Graduate CPEx will open on:</strong> {gdCPEx.start}
144+
</p>
145+
</div>
146+
))}
123147
</>
124148
)}
125149
</div>

0 commit comments

Comments
 (0)