Skip to content

Commit

Permalink
chore(StudentResult): rename "id" to "matricolaHash", also its column…
Browse files Browse the repository at this point in the history
… id (#260)

* chore(StudentResult): rename "id" to "matricolaHash", also its column id

* fix: replace reference in data-store

---------

Co-authored-by: angeousta <[email protected]>
  • Loading branch information
lorenzocorallo and angeousta authored Aug 22, 2024
1 parent c47171c commit f0331bd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/routes/viewer/Table/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("");
const [matricolaFilterSubmitted, setMatricolaFilterSubmitted] =
useState<boolean>(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<HTMLInputElement>,
) {
if (matricolaFilterSubmitted) clearMatricolaTableFilter();
if (matricolaFilterSubmitted) filterTableMatricolaCol();
const input = event.target.value;
setMatricolaFilter(input);
setMatricolaFilterSubmitted(false);
Expand All @@ -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 (
<div className="flex w-full flex-wrap items-start justify-start gap-6 max-2xs:flex-col">
{table.getColumn("id") && (
{has.matricolaHash && matricolaCol && (
<div className="grid grid-cols-[auto_220px] grid-rows-[auto_auto] gap-x-4 gap-y-1">
<p className="self-center text-sm">Matricola</p>
{filteredRows.length > 0 && matricolaFilterSubmitted ? (
Expand Down
4 changes: 2 additions & 2 deletions src/routes/viewer/Table/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ export function getColumns(rows: StudentResult[]): ColumnDef<StudentResult>[] {
header: "Dati personali",
columns: [
{
accessorKey: "id",
accessorKey: "matricolaHash",
header: "Matricola hash",
id: "id",
id: "matricolaHash",
cell: ({ getValue }) => {
const value = getValue();
return Formatter.displayHash(value);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/viewer/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function makeHas(rows: StudentResult[]): Record<StudentResultKeys, boolean> {
enrollStatus: true,
enrollAllowed: true,
enrollCourse: true,
id: true,
matricolaHash: true,
};

function checkKey(key: StudentResultKeys): boolean {
Expand All @@ -77,7 +77,7 @@ function makeHas(rows: StudentResult[]): Record<StudentResultKeys, boolean> {
enrollStatus: checkKey("enrollStatus"),
enrollAllowed: checkKey("enrollAllowed"),
enrollCourse: checkKey("enrollCourse"),
id: checkKey("id"),
matricolaHash: checkKey("matricolaHash"),
};
return has;
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/data/jsonParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default class JsonParser {
canEnrollInto,
sectionsResults,
enrollType,
id,
...rowBase
} = json;
const ofaMap: StudentResult_OfaMap = new CustomMap();
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/data/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/types/data/parsed/Ranking/StudentResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CustomMap from "../../../../CustomMap";
type StudentResult = {
birthDate?: string;
englishCorrectAnswers?: number;
id?: string;
matricolaHash?: string;
positionAbsolute?: number;
positionCourse?: number;
result?: number;
Expand Down

0 comments on commit f0331bd

Please sign in to comment.