Skip to content

Commit

Permalink
Reset search term with Clear All Filters button
Browse files Browse the repository at this point in the history
- Refactored Clear All Filters button to use setSearchTerm function to reset search term to an empty string and clear filters.
- This change renders clearFilters function unnecessary and has been removed.
- Removed clearFilters function from FilterDrawerV2.tsx, DrawerInterior.tsx, Risk.tsx, and Inventory.tsx.
- Cleaned up html and css in DrawerInterior.tsx.
  • Loading branch information
hawkishpolicy committed Feb 19, 2025
1 parent 69d18d0 commit c93a2de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
26 changes: 15 additions & 11 deletions frontend/src/components/DrawerInterior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface Props {
removeFilter: ContextType['removeFilter'];
filters: ContextType['filters'];
facets: ContextType['facets'];
clearFilters: ContextType['clearFilters'];
searchTerm: ContextType['searchTerm'];
setSearchTerm: ContextType['setSearchTerm'];
initialFilters: any[];
Expand Down Expand Up @@ -70,7 +69,6 @@ export const DrawerInterior: React.FC<Props> = (props) => {
addFilter,
removeFilter,
facets,
clearFilters,
setSearchTerm,
initialFilters
} = props;
Expand Down Expand Up @@ -119,6 +117,13 @@ export const DrawerInterior: React.FC<Props> = (props) => {
});
};

const clearFiltersAndSearch = () => {
setSearchTerm('', {
shouldClearFilters: true,
autocompleteResults: false
});
};

const revertSearch = () => {
setSearchTerm('', {
shouldClearFilters: true,
Expand Down Expand Up @@ -244,17 +249,16 @@ export const DrawerInterior: React.FC<Props> = (props) => {
<FilterAlt />
</Stack>
</Toolbar>
<Divider />

{clearFilters && (
<Box display="flex" width="100%" justifyContent="center">
<Button onClick={clearFilters}>Clear All Filters</Button>
</Box>
)}
{filters.length > 0 ? (
<>
<Divider />
<Box marginY={1} display="flex" width="100%" justifyContent="center">
<Button onClick={clearFiltersAndSearch}>Clear All Filters</Button>
</Box>
</>
) : null}
<Accordion
sx={{
marginTop: 1
}}
elevation={0}
square
classes={{
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/FilterDrawerV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const FilterDrawer: FC<
addFilter,
removeFilter,
facets,
clearFilters,
searchTerm,
setSearchTerm,
filters,
Expand Down Expand Up @@ -62,7 +61,6 @@ export const FilterDrawer: FC<
removeFilter={removeFilter}
filters={filters}
facets={facets}
clearFilters={filters.length > 0 ? () => clearFilters([]) : undefined}
searchTerm={searchTerm}
setSearchTerm={setSearchTerm}
initialFilters={initialFilters}
Expand Down Expand Up @@ -100,15 +98,13 @@ export const FilterDrawerV2 = withSearch(
removeFilter,
filters,
facets,
clearFilters,
searchTerm,
setSearchTerm
}: ContextType) => ({
addFilter,
removeFilter,
filters,
facets,
clearFilters,
searchTerm,
setSearchTerm
})
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/pages/Risk/Risk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,13 @@ export const RiskWithSearch = withSearch(
removeFilter,
filters,
facets,
clearFilters,
searchTerm,
setSearchTerm
}: ContextType) => ({
addFilter,
removeFilter,
filters,
facets,
clearFilters,
searchTerm,
setSearchTerm
})
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/pages/Search/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ export const Dashboard = withSearch(
searchTerm,
setSearchTerm,
autocompletedResults,
clearFilters,
saveSearch,
sortDirection,
sortField,
Expand All @@ -265,7 +264,6 @@ export const Dashboard = withSearch(
searchTerm,
setSearchTerm,
autocompletedResults,
clearFilters,
saveSearch,
sortDirection,
sortField,
Expand Down

0 comments on commit c93a2de

Please sign in to comment.