Skip to content

Commit 8780709

Browse files
authored
Fix: Add null/undefined checks for status matrix parent block access (#5813)
* Fix null parent access in status matrix checks * Apply prettier formatting to updated block files
1 parent 2447583 commit 8780709

File tree

6 files changed

+113
-84
lines changed

6 files changed

+113
-84
lines changed

js/blocks/BoxesBlocks.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,13 @@ function setupBoxesBlocks(activity) {
452452
arg(logo, turtle, blk) {
453453
const name = activity.blocks.blockList[blk].privateData;
454454

455+
const connections = activity.blocks.blockList[blk]?.connections;
456+
const parentId = connections?.[0];
455457
if (
456458
logo.inStatusMatrix &&
457-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
458-
"print"
459+
parentId != null &&
460+
parentId in activity.blocks.blockList &&
461+
activity.blocks.blockList[parentId]?.name === "print"
459462
) {
460463
logo.statusFields.push([blk, activity.blocks.blockList[blk].name]);
461464
} else if (!logo.updatingStatusMatrix) {

js/blocks/GraphicsBlocks.js

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ function setupGraphicsBlocks(activity) {
9797
* @returns {number} - The heading value.
9898
*/
9999
arg(logo, turtle, blk) {
100+
const connections = activity.blocks.blockList[blk]?.connections;
101+
const parentId = connections?.[0];
100102
if (
101103
logo.inStatusMatrix &&
102-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
103-
"print"
104+
parentId != null &&
105+
parentId in activity.blocks.blockList &&
106+
activity.blocks.blockList[parentId]?.name === "print"
104107
) {
105108
logo.statusFields.push([blk, "heading"]);
106109
} else {
@@ -179,10 +182,13 @@ function setupGraphicsBlocks(activity) {
179182
* @returns {number} - The Y-coordinate value.
180183
*/
181184
arg(logo, turtle, blk) {
185+
const connections = activity.blocks.blockList[blk]?.connections;
186+
const parentId = connections?.[0];
182187
if (
183188
logo.inStatusMatrix &&
184-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
185-
"print"
189+
parentId != null &&
190+
parentId in activity.blocks.blockList &&
191+
activity.blocks.blockList[parentId]?.name === "print"
186192
) {
187193
logo.statusFields.push([blk, "y"]);
188194
} else {
@@ -262,10 +268,13 @@ function setupGraphicsBlocks(activity) {
262268
* @returns {number} - The X-coordinate value.
263269
*/
264270
arg(logo, turtle, blk) {
271+
const connections = activity.blocks.blockList[blk]?.connections;
272+
const parentId = connections?.[0];
265273
if (
266274
logo.inStatusMatrix &&
267-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
268-
"print"
275+
parentId != null &&
276+
parentId in activity.blocks.blockList &&
277+
activity.blocks.blockList[parentId]?.name === "print"
269278
) {
270279
logo.statusFields.push([blk, "x"]);
271280
} else {
@@ -569,30 +578,8 @@ function setupGraphicsBlocks(activity) {
569578

570579
// Set piemenu values for C1 and C2
571580
this.piemenuValuesC1 = [
572-
15,
573-
30,
574-
45,
575-
60,
576-
75,
577-
90,
578-
105,
579-
120,
580-
135,
581-
150,
582-
165,
583-
180,
584-
195,
585-
210,
586-
225,
587-
240,
588-
255,
589-
270,
590-
285,
591-
300,
592-
315,
593-
330,
594-
345,
595-
360
581+
15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270,
582+
285, 300, 315, 330, 345, 360
596583
];
597584
this.piemenuValuesC2 = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300];
598585

@@ -680,22 +667,7 @@ function setupGraphicsBlocks(activity) {
680667

681668
// Set piemenu values for C1
682669
this.piemenuValuesC1 = [
683-
0,
684-
30,
685-
45,
686-
60,
687-
90,
688-
120,
689-
135,
690-
150,
691-
180,
692-
210,
693-
225,
694-
240,
695-
270,
696-
300,
697-
315,
698-
330
670+
0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 240, 270, 300, 315, 330
699671
];
700672

701673
// Set the help string for the Set Heading block

js/blocks/IntervalsBlocks.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,13 @@ function setupIntervalsBlocks(activity) {
292292
* @returns {*} - The argument for the IntervalNumber block.
293293
*/
294294
arg(logo, turtle, blk) {
295+
const connections = activity.blocks.blockList[blk]?.connections;
296+
const parentId = connections?.[0];
295297
if (
296298
logo.inStatusMatrix &&
297-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
298-
"print"
299+
parentId != null &&
300+
parentId in activity.blocks.blockList &&
301+
activity.blocks.blockList[parentId]?.name === "print"
299302
) {
300303
logo.statusFields.push([blk, "intervalnumber"]);
301304
} else {
@@ -347,10 +350,13 @@ function setupIntervalsBlocks(activity) {
347350
* @returns {*} - The argument for the CurrentInterval block.
348351
*/
349352
arg(logo, turtle, blk) {
353+
const connections = activity.blocks.blockList[blk]?.connections;
354+
const parentId = connections?.[0];
350355
if (
351356
logo.inStatusMatrix &&
352-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
353-
"print"
357+
parentId != null &&
358+
parentId in activity.blocks.blockList &&
359+
activity.blocks.blockList[parentId]?.name === "print"
354360
) {
355361
logo.statusFields.push([blk, "currentinterval"]);
356362
} else {
@@ -1275,10 +1281,13 @@ function setupIntervalsBlocks(activity) {
12751281
* @returns {any} - The argument value.
12761282
*/
12771283
arg(logo, turtle, blk) {
1284+
const connections = activity.blocks.blockList[blk]?.connections;
1285+
const parentId = connections?.[0];
12781286
if (
12791287
logo.inStatusMatrix &&
1280-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
1281-
"print"
1288+
parentId != null &&
1289+
parentId in activity.blocks.blockList &&
1290+
activity.blocks.blockList[parentId]?.name === "print"
12821291
) {
12831292
logo.statusFields.push([blk, "modelength"]);
12841293
} else {
@@ -1328,10 +1337,13 @@ function setupIntervalsBlocks(activity) {
13281337
* @returns {any} - The argument value.
13291338
*/
13301339
arg(logo, turtle, blk) {
1340+
const connections = activity.blocks.blockList[blk]?.connections;
1341+
const parentId = connections?.[0];
13311342
if (
13321343
logo.inStatusMatrix &&
1333-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
1334-
"print"
1344+
parentId != null &&
1345+
parentId in activity.blocks.blockList &&
1346+
activity.blocks.blockList[parentId]?.name === "print"
13351347
) {
13361348
logo.statusFields.push([blk, "currentmode"]);
13371349
} else {
@@ -1381,10 +1393,13 @@ function setupIntervalsBlocks(activity) {
13811393
* @returns {any} - The argument value.
13821394
*/
13831395
arg(logo, turtle, blk) {
1396+
const connections = activity.blocks.blockList[blk]?.connections;
1397+
const parentId = connections?.[0];
13841398
if (
13851399
logo.inStatusMatrix &&
1386-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
1387-
"print"
1400+
parentId != null &&
1401+
parentId in activity.blocks.blockList &&
1402+
activity.blocks.blockList[parentId]?.name === "print"
13881403
) {
13891404
logo.statusFields.push([blk, "key"]);
13901405
} else {

js/blocks/MeterBlocks.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ function setupMeterBlocks(activity) {
5858
* @returns {*} - The argument value.
5959
*/
6060
arg(logo, turtle, blk) {
61+
const connections = activity.blocks.blockList[blk]?.connections;
62+
const parentId = connections?.[0];
6163
if (
6264
logo.inStatusMatrix &&
63-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
64-
"print"
65+
parentId != null &&
66+
parentId in activity.blocks.blockList &&
67+
activity.blocks.blockList[parentId]?.name === "print"
6568
) {
6669
logo.statusFields.push([blk, "currentmeter"]);
6770
} else {
@@ -127,10 +130,13 @@ function setupMeterBlocks(activity) {
127130
* @returns {*} - The argument value.
128131
*/
129132
arg(logo, turtle, blk) {
133+
const connections = activity.blocks.blockList[blk]?.connections;
134+
const parentId = connections?.[0];
130135
if (
131136
logo.inStatusMatrix &&
132-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
133-
"print"
137+
parentId != null &&
138+
parentId in activity.blocks.blockList &&
139+
activity.blocks.blockList[parentId]?.name === "print"
134140
) {
135141
logo.statusFields.push([blk, "beatfactor"]);
136142
} else {
@@ -220,10 +226,13 @@ function setupMeterBlocks(activity) {
220226
* @returns {*} - The argument value.
221227
*/
222228
arg(logo, turtle, blk) {
229+
const connections = activity.blocks.blockList[blk]?.connections;
230+
const parentId = connections?.[0];
223231
if (
224232
logo.inStatusMatrix &&
225-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
226-
"print"
233+
parentId != null &&
234+
parentId in activity.blocks.blockList &&
235+
activity.blocks.blockList[parentId]?.name === "print"
227236
) {
228237
logo.statusFields.push([blk, "bpm"]);
229238
} else {
@@ -277,10 +286,13 @@ function setupMeterBlocks(activity) {
277286
* @returns {*} - The argument value.
278287
*/
279288
arg(logo, turtle, blk) {
289+
const connections = activity.blocks.blockList[blk]?.connections;
290+
const parentId = connections?.[0];
280291
if (
281292
logo.inStatusMatrix &&
282-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
283-
"print"
293+
parentId != null &&
294+
parentId in activity.blocks.blockList &&
295+
activity.blocks.blockList[parentId]?.name === "print"
284296
) {
285297
logo.statusFields.push([blk, "measurevalue"]);
286298
} else {
@@ -355,10 +367,13 @@ function setupMeterBlocks(activity) {
355367
* @returns {*} - The argument value.
356368
*/
357369
arg(logo, turtle, blk) {
370+
const connections = activity.blocks.blockList[blk]?.connections;
371+
const parentId = connections?.[0];
358372
if (
359373
logo.inStatusMatrix &&
360-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
361-
"print"
374+
parentId != null &&
375+
parentId in activity.blocks.blockList &&
376+
activity.blocks.blockList[parentId]?.name === "print"
362377
) {
363378
logo.statusFields.push([blk, "beatvalue"]);
364379
} else {
@@ -542,10 +557,13 @@ function setupMeterBlocks(activity) {
542557
* @returns {*} - The argument value.
543558
*/
544559
arg(logo, turtle, blk) {
560+
const connections = activity.blocks.blockList[blk]?.connections;
561+
const parentId = connections?.[0];
545562
if (
546563
logo.inStatusMatrix &&
547-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
548-
"print"
564+
parentId != null &&
565+
parentId in activity.blocks.blockList &&
566+
activity.blocks.blockList[parentId]?.name === "print"
549567
) {
550568
logo.statusFields.push([blk, "elapsednotes"]);
551569
} else {
@@ -634,10 +652,13 @@ function setupMeterBlocks(activity) {
634652
* @returns {*} - The argument value.
635653
*/
636654
arg(logo, turtle, blk, receivedArg) {
655+
const connections = activity.blocks.blockList[blk]?.connections;
656+
const parentId = connections?.[0];
637657
if (
638658
logo.inStatusMatrix &&
639-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
640-
"print"
659+
parentId != null &&
660+
parentId in activity.blocks.blockList &&
661+
activity.blocks.blockList[parentId]?.name === "print"
641662
) {
642663
logo.statusFields.push([blk, "elapsednotes2"]);
643664
} else {

js/blocks/PenBlocks.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,13 @@ function setupPenBlocks(activity) {
301301
* @returns {number} The argument value.
302302
*/
303303
arg(logo, turtle, blk) {
304+
const connections = activity.blocks.blockList[blk]?.connections;
305+
const parentId = connections?.[0];
304306
if (
305307
logo.inStatusMatrix &&
306-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
307-
"print"
308+
parentId != null &&
309+
parentId in activity.blocks.blockList &&
310+
activity.blocks.blockList[parentId]?.name === "print"
308311
) {
309312
logo.statusFields.push([blk, "grey"]);
310313
} else {
@@ -366,10 +369,13 @@ function setupPenBlocks(activity) {
366369
* @returns {number} The argument value.
367370
*/
368371
arg(logo, turtle, blk) {
372+
const connections = activity.blocks.blockList[blk]?.connections;
373+
const parentId = connections?.[0];
369374
if (
370375
logo.inStatusMatrix &&
371-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
372-
"print"
376+
parentId != null &&
377+
parentId in activity.blocks.blockList &&
378+
activity.blocks.blockList[parentId]?.name === "print"
373379
) {
374380
logo.statusFields.push([blk, "shade"]);
375381
} else {
@@ -434,10 +440,13 @@ function setupPenBlocks(activity) {
434440
* @returns {number} The argument value.
435441
*/
436442
arg(logo, turtle, blk) {
443+
const connections = activity.blocks.blockList[blk]?.connections;
444+
const parentId = connections?.[0];
437445
if (
438446
logo.inStatusMatrix &&
439-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
440-
"print"
447+
parentId != null &&
448+
parentId in activity.blocks.blockList &&
449+
activity.blocks.blockList[parentId]?.name === "print"
441450
) {
442451
logo.statusFields.push([blk, "color"]);
443452
} else {
@@ -474,10 +483,13 @@ function setupPenBlocks(activity) {
474483
}
475484

476485
arg(logo, turtle, blk) {
486+
const connections = activity.blocks.blockList[blk]?.connections;
487+
const parentId = connections?.[0];
477488
if (
478489
logo.inStatusMatrix &&
479-
activity.blocks.blockList[activity.blocks.blockList[blk].connections[0]].name ===
480-
"print"
490+
parentId != null &&
491+
parentId in activity.blocks.blockList &&
492+
activity.blocks.blockList[parentId]?.name === "print"
481493
) {
482494
logo.statusFields.push([blk, "pensize"]);
483495
} else {

0 commit comments

Comments
 (0)