-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #1489] Complete search filter accordion logic #1490
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Accordion } from "@trussworks/react-uswds"; | ||
import React from "react"; | ||
import { QueryParamKey } from "../../../types/searchTypes"; | ||
import SearchFilterCheckbox from "./SearchFilterCheckbox"; | ||
import SearchFilterSection from "./SearchFilterSection/SearchFilterSection"; | ||
import SearchFilterToggleAll from "./SearchFilterToggleAll"; | ||
|
@@ -25,12 +25,18 @@ export interface FilterOption { | |
|
||
interface SearchFilterAccordionProps { | ||
initialFilterOptions: FilterOption[]; | ||
title: string; | ||
title: string; // Title in header of accordion | ||
initialQueryParams: string; // comma-separated string list of query params from the request URL | ||
queryParamKey: QueryParamKey; // Ex - In query params, search?{key}=first,second,third | ||
formRef: React.RefObject<HTMLFormElement>; | ||
} | ||
|
||
export function SearchFilterAccordion({ | ||
initialFilterOptions, | ||
title, | ||
queryParamKey, | ||
initialQueryParams, | ||
formRef, | ||
}: SearchFilterAccordionProps) { | ||
// manage most of state in custom hook | ||
const { | ||
|
@@ -41,7 +47,12 @@ export function SearchFilterAccordion({ | |
toggleSelectAll, | ||
incrementTotal, | ||
decrementTotal, | ||
} = useSearchFilter(initialFilterOptions); | ||
} = useSearchFilter( | ||
initialFilterOptions, | ||
initialQueryParams, | ||
queryParamKey, | ||
formRef, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More logic was added to |
||
|
||
const getAccordionTitle = () => ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"use client"; | ||
|
||
interface SearchFilterToggleAllProps { | ||
onSelectAll?: () => void; | ||
onClearAll?: () => void; | ||
|
@@ -11,15 +13,23 @@ const SearchFilterToggleAll: React.FC<SearchFilterToggleAllProps> = ({ | |
<div className="grid-col-fill"> | ||
<button | ||
className="usa-button usa-button--unstyled font-sans-xs" | ||
onClick={onSelectAll} | ||
onClick={(event) => { | ||
// form submission is done in useSearchFilter, so | ||
// prevent the onClick from submitting here. | ||
event.preventDefault(); | ||
onSelectAll?.(); | ||
}} | ||
> | ||
Select All | ||
</button> | ||
</div> | ||
<div className="grid-col-fill text-right"> | ||
<button | ||
className="usa-button usa-button--unstyled font-sans-xs" | ||
onClick={onClearAll} | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
onClearAll?.(); | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
> | ||
Clear All | ||
</button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
"use client"; | ||
|
||
import { SearchFilterAccordion } from "src/components/search/SearchFilterAccordion/SearchFilterAccordion"; | ||
import { agencyFilterList } from "./SearchFilterAccordion/filterJSONLists/agencyFilterList"; | ||
|
||
export default function SearchFilterAgency() { | ||
export interface SearchFilterAgencyProps { | ||
initialQueryParams: string; | ||
formRef: React.RefObject<HTMLFormElement>; | ||
} | ||
|
||
export default function SearchFilterAgency({ | ||
initialQueryParams, | ||
formRef, | ||
}: SearchFilterAgencyProps) { | ||
return ( | ||
<SearchFilterAccordion | ||
initialFilterOptions={agencyFilterList} | ||
title="Agency" | ||
queryParamKey="agency" | ||
initialQueryParams={initialQueryParams} | ||
formRef={formRef} | ||
/> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow a value to be passed in case we want to explicitly have a value set for checkbox submissions on search
Without this it's just
{ name: "status-forecased", value: "on"}