From c8be4c401fca54cdf7bf9677e1da5978c4732348 Mon Sep 17 00:00:00 2001 From: David Joy Date: Mon, 23 Mar 2020 16:40:50 -0400 Subject: [PATCH] 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. --- src/courseware/course/sequence/Sequence.jsx | 6 +-- .../SequenceNavigation.jsx | 39 +++++++++++++------ src/data/api.js | 6 +-- src/data/thunks.js | 7 ++-- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/courseware/course/sequence/Sequence.jsx b/src/courseware/course/sequence/Sequence.jsx index e34283d8..14a62ff4 100644 --- a/src/courseware/course/sequence/Sequence.jsx +++ b/src/courseware/course/sequence/Sequence.jsx @@ -55,7 +55,7 @@ function Sequence({ const logEvent = (eventName, widgetPlacement, targetUnitId) => { // Note: tabs are tracked with a 1-indexed position // as opposed to a 0-index used throughout this MFE - const currentIndex = sequence.unitIds.indexOf(unitId); + const currentIndex = sequence.unitIds.length > 0 ? sequence.unitIds.indexOf(unitId) : 0; const payload = { current_tab: currentIndex + 1, id: unitId, @@ -110,7 +110,7 @@ function Sequence({ const gated = sequence.gatedContent !== undefined && sequence.gatedContent.gated; - if (sequenceStatus === 'loaded' && unit) { + if (sequenceStatus === 'loaded') { return (
)} - {!gated && ( + {!gated && unitId !== null && ( state.courseware.sequenceStatus); - return ( + const renderUnitButtons = () => { + if (isLocked) { + return ( + {}} /> + ); + } + if (sequence.unitIds.length === 0 || unitId === null) { + return ( +
+ ); + } + return ( + + ); + }; + + return sequenceStatus === 'loaded' && (