From 691079be1586593c67f80afc444600399c4f2a39 Mon Sep 17 00:00:00 2001 From: djnunez-aot <103138766+djnunez-aot@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:16:01 -0400 Subject: [PATCH] Add filters for officer analysts (#1998) * add filters for officer analysts * add tooltip and addresss comments --- .../Work/Tabs/Staff/Charts/workListing.tsx | 86 ++++++++++++++++--- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/epictrack-web/src/components/insights/Work/Tabs/Staff/Charts/workListing.tsx b/epictrack-web/src/components/insights/Work/Tabs/Staff/Charts/workListing.tsx index effd45e74..6184da69d 100644 --- a/epictrack-web/src/components/insights/Work/Tabs/Staff/Charts/workListing.tsx +++ b/epictrack-web/src/components/insights/Work/Tabs/Staff/Charts/workListing.tsx @@ -68,30 +68,96 @@ const WorkList = () => { getWorkStaffAllocation(); }, []); - React.useEffect(() => { - let columns: Array> = []; + const tableColumns = React.useMemo(() => { + let cols: Array> = []; if (wsData && wsData.length > 0) { const rolename = WorkStaffRoleNames[WorkStaffRole.OFFICER_ANALYST]; - columns = [ + + // Extract all officer analysts from wsData + const officerAnalysts = wsData.flatMap((row: any) => + row.staff + ? row.staff.filter( + (p: { role: Role }) => p.role.id === WorkStaffRole.OFFICER_ANALYST + ) + : [] + ); + + // Create an array of strings for each officer analyst + const officerAnalystOptions = Array.from( + new Set( + officerAnalysts.map( + (officerAnalyst: any) => + `${officerAnalyst.first_name} ${officerAnalyst.last_name}` + ) + ) + ); + + cols = [ { header: rolename, + filterSelectOptions: officerAnalystOptions, accessorFn: (row: any) => { - const officerAnalyst = row.staff - ? row.staff.find( + if (!row.staff) { + return ""; + } + const officerAnalysts = row.staff + ? row.staff.filter( (p: { role: Role }) => p.role.id === WorkStaffRole.OFFICER_ANALYST ) - : null; - return officerAnalyst - ? `${officerAnalyst.first_name} ${officerAnalyst.last_name}` - : ""; + : []; + return officerAnalysts + .map( + (officerAnalyst: any) => + `${officerAnalyst.first_name} ${officerAnalyst.last_name}` + ) + .join(", "); }, + Cell: ({ renderedCellValue }) => ( + + {renderedCellValue} + + ), enableHiding: false, enableColumnFilter: true, + sortingFn: "sortFn", + filterVariant: "multi-select", + Filter: ({ header, column }) => { + return ( + + ); + }, + filterFn: (row, id, filterValue) => { + if ( + !filterValue.length || + filterValue.length > officerAnalystOptions.length // select all is selected + ) { + return true; + } + + const value: string = row.getValue(id) || ""; + + // Split the cell value into individual names + const names = value.split(", "); + + // Check if any name includes the filter value + return names.some((name) => filterValue.includes(name)); + }, } as MRT_ColumnDef, ]; } - setWorkRoles(columns); + setWorkRoles(cols); }, [wsData]); const codeTypes: { [x: string]: any } = {