From 8ddfe6f00907b3d75afa78c80dcd349645d1f551 Mon Sep 17 00:00:00 2001 From: David Nunez Date: Fri, 12 Jan 2024 11:25:54 -0500 Subject: [PATCH 1/3] add proponent field --- .../src/components/project/ProjectList.tsx | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/epictrack-web/src/components/project/ProjectList.tsx b/epictrack-web/src/components/project/ProjectList.tsx index b3aaa57d4..80213d8f6 100644 --- a/epictrack-web/src/components/project/ProjectList.tsx +++ b/epictrack-web/src/components/project/ProjectList.tsx @@ -19,6 +19,7 @@ import { useAppSelector } from "../../hooks"; const ProjectList = () => { const [envRegions, setEnvRegions] = React.useState([]); const [subTypes, setSubTypes] = React.useState([]); + const [proponents, setProponents] = React.useState([]); const [types, setTypes] = React.useState([]); const [projectId, setProjectId] = React.useState(); const ctx = React.useContext(MasterContext); @@ -57,11 +58,15 @@ const ProjectList = () => { const subTypes = projects .map((p) => p.sub_type.name) .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); + const project_proponents = projects + .map((p) => p.proponent_id) + .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); const envRegions = projects .map((p) => p.region_env?.name) .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); setTypes(types); setSubTypes(subTypes); + setProponents(project_proponents); setEnvRegions(envRegions); }, [projects]); @@ -159,6 +164,35 @@ const ProjectList = () => { return filterValue.includes(value); }, }, + { + accessorKey: "proponent.name", + header: "Proponents", + filterSelectOptions: proponents, + filterVariant: "multi-select", + Filter: ({ header, column }) => { + return ( + + ); + }, + filterFn: (row, id, filterValue) => { + if ( + !filterValue.length || + filterValue.length > proponents.length // select all is selected + ) { + return true; + } + + const value: string = row.getValue(id) || ""; + + return filterValue.includes(value); + }, + }, { accessorKey: "region_env.name", header: "ENV Region", @@ -231,7 +265,7 @@ const ProjectList = () => { ), }, ], - [types, subTypes, envRegions] + [types, subTypes, envRegions, proponents] ); return ( <> From 0b6555d94633fde41def64579c217eafdc7c6a01 Mon Sep 17 00:00:00 2001 From: David Nunez Date: Mon, 15 Jan 2024 10:21:52 -0500 Subject: [PATCH 2/3] create add proponent field --- .../src/components/project/ProjectList.tsx | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/epictrack-web/src/components/project/ProjectList.tsx b/epictrack-web/src/components/project/ProjectList.tsx index 80213d8f6..779831791 100644 --- a/epictrack-web/src/components/project/ProjectList.tsx +++ b/epictrack-web/src/components/project/ProjectList.tsx @@ -15,15 +15,16 @@ import { Restricted, hasPermission } from "../shared/restricted"; import { ROLES } from "../../constants/application-constant"; import { searchFilter } from "../shared/MasterTrackTable/filters"; import { useAppSelector } from "../../hooks"; +import proponentService from "services/proponentService/proponentService"; +import { Proponent } from "models/proponent"; const ProjectList = () => { const [envRegions, setEnvRegions] = React.useState([]); const [subTypes, setSubTypes] = React.useState([]); - const [proponents, setProponents] = React.useState([]); + const [proponents, setProponents] = React.useState([]); const [types, setTypes] = React.useState([]); const [projectId, setProjectId] = React.useState(); const ctx = React.useContext(MasterContext); - const { roles } = useAppSelector((state) => state.user.userDetail); const canEdit = hasPermission({ roles, allowed: [ROLES.EDIT] }); @@ -51,6 +52,21 @@ const ProjectList = () => { const projects = React.useMemo(() => ctx.data as Project[], [ctx.data]); + async function fetchProponents() { + const project_proponents = projects + .map((p) => p.proponent_id) + .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); + + const proponentsResponses = await Promise.all( + project_proponents.map((proponentId) => + proponentService.getById(proponentId.toString()) + ) + ); + + const proponents = proponentsResponses.map((response) => response.data); + setProponents(proponents as Proponent[]); + } + React.useEffect(() => { const types = projects .map((p) => p.type.name) @@ -58,16 +74,13 @@ const ProjectList = () => { const subTypes = projects .map((p) => p.sub_type.name) .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); - const project_proponents = projects - .map((p) => p.proponent_id) - .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); const envRegions = projects .map((p) => p.region_env?.name) .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); setTypes(types); setSubTypes(subTypes); - setProponents(project_proponents); setEnvRegions(envRegions); + fetchProponents(); }, [projects]); const statusesOptions = useMemo( @@ -167,7 +180,7 @@ const ProjectList = () => { { accessorKey: "proponent.name", header: "Proponents", - filterSelectOptions: proponents, + filterSelectOptions: proponents.map((p) => p.name), filterVariant: "multi-select", Filter: ({ header, column }) => { return ( From a20da41d04bbaa31423c27e0d578fbee975c43b2 Mon Sep 17 00:00:00 2001 From: David Nunez Date: Mon, 15 Jan 2024 14:57:52 -0500 Subject: [PATCH 3/3] update proponent names --- .../src/components/project/ProjectList.tsx | 26 +++++-------------- epictrack-web/src/models/project.ts | 2 ++ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/epictrack-web/src/components/project/ProjectList.tsx b/epictrack-web/src/components/project/ProjectList.tsx index 779831791..47d6b143e 100644 --- a/epictrack-web/src/components/project/ProjectList.tsx +++ b/epictrack-web/src/components/project/ProjectList.tsx @@ -15,13 +15,11 @@ import { Restricted, hasPermission } from "../shared/restricted"; import { ROLES } from "../../constants/application-constant"; import { searchFilter } from "../shared/MasterTrackTable/filters"; import { useAppSelector } from "../../hooks"; -import proponentService from "services/proponentService/proponentService"; -import { Proponent } from "models/proponent"; const ProjectList = () => { const [envRegions, setEnvRegions] = React.useState([]); const [subTypes, setSubTypes] = React.useState([]); - const [proponents, setProponents] = React.useState([]); + const [proponents, setProponents] = React.useState([]); const [types, setTypes] = React.useState([]); const [projectId, setProjectId] = React.useState(); const ctx = React.useContext(MasterContext); @@ -52,21 +50,6 @@ const ProjectList = () => { const projects = React.useMemo(() => ctx.data as Project[], [ctx.data]); - async function fetchProponents() { - const project_proponents = projects - .map((p) => p.proponent_id) - .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); - - const proponentsResponses = await Promise.all( - project_proponents.map((proponentId) => - proponentService.getById(proponentId.toString()) - ) - ); - - const proponents = proponentsResponses.map((response) => response.data); - setProponents(proponents as Proponent[]); - } - React.useEffect(() => { const types = projects .map((p) => p.type.name) @@ -77,10 +60,13 @@ const ProjectList = () => { const envRegions = projects .map((p) => p.region_env?.name) .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); + const projectProponents = projects + .map((p) => p.proponent.name) + .filter((ele, index, arr) => arr.findIndex((t) => t === ele) === index); + setProponents(projectProponents); setTypes(types); setSubTypes(subTypes); setEnvRegions(envRegions); - fetchProponents(); }, [projects]); const statusesOptions = useMemo( @@ -180,7 +166,7 @@ const ProjectList = () => { { accessorKey: "proponent.name", header: "Proponents", - filterSelectOptions: proponents.map((p) => p.name), + filterSelectOptions: proponents, filterVariant: "multi-select", Filter: ({ header, column }) => { return ( diff --git a/epictrack-web/src/models/project.ts b/epictrack-web/src/models/project.ts index 4b7f3643f..373b302ad 100644 --- a/epictrack-web/src/models/project.ts +++ b/epictrack-web/src/models/project.ts @@ -1,6 +1,7 @@ import { Type } from "./type"; import { SubType } from "./subtype"; import { Region } from "./region"; +import { Proponent } from "./proponent"; export interface Project { id: number; @@ -14,6 +15,7 @@ export interface Project { region_id_env: number; region_id_flnro: number; proponent_id: number; + proponent: Proponent; ea_certificate: string; abbreviation: string; epic_guid: string;