Skip to content

Commit

Permalink
wire up clearFilters trigger and button
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Jan 20, 2025
1 parent c78a06a commit 17e8d65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 0 additions & 2 deletions editor.planx.uk/src/pages/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export const Filters: React.FC<FiltersProps> = ({
setSelectedFilters([]);
formik.setFieldValue("pattern", "");
clearSearchParams();
window.location.reload();
};

const handleFiltering = (filtersArg: FilterState | undefined) => {
Expand Down Expand Up @@ -300,7 +299,6 @@ export const Filters: React.FC<FiltersProps> = ({
{expanded ? "Hide filters" : "Show filters"}
</Typography>
</FiltersToggle>
<Button onClick={() => clearAllFilters()} title="Clear" />
<Box sx={{ display: "flex", gap: 1 }}>
{selectedFilters &&
selectedFilters.map((filter) => {
Expand Down
27 changes: 19 additions & 8 deletions editor.planx.uk/src/pages/Team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ const Team: React.FC = () => {
onSubmit: () => {},
});

const haveFlowsBeenFiltered = filteredFlows?.length !== flows?.length;

useEffect(() => {
// resets trigger when filters cleared
if (!haveFlowsBeenFiltered) {
setTriggerClearFilters(false);
}
}, [haveFlowsBeenFiltered]);

const sortOptions: SortableFields<FlowSummary>[] = [
{
displayName: "Last updated",
Expand Down Expand Up @@ -442,7 +451,6 @@ const Team: React.FC = () => {

const numberOfServices = filteredFlows?.length || 0;
const pluralisedService = numberOfServices === 1 ? "service" : "services";
const haveFlowsBeenFiltered = filteredFlows?.length === flows?.length;
const listTitle = haveFlowsBeenFiltered
? "Showing all services"
: `Showing ${numberOfServices} ${pluralisedService}`;
Expand Down Expand Up @@ -544,14 +552,15 @@ const Team: React.FC = () => {
<Typography variant="h3" component="h2">
{listTitle}
</Typography>
{!haveFlowsBeenFiltered && (
<Button variant="link">Clear filters</Button>
{haveFlowsBeenFiltered && (
<Button
onClick={() => setTriggerClearFilters(true)}
variant="link"
>
Clear filters
</Button>
)}
</Box>
<Button
title="Clear"
onClick={() => setTriggerClearFilters(true)}
/>
{hasFeatureFlag("SORT_FLOWS") && flows && (
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
<Typography variant="body2">
Expand Down Expand Up @@ -594,7 +603,9 @@ const Team: React.FC = () => {
<Typography variant="h3" textAlign="center">
No results
</Typography>
<Button variant="link">Clear filters</Button>
<Button onClick={() => setTriggerClearFilters(true)} variant="link">
Clear filters
</Button>
</Box>
)}
{flows && !flows.length && <GetStarted flows={flows} />}
Expand Down

0 comments on commit 17e8d65

Please sign in to comment.