From a615afa934baedd73dd63f0a65d60789d1d2a192 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 22 Nov 2025 16:05:07 +0100 Subject: [PATCH] fix(components): add undefined checks in GanttChartPrimitive - Add undefined check for first row before accessing cellsByRow - Add nullish coalescing for focusedRow.value in emit calls --- .../gantt/primitives/GanttChartPrimitive.vue | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/gantt/primitives/GanttChartPrimitive.vue b/frontend/src/components/gantt/primitives/GanttChartPrimitive.vue index 514648361..e5454ba0a 100644 --- a/frontend/src/components/gantt/primitives/GanttChartPrimitive.vue +++ b/frontend/src/components/gantt/primitives/GanttChartPrimitive.vue @@ -35,9 +35,12 @@ const focusedCellIndex = ref(null) const focusedRow = computed(() => focusedRowIndex.value === null ? null : props.rows[focusedRowIndex.value]) -const cellsCount = computed(() => props.rows.length - ? props.cellsByRow[props.rows[0]].length - : 0) +const cellsCount = computed(() => { + const firstRow = props.rows[0] + return firstRow !== undefined && props.cellsByRow[firstRow] + ? props.cellsByRow[firstRow].length + : 0 +}) onClickOutside(chartRef, () => { focusedRowIndex.value = null @@ -63,7 +66,7 @@ function initializeFocus() { if (focusedRowIndex.value === null && props.rows.length > 0) { focusedRowIndex.value = 0 focusedCellIndex.value = 0 - emit('update:focused', { row: focusedRow.value, cell: focusedCellIndex.value }) + emit('update:focused', { row: focusedRow.value ?? null, cell: focusedCellIndex.value }) } } @@ -72,7 +75,7 @@ function setFocus(rowId: string, cellIndex: number = 0) { if (rowIndex !== -1) { focusedRowIndex.value = rowIndex focusedCellIndex.value = Math.max(0, Math.min(cellIndex, cellsCount.value - 1)) - emit('update:focused', { row: focusedRow.value, cell: focusedCellIndex.value }) + emit('update:focused', { row: focusedRow.value ?? null, cell: focusedCellIndex.value }) } }