From 0daaf671322957aa6d50de997d1a9332ee493146 Mon Sep 17 00:00:00 2001 From: Armando Jr Date: Wed, 29 May 2024 07:56:11 -0300 Subject: [PATCH 01/11] initial test to show filtro Status do Item no Abrigo quando selecionados --- .../components/ShelterListView/ShelterListView.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pages/Home/components/ShelterListView/ShelterListView.tsx b/src/pages/Home/components/ShelterListView/ShelterListView.tsx index ec57fc7b..de863016 100644 --- a/src/pages/Home/components/ShelterListView/ShelterListView.tsx +++ b/src/pages/Home/components/ShelterListView/ShelterListView.tsx @@ -8,7 +8,7 @@ import { ShelterListItem, } from '@/components'; import { Button } from '@/components/ui/button'; -import { cn } from '@/lib/utils'; +import { cn, getSupplyPriorityProps } from '@/lib/utils'; import { IShelterListViewProps } from './types'; import { useSearchParams } from 'react-router-dom'; import { LoadingSkeleton } from '@/components/LoadingSkeleton'; @@ -64,6 +64,18 @@ const ShelterListView = React.forwardRef( {item} ))} + + {filterData.priority?.map((item) => ( +
+ {getSupplyPriorityProps(+item).label} +
+ + ))} + +
))} -{/* - {filterData.supplyCategoryIds?.map((item) => ( + + {filterData.supplyCategoryIds?.map((supplyCategoryId) => (
- onCitiesChange?.(removeFilter({from: filterData, in: item})) + onCitiesChange?.(removeFilter({from: filterData, filter: supplyCategoryId})) } > - {getSupplyPriorityProps(+item).label} + {supplyCategoryId}
- ))} */} + ))} From d9e622cb5583f8abc888a1d0d473e1a6e7b8eac3 Mon Sep 17 00:00:00 2001 From: Armando Jr Date: Thu, 30 May 2024 10:08:21 -0300 Subject: [PATCH 04/11] refactor to reuse mapSupplyCategories and provide a Label to SupplyCategories filter --- src/pages/Home/components/Filter/Filter.tsx | 14 ++++++++------ .../components/ShelterListView/ShelterListView.tsx | 9 +++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pages/Home/components/Filter/Filter.tsx b/src/pages/Home/components/Filter/Filter.tsx index f71d98b7..1d164158 100644 --- a/src/pages/Home/components/Filter/Filter.tsx +++ b/src/pages/Home/components/Filter/Filter.tsx @@ -43,17 +43,19 @@ const priorityOpts = Object.entries(priorityOptions).reduce( {} as Record ); +export const mapSupplyCategories = (supplyCategories: ISupplyCategory[]) => + supplyCategories.reduce( + (prev, current) => ({ ...prev, [current.id]: current }), + {} as Record + ); + const Filter = (props: IFilterProps) => { const { data, onClose, onSubmit, open } = props; const { data: supplies, loading: loadingSupplies } = useSupplies(); const { data: supplyCategories, loading: loadingSupplyCategories } = useSupplyCategories(); - const mappedSupplyCategories = useMemo(() => { - return supplyCategories.reduce( - (prev, current) => ({ ...prev, [current.id]: current }), - {} as Record - ); - }, [supplyCategories]); + const mappedSupplyCategories = useMemo(() => + mapSupplyCategories(supplyCategories), [supplyCategories]); const mappedSupplies = useMemo(() => { return supplies.reduce( (prev, current) => ({ ...prev, [current.id]: current }), diff --git a/src/pages/Home/components/ShelterListView/ShelterListView.tsx b/src/pages/Home/components/ShelterListView/ShelterListView.tsx index aa41d17d..9e42b8ce 100644 --- a/src/pages/Home/components/ShelterListView/ShelterListView.tsx +++ b/src/pages/Home/components/ShelterListView/ShelterListView.tsx @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react'; +import React, { Fragment, useMemo } from 'react'; import { CircleAlert, ListFilter, X } from 'lucide-react'; import { @@ -13,6 +13,8 @@ import { IShelterListViewProps } from './types'; import { useSearchParams } from 'react-router-dom'; import { LoadingSkeleton } from '@/components/LoadingSkeleton'; import { IFilterFormProps } from '../Filter/types'; +import { useSupplyCategories } from '@/hooks/useSupplyCategories'; +import { mapSupplyCategories } from '../Filter/Filter'; function removeFilter({ from: filterData, filter: item } : { from: IFilterFormProps, filter: string }): IFilterFormProps { @@ -58,6 +60,9 @@ const ShelterListView = React.forwardRef( } = props; const [searchParams] = useSearchParams(); + const { data: supplyCategories } = useSupplyCategories(); + const mappedSupplyCategories = useMemo(() => + mapSupplyCategories(supplyCategories), [supplyCategories]); return (
@@ -112,7 +117,7 @@ const ShelterListView = React.forwardRef( onCitiesChange?.(removeFilter({from: filterData, filter: supplyCategoryId})) } > - {supplyCategoryId} + {mappedSupplyCategories[supplyCategoryId]?.name}
))} From 339dc8cb4b178d9caeb966c34a6d5813fafa366e Mon Sep 17 00:00:00 2001 From: Armando Jr Date: Thu, 30 May 2024 10:19:43 -0300 Subject: [PATCH 05/11] provided to show supplies filter --- src/pages/Home/components/Filter/Filter.tsx | 16 ++++++++-------- .../ShelterListView/ShelterListView.tsx | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/pages/Home/components/Filter/Filter.tsx b/src/pages/Home/components/Filter/Filter.tsx index 1d164158..e724b442 100644 --- a/src/pages/Home/components/Filter/Filter.tsx +++ b/src/pages/Home/components/Filter/Filter.tsx @@ -49,19 +49,19 @@ export const mapSupplyCategories = (supplyCategories: ISupplyCategory[]) => {} as Record ); +export const mapSupplies = (supplies: IUseSuppliesData[]) => + supplies.reduce( + (prev, current) => ({ ...prev, [current.id]: current }), + {} as Record + ); + const Filter = (props: IFilterProps) => { const { data, onClose, onSubmit, open } = props; const { data: supplies, loading: loadingSupplies } = useSupplies(); const { data: supplyCategories, loading: loadingSupplyCategories } = useSupplyCategories(); - const mappedSupplyCategories = useMemo(() => - mapSupplyCategories(supplyCategories), [supplyCategories]); - const mappedSupplies = useMemo(() => { - return supplies.reduce( - (prev, current) => ({ ...prev, [current.id]: current }), - {} as Record - ); - }, [supplies]); + const mappedSupplyCategories = useMemo(() => mapSupplyCategories(supplyCategories), [supplyCategories]); + const mappedSupplies = useMemo(() => mapSupplies(supplies), [supplies]); const { handleSubmit, values, setFieldValue } = useFormik( { diff --git a/src/pages/Home/components/ShelterListView/ShelterListView.tsx b/src/pages/Home/components/ShelterListView/ShelterListView.tsx index 9e42b8ce..f1235157 100644 --- a/src/pages/Home/components/ShelterListView/ShelterListView.tsx +++ b/src/pages/Home/components/ShelterListView/ShelterListView.tsx @@ -14,7 +14,8 @@ import { useSearchParams } from 'react-router-dom'; import { LoadingSkeleton } from '@/components/LoadingSkeleton'; import { IFilterFormProps } from '../Filter/types'; import { useSupplyCategories } from '@/hooks/useSupplyCategories'; -import { mapSupplyCategories } from '../Filter/Filter'; +import { mapSupplies, mapSupplyCategories } from '../Filter/Filter'; +import { useSupplies } from '@/hooks/useSupplies'; function removeFilter({ from: filterData, filter: item } : { from: IFilterFormProps, filter: string }): IFilterFormProps { @@ -63,7 +64,9 @@ const ShelterListView = React.forwardRef( const { data: supplyCategories } = useSupplyCategories(); const mappedSupplyCategories = useMemo(() => mapSupplyCategories(supplyCategories), [supplyCategories]); - + const { data: supplies } = useSupplies(); + const mappedSupplies = useMemo(() => mapSupplies(supplies), [supplies]); + return (

@@ -122,8 +125,18 @@ const ShelterListView = React.forwardRef( ))} + {filterData.supplyIds?.map((supplyId) => ( +
+ onCitiesChange?.(removeFilter({from: filterData, filter: supplyId})) + } + > + {mappedSupplies[supplyId]?.name} +
- + ))}

From 0de346260dba7a22c390514c6a45790fe1f66839 Mon Sep 17 00:00:00 2001 From: Armando Jr Date: Thu, 30 May 2024 10:34:19 -0300 Subject: [PATCH 06/11] was refactor to be more maintainable --- src/pages/Home/components/Filter/Filter.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/Home/components/Filter/Filter.tsx b/src/pages/Home/components/Filter/Filter.tsx index e724b442..467d1b81 100644 --- a/src/pages/Home/components/Filter/Filter.tsx +++ b/src/pages/Home/components/Filter/Filter.tsx @@ -43,17 +43,19 @@ const priorityOpts = Object.entries(priorityOptions).reduce( {} as Record ); +const dataKeyToIdValueToObj = + ( + prev: Record, + current: ISupplyCategory | IUseSuppliesData + ) => + ({ ...prev, [current.id]: current }); + + export const mapSupplyCategories = (supplyCategories: ISupplyCategory[]) => - supplyCategories.reduce( - (prev, current) => ({ ...prev, [current.id]: current }), - {} as Record - ); + supplyCategories.reduce(dataKeyToIdValueToObj, {} as Record); export const mapSupplies = (supplies: IUseSuppliesData[]) => - supplies.reduce( - (prev, current) => ({ ...prev, [current.id]: current }), - {} as Record - ); + supplies.reduce(dataKeyToIdValueToObj, {} as Record); const Filter = (props: IFilterProps) => { const { data, onClose, onSubmit, open } = props; From f81ebb13813b7cbd41ce20c24a9a99a6beabc22c Mon Sep 17 00:00:00 2001 From: Armando Jr Date: Thu, 30 May 2024 10:58:20 -0300 Subject: [PATCH 07/11] provided to show Shelter status filter --- src/pages/Home/components/Filter/Filter.tsx | 2 +- .../ShelterListView/ShelterListView.tsx | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pages/Home/components/Filter/Filter.tsx b/src/pages/Home/components/Filter/Filter.tsx index 467d1b81..eb4c71a2 100644 --- a/src/pages/Home/components/Filter/Filter.tsx +++ b/src/pages/Home/components/Filter/Filter.tsx @@ -26,7 +26,7 @@ import CitiesFilter from './CitiesFilter'; import { IUseSuppliesData } from '@/hooks/useSupplies/types'; import { SupplyPriority } from '@/service/supply/types'; -const ShelterAvailabilityStatusMapped: Record< +export const ShelterAvailabilityStatusMapped: Record< ShelterAvailabilityStatus, string > = { diff --git a/src/pages/Home/components/ShelterListView/ShelterListView.tsx b/src/pages/Home/components/ShelterListView/ShelterListView.tsx index f1235157..1069b953 100644 --- a/src/pages/Home/components/ShelterListView/ShelterListView.tsx +++ b/src/pages/Home/components/ShelterListView/ShelterListView.tsx @@ -14,7 +14,7 @@ import { useSearchParams } from 'react-router-dom'; import { LoadingSkeleton } from '@/components/LoadingSkeleton'; import { IFilterFormProps } from '../Filter/types'; import { useSupplyCategories } from '@/hooks/useSupplyCategories'; -import { mapSupplies, mapSupplyCategories } from '../Filter/Filter'; +import { ShelterAvailabilityStatusMapped, mapSupplies, mapSupplyCategories } from '../Filter/Filter'; import { useSupplies } from '@/hooks/useSupplies'; @@ -138,6 +138,19 @@ const ShelterListView = React.forwardRef( ))} + {filterData.shelterStatus?.map((statusLabel) => ( +
+ onCitiesChange?.(removeFilter({from: filterData, filter: statusLabel})) + } + > + {ShelterAvailabilityStatusMapped[statusLabel]} +
+ + ))} +