2 // Copyright (C) The Arvados Authors. All rights reserved.
4 // SPDX-License-Identifier: AGPL-3.0
6 import * as parser from '~/store/search-bar/search-query/parser';
13 export enum Keywords {
26 const keyValuePattern = (key: string) => new RegExp(`${key}:([^ ]*)`);
27 const propertyPattern = /has:"(.*?)":"(.*?)"/;
30 keyValuePattern(Keywords.TYPE),
31 keyValuePattern(Keywords.CLUSTER),
32 keyValuePattern(Keywords.PROJECT),
33 keyValuePattern(Keywords.IS),
34 keyValuePattern(Keywords.FROM),
35 keyValuePattern(Keywords.TO),
39 export const parseSearchQuery = parser.parseSearchQuery(patterns);
41 export const getValue = (tokens: string[]) => (key: string) => {
42 const pattern = keyValuePattern(key);
43 const token = tokens.find(t => pattern.test(t));
45 const [, value] = token.split(':');
51 export const getProperties = (tokens: string[]) =>
52 tokens.reduce((properties, token) => {
53 const match = token.match(propertyPattern);
55 const [, key, value] = match;
56 const newProperty = { key, value };
57 return [...properties, newProperty];
63 export const isTrashed = (tokens: string[]) => {
64 for (const token of tokens) {
65 const match = token.match(keyValuePattern(Keywords.IS)) || ['', ''];
67 const [, value] = match;
68 if(value === States.TRASHED) {