Skip to content

Commit

Permalink
Fixing several issues where safeGet should have returned empty array …
Browse files Browse the repository at this point in the history
…as fallback.
  • Loading branch information
krulis-martin committed Oct 7, 2021
1 parent 1362be2 commit bccf304
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/helpers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const computeMap = (groups, filter) => {
const res = {};
groups.filter(filter).forEach((group, id) => {
res[id] = true;
group.getIn(['data', 'parentGroupsIds'], []).forEach(parentId => {
(group.getIn(['data', 'parentGroupsIds'], []) || []).forEach(parentId => {
res[parentId] = true;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default connect(
(dispatch, { groupId, id }) => ({
loadAsync: () =>
dispatch(fetchGroupIfNeeded(groupId)).then(({ value: group }) =>
dispatch(fetchByIds(safeGet(group, ['privateData', 'students'], [])))
dispatch(fetchByIds(safeGet(group, ['privateData', 'students']) || []))
),
setPoints: ({ awardeeId, pointsId, points, note, awardedAt }) =>
dispatch(setShadowAssignmentPoints(groupId, id, awardeeId, pointsId, points, note, awardedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ class SisSupervisorGroupsContainer extends Component {
groupsAccessor,
locale
)}
{safeGet(group, ['privateData', 'bindings', 'sis'], [])
.length > 1 && (
{(
safeGet(group, ['privateData', 'bindings', 'sis']) ||
[]
).length > 1 && (
<OverlayTrigger
placement="right"
overlay={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default connect(
Promise.all([
dispatch(fetchGroupStatsIfNeeded(groupId)),
dispatch(fetchGroupIfNeeded(groupId)).then(({ value: group }) =>
dispatch(fetchByIds(safeGet(group, ['privateData', 'students'], [])))
dispatch(fetchByIds(safeGet(group, ['privateData', 'students']) || []))
),
]),
})
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/exercise/configAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { safeGet, arrayToObject, encodeNumId, encodeId } from '../common';
*/
export const getPipelines = defaultMemoize(config =>
// There should be only one environment and all tests have the same pipelines (hence we take first and first)
safeGet(config, [0, 'tests', 0, 'pipelines'], []).map(({ name }) => name)
(safeGet(config, [0, 'tests', 0, 'pipelines']) || []).map(({ name }) => name)
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/exercise/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getFirstEnvironmentId = environmentConfigs =>
*/
export const getEnvironmentInitValues = environmentConfigs => {
const environmentId = getFirstEnvironmentId(environmentConfigs);
const variables = safeGet(environmentConfigs, [0, 'variablesTable'], []);
const variables = safeGet(environmentConfigs, [0, 'variablesTable']) || [];
return { environmentId, variables };
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/AssignmentStats/AssignmentStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class AssignmentStats extends Component {
.then(res => res.value)
.then(assignment =>
dispatch(fetchGroupIfNeeded(assignment.groupId)).then(({ value: group }) =>
dispatch(fetchByIds(safeGet(group, ['privateData', 'students'], [])))
dispatch(fetchByIds(safeGet(group, ['privateData', 'students']) || []))
)
),
dispatch(fetchRuntimeEnvironments()),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/GroupDetail/GroupDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class GroupDetail extends Component {
])
: Promise.resolve(),
hasPermissions(group, 'viewStudents')
? dispatch(fetchByIds(safeGet(group, ['privateData', 'students'], [])))
? dispatch(fetchByIds(safeGet(group, ['privateData', 'students']) || []))
: Promise.resolve(),
dispatch(fetchGroupStats(groupId)),
])
Expand Down
12 changes: 6 additions & 6 deletions src/pages/GroupInfo/GroupInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class GroupInfo extends Component {
.then(res => res.value)
.then(group =>
Promise.all([
dispatch(fetchByIds(safeGet(group, ['primaryAdminsIds'], []))),
dispatch(fetchByIds(safeGet(group, ['privateData', 'supervisors'], []))),
dispatch(fetchByIds(safeGet(group, ['privateData', 'observers'], []))),
dispatch(fetchByIds(safeGet(group, ['primaryAdminsIds']) || [])),
dispatch(fetchByIds(safeGet(group, ['privateData', 'supervisors']) || [])),
dispatch(fetchByIds(safeGet(group, ['privateData', 'observers']) || [])),
])
);

Expand All @@ -73,13 +73,13 @@ class GroupInfo extends Component {
const prevData = prevProps.group.toJS().data.privateData;
const groupJs = this.props.group.toJS();
if (safeGet(prevData, ['primaryAdmins', 'length'], -1) !== safeGet(newData, ['primaryAdmins', 'length'], -1)) {
this.props.refetchUsers(safeGet(groupJs, ['data', 'primaryAdminsIds'], []));
this.props.refetchUsers(safeGet(groupJs, ['data', 'primaryAdminsIds']) || []);
}
if (safeGet(prevData, ['supervisors', 'length'], -1) !== safeGet(newData, ['supervisors', 'length'], -1)) {
this.props.refetchUsers(safeGet(groupJs, ['data', 'privateData', 'supervisors'], []));
this.props.refetchUsers(safeGet(groupJs, ['data', 'privateData', 'supervisors']) || []);
}
if (safeGet(prevData, ['observers', 'length'], -1) !== safeGet(newData, ['observers', 'length'], -1)) {
this.props.refetchUsers(safeGet(groupJs, ['data', 'privateData', 'observers'], []));
this.props.refetchUsers(safeGet(groupJs, ['data', 'privateData', 'observers']) || []);
}
}
}
Expand Down

0 comments on commit bccf304

Please sign in to comment.