From d052ecf67105b5a65511a335e4c3112c74a662a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 16 Feb 2020 01:35:13 +0100 Subject: [PATCH] webui: in the bug list, toggle open and close when clicking --- webui/src/pages/list/Filter.tsx | 2 +- webui/src/pages/list/FilterToolbar.tsx | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/webui/src/pages/list/Filter.tsx b/webui/src/pages/list/Filter.tsx index 1a3cdd6bff16271de83243c2d51ff3b767a23fab..0635e7f053b427dcd618071e600259d4fe440837 100644 --- a/webui/src/pages/list/Filter.tsx +++ b/webui/src/pages/list/Filter.tsx @@ -154,7 +154,7 @@ function FilterDropdown({ export type FilterProps = { active: boolean; - to: LocationDescriptor; + to: LocationDescriptor; // the target on click icon?: React.ComponentType; children: React.ReactNode; }; diff --git a/webui/src/pages/list/FilterToolbar.tsx b/webui/src/pages/list/FilterToolbar.tsx index 825a9dee455f0cee6a49d8f1df0fd7c92ef77a06..c568a9dd31d7a388c13c06fda2c16b051d727d38 100644 --- a/webui/src/pages/list/FilterToolbar.tsx +++ b/webui/src/pages/list/FilterToolbar.tsx @@ -32,7 +32,7 @@ const useStyles = makeStyles(theme => ({ // This prepends the filter text with a count type CountingFilterProps = { - query: string; + query: string; // the query used as a source to count the number of element children: React.ReactNode; } & FilterProps; function CountingFilter({ query, children, ...props }: CountingFilterProps) { @@ -72,6 +72,12 @@ function FilterToolbar({ query, queryLocation }: Props) { ...params, [key]: [value], }); + const toggleParam = (key: string, value: string) => ( + params: Query + ): Query => ({ + ...params, + [key]: params[key] && params[key].includes(value) ? [] : [value], + }); const clearParam = (key: string) => (params: Query): Query => ({ ...params, [key]: [], @@ -87,7 +93,7 @@ function FilterToolbar({ query, queryLocation }: Props) { clearParam('sort'), stringify )(params)} - to={pipe(replaceParam('status', 'open'), loc)(params)} + to={pipe(toggleParam('status', 'open'), loc)(params)} icon={ErrorOutline} > open @@ -99,7 +105,7 @@ function FilterToolbar({ query, queryLocation }: Props) { clearParam('sort'), stringify )(params)} - to={pipe(replaceParam('status', 'closed'), loc)(params)} + to={pipe(toggleParam('status', 'closed'), loc)(params)} icon={CheckCircleOutline} > closed