From f0331bdbddb29d710562d34192cbf4f885753514 Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo <66379281+lorenzocorallo@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:27:07 +0200 Subject: [PATCH] chore(StudentResult): rename "id" to "matricolaHash", also its column id (#260) * chore(StudentResult): rename "id" to "matricolaHash", also its column id * fix: replace reference in data-store --------- Co-authored-by: angeousta <132761637+angeousta@users.noreply.github.com> --- src/routes/viewer/Table/Toolbar.tsx | 14 ++++++++------ src/routes/viewer/Table/columns.tsx | 4 ++-- src/routes/viewer/Table/index.tsx | 4 ++-- src/utils/data/jsonParser.ts | 2 ++ src/utils/data/store.ts | 2 +- .../types/data/parsed/Ranking/StudentResult.ts | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/routes/viewer/Table/Toolbar.tsx b/src/routes/viewer/Table/Toolbar.tsx index 367d223a..bac39801 100644 --- a/src/routes/viewer/Table/Toolbar.tsx +++ b/src/routes/viewer/Table/Toolbar.tsx @@ -18,27 +18,29 @@ type Props = { }; export function Toolbar({ has, onCsvClick, table }: Props) { + const matricolaCol = table.getColumn("matricolaHash"); const enrollStatusCol = table.getColumn("enrollStatus"); const enrollAllowedCol = table.getColumn("enrollAllowed"); + const [matricolaFilter, setMatricolaFilter] = useState(""); const [matricolaFilterSubmitted, setMatricolaFilterSubmitted] = useState(false); const { rows: filteredRows } = table.getFilteredRowModel(); - function clearMatricolaTableFilter() { - table.getColumn("id")?.setFilterValue(undefined); + function filterTableMatricolaCol(value?: string) { + matricolaCol?.setFilterValue(value); } function handleClearMatricolaFilter() { setMatricolaFilter(""); - clearMatricolaTableFilter(); + filterTableMatricolaCol(); setMatricolaFilterSubmitted(false); } function handleMatricolaFilterChange( event: React.ChangeEvent, ) { - if (matricolaFilterSubmitted) clearMatricolaTableFilter(); + if (matricolaFilterSubmitted) filterTableMatricolaCol(); const input = event.target.value; setMatricolaFilter(input); setMatricolaFilterSubmitted(false); @@ -52,14 +54,14 @@ export function Toolbar({ has, onCsvClick, table }: Props) { if (matricolaFilter.length === 0) handleClearMatricolaFilter(); else { const hash = await sha256(matricolaFilter); - table.getColumn("id")?.setFilterValue(hash); + filterTableMatricolaCol(hash); setMatricolaFilterSubmitted(true); } } return (
- {table.getColumn("id") && ( + {has.matricolaHash && matricolaCol && (

Matricola

{filteredRows.length > 0 && matricolaFilterSubmitted ? ( diff --git a/src/routes/viewer/Table/columns.tsx b/src/routes/viewer/Table/columns.tsx index 49112e51..dccfd647 100644 --- a/src/routes/viewer/Table/columns.tsx +++ b/src/routes/viewer/Table/columns.tsx @@ -200,9 +200,9 @@ export function getColumns(rows: StudentResult[]): ColumnDef[] { header: "Dati personali", columns: [ { - accessorKey: "id", + accessorKey: "matricolaHash", header: "Matricola hash", - id: "id", + id: "matricolaHash", cell: ({ getValue }) => { const value = getValue(); return Formatter.displayHash(value); diff --git a/src/routes/viewer/Table/index.tsx b/src/routes/viewer/Table/index.tsx index 20c412bc..cabb9b6c 100644 --- a/src/routes/viewer/Table/index.tsx +++ b/src/routes/viewer/Table/index.tsx @@ -50,7 +50,7 @@ function makeHas(rows: StudentResult[]): Record { enrollStatus: true, enrollAllowed: true, enrollCourse: true, - id: true, + matricolaHash: true, }; function checkKey(key: StudentResultKeys): boolean { @@ -77,7 +77,7 @@ function makeHas(rows: StudentResult[]): Record { enrollStatus: checkKey("enrollStatus"), enrollAllowed: checkKey("enrollAllowed"), enrollCourse: checkKey("enrollCourse"), - id: checkKey("id"), + matricolaHash: checkKey("matricolaHash"), }; return has; } diff --git a/src/utils/data/jsonParser.ts b/src/utils/data/jsonParser.ts index 5d269606..06925bae 100644 --- a/src/utils/data/jsonParser.ts +++ b/src/utils/data/jsonParser.ts @@ -118,6 +118,7 @@ export default class JsonParser { canEnrollInto, sectionsResults, enrollType, + id, ...rowBase } = json; const ofaMap: StudentResult_OfaMap = new CustomMap(); @@ -135,6 +136,7 @@ export default class JsonParser { return { ...rowBase, + matricolaHash: id, enrollAllowed: enrollType?.canEnroll ?? canEnroll ?? false, enrollCourse: enrollType?.course ?? canEnrollInto, enrollStatus: enrollType?.type?.toLowerCase(), diff --git a/src/utils/data/store.ts b/src/utils/data/store.ts index 5eb93a07..bd1aa505 100644 --- a/src/utils/data/store.ts +++ b/src/utils/data/store.ts @@ -111,7 +111,7 @@ export default class Store { if (rows.length === 0) return []; return rows.map((row) => { const a = [ - row.id ?? null, + row.matricolaHash ?? null, row.birthDate ?? null, row.result ?? null, row.positionAbsolute ?? null, diff --git a/src/utils/types/data/parsed/Ranking/StudentResult.ts b/src/utils/types/data/parsed/Ranking/StudentResult.ts index a3a38838..e680ae84 100644 --- a/src/utils/types/data/parsed/Ranking/StudentResult.ts +++ b/src/utils/types/data/parsed/Ranking/StudentResult.ts @@ -3,7 +3,7 @@ import CustomMap from "../../../../CustomMap"; type StudentResult = { birthDate?: string; englishCorrectAnswers?: number; - id?: string; + matricolaHash?: string; positionAbsolute?: number; positionCourse?: number; result?: number;