Skip to content

Commit c61378e

Browse files
authored
fix: Clearing filters (#5258)
* fix: clear filters * fix: regions default value * test: fix * fix: apply clear filters on button clear * fix: clear filters without closing filter drawer * fix: add missing translations
1 parent 02850e7 commit c61378e

File tree

9 files changed

+25
-9
lines changed

9 files changed

+25
-9
lines changed

shared-helpers/src/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@
629629
"leasingAgent.contact": "Comuníquese con el agente de alquiler",
630630
"leasingAgent.dueToHighCallVolume": "Debido al alto volumen de llamadas, usted podría escuchar un mensaje.",
631631
"leasingAgent.officeHours": "Horario de oficina",
632+
"listingFilters.clear": "Borrar",
632633
"listingFilters.program.Families": "Familias",
633634
"listingFilters.program.Residents with Disabilities": "Residentes con discapacidades",
634635
"listingFilters.program.Seniors 55+": "Adultos mayores de 55 años",

shared-helpers/src/locales/general.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@
620620
"leasingAgent.contact": "Contact leasing agent",
621621
"leasingAgent.dueToHighCallVolume": "Due to high call volume you may hear a message.",
622622
"leasingAgent.officeHours": "Office hours",
623+
"listingFilters.clear": "Clear",
623624
"listingFilters.program.Families": "Families",
624625
"listingFilters.program.Residents with Disabilities": "Residents with disabilities",
625626
"listingFilters.program.Seniors 55+": "Seniors 55+",

shared-helpers/src/locales/vi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@
629629
"leasingAgent.contact": "Liên hệ với đại lý cho thuê",
630630
"leasingAgent.dueToHighCallVolume": "Do có nhiều cuộc gọi đến, quý vị có thể nghe thấy một lời nhắn.",
631631
"leasingAgent.officeHours": "Giờ làm việc",
632+
"listingFilters.clear": "Xóa",
632633
"listingFilters.program.Families": "Gia đình",
633634
"listingFilters.program.Residents with Disabilities": "Người dân khuyết tật",
634635
"listingFilters.program.Seniors 55+": "Người cao tuổi từ 55 tuổi trở lên",

shared-helpers/src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@
629629
"leasingAgent.contact": "联系租赁代理",
630630
"leasingAgent.dueToHighCallVolume": "由於來電人數眾多,您可能會聽到訊息留言。",
631631
"leasingAgent.officeHours": "办公时间",
632+
"listingFilters.clear": "清除",
632633
"listingFilters.program.Families": "家庭",
633634
"listingFilters.program.Residents with Disabilities": "残疾居民",
634635
"listingFilters.program.Seniors 55+": "55岁以上的老年人",

sites/public/__tests__/components/browse/FilterDrawer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe("FilterDrawer", () => {
196196
expect(screen.getByRole("checkbox", { name: "Community Type Four" })).not.toBeChecked()
197197

198198
expect(screen.getByRole("button", { name: "Show matching listings" })).toBeInTheDocument()
199-
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument()
199+
expect(screen.getByRole("button", { name: "Clear" })).toBeInTheDocument()
200200
})
201201

202202
it("should return all filter fields correctly with previous selections", () => {
@@ -355,7 +355,7 @@ describe("FilterDrawer", () => {
355355
expect(screen.getByRole("checkbox", { name: "Community Type Four" })).not.toBeChecked()
356356

357357
expect(screen.getByRole("button", { name: "Show matching listings" })).toBeInTheDocument()
358-
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument()
358+
expect(screen.getByRole("button", { name: "Clear" })).toBeInTheDocument()
359359
})
360360

361361
it("should return correct unit types fields with unit groups", () => {

sites/public/__tests__/components/browse/ListingBrowse.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ describe("<ListingBrowse>", () => {
649649
})
650650
expect(listingNameField).toHaveValue("Test Search")
651651

652-
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument()
652+
expect(screen.getByRole("button", { name: "Clear" })).toBeInTheDocument()
653653
const showMatchingButton = screen.getByRole("button", { name: "Show matching listings" })
654654
expect(showMatchingButton).toBeInTheDocument()
655655
fireEvent.click(showMatchingButton)

sites/public/src/components/browse/FilterDrawer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface FilterDrawerProps {
2929
isOpen: boolean
3030
onClose: () => void
3131
onSubmit: (data: FilterData) => void
32+
onClear: (resetFilters: (data: FilterData) => void) => void
3233
multiselectData: MultiselectQuestion[]
3334
activeFeatureFlags?: FeatureFlagEnum[]
3435
}
@@ -42,6 +43,7 @@ const FilterDrawer = (props: FilterDrawerProps) => {
4243
setValue,
4344
setError,
4445
clearErrors,
46+
reset,
4547
formState: { errors },
4648
} = useForm({ mode: "onBlur" })
4749

@@ -125,7 +127,7 @@ const FilterDrawer = (props: FilterDrawerProps) => {
125127
return {
126128
key: `${ListingFilterKeys.regions}.${region}`,
127129
label: region.replace("_", " "),
128-
defaultChecked: props.filterState?.[ListingFilterKeys.regions]?.[region],
130+
defaultChecked: isTrue(props.filterState?.[ListingFilterKeys.regions]?.[region]),
129131
}
130132
})}
131133
register={register}
@@ -159,8 +161,8 @@ const FilterDrawer = (props: FilterDrawerProps) => {
159161
<Button type="submit" variant="primary" size="sm" nativeButtonProps={{ form: "filter" }}>
160162
{t("listings.showMatchingListings")}
161163
</Button>
162-
<Button variant="primary-outlined" size="sm" onClick={props.onClose}>
163-
{t("t.cancel")}
164+
<Button variant="primary-outlined" size="sm" onClick={() => props.onClear(reset)}>
165+
{t("listingFilters.clear")}
164166
</Button>
165167
</Drawer.Footer>
166168
</Drawer>

sites/public/src/components/browse/ListingBrowse.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const ListingBrowse = (props: ListingBrowseProps) => {
9292
useEffect(() => {
9393
const filterData = decodeQueryToFilterData(router.query)
9494
setFilterState(filterData)
95+
setIsLoading(false)
9596
}, [router.asPath, router.query])
9697

9798
const saveFavoriteFn = (listingId: string) => {
@@ -141,6 +142,17 @@ export const ListingBrowse = (props: ListingBrowseProps) => {
141142
}
142143
}
143144

145+
const onFilterClear = (resetFilters: (data: FilterData) => void) => {
146+
if (Object.keys(filterState).length > 0) {
147+
setIsLoading(true)
148+
router.pathname.includes("listings-closed")
149+
? void router.push(`/listings-closed`)
150+
: void router.push(`/listings`)
151+
}
152+
resetFilters({ name: "", monthlyRent: { minRent: "", maxRent: "" } })
153+
setFilterState({})
154+
}
155+
144156
const onShowAll = useCallback(async () => {
145157
await router.replace(router.pathname)
146158
}, [router])
@@ -168,6 +180,7 @@ export const ListingBrowse = (props: ListingBrowseProps) => {
168180
filterState={filterState}
169181
multiselectData={props.multiselectData}
170182
activeFeatureFlags={jurisdictionActiveFeatureFlags}
183+
onClear={onFilterClear}
171184
/>
172185
<LoadingState loading={isLoading}>
173186
<div className={styles["listing-directory"]}>

sites/public/src/pages/listings.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export interface ListingsProps {
3737
}
3838

3939
export default function ListingsPage(props: ListingsProps) {
40-
const router = useRouter()
41-
4240
return (
4341
<>
4442
{process.env.showNewSeedsDesigns ? (
@@ -48,7 +46,6 @@ export default function ListingsPage(props: ListingsProps) {
4846
jurisdiction={props.jurisdiction}
4947
multiselectData={props.multiselectData}
5048
paginationData={props.paginationData}
51-
key={router.asPath}
5249
areFiltersActive={props.areFiltersActive}
5350
/>
5451
) : (

0 commit comments

Comments
 (0)