Skip to content

Commit 45b33c3

Browse files
committed
Upgrading React Router to 6.x.
1 parent 9430f3d commit 45b33c3

File tree

73 files changed

+1051
-1574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1051
-1574
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
"react-intl": "6.4.4",
8080
"react-motion": "^0.5.2",
8181
"react-redux": "^8.1.2",
82-
"react-router": "^5.3.4",
83-
"react-router-dom": "^5.3.4",
82+
"react-router": "^6.14.2",
83+
"react-router-dom": "^6.14.2",
8484
"react-syntax-highlighter": "^15.5.0",
8585
"react-toggle": "4.1.3",
8686
"redux": "^4.2.1",

src/components/Assignments/Assignment/AssignmentsTable/AssignmentsTable.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
33
import ImmutablePropTypes from 'react-immutable-proptypes';
44
import { Table, Modal } from 'react-bootstrap';
55
import { FormattedMessage, injectIntl } from 'react-intl';
6-
import { withRouter } from 'react-router';
76
import { defaultMemoize } from 'reselect';
87
import moment from 'moment';
98

@@ -18,6 +17,8 @@ import { UserUIDataContext } from '../../../../helpers/contexts';
1817
import { EMPTY_LIST, EMPTY_OBJ, EMPTY_ARRAY } from '../../../../helpers/common';
1918
import { prepareInitialValues, transformSubmittedData } from '../../../forms/EditAssignmentForm';
2019

20+
import withRouter, { withRouterProps } from '../../../../helpers/withRouter';
21+
2122
const fetchAssignmentStatus = (statuses, assignmentId) => {
2223
const assignStatus =
2324
statuses && Array.isArray(statuses) ? statuses.find(assignStatus => assignStatus.id === assignmentId) : null;
@@ -182,7 +183,7 @@ class AssignmentsTable extends Component {
182183
editAssignment = null,
183184
deleteAssignment = null,
184185
intl: { locale },
185-
history: { push },
186+
navigate,
186187
} = this.props;
187188
const someAssignmentsAreLoading = assignments.some(isLoading);
188189
const assignmentsPreprocessedAll = assignments
@@ -297,7 +298,7 @@ class AssignmentsTable extends Component {
297298
discussionOpen={() => this.openDialog(assignment)}
298299
setSelected={multiActions ? this.selectAssignmentClickHandler(assignmentsPreprocessedAll) : null}
299300
selected={Boolean(this.state.selectedAssignments[assignment.id])}
300-
doubleClickPush={openOnDoubleclick ? push : null}
301+
doubleClickPush={openOnDoubleclick ? navigate : null}
301302
/>
302303
))}
303304
</tbody>
@@ -479,9 +480,7 @@ AssignmentsTable.propTypes = {
479480
editAssignment: PropTypes.func,
480481
deleteAssignment: PropTypes.func,
481482
intl: PropTypes.object.isRequired,
482-
history: PropTypes.shape({
483-
push: PropTypes.func.isRequired,
484-
}),
483+
navigate: withRouterProps.navigate,
485484
};
486485

487486
export default withRouter(injectIntl(AssignmentsTable));

src/components/Assignments/ShadowAssignment/ShadowAssignmentsTable/ShadowAssignmentsTable.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import ImmutablePropTypes from 'react-immutable-proptypes';
44
import { Table } from 'react-bootstrap';
5-
import { withRouter } from 'react-router';
65
import { FormattedMessage, injectIntl } from 'react-intl';
76

87
import { isReady, isLoading, getJsData } from '../../../../redux/helpers/resourceManager';
@@ -11,14 +10,15 @@ import { compareShadowAssignments } from '../../../helpers/assignments';
1110
import { LoadingIcon } from '../../../icons';
1211
import { UserUIDataContext } from '../../../../helpers/contexts';
1312
import { EMPTY_LIST, EMPTY_OBJ } from '../../../../helpers/common';
13+
import withRouter, { withRouterProps } from '../../../../helpers/withRouter';
1414

1515
const ShadowAssignmentsTable = ({
1616
shadowAssignments = EMPTY_LIST,
1717
userId,
1818
stats = EMPTY_OBJ,
1919
isAdmin = false,
2020
intl: { locale },
21-
history: { push },
21+
navigate,
2222
}) => (
2323
<UserUIDataContext.Consumer>
2424
{({ openOnDoubleclick = false }) => (
@@ -93,7 +93,7 @@ const ShadowAssignmentsTable = ({
9393
Object.keys(stats).length !== 0 ? stats.assignments.find(item => item.id === assignment.id) : null
9494
}
9595
isAdmin={isAdmin}
96-
doubleClickPush={openOnDoubleclick ? push : null}
96+
doubleClickPush={openOnDoubleclick ? navigate : null}
9797
/>
9898
))}
9999
</tbody>
@@ -108,9 +108,7 @@ ShadowAssignmentsTable.propTypes = {
108108
stats: PropTypes.object,
109109
isAdmin: PropTypes.bool,
110110
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired,
111-
history: PropTypes.shape({
112-
push: PropTypes.func.isRequired,
113-
}),
111+
navigate: withRouterProps.navigate,
114112
};
115113

116114
export default withRouter(injectIntl(ShadowAssignmentsTable));

src/components/Assignments/SolutionsTable/SolutionsTable.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import ImmutablePropTypes from 'react-immutable-proptypes';
44
import { FormattedMessage } from 'react-intl';
55
import { Table } from 'react-bootstrap';
6-
import { withRouter } from 'react-router';
6+
import { useNavigate } from 'react-router-dom';
77
import { defaultMemoize } from 'reselect';
88

99
import NoSolutionYetTableRow from './NoSolutionYetTableRow';
@@ -29,8 +29,8 @@ const SolutionsTable = ({
2929
assignmentSolversLoading = false,
3030
showActionButtons = true,
3131
onSelect = null,
32-
history: { push },
3332
}) => {
33+
const navigate = useNavigate();
3434
const highlightsIndex = createHighlightsIndex(highlights);
3535

3636
return (
@@ -141,7 +141,7 @@ const SolutionsTable = ({
141141
highlighted={highlightsIndex.has(id)}
142142
showActionButtons={showActionButtons}
143143
onSelect={onSelect}
144-
doubleclickAction={openOnDoubleclick ? push : null}
144+
doubleclickAction={openOnDoubleclick ? navigate : null}
145145
{...data}
146146
/>
147147
);
@@ -166,9 +166,6 @@ SolutionsTable.propTypes = {
166166
assignmentSolversLoading: PropTypes.bool,
167167
showActionButtons: PropTypes.bool,
168168
onSelect: PropTypes.func,
169-
history: PropTypes.shape({
170-
push: PropTypes.func.isRequired,
171-
}),
172169
};
173170

174-
export default withRouter(SolutionsTable);
171+
export default SolutionsTable;

src/components/Exercises/ExercisesList/ExercisesList.js

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { Table } from 'react-bootstrap';
44
import { FormattedMessage } from 'react-intl';
5-
import { withRouter } from 'react-router';
5+
import { useNavigate } from 'react-router-dom';
66

77
import ExercisesListItem from '../ExercisesListItem';
88
import { LoadingIcon } from '../../icons';
@@ -15,46 +15,51 @@ const ExercisesList = ({
1515
showAssignButton = false,
1616
assignExercise = null,
1717
reload,
18-
history: { push },
19-
}) => (
20-
<UserUIDataContext.Consumer>
21-
{({ openOnDoubleclick = false }) => (
22-
<Table hover>
23-
{Boolean(heading) && <thead>{heading}</thead>}
24-
<tbody>
25-
{exercises.map((exercise, idx) =>
26-
exercise ? (
27-
<ExercisesListItem
28-
{...exercise}
29-
showGroups={showGroups}
30-
showAssignButton={showAssignButton}
31-
assignExercise={assignExercise}
32-
key={exercise ? exercise.id : idx}
33-
reload={reload}
34-
doubleClickPush={openOnDoubleclick ? push : null}
35-
/>
36-
) : (
37-
<tr key={idx}>
38-
<td colSpan={showGroups ? 8 : 7}>
39-
<LoadingIcon gapRight />
40-
<FormattedMessage id="generic.loading" defaultMessage="Loading..." />
18+
}) => {
19+
const navigate = useNavigate();
20+
return (
21+
<UserUIDataContext.Consumer>
22+
{({ openOnDoubleclick = false }) => (
23+
<Table hover>
24+
{Boolean(heading) && <thead>{heading}</thead>}
25+
<tbody>
26+
{exercises.map((exercise, idx) =>
27+
exercise ? (
28+
<ExercisesListItem
29+
{...exercise}
30+
showGroups={showGroups}
31+
showAssignButton={showAssignButton}
32+
assignExercise={assignExercise}
33+
key={exercise ? exercise.id : idx}
34+
reload={reload}
35+
doubleClickPush={openOnDoubleclick ? navigate : null}
36+
/>
37+
) : (
38+
<tr key={idx}>
39+
<td colSpan={showGroups ? 8 : 7}>
40+
<LoadingIcon gapRight />
41+
<FormattedMessage id="generic.loading" defaultMessage="Loading..." />
42+
</td>
43+
</tr>
44+
)
45+
)}
46+
47+
{exercises.length === 0 && (
48+
<tr>
49+
<td className="text-center text-muted" colSpan={showGroups ? 8 : 7}>
50+
<FormattedMessage
51+
id="app.exercisesList.empty"
52+
defaultMessage="No exercises match selected filters."
53+
/>
4154
</td>
4255
</tr>
43-
)
44-
)}
45-
46-
{exercises.length === 0 && (
47-
<tr>
48-
<td className="text-center text-muted" colSpan={showGroups ? 8 : 7}>
49-
<FormattedMessage id="app.exercisesList.empty" defaultMessage="No exercises match selected filters." />
50-
</td>
51-
</tr>
52-
)}
53-
</tbody>
54-
</Table>
55-
)}
56-
</UserUIDataContext.Consumer>
57-
);
56+
)}
57+
</tbody>
58+
</Table>
59+
)}
60+
</UserUIDataContext.Consumer>
61+
);
62+
};
5863

5964
ExercisesList.propTypes = {
6065
heading: PropTypes.any,
@@ -63,9 +68,6 @@ ExercisesList.propTypes = {
6368
showAssignButton: PropTypes.bool,
6469
assignExercise: PropTypes.func,
6570
reload: PropTypes.func,
66-
history: PropTypes.shape({
67-
push: PropTypes.func.isRequired,
68-
}),
6971
};
7072

71-
export default withRouter(ExercisesList);
73+
export default ExercisesList;

src/components/Groups/ResultsTable/ResultsTable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class ResultsTable extends Component {
143143
showOnlyMe: false,
144144
};
145145

146-
componentDidMount = () => {
146+
componentDidMount() {
147147
this.setState({ showOnlyMe: storageGetItem(localStorageShowOnlyMeKey, false) });
148-
};
148+
}
149149

150150
toggleShowOnlyMe = () => {
151151
const showOnlyMe = !this.state.showOnlyMe;

src/components/Solutions/SolutionActions/SolutionActions.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { FormattedMessage } from 'react-intl';
4-
import { withRouter } from 'react-router';
4+
import { useLocation, useNavigate } from 'react-router-dom';
55

66
import withLinks from '../../../helpers/withLinks';
77
import { safeGet } from '../../../helpers/common';
@@ -112,10 +112,11 @@ const SolutionActions = ({
112112
setReviewState = null,
113113
deleteReview = null,
114114
setPoints = null,
115-
history: { push },
116-
location: { pathname },
117115
links: { SOLUTION_SOURCE_CODES_URI_FACTORY },
118116
}) => {
117+
const { pathname } = useLocation();
118+
const navigate = useNavigate();
119+
119120
const review = solution && solution.review;
120121
const assignmentId = solution && solution.assignmentId;
121122
const accepted = solution && solution.accepted;
@@ -154,12 +155,12 @@ const SolutionActions = ({
154155
open:
155156
openReview &&
156157
(!review || !review.startedAt) &&
157-
(isOnReviewPage ? openReview : () => openReview().then(() => push(reviewPageUri))),
158+
(isOnReviewPage ? openReview : () => openReview().then(() => navigate(reviewPageUri))),
158159
reopen:
159160
openReview &&
160161
review &&
161162
review.closedAt &&
162-
(isOnReviewPage ? openReview : () => openReview().then(() => push(reviewPageUri))),
163+
(isOnReviewPage ? openReview : () => openReview().then(() => navigate(reviewPageUri))),
163164
openClose: setReviewState && (!review || !review.startedAt) && showAllButtons && (() => setReviewState(true)),
164165
close: setReviewState && review && review.startedAt && !review.closedAt && (() => setReviewState(true)),
165166
delete: showAllButtons && review && review.startedAt && deleteReview,
@@ -224,13 +225,7 @@ SolutionActions.propTypes = {
224225
setReviewState: PropTypes.func,
225226
deleteReview: PropTypes.func,
226227
setPoints: PropTypes.func,
227-
history: PropTypes.shape({
228-
push: PropTypes.func.isRequired,
229-
}),
230-
location: PropTypes.shape({
231-
pathname: PropTypes.string.isRequired,
232-
}).isRequired,
233228
links: PropTypes.object.isRequired,
234229
};
235230

236-
export default withLinks(withRouter(SolutionActions));
231+
export default withLinks(SolutionActions);

0 commit comments

Comments
 (0)