1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ServiceRepository } from 'services/services';
6 import { MiddlewareAPI, Dispatch } from 'redux';
8 DataExplorerMiddlewareService, dataExplorerToListParams, listResultsToDataExplorerItemsMeta, getDataExplorerColumnFilters, getOrder
9 } from 'store/data-explorer/data-explorer-middleware-service';
10 import { RootState } from 'store/store';
11 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
12 import { DataExplorer, getDataExplorer } from 'store/data-explorer/data-explorer-reducer';
13 import { BoundDataExplorerActions } from 'store/data-explorer/data-explorer-action';
14 import { updateResources } from 'store/resources/resources-actions';
15 import { ListArguments } from 'services/common-service/common-service';
16 import { ProcessResource } from 'models/process';
17 import { FilterBuilder, joinFilters } from 'services/api/filter-builder';
18 import { DataColumns } from 'components/data-table/data-table';
19 import { ProcessStatusFilter, buildProcessStatusFilters } from '../resource-type-filters/resource-type-filters';
20 import { ContainerRequestResource, containerRequestFieldsNoMounts } from 'models/container-request';
21 import { progressIndicatorActions } from '../progress-indicator/progress-indicator-actions';
22 import { loadMissingProcessesInformation } from '../project-panel/project-panel-middleware-service';
24 export class ProcessesMiddlewareService extends DataExplorerMiddlewareService {
25 constructor(private services: ServiceRepository, private actions: BoundDataExplorerActions, id: string) {
29 getFilters(api: MiddlewareAPI<Dispatch, RootState>, dataExplorer: DataExplorer): string | null {
30 const columns = dataExplorer.columns as DataColumns<string, ContainerRequestResource>;
31 const statusColumnFilters = getDataExplorerColumnFilters(columns, 'Status');
32 const activeStatusFilter = Object.keys(statusColumnFilters).find(
33 filterName => statusColumnFilters[filterName].selected
34 ) || ProcessStatusFilter.ALL;
36 const nameFilter = new FilterBuilder().addILike("name", dataExplorer.searchValue).getFilters();
37 const statusFilter = buildProcessStatusFilters(new FilterBuilder(), activeStatusFilter).getFilters();
45 getParams(api: MiddlewareAPI<Dispatch, RootState>, dataExplorer: DataExplorer): ListArguments | null {
46 const filters = this.getFilters(api, dataExplorer)
47 if (filters === null) {
51 ...dataExplorerToListParams(dataExplorer),
52 order: getOrder<ProcessResource>(dataExplorer),
57 async requestItems(api: MiddlewareAPI<Dispatch, RootState>, criteriaChanged?: boolean, background?: boolean) {
58 const state = api.getState();
59 const dataExplorer = getDataExplorer(state.dataExplorer, this.getId());
62 if (!background) { api.dispatch(progressIndicatorActions.START_WORKING(this.getId())); }
64 const params = this.getParams(api, dataExplorer);
66 if (params !== null) {
67 const containerRequests = await this.services.containerRequestService.list(
69 ...this.getParams(api, dataExplorer),
70 select: containerRequestFieldsNoMounts
72 api.dispatch(updateResources(containerRequests.items));
73 await api.dispatch<any>(loadMissingProcessesInformation(containerRequests.items));
74 api.dispatch(this.actions.SET_ITEMS({
75 ...listResultsToDataExplorerItemsMeta(containerRequests),
76 items: containerRequests.items.map(resource => resource.uuid),
79 api.dispatch(this.actions.SET_ITEMS({
82 rowsPerPage: dataExplorer.rowsPerPage,
86 if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }
88 api.dispatch(snackbarActions.OPEN_SNACKBAR({
89 message: 'Could not fetch process list.',
90 kind: SnackbarKind.ERROR
92 if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }