1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { DataExplorerMiddlewareService, dataExplorerToListParams, getDataExplorerColumnFilters } from "store/data-explorer/data-explorer-middleware-service";
6 import { RootState } from "../store";
7 import { ServiceRepository } from "services/services";
8 import { FilterBuilder, joinFilters } from "services/api/filter-builder";
9 import { allProcessesPanelActions } from "./all-processes-panel-action";
10 import { Dispatch, MiddlewareAPI } from "redux";
11 import { resourcesActions } from "store/resources/resources-actions";
12 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
13 import { progressIndicatorActions } from 'store/progress-indicator/progress-indicator-actions';
14 import { getDataExplorer, DataExplorer, getSortColumn } from "store/data-explorer/data-explorer-reducer";
15 import { loadMissingProcessesInformation } from "store/project-panel/project-panel-middleware-service";
16 import { DataColumns } from "components/data-table/data-table";
19 buildProcessStatusFilters,
20 serializeOnlyProcessTypeFilters
21 } from "../resource-type-filters/resource-type-filters";
22 import { AllProcessesPanelColumnNames } from "views/all-processes-panel/all-processes-panel";
23 import { OrderBuilder, OrderDirection } from "services/api/order-builder";
24 import { ProcessResource } from "models/process";
25 import { SortDirection } from "components/data-table/data-column";
26 import { containerRequestFieldsNoMounts } from "models/container-request";
28 export class AllProcessesPanelMiddlewareService extends DataExplorerMiddlewareService {
29 constructor(private services: ServiceRepository, id: string) {
33 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
34 const dataExplorer = getDataExplorer(api.getState().dataExplorer, this.getId());
36 api.dispatch(allProcessesPanelDataExplorerIsNotSet());
39 api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
40 const processItems = await this.services.containerRequestService.list(
42 ...getParams(dataExplorer),
43 // Omit mounts when viewing all process panel
44 select: containerRequestFieldsNoMounts,
47 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
48 api.dispatch(resourcesActions.SET_RESOURCES(processItems.items));
49 await api.dispatch<any>(loadMissingProcessesInformation(processItems.items));
50 api.dispatch(allProcessesPanelActions.SET_ITEMS({
51 items: processItems.items.map((resource: any) => resource.uuid),
52 itemsAvailable: processItems.itemsAvailable,
53 page: Math.floor(processItems.offset / processItems.limit),
54 rowsPerPage: processItems.limit
57 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
58 api.dispatch(allProcessesPanelActions.SET_ITEMS({
62 rowsPerPage: dataExplorer.rowsPerPage
64 api.dispatch(couldNotFetchAllProcessesListing());
70 const getParams = ( dataExplorer: DataExplorer ) => ({
71 ...dataExplorerToListParams(dataExplorer),
72 order: getOrder(dataExplorer),
73 filters: getFilters(dataExplorer)
76 const getFilters = ( dataExplorer: DataExplorer ) => {
77 const columns = dataExplorer.columns as DataColumns<string>;
78 const statusColumnFilters = getDataExplorerColumnFilters(columns, 'Status');
79 const activeStatusFilter = Object.keys(statusColumnFilters).find(
80 filterName => statusColumnFilters[filterName].selected
81 ) || ProcessStatusFilter.ALL;
83 const nameFilter = new FilterBuilder().addILike("name", dataExplorer.searchValue).getFilters();
84 const statusFilter = buildProcessStatusFilters(new FilterBuilder(), activeStatusFilter).getFilters();
85 const typeFilters = serializeOnlyProcessTypeFilters(getDataExplorerColumnFilters(columns, AllProcessesPanelColumnNames.TYPE));
94 const getOrder = (dataExplorer: DataExplorer) => {
95 const sortColumn = getSortColumn(dataExplorer);
96 const order = new OrderBuilder<ProcessResource>();
98 const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.ASC
100 : OrderDirection.DESC;
102 const columnName = sortColumn && sortColumn.name === AllProcessesPanelColumnNames.NAME ? "name" : "createdAt";
104 .addOrder(sortDirection, columnName)
107 return order.getOrder();
111 const allProcessesPanelDataExplorerIsNotSet = () =>
112 snackbarActions.OPEN_SNACKBAR({
113 message: 'All Processes panel is not ready.',
114 kind: SnackbarKind.ERROR
117 const couldNotFetchAllProcessesListing = () =>
118 snackbarActions.OPEN_SNACKBAR({
119 message: 'Could not fetch All Processes listing.',
120 kind: SnackbarKind.ERROR