Added search to table
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
import Checkbox from "@/components/Low/Checkbox";
|
import Checkbox from "@/components/Low/Checkbox";
|
||||||
|
import { useListSearch } from "@/hooks/useListSearch";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
corporateUsers: User[];
|
corporateUsers: User[];
|
||||||
@@ -24,6 +25,7 @@ interface Props {
|
|||||||
|
|
||||||
interface TableData {
|
interface TableData {
|
||||||
user: string;
|
user: string;
|
||||||
|
email: string;
|
||||||
correct: number;
|
correct: number;
|
||||||
corporate: string;
|
corporate: string;
|
||||||
submitted: boolean;
|
submitted: boolean;
|
||||||
@@ -37,6 +39,8 @@ interface UserCount {
|
|||||||
maxUserCount: number;
|
maxUserCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchFilters = [["email"], ["user"], ["userId"], ];
|
||||||
|
|
||||||
const MasterStatistical = (props: Props) => {
|
const MasterStatistical = (props: Props) => {
|
||||||
const { users, corporateUsers } = props;
|
const { users, corporateUsers } = props;
|
||||||
|
|
||||||
@@ -72,10 +76,12 @@ const MasterStatistical = (props: Props) => {
|
|||||||
const userResults = a.assignees.map((assignee) => {
|
const userResults = a.assignees.map((assignee) => {
|
||||||
const userStats =
|
const userStats =
|
||||||
a.results.find((r) => r.user === assignee)?.stats || [];
|
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 corporate = users.find((u) => u.id === a.assigner)?.name || "";
|
||||||
const commonData = {
|
const commonData = {
|
||||||
user: userName,
|
user: userData?.name || "",
|
||||||
|
email: userData?.email || "",
|
||||||
|
userId: assignee,
|
||||||
corporateId: a.corporateId,
|
corporateId: a.corporateId,
|
||||||
corporate,
|
corporate,
|
||||||
assignment: a.name,
|
assignment: a.name,
|
||||||
@@ -146,6 +152,13 @@ const MasterStatistical = (props: Props) => {
|
|||||||
return <span>{info.getValue()}</span>;
|
return <span>{info.getValue()}</span>;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
columnHelper.accessor("email", {
|
||||||
|
header: "Email",
|
||||||
|
id: "email",
|
||||||
|
cell: (info) => {
|
||||||
|
return <span>{info.getValue()}</span>;
|
||||||
|
},
|
||||||
|
}),
|
||||||
columnHelper.accessor("corporate", {
|
columnHelper.accessor("corporate", {
|
||||||
header: "Corporate",
|
header: "Corporate",
|
||||||
id: "corporate",
|
id: "corporate",
|
||||||
@@ -192,12 +205,19 @@ const MasterStatistical = (props: Props) => {
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const { rows: filteredRows, renderSearch } = useListSearch(
|
||||||
|
searchFilters,
|
||||||
|
tableResults,
|
||||||
|
);
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: tableResults,
|
data: filteredRows,
|
||||||
columns: defaultColumns,
|
columns: defaultColumns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const areAllSelected = selectedCorporates.length === corporates.length;
|
const areAllSelected = selectedCorporates.length === corporates.length;
|
||||||
|
|
||||||
const getStudentsConsolidateScore = () => {
|
const getStudentsConsolidateScore = () => {
|
||||||
@@ -261,7 +281,8 @@ const MasterStatistical = (props: Props) => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex gap-3 w-full">
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">Date</label>
|
<label className="font-normal text-base text-mti-gray-dim">Date</label>
|
||||||
<ReactDatePicker
|
<ReactDatePicker
|
||||||
dateFormat="dd/MM/yyyy"
|
dateFormat="dd/MM/yyyy"
|
||||||
@@ -282,7 +303,10 @@ const MasterStatistical = (props: Props) => {
|
|||||||
setEndDate(null);
|
setEndDate(null);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
{renderSearch()}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<table className="rounded-xl h-full bg-mti-purple-ultralight/40 w-full">
|
<table className="rounded-xl h-full bg-mti-purple-ultralight/40 w-full">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
Reference in New Issue
Block a user