From f3a5275522c90a9ddc961b994a8c9adc041d0f3d Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sat, 17 Apr 2021 15:13:00 +0300
Subject: feat: complete filtering logic

---
 src/lib/ServiceList.tsx | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'src/lib/ServiceList.tsx')

diff --git a/src/lib/ServiceList.tsx b/src/lib/ServiceList.tsx
index 5abae6b..6316ea1 100644
--- a/src/lib/ServiceList.tsx
+++ b/src/lib/ServiceList.tsx
@@ -52,8 +52,16 @@ const ServiceList: React.FC = () => {
     history.push(route);
   };
 
+  const applyFilter = (key: string, value: string) => {
+    const updatedQuery = { ...query, [key]: value };
+    if (value === '-') delete updatedQuery[key];
+
+    const queryString = new URLSearchParams(updatedQuery);
+    history.push(`${service.route}?${queryString}`);
+  };
+
   return (
-    <Page title={service.name} actions={actions} filters={filters}>
+    <Page title={service.name} actions={actions} filters={filters} applyFilter={applyFilter}>
       <ListTable items={data} fields={service.tableFields} handleRowClick={handleRowClick} />
     </Page>
   );
-- 
cgit v1.2.3

