Skip to content

Commit c9c1be8

Browse files
fix: accessing zero-index array without guard
1 parent 359122c commit c9c1be8

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/app/_home/$school/$year/$id/-Table/columns.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,32 @@ export function getColumns(
165165
{
166166
id: "ofa",
167167
header: "Ofa",
168-
columns: Object.keys(rows[0].ofa).map((k) => ({
169-
header: k,
170-
accessorFn: (row) => row.ofa[k],
171-
cell: ({ getValue }) => {
172-
const value = getValue()
173-
return Formatter.displayBool(value)
174-
},
175-
})),
168+
columns:
169+
rows.length > 0
170+
? Object.keys(rows[0].ofa).map((k) => ({
171+
header: k,
172+
accessorFn: (row) => row.ofa[k],
173+
cell: ({ getValue }) => {
174+
const value = getValue()
175+
return Formatter.displayBool(value)
176+
},
177+
}))
178+
: [],
176179
},
177180
{
178181
header: "Risultati singole sezioni",
179182
id: "sectionsResults",
180-
columns: rows[0].sectionsResults
181-
? Object.keys(rows[0].sectionsResults).map((k) => ({
182-
header: k,
183-
accessorFn: (row) => row.sectionsResults?.[k],
184-
cell: ({ getValue }) => {
185-
const value = getValue()
186-
return Formatter.displayScore(value)
187-
},
188-
}))
189-
: [],
183+
columns:
184+
rows.length > 0 && rows[0].sectionsResults
185+
? Object.keys(rows[0].sectionsResults).map((k) => ({
186+
header: k,
187+
accessorFn: (row) => row.sectionsResults?.[k],
188+
cell: ({ getValue }) => {
189+
const value = getValue()
190+
return Formatter.displayScore(value)
191+
},
192+
}))
193+
: [],
190194
},
191195
{
192196
header: "Risposte corrette",

0 commit comments

Comments
 (0)