From 4b19f04956fd6a1a7a9996f16d085a0cfcd5474d Mon Sep 17 00:00:00 2001 From: atrincas Date: Thu, 26 Dec 2024 10:03:00 +0100 Subject: [PATCH] feat: Update project size filter to support multiple selections --- client/src/app/(overview)/url-store.ts | 4 +- .../src/containers/overview/filters/index.tsx | 40 +++++++++++++++++++ .../overview/header/parameters/index.tsx | 21 ---------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/client/src/app/(overview)/url-store.ts b/client/src/app/(overview)/url-store.ts index ee06d7f7..f89a14b7 100644 --- a/client/src/app/(overview)/url-store.ts +++ b/client/src/app/(overview)/url-store.ts @@ -37,7 +37,7 @@ export interface Parameter> { export const filtersSchema = z.object({ [FILTER_KEYS[0]]: z.string().optional(), - [FILTER_KEYS[1]]: z.nativeEnum(PROJECT_SIZE_FILTER), + [FILTER_KEYS[1]]: z.array(z.nativeEnum(PROJECT_SIZE_FILTER)), [FILTER_KEYS[2]]: z.nativeEnum(PROJECT_PRICE_TYPE), [FILTER_KEYS[3]]: z.nativeEnum(COST_TYPE_SELECTOR), [FILTER_KEYS[4]]: z.string().optional(), @@ -50,7 +50,7 @@ export const filtersSchema = z.object({ export const INITIAL_FILTERS_STATE: z.infer = { keyword: "", - projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM, + projectSizeFilter: [], priceType: PROJECT_PRICE_TYPE.MARKET_PRICE, costRangeSelector: COST_TYPE_SELECTOR.NPV, countryCode: "", diff --git a/client/src/containers/overview/filters/index.tsx b/client/src/containers/overview/filters/index.tsx index bd6b173d..c7bcdc92 100644 --- a/client/src/containers/overview/filters/index.tsx +++ b/client/src/containers/overview/filters/index.tsx @@ -3,6 +3,7 @@ import { useState, useEffect } from "react"; import { CheckedState } from "@radix-ui/react-checkbox"; import { ACTIVITY } from "@shared/entities/activity.enum"; import { ECOSYSTEM } from "@shared/entities/ecosystem.enum"; +import { PROJECT_SIZE_FILTER } from "@shared/entities/projects.entity"; import { useSetAtom } from "jotai/index"; import { XIcon } from "lucide-react"; import { useDebounce } from "rooks"; @@ -18,6 +19,8 @@ import { useProjectOverviewFilters, } from "@/app/(overview)/url-store"; +import { FILTERS } from "@/constants/tooltip"; + import { Button } from "@/components/ui/button"; import { CheckboxWrapper } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; @@ -123,6 +126,18 @@ export default function ProjectsFilters() { })); }; + const handleProjectSizeChange = async ( + isChecked: CheckedState, + size: PROJECT_SIZE_FILTER, + ) => { + await setFilters((prev) => ({ + ...prev, + projectSizeFilter: isChecked + ? [...prev.projectSizeFilter, size] + : prev.projectSizeFilter.filter((e) => e !== size), + })); + }; + const debouncedCostChange = useDebounce(async (cost: number[]) => { await setFilters((prev) => ({ ...prev, @@ -350,6 +365,31 @@ export default function ProjectsFilters() { max={formatNumber(INITIAL_ABATEMENT_POTENTIAL_RANGE[1])} /> + +
+ +
    + {Object.values(PROJECT_SIZE_FILTER).map((size) => ( +
  • + { + await handleProjectSizeChange(isChecked, size); + }} + /> +
  • + ))} +
+
); } diff --git a/client/src/containers/overview/header/parameters/index.tsx b/client/src/containers/overview/header/parameters/index.tsx index 0c1fccf1..2cd80f15 100644 --- a/client/src/containers/overview/header/parameters/index.tsx +++ b/client/src/containers/overview/header/parameters/index.tsx @@ -1,5 +1,4 @@ import { - PROJECT_SIZE_FILTER, COST_TYPE_SELECTOR, PROJECT_PRICE_TYPE, } from "@shared/entities/projects.entity"; @@ -25,26 +24,6 @@ import { } from "@/components/ui/select"; export const PROJECT_PARAMETERS: Parameter[] = [ - { - key: FILTER_KEYS[1], - label: "Project size", - className: "w-[125px]", - tooltipContent: FILTERS.PROJECT_SIZE, - options: [ - { - label: PROJECT_SIZE_FILTER.SMALL, - value: PROJECT_SIZE_FILTER.SMALL, - }, - { - label: PROJECT_SIZE_FILTER.MEDIUM, - value: PROJECT_SIZE_FILTER.MEDIUM, - }, - { - label: PROJECT_SIZE_FILTER.LARGE, - value: PROJECT_SIZE_FILTER.LARGE, - }, - ], - }, { key: FILTER_KEYS[2], label: "Carbon pricing type",