X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/bf5bf5faa1f61a2b78ff6153daff70a7bb08e939..c859c9d9325e2ed86d5d7b067e1209e73ee81251:/src/store/search-bar/search-query/arv-parser.ts diff --git a/src/store/search-bar/search-query/arv-parser.ts b/src/store/search-bar/search-query/arv-parser.ts index 3a52be6c..1d0618c6 100644 --- a/src/store/search-bar/search-query/arv-parser.ts +++ b/src/store/search-bar/search-query/arv-parser.ts @@ -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; +};