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 {
24 PAST_VERSION = 'pastVersion'
27 const keyValuePattern = (key: string) => new RegExp(`${key}:([^ ]*)`);
28 const propertyPattern = /has:"(.*?)":"(.*?)"/;
31 keyValuePattern(Keywords.TYPE),
32 keyValuePattern(Keywords.CLUSTER),
33 keyValuePattern(Keywords.PROJECT),
34 keyValuePattern(Keywords.IS),
35 keyValuePattern(Keywords.FROM),
36 keyValuePattern(Keywords.TO),
40 export const parseSearchQuery = parser.parseSearchQuery(patterns);
42 export const getValue = (tokens: string[]) => (key: string) => {
43 const pattern = keyValuePattern(key);
44 const token = tokens.find(t => pattern.test(t));
46 const [, value] = token.split(':');
52 export const getProperties = (tokens: string[]) =>
53 tokens.reduce((properties, token) => {
54 const match = token.match(propertyPattern);
56 const [, key, value] = match;
57 const newProperty = { key, value };
58 return [...properties, newProperty];
64 export const isTrashed = (tokens: string[]) => isSomeState(States.TRASHED, tokens);
66 export const isPastVersion = (tokens: string[]) => isSomeState(States.PAST_VERSION, tokens);
68 const isSomeState = (state: string, tokens: string[]) => {
69 for (const token of tokens) {
70 const match = token.match(keyValuePattern(Keywords.IS)) || ['', ''];
72 const [, value] = match;