Skip to content

Commit 868c4d0

Browse files
author
Ben Warzeski
authored
Merge pull request #22 from Syed-Ali-Abbas-Zaidi/Ali-Abbas/react-router-upgrade
feat: upgrade react router to v6
2 parents 808388e + bc61962 commit 868c4d0

File tree

5 files changed

+60
-88
lines changed

5 files changed

+60
-88
lines changed

package-lock.json

Lines changed: 35 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@edx/brand": "npm:@edx/[email protected]",
3737
"@edx/frontend-component-footer": "12.2.1",
3838
"@edx/frontend-component-header": "4.6.0",
39-
"@edx/frontend-platform": "4.6.3",
39+
"@edx/frontend-platform": "5.1.0",
4040
"@edx/paragon": "^20.20.0",
4141
"@edx/react-unit-test-utils": "1.7.0",
4242
"@edx/tinymce-language-selector": "1.1.0",
@@ -58,8 +58,8 @@
5858
"react": "^17.0.2",
5959
"react-dom": "^17.0.2",
6060
"react-redux": "7.2.9",
61-
"react-router": "5.3.4",
62-
"react-router-dom": "5.3.4",
61+
"react-router": "6.15.0",
62+
"react-router-dom": "6.15.0",
6363
"redux": "4.2.1",
6464
"redux-devtools-extension": "^2.13.9",
6565
"redux-logger": "^3.0.6",

src/App.jsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
1+
import { Routes, Route } from 'react-router-dom';
22
import { ErrorPage } from '@edx/frontend-platform/react';
33
import { useIntl } from '@edx/frontend-platform/i18n';
44

@@ -13,25 +13,13 @@ const RouterRoot = () => {
1313
const { formatMessage } = useIntl();
1414

1515
return (
16-
<Router>
17-
<Switch>
18-
<Route path={routes.peerAssessment}>
19-
<PeerAssessmentView />
20-
</Route>
21-
<Route path={routes.selfAssessment}>
22-
<SelfAssessmentView />
23-
</Route>
24-
<Route path={routes.studentTraining}>
25-
<StudentTrainingView />
26-
</Route>
27-
<Route path={routes.submission}>
28-
<SubmissionView />
29-
</Route>
30-
<Route path={routes.root}>
31-
<ErrorPage message={formatMessage(messages.error404Message)} />
32-
</Route>
33-
</Switch>
34-
</Router>
16+
<Routes>
17+
<Route path={routes.peerAssessment} element={<PeerAssessmentView />} />
18+
<Route path={routes.selfAssessment} element={<SelfAssessmentView />} />
19+
<Route path={routes.studentTraining} element={<StudentTrainingView />} />
20+
<Route path={routes.submission} element={<SubmissionView />} />
21+
<Route path={routes.root} element={<ErrorPage message={formatMessage(messages.error404Message)} />} />
22+
</Routes>
3523
);
3624
};
3725

src/data/services/lms/hooks/api.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery } from '@tanstack/react-query';
2-
import { useRouteMatch } from 'react-router-dom';
2+
import { useMatch } from 'react-router-dom';
33
import { camelCaseObject } from '@edx/frontend-platform';
44
import { when } from 'jest-when';
55

@@ -12,7 +12,7 @@ import { useORAConfig, usePageData } from './api';
1212

1313
jest.mock('@tanstack/react-query', () => ({ useQuery: jest.fn() }));
1414

15-
jest.mock('react-router-dom', () => ({ useRouteMatch: jest.fn() }));
15+
jest.mock('react-router-dom', () => ({ useMatch: jest.fn() }));
1616

1717
interface QueryFn { (): string }
1818
interface QueryArgs { queryKey: string, queryFn: QueryFn }
@@ -52,8 +52,8 @@ describe('lms api hooks', () => {
5252
});
5353
it('initializes query with promise pointing to assessment text', async () => {
5454
const old = window.location;
55-
Object.defineProperty(window, "location", {
56-
value: new URL(`http://dummy.com/text`),
55+
Object.defineProperty(window, 'location', {
56+
value: new URL('http://dummy.com/text'),
5757
writable: true,
5858
});
5959
const response = await out.queryFn();
@@ -86,16 +86,16 @@ describe('lms api hooks', () => {
8686
.mockImplementationOnce(mockUseQuery(data));
8787
};
8888

89-
const mockUseRouteMatch = (path) => {
90-
when(useRouteMatch)
91-
.calledWith()
92-
.mockReturnValueOnce({ path });
89+
const mockUseMatch = (path) => {
90+
when(useMatch)
91+
.calledWith(path)
92+
.mockReturnValueOnce({ pattern: { path } });
9393
};
9494

9595
const testUsePageData = usePageData as unknown as MockPageDataUseConfigHook;
9696
describe('submission', () => {
9797
beforeEach(() => {
98-
mockUseRouteMatch(routes.submission);
98+
mockUseMatch(routes.submission);
9999
mockUseQueryForPageData(fakeData.pageData.shapes.emptySubmission, false);
100100
out = testUsePageData();
101101
});
@@ -112,7 +112,7 @@ describe('lms api hooks', () => {
112112
});
113113
describe('assessment', () => {
114114
beforeEach(() => {
115-
mockUseRouteMatch(routes.peerAssessment);
115+
mockUseMatch(routes.peerAssessment);
116116
mockUseQueryForPageData(fakeData.pageData.shapes.peerAssessment, true);
117117
out = testUsePageData();
118118
});
@@ -128,7 +128,7 @@ describe('lms api hooks', () => {
128128
});
129129
});
130130
it('returns empty object from data if data has not been returned', () => {
131-
mockUseRouteMatch(routes.submission);
131+
mockUseMatch(routes.submission);
132132
mockUseQueryForPageData(undefined, false);
133133
out = testUsePageData();
134134
expect(out.data).toEqual({});

src/data/services/lms/hooks/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from '@tanstack/react-query';
22

3-
import { useRouteMatch } from 'react-router-dom';
3+
import { useMatch } from 'react-router-dom';
44
import { camelCaseObject } from '@edx/frontend-platform';
55

66
import routes from 'routes';
@@ -24,8 +24,8 @@ export const useORAConfig = (): types.QueryData<types.ORAConfig> => {
2424
};
2525

2626
export const usePageData = (): types.QueryData<types.PageData> => {
27-
const route = useRouteMatch();
28-
const isAssessment = route.path === routes.peerAssessment;
27+
const route = useMatch(routes.peerAssessment);
28+
const isAssessment = !!route && route.pattern.path === routes.peerAssessment;
2929
const returnData = isAssessment
3030
? fakeData.pageData.shapes.peerAssessment
3131
: fakeData.pageData.shapes.emptySubmission;

0 commit comments

Comments
 (0)