From dc10e586102b4aad5d3c82d6b6cf799a9277a929 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 5 Oct 2020 13:13:52 -0300 Subject: [PATCH] 16718: Adds option to search for collection's past versions. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/models/search-bar.ts | 1 + src/store/search-bar/search-bar-actions.test.ts | 6 ++++++ src/store/search-bar/search-bar-actions.ts | 3 +++ src/store/search-bar/search-query/arv-parser.ts | 11 ++++++++--- .../search-results-middleware-service.ts | 3 ++- .../form-fields/search-bar-form-fields.tsx | 6 ++++++ .../search-bar/search-bar-advanced-view.tsx | 5 ++++- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/models/search-bar.ts b/src/models/search-bar.ts index c71faf2f..09b8b6b7 100644 --- a/src/models/search-bar.ts +++ b/src/models/search-bar.ts @@ -9,6 +9,7 @@ export type SearchBarAdvancedFormData = { cluster?: string; projectUuid?: string; inTrash: boolean; + pastVersions: boolean; dateFrom: string; dateTo: string; saveQuery: boolean; diff --git a/src/store/search-bar/search-bar-actions.test.ts b/src/store/search-bar/search-bar-actions.test.ts index 68804dfb..a579183c 100644 --- a/src/store/search-bar/search-bar-actions.test.ts +++ b/src/store/search-bar/search-bar-actions.test.ts @@ -15,6 +15,7 @@ describe('search-bar-actions', () => { cluster: undefined, projectUuid: undefined, inTrash: true, + pastVersions: false, dateFrom: '', dateTo: '', properties: [{ @@ -37,6 +38,7 @@ describe('search-bar-actions', () => { cluster: 'c97qx', projectUuid: undefined, inTrash: true, + pastVersions: false, dateFrom: '2017-08-01', dateTo: '', properties: [{ @@ -57,6 +59,7 @@ describe('search-bar-actions', () => { cluster: 'c97qx', projectUuid: undefined, inTrash: true, + pastVersions: false, dateFrom: '2017-08-01', dateTo: '', properties: [ @@ -78,6 +81,7 @@ describe('search-bar-actions', () => { cluster: undefined, projectUuid: undefined, inTrash: false, + pastVersions: false, dateFrom: '', dateTo: '', properties: [ @@ -107,6 +111,7 @@ describe('search-bar-actions', () => { cluster: undefined, projectUuid: undefined, inTrash: false, + pastVersions: false, dateFrom: '', dateTo: '', properties: [ @@ -134,6 +139,7 @@ describe('search-bar-actions', () => { cluster: undefined, projectUuid: undefined, inTrash: false, + pastVersions: false, dateFrom: '', dateTo: '', properties: [ diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index d9dc0a64..b010af14 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -268,6 +268,7 @@ export const getQueryFromAdvancedData = (data: SearchBarAdvancedFormData, prevDa cluster: data.cluster, projectUuid: data.projectUuid, inTrash: data.inTrash, + pastVersions: data.pastVersions, dateFrom: data.dateFrom, dateTo: data.dateTo, }; @@ -282,6 +283,7 @@ export const getQueryFromAdvancedData = (data: SearchBarAdvancedFormData, prevDa ['cluster', 'cluster'], ['project', 'projectUuid'], [`is:${parser.States.TRASHED}`, 'inTrash'], + [`is:${parser.States.PAST_VERSION}`, 'pastVersions'], ['from', 'dateFrom'], ['to', 'dateTo'] ]; @@ -307,6 +309,7 @@ export const getAdvancedDataFromQuery = (query: string, vocabulary?: Vocabulary) cluster: getValue(Keywords.CLUSTER), projectUuid: getValue(Keywords.PROJECT), inTrash: parser.isTrashed(tokens), + pastVersions: parser.isPastVersion(tokens), dateFrom: getValue(Keywords.FROM) || '', dateTo: getValue(Keywords.TO) || '', properties: vocabulary diff --git a/src/store/search-bar/search-query/arv-parser.ts b/src/store/search-bar/search-query/arv-parser.ts index c9b7024b..1d0618c6 100644 --- a/src/store/search-bar/search-query/arv-parser.ts +++ b/src/store/search-bar/search-query/arv-parser.ts @@ -20,7 +20,8 @@ export enum Keywords { } export enum States { - TRASHED = 'trashed' + TRASHED = 'trashed', + PAST_VERSION = 'pastVersion' } const keyValuePattern = (key: string) => new RegExp(`${key}:([^ ]*)`); @@ -60,12 +61,16 @@ export const getProperties = (tokens: string[]) => }, [] as Property[]); -export const isTrashed = (tokens: string[]) => { +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 === States.TRASHED) { + if(value === state) { return true; } } diff --git a/src/store/search-results-panel/search-results-middleware-service.ts b/src/store/search-results-panel/search-results-middleware-service.ts index f054a4e4..6d2dce7c 100644 --- a/src/store/search-results-panel/search-results-middleware-service.ts +++ b/src/store/search-results-panel/search-results-middleware-service.ts @@ -77,7 +77,8 @@ const getParams = (dataExplorer: DataExplorer, query: string, apiRevision: numbe typeFilters(dataExplorer.columns) ), order: getOrder(dataExplorer), - includeTrash: getAdvancedDataFromQuery(query).inTrash + includeTrash: getAdvancedDataFromQuery(query).inTrash, + includeOldVersions: getAdvancedDataFromQuery(query).pastVersions }); const getOrder = (dataExplorer: DataExplorer) => { diff --git a/src/views-components/form-fields/search-bar-form-fields.tsx b/src/views-components/form-fields/search-bar-form-fields.tsx index 837f13cb..2eea38c4 100644 --- a/src/views-components/form-fields/search-bar-form-fields.tsx +++ b/src/views-components/form-fields/search-bar-form-fields.tsx @@ -71,6 +71,12 @@ export const SearchBarTrashField = () => component={CheckboxField} label="In trash" />; +export const SearchBarPastVersionsField = () => + ; + export const SearchBarDateFromField = () => + + + -- 2.30.2