Allow loading with no unit, and of sequences with no unitIds. (#34)

This requires some defensive programming here and there to let things load in a minimal state.
This commit is contained in:
David Joy
2020-03-23 16:40:50 -04:00
committed by GitHub
parent 781508dd03
commit c8be4c401f
4 changed files with 37 additions and 21 deletions

View File

@@ -41,14 +41,14 @@ function normalizeBlocks(courseUsageKey, blocks) {
models.courses[block.id] = {
id: courseUsageKey,
title: block.display_name,
sectionIds: block.children,
sectionIds: block.children || [],
};
break;
case 'chapter':
models.sections[block.id] = {
id: block.id,
title: block.display_name,
sequenceIds: block.children,
sequenceIds: block.children || [],
};
break;
@@ -57,7 +57,7 @@ function normalizeBlocks(courseUsageKey, blocks) {
id: block.id,
title: block.display_name,
lmsWebUrl: block.lms_web_url,
unitIds: block.children,
unitIds: block.children || [],
};
break;
case 'vertical':

View File

@@ -5,7 +5,7 @@ import {
getSequenceMetadata,
} from './api';
import {
addModelsMap, updateModel, updateModels,
addModelsMap, updateModel, updateModels, updateModelsMap,
} from '../model-store';
import {
fetchCourseRequest,
@@ -40,11 +40,12 @@ export function fetchCourse(courseUsageKey) {
modelType: 'sections',
modelsMap: sections,
}));
dispatch(addModelsMap({
// We update for sequences and units because the sequence metadata may have come back first.
dispatch(updateModelsMap({
modelType: 'sequences',
modelsMap: sequences,
}));
dispatch(addModelsMap({
dispatch(updateModelsMap({
modelType: 'units',
modelsMap: units,
}));