-
Notifications
You must be signed in to change notification settings - Fork 13
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 #1491]: Setup states to hide clear all and select all in filter accordion #1495
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e196e3d
initial commit
rylew1 c2f270e
initial commit
rylew1 6c9ee88
format
rylew1 bf8a5f5
Merge branch 'main' into rylew/1491-selectAll-clearAll-disabled
rylew1 a6a8caf
Merge branch 'main' into rylew/1491-selectAll-clearAll-disabled
rylew1 0e3dd15
update search.test mock reference
rylew1 f59293e
add Todo comment on SearchFilterManager
rylew1 c0c22ed
Merge branch 'main' into rylew/1491-selectAll-clearAll-disabled
rylew1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,16 @@ export function SearchFilterAccordion({ | |
toggleSelectAll, | ||
incrementTotal, | ||
decrementTotal, | ||
} = useSearchFilter(initialFilterOptions); | ||
isAllSelected, | ||
isNoneSelected, | ||
isSectionAllSelected, | ||
isSectionNoneSelected, | ||
} = useSearchFilter( | ||
initialFilterOptions, | ||
initialQueryParams, | ||
queryParamKey, | ||
formRef, | ||
); | ||
|
||
const getAccordionTitle = () => ( | ||
<> | ||
|
@@ -59,6 +74,8 @@ export function SearchFilterAccordion({ | |
<SearchFilterToggleAll | ||
onSelectAll={() => toggleSelectAll(true)} | ||
onClearAll={() => toggleSelectAll(false)} | ||
isAllSelected={isAllSelected} | ||
isNoneSelected={isNoneSelected} | ||
/> | ||
<ul className="usa-list usa-list--unstyled"> | ||
{options.map((option) => ( | ||
|
@@ -73,6 +90,8 @@ export function SearchFilterAccordion({ | |
mounted={mounted} | ||
updateCheckedOption={toggleOptionChecked} | ||
toggleSelectAll={toggleSelectAll} | ||
isSectionAllSelected={isSectionAllSelected[option.id]} | ||
isSectionNoneSelected={isSectionNoneSelected[option.id]} | ||
/> | ||
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. Nice. 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. Yea the logic to setup those values is kind of a lot but once you have it it's very easy to use in the components |
||
) : ( | ||
<SearchFilterCheckbox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 37 additions & 19 deletions
56
frontend/src/components/search/SearchFilterAccordion/SearchFilterToggleAll.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,48 @@ | ||
"use client"; | ||
|
||
interface SearchFilterToggleAllProps { | ||
isAllSelected: boolean; | ||
isNoneSelected: boolean; | ||
onSelectAll?: () => void; | ||
onClearAll?: () => void; | ||
} | ||
|
||
const SearchFilterToggleAll: React.FC<SearchFilterToggleAllProps> = ({ | ||
onSelectAll, | ||
onClearAll, | ||
}) => ( | ||
<div className="grid-row"> | ||
<div className="grid-col-fill"> | ||
<button | ||
className="usa-button usa-button--unstyled font-sans-xs" | ||
onClick={onSelectAll} | ||
> | ||
Select All | ||
</button> | ||
</div> | ||
<div className="grid-col-fill text-right"> | ||
<button | ||
className="usa-button usa-button--unstyled font-sans-xs" | ||
onClick={onClearAll} | ||
> | ||
Clear All | ||
</button> | ||
isAllSelected, | ||
isNoneSelected, | ||
}) => { | ||
return ( | ||
<div className="grid-row"> | ||
<div className="grid-col-fill"> | ||
<button | ||
className="usa-button usa-button--unstyled font-sans-xs" | ||
onClick={(event) => { | ||
// form submission is done in useSearchFilter, so | ||
// prevent the onClick from submitting here. | ||
event.preventDefault(); | ||
onSelectAll?.(); | ||
}} | ||
disabled={isAllSelected} | ||
> | ||
Select All | ||
</button> | ||
</div> | ||
<div className="grid-col-fill text-right"> | ||
<button | ||
className="usa-button usa-button--unstyled font-sans-xs" | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
onClearAll?.(); | ||
}} | ||
disabled={isNoneSelected} | ||
> | ||
Clear All | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export default SearchFilterToggleAll; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I also moved the
SearchFetcher
classes from/services/searchfetcher
toservices/search/searchfetcher/
so there's a bunch of updates in this PR for that