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 {
22 const keyValuePattern = (key: string) => new RegExp(`${key}:([^ ]*)`);
23 const propertyPattern = /has:"(.*?)":"(.*?)"/;
26 keyValuePattern(Keywords.TYPE),
27 keyValuePattern(Keywords.CLUSTER),
28 keyValuePattern(Keywords.PROJECT),
29 keyValuePattern(Keywords.IS),
30 keyValuePattern(Keywords.FROM),
31 keyValuePattern(Keywords.TO),
35 export const parseSearchQuery = parser.parseSearchQuery(patterns);
37 export const getValue = (tokens: string[]) => (key: string) => {
38 const pattern = keyValuePattern(key);
39 const token = tokens.find(t => pattern.test(t));
41 const [, value] = token.split(':');
47 export const getProperties = (tokens: string[]) =>
48 tokens.reduce((properties, token) => {
49 const match = token.match(propertyPattern);
51 const [, key, value] = match;
52 const newProperty = { key, value };
53 return [...properties, newProperty];