From d83b1b69ca6e9078e16a4b0e40a93b41b0d70746 Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo <66379281+lorenzocorallo@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:03:56 +0200 Subject: [PATCH 1/6] feat: add version in about page (#256) --- src/routes/about/index.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/routes/about/index.tsx b/src/routes/about/index.tsx index a1a4b7c6..dc2910ec 100644 --- a/src/routes/about/index.tsx +++ b/src/routes/about/index.tsx @@ -62,16 +62,19 @@ export const aboutRoute = new Route({ -
- Sviluppato con amore da{" "} - - PoliNetwork - {" "} +
+

Versione: {APP_VERSION}

+

+ Sviluppato con amore da{" "} + + PoliNetwork + {" "} ❤️ +

From cdf9bb15e94179ebca77f56c10cdfb62e4aee122 Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo <66379281+lorenzocorallo@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:05:13 +0200 Subject: [PATCH 2/6] feat: close filter popover when clearing it (#257) Co-authored-by: angeousta <132761637+angeousta@users.noreply.github.com> --- src/routes/viewer/Table/FilterBtn.tsx | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/routes/viewer/Table/FilterBtn.tsx b/src/routes/viewer/Table/FilterBtn.tsx index 3466db22..f44dc8a4 100644 --- a/src/routes/viewer/Table/FilterBtn.tsx +++ b/src/routes/viewer/Table/FilterBtn.tsx @@ -19,6 +19,7 @@ import { PopoverTrigger, } from "@/components/ui/popover"; import { Separator } from "@/components/ui/separator"; +import { useState } from "react"; export type FilterOption = { originalValue: T; @@ -38,11 +39,29 @@ export function FilterBtn({ title, options, }: Props) { + const [open, setOpen] = useState(false); const facets = column.getFacetedUniqueValues(); const selectedValues = new Set(column?.getFilterValue() as string[]); + function handleClearFilter(): void { + column?.setFilterValue(undefined); + setOpen(false); + } + + function handleOptionSelect( + option: FilterOption, + isSelected: boolean, + ): void { + if (options.length <= 2) selectedValues.clear(); // filter with radio behaviour + if (isSelected) selectedValues.delete(option.value); // toggle behaviour + else selectedValues.add(option.value); + + const filterValues = Array.from(selectedValues); // get selected filter options + column?.setFilterValue(filterValues.length ? filterValues : undefined); // update table + } + return ( - + diff --git a/tsconfig.json b/tsconfig.json index ea0727c5..ad6b6e1c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,9 +15,11 @@ /* Linting */ "strict": true, + "strictNullChecks": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, // for shadcn/ui "baseUrl": ".", From a1b4b986c9ed38d66e948beccbd7c7d7f26201dd Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo <66379281+lorenzocorallo@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:08:01 +0200 Subject: [PATCH 5/6] fix: update row total number when filtering the table (#265) Co-authored-by: angeousta <132761637+angeousta@users.noreply.github.com> --- src/routes/viewer/Table/Pagination.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/viewer/Table/Pagination.tsx b/src/routes/viewer/Table/Pagination.tsx index e2c75fbf..bd23dbab 100644 --- a/src/routes/viewer/Table/Pagination.tsx +++ b/src/routes/viewer/Table/Pagination.tsx @@ -25,7 +25,7 @@ export default function Pagination({

- Totale righe: {table.getCoreRowModel().rows.length} + Totale righe: {table.getFilteredRowModel().rows.length}

From c47171ce53905b9e24114f25056df35e6f32270d Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo <66379281+lorenzocorallo@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:16:00 +0200 Subject: [PATCH 6/6] feat: matricola search (#264) * fix: matricola searching before it was not working at all * feat: improve matricola search filter * style: change matricola input width to show error in one line --- src/routes/viewer/CourseCombobox.tsx | 2 +- src/routes/viewer/LocationSelect.tsx | 2 +- .../viewer/PhaseSelect/GroupSelect/index.tsx | 2 +- .../viewer/PhaseSelect/LangSelect/index.tsx | 2 +- .../PhaseSelect/RankingSelect/index.tsx | 2 +- src/routes/viewer/Table/FilterBtn.tsx | 4 +- src/routes/viewer/Table/Toolbar.tsx | 95 ++++++++++++++++--- src/routes/viewer/Table/columns.tsx | 4 +- 8 files changed, 91 insertions(+), 22 deletions(-) diff --git a/src/routes/viewer/CourseCombobox.tsx b/src/routes/viewer/CourseCombobox.tsx index d6e81e49..7ff13626 100644 --- a/src/routes/viewer/CourseCombobox.tsx +++ b/src/routes/viewer/CourseCombobox.tsx @@ -38,7 +38,7 @@ export function CourseCombobox({ value, courses: c, onSelect }: Props) { return (
-

Corso

+

Corso

{selectedCourse ? ( handleSelect(absCourse.value)}> {selectedCourse.label} diff --git a/src/routes/viewer/LocationSelect.tsx b/src/routes/viewer/LocationSelect.tsx index 324b8545..873a7af1 100644 --- a/src/routes/viewer/LocationSelect.tsx +++ b/src/routes/viewer/LocationSelect.tsx @@ -35,7 +35,7 @@ export default function LocationsSelect(props: Props) { if (locations.length === 0) return <>; return (
-

Sede

+

Sede

{locations.length >= 2 ? ( isMobile ? ( LocationCombobox(props) diff --git a/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx b/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx index 1918331f..df12e6ae 100644 --- a/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx +++ b/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx @@ -11,7 +11,7 @@ export default function GroupSelect(props: GroupSelectProps) { const { groups, isCombobox, selectedGroup, groupOpen, onChange } = props; return (
-

Fase

+

Fase

{groups.size >= 2 ? ( isCombobox ? ( -

Lingua

+

Lingua

{canChoose ? ( -

Graduatoria

+

Graduatoria

{phases.length >= 2 ? ( isCombobox ? ( ({ >
- {option.icon && ( - - )} + {option.icon && } {option.label} {facet && ( diff --git a/src/routes/viewer/Table/Toolbar.tsx b/src/routes/viewer/Table/Toolbar.tsx index 7ff49ca5..367d223a 100644 --- a/src/routes/viewer/Table/Toolbar.tsx +++ b/src/routes/viewer/Table/Toolbar.tsx @@ -6,6 +6,10 @@ import { FilterBtn } from "./FilterBtn"; import { enrollStatusOpts, enrollAllowedOpts } from "./columns"; import { StudentResultKeys } from "."; import StudentResult from "@/utils/types/data/parsed/Ranking/StudentResult"; +import { sha256 } from "@/utils/strings/crypto"; +import { useState } from "react"; +import { LuXCircle } from "react-icons/lu"; +import { Removable } from "@/components/custom-ui/Removable"; type Props = { has: Record; @@ -16,20 +20,89 @@ type Props = { export function Toolbar({ has, onCsvClick, table }: Props) { 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 handleClearMatricolaFilter() { + setMatricolaFilter(""); + clearMatricolaTableFilter(); + setMatricolaFilterSubmitted(false); + } + + function handleMatricolaFilterChange( + event: React.ChangeEvent, + ) { + if (matricolaFilterSubmitted) clearMatricolaTableFilter(); + const input = event.target.value; + setMatricolaFilter(input); + setMatricolaFilterSubmitted(false); + } + + async function handleMatricolaFilterSubmit( + e: React.FormEvent, + ) { + e.preventDefault(); + + if (matricolaFilter.length === 0) handleClearMatricolaFilter(); + else { + const hash = await sha256(matricolaFilter); + table.getColumn("id")?.setFilterValue(hash); + setMatricolaFilterSubmitted(true); + } + } return ( -
+
{table.getColumn("id") && ( - - table.getColumn("id")?.setFilterValue(event.target.value) - } - /> +
+

Matricola

+ {filteredRows.length > 0 && matricolaFilterSubmitted ? ( + + {matricolaFilter} + + ) : ( + <> +
+ + {matricolaFilter.length > 0 && ( + + )} +
+ {matricolaFilterSubmitted && ( +

+ Matricola non trovata, ricontrolla. +

+ )} + + )} +
)} -
+
{has.enrollAllowed && enrollAllowedCol && ( )}
-
+
);