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

@@ -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 (
<div className="sequence">
<SequenceNavigation
@@ -147,7 +147,7 @@ function Sequence({
/>
</Suspense>
)}
{!gated && (
{!gated && unitId !== null && (
<Unit
key={unitId}
id={unitId}