X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2508b089d2369bf57811f9f96c14c2ee22dd664f..7a840279498805223af62491cb9b18fd1335bc9c:/services/workbench2/src/store/search-results-panel/search-results-middleware-service.ts diff --git a/services/workbench2/src/store/search-results-panel/search-results-middleware-service.ts b/services/workbench2/src/store/search-results-panel/search-results-middleware-service.ts index c13092d485..8e5ad1bec1 100644 --- a/services/workbench2/src/store/search-results-panel/search-results-middleware-service.ts +++ b/services/workbench2/src/store/search-results-panel/search-results-middleware-service.ts @@ -17,7 +17,7 @@ import { searchResultsPanelActions } from 'store/search-results-panel/search-res import { getSearchSessions, queryToFilters, - getAdvancedDataFromQuery + getAdvancedDataFromQuery, } from 'store/search-bar/search-bar-actions'; import { getSortColumn } from "store/data-explorer/data-explorer-reducer"; import { FilterBuilder, joinFilters } from 'services/api/filter-builder'; @@ -26,6 +26,8 @@ import { serializeResourceTypeFilters } from 'store//resource-type-filters/resou import { ProjectPanelColumnNames } from 'views/project-panel/project-panel'; import { ResourceKind } from 'models/resource'; import { ContainerRequestResource } from 'models/container-request'; +import { progressIndicatorActions } from 'store/progress-indicator/progress-indicator-actions'; +import { dataExplorerActions } from 'store/data-explorer/data-explorer-action'; export class SearchResultsMiddlewareService extends DataExplorerMiddlewareService { constructor(private services: ServiceRepository, id: string) { @@ -55,12 +57,30 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic api.dispatch(setItems(initial)); } + const numberOfSessions = sessions.length; + let numberOfResolvedResponses = 0; + let totalNumItemsAvailable = 0; + api.dispatch(progressIndicatorActions.START_WORKING(this.id)) + api.dispatch(dataExplorerActions.SET_IS_NOT_FOUND({ id: this.id, isNotFound: false })); + + //In all other data tables, itemsAvailable will equal the number of returned items for a single session. + //In SearchResultsPanel, multiple sessions can be queried so items available needs to be + //reset in order to prevent adding the current value to the previous value every time + //the 'load more' button is clicked. + api.dispatch(resetItemsAvailable()); + sessions.forEach(session => { const params = getParams(dataExplorer, searchValue, session.apiRevision); this.services.groupsService.contents('', params, session) .then((response) => { api.dispatch(updateResources(response.items)); api.dispatch(appendItems(response)); + numberOfResolvedResponses++; + totalNumItemsAvailable += response.itemsAvailable; + if (numberOfResolvedResponses === numberOfSessions) { + api.dispatch(progressIndicatorActions.STOP_WORKING(this.id)) + if(totalNumItemsAvailable === 0) api.dispatch(dataExplorerActions.SET_IS_NOT_FOUND({ id: this.id, isNotFound: true })) + } // Request all containers for process status to be available const containerRequests = response.items.filter((item) => item.kind === ResourceKind.CONTAINER_REQUEST) as ContainerRequestResource[]; const containerUuids = containerRequests.map(container => container.containerUuid).filter(uuid => uuid !== null) as string[]; @@ -73,9 +93,10 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic .then((containers) => { api.dispatch(updateResources(containers.items)); }); - }).catch(() => { - api.dispatch(couldNotFetchSearchResults(session.clusterId)); - }); + }).catch(() => { + api.dispatch(couldNotFetchSearchResults(session.clusterId)); + api.dispatch(progressIndicatorActions.STOP_WORKING(this.id)) + }); } ); } @@ -102,10 +123,12 @@ const getOrder = (dataExplorer: DataExplorer) => { ? OrderDirection.ASC : OrderDirection.DESC; + // Use createdAt as a secondary sort column so we break ties consistently. return order .addOrder(sortDirection, sortColumn.sort.field, GroupContentsResourcePrefix.COLLECTION) .addOrder(sortDirection, sortColumn.sort.field, GroupContentsResourcePrefix.PROCESS) .addOrder(sortDirection, sortColumn.sort.field, GroupContentsResourcePrefix.PROJECT) + .addOrder(OrderDirection.DESC, "createdAt", GroupContentsResourcePrefix.PROCESS) .getOrder(); } else { return order.getOrder(); @@ -118,6 +141,9 @@ export const setItems = (listResults: ListResults) => items: listResults.items.map(resource => resource.uuid), }); +export const resetItemsAvailable = () => + searchResultsPanelActions.RESET_ITEMS_AVAILABLE(); + export const appendItems = (listResults: ListResults) => searchResultsPanelActions.APPEND_ITEMS({ ...listResultsToDataExplorerItemsMeta(listResults),