Skip to content

Commit

Permalink
fix: table crash when switching to a phase without the selected course (
Browse files Browse the repository at this point in the history
#259)

Co-authored-by: angeousta <[email protected]>
  • Loading branch information
lorenzocorallo and angeousta authored Aug 22, 2024
1 parent cdf9bb1 commit 9545155
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/routes/viewer/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
}

function makeHas(rows: StudentResult[]): Record<StudentResultKeys, boolean> {
if (rows.length === 0)
return {
englishCorrectAnswers: true,
sectionsResults: true,
positionAbsolute: true,
positionCourse: true,
birthDate: true,
result: true,
ofa: true,
enrollStatus: true,
enrollAllowed: true,
enrollCourse: true,
id: true,
};

function checkKey(key: StudentResultKeys): boolean {
const isThereAny = rows.some((r) => r[key]);
if (!isThereAny) return false;
Expand Down Expand Up @@ -74,19 +89,18 @@ type ColumnVisibility = {
};

export default function Table({ table: _table, csvFilename }: TableProps) {
const { rows } = _table;
const has = makeHas(rows);
const has = makeHas(_table.rows);
const [columnVisibility, setColumnVisibility] =
useState<ColumnVisibility>(has);
const columns = getColumns(rows);
const columns = getColumns(_table.rows);
const [pagination, setPagination] = useState<PaginationState>({
pageSize: 15,
pageIndex: 0,
});

const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const table = useReactTable({
data: rows,
data: _table.rows,
columns,
state: {
columnVisibility,
Expand Down Expand Up @@ -169,12 +183,12 @@ export default function Table({ table: _table, csvFilename }: TableProps) {
) : (
<TableRow>
<TableCell
colSpan={table.getHeaderGroups()[1].headers.length}
colSpan={table.getHeaderGroups()[1]?.headers.length ?? 1}
className="h-24 text-center"
>
{rows.length > 0
? "Nessuna riga trovata"
: "Nessun dato disponibile"}
{_table.rows.length > 0
? "La ricerca ha restituito nessun risultato"
: "La tabella di questo corso non contiene righe"}
</TableCell>
</TableRow>
)}
Expand Down
1 change: 0 additions & 1 deletion src/routes/viewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export const viewerRoute = new Route({
[selectedCourse, selectedLocation, store],
);

console.log({ ranking, selectedPhaseLink });
return (
<Page
className={`flex gap-4 px-0 ${
Expand Down

0 comments on commit 9545155

Please sign in to comment.