Skip to content

Commit 05bb752

Browse files
fix(number-line): add sanity check for initialElements map to fix crash PD-4056
1 parent 65f7c82 commit 05bb752

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

  • packages/number-line/configure/src

packages/number-line/configure/src/main.jsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ export class Main extends React.Component {
223223
const { model, onChange } = this.props;
224224
let { ticks } = object;
225225
const correctResponse = tickUtils.snapElements(model.graph.domain, ticks, model.correctResponse);
226-
const initialElements = tickUtils.snapElements(model.graph.domain, ticks, model.graph.initialElements);
226+
const initialElements = model.graph.initialElements
227+
? tickUtils.snapElements(model.graph.domain, ticks, model.graph.initialElements)
228+
: [];
227229
let updatedGraph = this.updateMajorValue({ ...model.graph, ticks });
228230
const graph = { ...updatedGraph, initialElements };
229231
onChange({ graph, correctResponse });
@@ -258,9 +260,9 @@ export class Main extends React.Component {
258260
ticks.minor < 1
259261
? math.number(math.ceil(minorLimits.min))
260262
: ticks.minor >= math.number(math.ceil(minorLimits.min)) &&
261-
ticks.minor <= math.number(math.floor(minorLimits.max))
262-
? ticks.minor
263-
: math.number(math.ceil(minorLimits.min));
263+
ticks.minor <= math.number(math.floor(minorLimits.max))
264+
? ticks.minor
265+
: math.number(math.ceil(minorLimits.min));
264266
ticks.integerTick = ticks.minor;
265267
minorValues = { decimal: [], fraction: [] };
266268
ticks.fractionTick = '0';
@@ -576,7 +578,7 @@ export class Main extends React.Component {
576578
placement={'right'}
577579
title={validationMessage}
578580
>
579-
<Info fontSize={'small'} color={'primary'} style={{ marginLeft: '8px' }} />
581+
<Info fontSize={'small'} color={'primary'} style={{ marginLeft: '8px' }}/>
580582
</Tooltip>
581583
}
582584
>
@@ -585,7 +587,7 @@ export class Main extends React.Component {
585587
</CardBar>
586588

587589
<div className={classes.row}>
588-
<Domain domain={graph.domain} errors={errors} onChange={(domain) => this.graphChange({ domain })} />
590+
<Domain domain={graph.domain} errors={errors} onChange={(domain) => this.graphChange({ domain })}/>
589591
</div>
590592

591593
{maxError && <div className={classes.errorText}>{maxError}</div>}
@@ -614,17 +616,22 @@ export class Main extends React.Component {
614616
/>
615617
)}
616618
<div></div>
617-
<Arrows arrows={graph.arrows} onChange={this.changeArrows} />
619+
<Arrows arrows={graph.arrows} onChange={this.changeArrows}/>
618620
</div>
619621

620622
{widthError && <div className={classes.errorText}>{widthError}</div>}
621623

622624
<NumberLineComponent
623-
onMoveElement={() => {}}
624-
onDeleteElements={() => {}}
625-
onAddElement={() => {}}
626-
onClearElements={() => {}}
627-
onUndoElement={() => {}}
625+
onMoveElement={() => {
626+
}}
627+
onDeleteElements={() => {
628+
}}
629+
onAddElement={() => {
630+
}}
631+
onClearElements={() => {
632+
}}
633+
onUndoElement={() => {
634+
}}
628635
minWidth={numberLineDimensions.min}
629636
maxWidth={numberLineDimensions.max}
630637
maxHeight={70}

0 commit comments

Comments
 (0)