[ARVADOS-WORKBENCH2] created: 1.3.0-346-g4a72c22d
Git user
git at public.curoverse.com
Mon Jan 28 03:18:45 EST 2019
at 4a72c22ddb45dce37ff0f9f18d4d73c289a08070 (commit)
commit 4a72c22ddb45dce37ff0f9f18d4d73c289a08070
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date: Mon Jan 28 09:18:24 2019 +0100
searching by description and uuid
Feature #14772
Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts
index 05b6f050..01a0311e 100644
--- a/src/store/search-bar/search-bar-actions.ts
+++ b/src/store/search-bar/search-bar-actions.ts
@@ -10,8 +10,7 @@ import { RootState } from '~/store/store';
import { initUserProject, treePickerActions } from '~/store/tree-picker/tree-picker-actions';
import { ServiceRepository } from '~/services/services';
import { FilterBuilder } from "~/services/api/filter-builder";
-import { ResourceKind } from '~/models/resource';
-import { GroupClass } from '~/models/group';
+import { ResourceKind, isResourceUuid, extractUuidKind } from '~/models/resource';
import { SearchView } from '~/store/search-bar/search-bar-reducer';
import { navigateTo, navigateToSearchResults } from '~/store/navigation/navigation-action';
import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
@@ -404,8 +403,8 @@ export const getSearchSessions = (clusterId: string | undefined, sessions: Sessi
export const getFilters = (filterName: string, searchValue: string, sq: ParseSearchQuery): string => {
const filter = new FilterBuilder();
-
- const resourceKind = getSearchQueryFirstProp(sq, 'type') as ResourceKind;
+ const isSearchQueryUuid = isResourceUuid(sq.values[0]);
+ const resourceKind = getSearchQueryFirstProp(sq, 'type') as ResourceKind;
let prefix = '';
switch (resourceKind) {
@@ -422,7 +421,7 @@ export const getFilters = (filterName: string, searchValue: string, sq: ParseSea
const isTrashed = getSearchQueryPropValue(sq, 'is', 'trashed');
- if (!sq.hasKeywords) {
+ if (!sq.hasKeywords && !isSearchQueryUuid) {
filter
.addILike(filterName, searchValue, GroupContentsResourcePrefix.COLLECTION)
.addILike(filterName, searchValue, GroupContentsResourcePrefix.PROJECT)
@@ -433,7 +432,15 @@ export const getFilters = (filterName: string, searchValue: string, sq: ParseSea
if (isTrashed) {
filter.addILike(filterName, searchValue, GroupContentsResourcePrefix.PROCESS);
}
- } else {
+ } else if (!sq.hasKeywords && isSearchQueryUuid) {
+ filter
+ .addILike('uuid', searchValue, GroupContentsResourcePrefix.COLLECTION)
+ .addILike('uuid', searchValue, GroupContentsResourcePrefix.PROJECT)
+ .addILike('uuid', searchValue, GroupContentsResourcePrefix.PROCESS)
+ .addEqual('is_trashed', false, GroupContentsResourcePrefix.COLLECTION)
+ .addEqual('is_trashed', false, GroupContentsResourcePrefix.PROJECT);
+ }
+ else {
if (prefix) {
sq.values.forEach(v =>
filter.addILike(filterName, v, prefix)
@@ -452,6 +459,13 @@ export const getFilters = (filterName: string, searchValue: string, sq: ParseSea
}
});
}
+ if (prefix && !isTrashed) {
+ sq.values.forEach(v =>
+ filter.addILike(filterName, v, prefix)
+ .addEqual('is_trashed', false, GroupContentsResourcePrefix.COLLECTION)
+ .addEqual('is_trashed', false, GroupContentsResourcePrefix.PROJECT)
+ );
+ }
if (isTrashed) {
sq.values.forEach(v => {
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 12578a2d..efe62f23 100644
--- a/src/store/search-results-panel/search-results-middleware-service.ts
+++ b/src/store/search-results-panel/search-results-middleware-service.ts
@@ -26,6 +26,7 @@ import { joinFilters } from '~/services/api/filter-builder';
import { DataColumns } from '~/components/data-table/data-table';
import { serializeResourceTypeFilters } from '~/store//resource-type-filters/resource-type-filters';
import { ProjectPanelColumnNames } from '~/views/project-panel/project-panel';
+import * as _ from 'lodash';
export class SearchResultsMiddlewareService extends DataExplorerMiddlewareService {
constructor(private services: ServiceRepository, id: string) {
@@ -46,29 +47,46 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic
}
try {
- const params = getParams(dataExplorer, searchValue, sq);
- const lists: ListResults<GroupContentsResource>[] = await Promise.all(sessions.map(session =>
- this.services.groupsService.contents('', params, session)
+ const nameParams = getParams(dataExplorer, searchValue, sq, 'name');
+
+ const nameLists: ListResults<GroupContentsResource>[] = await Promise.all(sessions.map(session =>
+ this.services.groupsService.contents('', nameParams, session)
));
- const items = lists
+ const nameItems = nameLists
.reduce((items, list) => items.concat(list.items), [] as GroupContentsResource[]);
- const itemsAvailable = lists
+ const nameItemsAvailable = nameLists
.reduce((itemsAvailable, list) => itemsAvailable + list.itemsAvailable, 0);
- const list: ListResults<GroupContentsResource> = {
- ...params,
+ const descriptionParams = getParams(dataExplorer, searchValue, sq, 'description');
+
+ const descriptionLists: ListResults<GroupContentsResource>[] = await Promise.all(sessions.map(session =>
+ this.services.groupsService.contents('', descriptionParams, session)
+ ));
+
+ const descriptionItems = descriptionLists
+ .reduce((items, list) => items.concat(list.items), [] as GroupContentsResource[]);
+
+ const descriptionItemsAvailable = descriptionLists
+ .reduce((itemsAvailable, list) => itemsAvailable + list.itemsAvailable, 0);
+
+ const items = nameItems.concat(descriptionItems);
+
+ const uniqueItems = _.uniqBy(items, 'uuid');
+
+ const mainList: ListResults<GroupContentsResource> = {
+ ...nameParams,
kind: '',
- items,
- itemsAvailable
+ items: uniqueItems,
+ itemsAvailable: nameItemsAvailable + descriptionItemsAvailable
};
- api.dispatch(updateResources(list.items));
+ api.dispatch(updateResources(mainList.items));
+
api.dispatch(criteriaChanged
- ? setItems(list)
- : appendItems(list)
- );
+ ? setItems(mainList)
+ : appendItems(mainList));
} catch {
api.dispatch(couldNotFetchSearchResults());
@@ -78,16 +96,16 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic
const typeFilters = (columns: DataColumns<string>) => serializeResourceTypeFilters(getDataExplorerColumnFilters(columns, ProjectPanelColumnNames.TYPE));
-export const getParams = (dataExplorer: DataExplorer, searchValue: string, sq: ParseSearchQuery) => ({
+export const getParams = (dataExplorer: DataExplorer, searchValue: string, sq: ParseSearchQuery, filter: string) => ({
...dataExplorerToListParams(dataExplorer),
filters: joinFilters(
- getFilters('name', searchValue, sq),
+ getFilters(filter, searchValue, sq),
typeFilters(dataExplorer.columns)),
- order: getOrder(dataExplorer),
+ order: getOrder(dataExplorer, filter),
includeTrash: true
});
-const getOrder = (dataExplorer: DataExplorer) => {
+const getOrder = (dataExplorer: DataExplorer, orderBy: any) => {
const sortColumn = getSortColumn(dataExplorer);
const order = new OrderBuilder<GroupContentsResource>();
if (sortColumn) {
@@ -95,7 +113,7 @@ const getOrder = (dataExplorer: DataExplorer) => {
? OrderDirection.ASC
: OrderDirection.DESC;
- const columnName = sortColumn && sortColumn.name === SearchResultsPanelColumnNames.NAME ? "name" : "modifiedAt";
+ const columnName = sortColumn && sortColumn.name === SearchResultsPanelColumnNames.NAME ? orderBy : "modifiedAt";
return order
.addOrder(sortDirection, columnName, GroupContentsResourcePrefix.COLLECTION)
.addOrder(sortDirection, columnName, GroupContentsResourcePrefix.PROCESS)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list