Skip to content

Commit 3dfd5b0

Browse files
committed
Upgrading immutable.js to 4.x.
1 parent ef0f0c5 commit 3dfd5b0

File tree

32 files changed

+186
-198
lines changed

32 files changed

+186
-198
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"glob": "^10.4.1",
5959
"global": "^4.4.0",
6060
"highlight.js": "^11.9.0",
61-
"immutable": "^3.8.2",
61+
"immutable": "^4.3.6",
6262
"jwt-decode": "^4.0.0",
6363
"markdown-it": "^14.1.0",
6464
"moment": "^2.30.1",

src/components/Groups/AddStudent/AddStudent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const AddStudent = ({ groups, groupsAccessor, groupId, instanceId, canSearch = f
9898
/>
9999
</InsetPanel>
100100

101-
<ResourceRenderer resource={groups.toArray()} returnAsArray>
101+
<ResourceRenderer resourceArray={groups}>
102102
{groups => (
103103
<InviteUserForm
104104
onSubmit={prepareInviteOnSubmitHandler(inviteUser, setDialogOpen, instanceId)}

src/components/Groups/GroupsList/GroupsList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import GroupsName from '../GroupsName';
88
import { GroupIcon } from '../../icons';
99

1010
const GroupsList = ({ groups = [], renderButtons = () => null, ...props }) => (
11-
<ResourceRenderer resource={groups.toArray()}>
12-
{(...groups) => (
11+
<ResourceRenderer resourceArray={groups}>
12+
{groups => (
1313
<Table hover {...props}>
1414
<tbody>
1515
{groups.map(({ id, name, localizedTexts, organizational, public: isPublic }) => (

src/components/Instances/InstancesManagement/InstancesManagement.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const InstancesManagement = ({ instances }) => (
1010
<Page
1111
title={<FormattedMessage id="app.instances.title" defaultMessage="Instances" />}
1212
description={<FormattedMessage id="app.instances.description" defaultMessage="Management of all instances" />}
13-
resource={instances.toArray()}>
14-
{(...instances) => (
13+
resourceArray={instances}>
14+
{instances => (
1515
<Row>
1616
<Col lg={6}>
1717
<Box title={<FormattedMessage id="app.instances.listTitle" defaultMessage="List of instances" />} noPadding>

src/components/Solutions/SolutionDetail/SolutionDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class SolutionDetail extends Component {
266266
evaluations.size > 1 && (
267267
<Row>
268268
<Col lg={12}>
269-
<ResourceRenderer resource={evaluations.toArray()} returnAsArray>
269+
<ResourceRenderer resourceArray={evaluations}>
270270
{evaluations => (
271271
<SubmissionEvaluations
272272
submissionId={id}

src/components/forms/ForkExerciseForm/ForkExerciseForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const ForkExerciseForm = ({
9393
</Callout>
9494
)}
9595
<Form className="forkForm">
96-
<ResourceRenderer resource={groups.toArray()} returnAsArray>
96+
<ResourceRenderer resourceArray={groups}>
9797
{groups => (
9898
<>
9999
<Field

src/components/helpers/ResourceRenderer/ResourceRenderer.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import ImmutablePropTypes from 'react-immutable-proptypes';
4-
import { List } from 'immutable';
4+
import { List, Map } from 'immutable';
55
import { FormattedMessage } from 'react-intl';
66
import { lruMemoize } from 'reselect';
77

@@ -56,9 +56,14 @@ class ResourceRenderer extends Component {
5656
oldResources = null;
5757
oldData = null;
5858

59+
returnAsArray = () => {
60+
const { returnAsArray = null, resourceArray = null } = this.props;
61+
return returnAsArray !== null ? returnAsArray : Boolean(resourceArray);
62+
};
63+
5964
renderFromCache = () => {
60-
const { children: ready, returnAsArray = false } = this.props;
61-
return returnAsArray ? ready(this.oldData) : ready(...this.oldData);
65+
const { children: ready } = this.props;
66+
return this.returnAsArray() ? ready(this.oldData) : ready(...this.oldData);
6267
};
6368

6469
// Perform rendering of the childs whilst keeping resource data cached ...
@@ -73,6 +78,7 @@ class ResourceRenderer extends Component {
7378
this.oldData = List.isList(this.oldData) ? this.oldData.toArray() : this.oldData;
7479
this.oldResources = resources;
7580
}
81+
7682
return this.renderFromCache();
7783
};
7884

@@ -117,16 +123,30 @@ class ResourceRenderer extends Component {
117123
);
118124
};
119125

126+
getResources = () => {
127+
const { resource = null, resourceArray = null } = this.props;
128+
if (resource) {
129+
// passed as single resource
130+
return Array.isArray(resource) || List.isList(resource) ? resource : [resource];
131+
}
132+
if (!resource && !resourceArray) {
133+
return null;
134+
}
135+
if (Map.isMap(resourceArray)) {
136+
// special case, needs converting
137+
return resourceArray.toArray().map(([_, val]) => val);
138+
}
139+
return Array.isArray(resourceArray) || List.isList(resourceArray) ? resource : [resource];
140+
};
141+
120142
render() {
121-
const { resource, hiddenUntilReady = false, forceLoading = false } = this.props;
143+
const { hiddenUntilReady = false, forceLoading = false } = this.props;
122144

123-
const resources = Array.isArray(resource) || List.isList(resource) ? resource : [resource];
124-
const stillLoading = !resource || resources.find(res => !res) || resources.some(isLoading) || forceLoading;
145+
const resources = this.getResources();
146+
const resourcesLength = (resources && (List.isList(resources) ? resources.size : resources.length)) || 0;
147+
const stillLoading = !resources || resources.find(res => !res) || resources.some(isLoading) || forceLoading;
125148
const isReloading =
126-
stillLoading &&
127-
!forceLoading &&
128-
(resources.length || resources.size) > 0 &&
129-
resources.every(res => res && isReadyOrReloading(res));
149+
stillLoading && !forceLoading && resourcesLength > 0 && resources.every(res => res && isReadyOrReloading(res));
130150

131151
if (isReloading && this.oldData !== null) {
132152
return this.renderFromCache();
@@ -149,6 +169,7 @@ ResourceRenderer.propTypes = {
149169
failed: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
150170
children: PropTypes.func.isRequired,
151171
resource: PropTypes.oneOfType([PropTypes.object, PropTypes.array, ImmutablePropTypes.list]),
172+
resourceArray: PropTypes.oneOfType([PropTypes.array, ImmutablePropTypes.list, ImmutablePropTypes.map]),
152173
hiddenUntilReady: PropTypes.bool,
153174
forceLoading: PropTypes.bool,
154175
noIcons: PropTypes.bool,

src/components/widgets/PaginationButtons/PaginationButtons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ const PaginationButtons = ({
4242
return (
4343
<Pagination size={size} className={className}>
4444
{prev && <Pagination.Prev disabled={activePage <= 1} onClick={() => onSelect && onSelect(activePage - 1)} />}
45-
{prepareButtonsIndices(activePage, items, maxButtons).map(index =>
45+
{prepareButtonsIndices(activePage, items, maxButtons).map((index, i) =>
4646
index ? (
4747
<Pagination.Item key={index} active={activePage === index} onClick={() => onSelect && onSelect(index)}>
4848
{index}
4949
</Pagination.Item>
5050
) : (
51-
<Pagination.Ellipsis key={index} />
51+
<Pagination.Ellipsis key={`elips-${i}`} />
5252
)
5353
)}
5454
{next && <Pagination.Next disabled={activePage >= items} onClick={() => onSelect && onSelect(activePage + 1)} />}

src/containers/ExercisesListContainer/ExercisesListContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ExercisesListContainer extends Component {
119119
const { id, runtimeEnvironments, rootGroup } = this.props;
120120

121121
return (
122-
<ResourceRenderer resource={runtimeEnvironments.toArray()} returnAsArray bulkyLoading>
122+
<ResourceRenderer resourceArray={runtimeEnvironments} bulkyLoading>
123123
{envs => (
124124
<FilterExercisesListForm
125125
form={`${id}-filterForm`}

src/containers/FilesTableContainer/FilesTableContainer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ class FilesTableContainer extends Component {
3131

3232
return (
3333
<Box title={title} collapsable isOpen={isOpen} unlimitedHeight>
34-
<ResourceRenderer
35-
resource={files.toArray()}
36-
returnAsArray
37-
forceLoading={fetchFilesStatus && isLoadingState(fetchFilesStatus)}>
34+
<ResourceRenderer resourceArray={files} forceLoading={fetchFilesStatus && isLoadingState(fetchFilesStatus)}>
3835
{filesJs => <FilesTable files={filesJs} {...restProps} />}
3936
</ResourceRenderer>
4037
</Box>

0 commit comments

Comments
 (0)