Skip to content

Commit 9b4babb

Browse files
author
Martin Krulis
committed
Upgrading react and redux (and some related packages) to most recent versions. Fixing some initialization issues raised by the upgrade.
1 parent 74ca9cf commit 9b4babb

File tree

12 files changed

+826
-427
lines changed

12 files changed

+826
-427
lines changed

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"format": "prettier --config .prettierrc --write \"src/**/*.js\""
2626
},
2727
"dependencies": {
28-
"@babel/plugin-transform-react-inline-elements": "^7.0.0",
28+
"@babel/plugin-transform-react-inline-elements": "^7.2.0",
2929
"@fortawesome/fontawesome-free": "^5.8.2",
3030
"@fortawesome/fontawesome-svg-core": "^1.2.18",
3131
"@fortawesome/free-brands-svg-icons": "^5.8.2",
@@ -58,52 +58,52 @@
5858
"immutable": "^3.8.1",
5959
"isomorphic-fetch": "^2.2.1",
6060
"js-yaml": "^3.13.1",
61-
"jwt-decode": "^2.0.1",
61+
"jwt-decode": "^2.2.0",
6262
"markdown-it": "^8.4.1",
63-
"moment": "^2.18.1",
63+
"moment": "^2.24.0",
6464
"pretty-ms": "^2.1.0",
6565
"prop-types": "^15.5.8",
66-
"react": "^16.2.0",
66+
"react": "^16.8.6",
6767
"react-ace": "5.9.0",
6868
"react-bootstrap": "0.31.5",
6969
"react-collapse": "^4.0.2",
7070
"react-copy-to-clipboard": "^5.0.1",
7171
"react-datetime": "^2.8.10",
72-
"react-dom": "^16.2.0",
72+
"react-dom": "^16.8.6",
7373
"react-dropzone": "^3.5.3",
7474
"react-height": "^3.0.0",
7575
"react-helmet": "^5.0.3",
7676
"react-immutable-proptypes": "^2.1.0",
7777
"react-intl": "2.4.0",
7878
"react-motion": "^0.5.2",
79-
"react-redux": "^5.0.4",
79+
"react-redux": "^7.1.0",
8080
"react-responsive": "^1.1.3",
81-
"react-router": "3.2.0",
81+
"react-router": "3.2.3",
8282
"react-router-bootstrap": "^0.23.3",
8383
"react-router-redux": "^4.0.8",
8484
"react-toggle": "4.0.2",
85-
"redux": "^3.5.1",
86-
"redux-actions": "^2.0.3",
87-
"redux-form": "^7.4.2",
88-
"redux-promise-middleware": "^4.2.0",
85+
"redux": "^4.0.4",
86+
"redux-actions": "^2.6.5",
87+
"redux-form": "^8.2.4",
88+
"redux-promise-middleware": "^6.1.1",
8989
"redux-storage": "^4.1.2",
9090
"redux-storage-decorator-filter": "^1.1.8",
9191
"redux-storage-engine-localstorage": "^1.1.4",
92-
"redux-thunk": "^2.0.1",
93-
"reselect": "^3.0.1",
92+
"redux-thunk": "^2.3.0",
93+
"reselect": "^4.0.0",
9494
"serialize-javascript": "^1.3.0",
9595
"statuscode": "0.0.0",
9696
"validator": "^7.0.0",
9797
"viz.js": "^1.8.0"
9898
},
9999
"devDependencies": {
100-
"@babel/cli": "^7.1.0",
101-
"@babel/core": "^7.1.2",
102-
"@babel/node": "^7.0.0",
103-
"@babel/plugin-proposal-class-properties": "^7.1.0",
104-
"@babel/preset-env": "^7.1.0",
100+
"@babel/cli": "^7.5.0",
101+
"@babel/core": "^7.5.4",
102+
"@babel/node": "^7.5.0",
103+
"@babel/plugin-proposal-class-properties": "^7.5.0",
104+
"@babel/preset-env": "^7.5.4",
105105
"@babel/preset-react": "^7.0.0",
106-
"@babel/register": "^7.0.0",
106+
"@babel/register": "^7.4.4",
107107
"async": "^2.4.0",
108108
"babel-eslint": "^10.0.1",
109109
"babel-loader": "^8.0.6",

src/components/forms/EditAssignmentForm/EditAssignmentForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ const validate = (
602602

603603
validateTwoDeadlines(errors, formatMessage, firstDeadline, secondDeadline, allowSecondDeadline);
604604

605-
const formEnabledRuntimes = runtimeEnvironmentIds.filter(key => enabledRuntime[key]);
605+
const formEnabledRuntimes = (runtimeEnvironmentIds || []).filter(key => enabledRuntime[key]);
606606
if (formEnabledRuntimes.length === 0) {
607607
errors._error = (
608608
<FormattedMessage

src/components/forms/EditLimitsForm/EditLimitsForm.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ EditLimitsForm.propTypes = {
188188

189189
const validate = ({ limits }, { constraints, environments }) => {
190190
const errors = {};
191+
if (!limits) {
192+
return errors;
193+
}
194+
191195
const brokenEnvironments = validateLimitsTimeTotals(limits, constraints.totalTime);
192196

193197
if (brokenEnvironments && brokenEnvironments.length > 0) {

src/components/forms/EditSystemMessageForm/EditSystemMessageForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const validate = ({ localizedTexts, type, role, visibleFrom, visibleTo }) => {
179179
);
180180
}
181181

182-
if (visibleTo.isBefore(visibleFrom)) {
182+
if (visibleTo && visibleTo.isBefore(visibleFrom)) {
183183
errors.visibleFrom = (
184184
<FormattedMessage
185185
id="app.editSystemMessageForm.validation.visibleFromBeforeTo"

src/components/forms/EditTestsForm/EditTestsForm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ EditTestsForm.propTypes = {
118118
formValues: PropTypes.object,
119119
};
120120

121-
const validate = ({ isUniform, tests }) => {
121+
const validate = ({ tests }) => {
122122
const errors = {};
123+
if (!tests) {
124+
return errors;
125+
}
123126

124127
const testsErrors = {};
125128
const knownTests = new Set();

src/components/forms/EditTestsForm/EditTestsTest.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { FormattedMessage } from 'react-intl';
66

77
import EditTestsTestRow from './EditTestsTestRow';
88
import { prettyPrintPercent } from '../../helpers/stringFormatters';
9+
import { safeGet } from '../../../helpers/common';
910

1011
const EditTestsTest = ({ fields, isUniform, testValues, readOnly = false }) => {
11-
const weightSum = isUniform ? fields.length : testValues.reduce((acc, val) => acc + Number(val.weight), 0);
12+
const weightSum = isUniform ? fields.length : (testValues || []).reduce((acc, val) => acc + Number(val.weight), 0);
1213

1314
return (
1415
<div>
@@ -38,7 +39,7 @@ const EditTestsTest = ({ fields, isUniform, testValues, readOnly = false }) => {
3839
isUniform={isUniform}
3940
readOnly={readOnly}
4041
percent={
41-
testValues[index] && testValues[index].weight
42+
safeGet(testValues, [index, 'weight'])
4243
? prettyPrintPercent((isUniform ? 1 : Number(testValues[index].weight)) / weightSum)
4344
: '?'
4445
}
@@ -63,7 +64,7 @@ EditTestsTest.propTypes = {
6364
readOnly: PropTypes.bool,
6465
fields: PropTypes.object.isRequired,
6566
isUniform: PropTypes.bool.isRequired,
66-
testValues: PropTypes.array.isRequired,
67+
testValues: PropTypes.array,
6768
};
6869

6970
export default formValues({

src/components/forms/GenerateTokenForm/GenerateTokenForm.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ GenerateTokenForm.propTypes = {
192192

193193
const validate = ({ scopes, expiration }) => {
194194
const errors = {};
195+
if (!scopes || !expiration) {
196+
return errors;
197+
}
198+
195199
if (!scopes['read-all'] && !scopes.master) {
196200
errors._error = (
197201
<FormattedHTMLMessage
@@ -212,7 +216,7 @@ const validate = ({ scopes, expiration }) => {
212216

213217
const warn = ({ scopes }) => {
214218
const warnings = {};
215-
if (scopes['read-all'] && scopes.master) {
219+
if (scopes && scopes['read-all'] && scopes.master) {
216220
warnings._warning = (
217221
<FormattedHTMLMessage
218222
id="app.generateTokenForm.warnBothMasterAndReadAll"

src/components/forms/LocalizedTextsFormField/SharedExerciseAssignmentLocalizedFields.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TextField, MarkdownTextAreaField } from '../Fields';
66

77
const isURL = url => {
88
const pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
9-
return url.trim() !== '' && !pattern.test(url.trim()) ? (
9+
return url && url.trim() !== '' && !pattern.test(url.trim()) ? (
1010
<FormattedMessage
1111
id="app.editAssignmentForm.localized.urlValidation"
1212
defaultMessage="Given string is not a valid URL."

src/helpers/localizedData.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export const transformLocalizedTextsFormData = formData => {
103103
* @param internalValidation {function} injected internal validator called on every enabled localized text
104104
*/
105105
export const validateLocalizedTextsFormData = (errors, formData, internalValidation = null) => {
106+
if (!formData) {
107+
return errors;
108+
}
109+
106110
// Ensure that at least one localized text version is enabled.
107111
const enabledCount = formData.reduce((acc, data) => acc + (data && data._enabled ? 1 : 0), 0);
108112
if (enabledCount < 1) {

src/pages/EditAssignment/EditAssignment.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,28 @@ EditAssignment.propTypes = {
239239

240240
const editAssignmentFormSelector = formValueSelector('editAssignment');
241241

242-
export default connect(
243-
(state, { params: { assignmentId } }) => {
244-
const assignment = getAssignment(state)(assignmentId);
245-
return {
246-
assignment,
247-
userId: loggedInUserIdSelector(state),
248-
exercise: getExerciseOfAssignmentJS(state)(assignmentId),
249-
runtimeEnvironments: runtimeEnvironmentsSelector(state),
250-
firstDeadline: editAssignmentFormSelector(state, 'firstDeadline'),
251-
allowSecondDeadline: editAssignmentFormSelector(state, 'allowSecondDeadline'),
252-
visibility: editAssignmentFormSelector(state, 'visibility'),
253-
allowVisibleFrom: editAssignmentFormSelector(state, 'allowVisibleFrom'),
254-
};
255-
},
256-
(dispatch, { params: { assignmentId } }) => ({
257-
push: url => dispatch(push(url)),
258-
reset: () => dispatch(reset('editAssignment')),
259-
loadAsync: () => EditAssignment.loadAsync({ assignmentId }, dispatch),
260-
editAssignment: data => dispatch(editAssignment(assignmentId, data)),
261-
exerciseSync: () => dispatch(syncWithExercise(assignmentId)),
262-
validateAssignment: version => dispatch(validateAssignment(assignmentId, version)),
263-
})
264-
)(withLinks(EditAssignment));
242+
export default withLinks(
243+
connect(
244+
(state, { params: { assignmentId } }) => {
245+
const assignment = getAssignment(state)(assignmentId);
246+
return {
247+
assignment,
248+
userId: loggedInUserIdSelector(state),
249+
exercise: getExerciseOfAssignmentJS(state)(assignmentId),
250+
runtimeEnvironments: runtimeEnvironmentsSelector(state),
251+
firstDeadline: editAssignmentFormSelector(state, 'firstDeadline'),
252+
allowSecondDeadline: editAssignmentFormSelector(state, 'allowSecondDeadline'),
253+
visibility: editAssignmentFormSelector(state, 'visibility'),
254+
allowVisibleFrom: editAssignmentFormSelector(state, 'allowVisibleFrom'),
255+
};
256+
},
257+
(dispatch, { params: { assignmentId } }) => ({
258+
push: url => dispatch(push(url)),
259+
reset: () => dispatch(reset('editAssignment')),
260+
loadAsync: () => EditAssignment.loadAsync({ assignmentId }, dispatch),
261+
editAssignment: data => dispatch(editAssignment(assignmentId, data)),
262+
exerciseSync: () => dispatch(syncWithExercise(assignmentId)),
263+
validateAssignment: version => dispatch(validateAssignment(assignmentId, version)),
264+
})
265+
)(EditAssignment)
266+
);

0 commit comments

Comments
 (0)