Skip to content

Commit

Permalink
Merge branch 'main' into feat-matricola-search
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocorallo authored Aug 22, 2024
2 parents 6ed470a + a1b4b98 commit 029a7e6
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 47 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
plugins: ["react-refresh", "prettier"],
rules: {
"@typescript-eslint/switch-exhaustiveness-check": "error",
"react-refresh/only-export-components": "warn",
"prettier/prettier": "warn",
},
Expand Down
32 changes: 20 additions & 12 deletions src/components/custom-ui/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@ export default function Alert({
}

function GetIcon(level: Level) {
if (level === "error") return <LuAlertCircle />;
if (level === "warning") return <LuAlertTriangle />;
if (level === "info") return <LuInfo />;
if (level === "success") return <LuCheckCircle2 />;
switch (level) {
case "error":
return <LuAlertCircle />;
case "warning":
return <LuAlertTriangle />;
case "info":
return <LuInfo />;
case "success":
return <LuCheckCircle2 />;
}
}

const getColors = (level: Level) => {
if (level === "error")
return "bg-red-300/5 border-red-600 text-red-600 dark:bg-red-100/5 dark:border-red-300 dark:text-red-300";
if (level === "warning")
return "bg-amber-300/5 border-amber-600 text-amber-600 dark:bg-amber-100/5 dark:border-amber-200 dark:text-amber-200";
if (level === "info")
return "bg-sky-300/5 border-sky-600 text-sky-600 dark:bg-sky-100/5 dark:border-sky-200 dark:text-sky-200";
if (level === "success")
return "bg-green-300/5 border-green-600 text-green-600 dark:bg-green-100/5 dark:border-green-200 dark:text-green-200";
switch (level) {
case "error":
return "bg-red-300/5 border-red-600 text-red-600 dark:bg-red-100/5 dark:border-red-300 dark:text-red-300";
case "warning":
return "bg-amber-300/5 border-amber-600 text-amber-600 dark:bg-amber-100/5 dark:border-amber-200 dark:text-amber-200";
case "info":
return "bg-sky-300/5 border-sky-600 text-sky-600 dark:bg-sky-100/5 dark:border-sky-200 dark:text-sky-200";
case "success":
return "bg-green-300/5 border-green-600 text-green-600 dark:bg-green-100/5 dark:border-green-200 dark:text-green-200";
}
};
21 changes: 12 additions & 9 deletions src/routes/about/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ export const aboutRoute = new Route({
</a>
</div>

<div className="text-right">
Sviluppato con amore da{" "}
<a
target="_blank"
rel="noreferrer noopener"
href="https://polinetwork.org"
>
PoliNetwork
</a>{" "}
<div className="flex items-center justify-between">
<p className="opacity-60">Versione: {APP_VERSION}</p>
<p>
Sviluppato con amore da{" "}
<a
target="_blank"
rel="noreferrer noopener"
href="https://polinetwork.org"
>
PoliNetwork
</a>{" "}
❤️
</p>
</div>
</div>
</Page>
Expand Down
15 changes: 15 additions & 0 deletions src/routes/homepage/chooseSchool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import { Button } from "@/components/ui/button";
import { homepageRoute } from ".";
import { ButtonGrid } from "@/components/Homepage/ButtonGrid";
import DevSettings from "@/components/DevSettings";
import School from "@/utils/types/data/School";

function getSchoolEmoji(school: School) {
switch (school) {
case "Architettura":
return (<span className="mr-2 text-lg rotate-[270deg]">&#128208;</span>);
case "Design":
return (<span className="mr-2 text-lg">&#128396;&#65039;</span>);
case "Ingegneria":
return (<span className="mr-2 text-lg">&#128736;&#65039;</span>);
case "Urbanistica":
return (<span className="mr-2 text-lg">&#127969;</span>);
}
}

export const chooseSchoolRoute = new Route({
getParentRoute: () => homepageRoute,
Expand Down Expand Up @@ -37,6 +51,7 @@ export const chooseSchoolRoute = new Route({
className="h-full"
>
<Button size="card" variant="secondary" className="h-full w-full">
{getSchoolEmoji(school)}
<span className="text-lg">{school}</span>
</Button>
</Link>
Expand Down
38 changes: 22 additions & 16 deletions src/routes/viewer/Table/FilterBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";
import { Separator } from "@/components/ui/separator";
import { useState } from "react";

export type FilterOption<T> = {
originalValue: T;
Expand All @@ -38,11 +39,29 @@ export function FilterBtn<TData, TValue>({
title,
options,
}: Props<TData, TValue>) {
const [open, setOpen] = useState<boolean>(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<TValue>,
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 (
<Popover>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
Expand Down Expand Up @@ -100,20 +119,7 @@ export function FilterBtn<TData, TValue>({
return (
<CommandItem
key={option.value}
onSelect={() => {
if (isSelected) {
selectedValues.delete(option.value);
} else {
if (options.length <= 2) {
selectedValues.clear();
}
selectedValues.add(option.value);
}
const filterValues = Array.from(selectedValues);
column?.setFilterValue(
filterValues.length ? filterValues : undefined,
);
}}
onSelect={() => handleOptionSelect(option, isSelected)}
>
<div
className={cn(
Expand Down Expand Up @@ -142,7 +148,7 @@ export function FilterBtn<TData, TValue>({
<CommandSeparator />
<CommandGroup>
<CommandItem
onSelect={() => column?.setFilterValue(undefined)}
onSelect={handleClearFilter}
className="justify-center text-center"
>
Pulisci i filtri
Expand Down
2 changes: 1 addition & 1 deletion src/routes/viewer/Table/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Pagination<TData>({
<div className="my-2 flex items-center justify-end max-sm:flex-col max-sm:items-start max-sm:gap-2 sm:space-x-6">
<div className="sm:flex-1">
<p className="text-sm font-medium">
Totale righe: {table.getCoreRowModel().rows.length}
Totale righe: {table.getFilteredRowModel().rows.length}
</p>
</div>
<div className="flex items-center space-x-2">
Expand Down
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
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

/* Linting */
"strict": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,

// for shadcn/ui
"baseUrl": ".",
Expand Down

0 comments on commit 029a7e6

Please sign in to comment.