fix: issue with regex

Aien Saidi created

Change summary

webui/src/pages/list/Filter.tsx        | 6 +++---
webui/src/pages/list/FilterToolbar.tsx | 7 ++++++-
2 files changed, 9 insertions(+), 4 deletions(-)

Detailed changes

webui/src/pages/list/Filter.tsx 🔗

@@ -28,7 +28,7 @@ function parse(query: string): Query {
   const params: Query = {};
 
   // TODO: support escaping without quotes
-  const re = /(\w+):([A-Za-z0-9-]+|(["'])(([^\3]|\\.)*)\3)+/g;
+  const re = /(\w+):([A-Za-z0-9-]+|"([^"]*)")/g;
   let matches;
   while ((matches = re.exec(query)) !== null) {
     if (!params[matches[1]]) {
@@ -36,8 +36,8 @@ function parse(query: string): Query {
     }
 
     let value;
-    if (matches[4]) {
-      value = matches[4];
+    if (matches[3]) {
+      value = matches[3];
     } else {
       value = matches[2];
     }

webui/src/pages/list/FilterToolbar.tsx 🔗

@@ -96,6 +96,8 @@ function FilterToolbar({ query, queryLocation }: Props) {
     params[key] && params[key].length > 0;
   const hasValue = (key: string, value: string): boolean =>
     hasKey(key) && params[key].includes(value);
+  const containsValue = (key: string, value: string): boolean =>
+    hasKey(key) && params[key].indexOf(value) !== -1;
   const loc = pipe(stringify, queryLocation);
   const replaceParam = (key: string, value: string) => (
     params: Query
@@ -170,7 +172,10 @@ function FilterToolbar({ query, queryLocation }: Props) {
       </FilterDropdown>
       <FilterDropdown
         dropdown={labels}
-        itemActive={(key) => hasValue('label', key)}
+        itemActive={(key) => {
+          console.log(params, params[key], key);
+          return containsValue('label', key);
+        }}
         to={(key) => pipe(toggleOrAddParam('label', key), loc)(params)}
         hasFilter
       >