X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f79d1cdf7696a3bbcc374df5ce4d1761a28a5ea5..18e6bbd6a0bb60b7f1137fab2dfb88ed7804a8ac:/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 dab83e0114..866e148bcd 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 @@ -30,7 +30,7 @@ import { progressIndicatorActions } from 'store/progress-indicator/progress-indi import { dataExplorerActions } from 'store/data-explorer/data-explorer-action'; export class SearchResultsMiddlewareService extends DataExplorerMiddlewareService { - constructor(private services: ServiceRepository, id: string) { + constructor(private services: ServiceRepository, id: string, private responseMap: Record = {}) { super(id); } @@ -40,6 +40,11 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic const searchValue = state.searchBar.searchValue; const { cluster: clusterId } = getAdvancedDataFromQuery(searchValue); const sessions = getSearchSessions(clusterId, state.auth.sessions); + const recentQueries = this.services.searchService.getRecentQueries(); + //the last query is compared to the current query to check if the value has changed + //once the search button is clicked, the value is pushed to the recentQueries array + //therefore, the last query is the second to last element in the array + const lastQuery = recentQueries[recentQueries.length - 2]; if (searchValue.trim() === '') { return; @@ -63,10 +68,19 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic api.dispatch(progressIndicatorActions.START_WORKING(this.id)) api.dispatch(dataExplorerActions.SET_IS_NOT_FOUND({ id: this.id, isNotFound: false })); + //In SearchResultsPanel, if we don't reset the items available, the items available will + //will be added 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) => { + //if items were added or deleted, we ignore them for "load more" button purposes + if (lastQuery === searchValue && this.responseMap[session.clusterId] && this.responseMap[session.clusterId] !== response.itemsAvailable) { + response.itemsAvailable = this.responseMap[session.clusterId]; + } + this.responseMap[session.clusterId] = response.itemsAvailable; api.dispatch(updateResources(response.items)); api.dispatch(appendItems(response)); numberOfResolvedResponses++; @@ -135,6 +149,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),