From 70de97766ebb6767c383b95fa2be9f4c1b10a206 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Thu, 5 Sep 2024 18:25:39 +0100 Subject: [PATCH] Added search to table --- src/dashboards/MasterStatistical.tsx | 32 ++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/dashboards/MasterStatistical.tsx b/src/dashboards/MasterStatistical.tsx index 3a4a2e57..69ec5d66 100644 --- a/src/dashboards/MasterStatistical.tsx +++ b/src/dashboards/MasterStatistical.tsx @@ -16,6 +16,7 @@ import { useReactTable, } from "@tanstack/react-table"; import Checkbox from "@/components/Low/Checkbox"; +import { useListSearch } from "@/hooks/useListSearch"; interface Props { corporateUsers: User[]; @@ -24,6 +25,7 @@ interface Props { interface TableData { user: string; + email: string; correct: number; corporate: string; submitted: boolean; @@ -37,6 +39,8 @@ interface UserCount { maxUserCount: number; } +const searchFilters = [["email"], ["user"], ["userId"], ]; + const MasterStatistical = (props: Props) => { const { users, corporateUsers } = props; @@ -72,10 +76,12 @@ const MasterStatistical = (props: Props) => { const userResults = a.assignees.map((assignee) => { const userStats = a.results.find((r) => r.user === assignee)?.stats || []; - const userName = users.find((u) => u.id === assignee)?.name || ""; + const userData = users.find((u) => u.id === assignee) const corporate = users.find((u) => u.id === a.assigner)?.name || ""; const commonData = { - user: userName, + user: userData?.name || "", + email: userData?.email || "", + userId: assignee, corporateId: a.corporateId, corporate, assignment: a.name, @@ -146,6 +152,13 @@ const MasterStatistical = (props: Props) => { return {info.getValue()}; }, }), + columnHelper.accessor("email", { + header: "Email", + id: "email", + cell: (info) => { + return {info.getValue()}; + }, + }), columnHelper.accessor("corporate", { header: "Corporate", id: "corporate", @@ -192,12 +205,19 @@ const MasterStatistical = (props: Props) => { }), ]; + const { rows: filteredRows, renderSearch } = useListSearch( + searchFilters, + tableResults, + ); + const table = useReactTable({ - data: tableResults, + data: filteredRows, columns: defaultColumns, getCoreRowModel: getCoreRowModel(), }); + + const areAllSelected = selectedCorporates.length === corporates.length; const getStudentsConsolidateScore = () => { @@ -261,7 +281,8 @@ const MasterStatistical = (props: Props) => { ); })} -
+
+
{ setEndDate(null); }} /> +
+ {renderSearch()}
+