17256: Added map to enable item resolution
[arvados-workbench2.git] / src / store / search-bar / search-query / arv-parser.ts
index 3a52be6c822f5030cd842787a8e51afd2bacbccd..1d0618c6fcc936b1a8cc05db5b7716f0ceecee62 100644 (file)
@@ -19,6 +19,11 @@ export enum Keywords {
     TO = 'to',
 }
 
+export enum States {
+    TRASHED = 'trashed',
+    PAST_VERSION = 'pastVersion'
+}
+
 const keyValuePattern = (key: string) => new RegExp(`${key}:([^ ]*)`);
 const propertyPattern = /has:"(.*?)":"(.*?)"/;
 
@@ -54,3 +59,21 @@ export const getProperties = (tokens: string[]) =>
         }
         return properties;
     }, [] as Property[]);
+
+
+export const isTrashed = (tokens: string[]) => isSomeState(States.TRASHED, tokens);
+
+export const isPastVersion = (tokens: string[]) => isSomeState(States.PAST_VERSION, tokens);
+
+const isSomeState = (state: string, tokens: string[]) => {
+    for (const token of tokens) {
+        const match = token.match(keyValuePattern(Keywords.IS)) || ['', ''];
+        if (match) {
+            const [, value] = match;
+            if(value === state) {
+                return true;
+            }
+        }
+    }
+    return false;
+};