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';
7 import { DataExplorerMiddlewareService, dataExplorerToListParams, getOrder, listResultsToDataExplorerItemsMeta } from 'store/data-explorer/data-explorer-middleware-service';
8 import { RootState } from 'store/store';
9 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
10 import { DataExplorer, getDataExplorer } from 'store/data-explorer/data-explorer-reducer';
11 import { updateResources } from 'store/resources/resources-actions';
12 import { FilterBuilder } from 'services/api/filter-builder';
13 import { WorkflowResource } from 'models/workflow';
14 import { ListResults } from 'services/common-service/common-service';
15 import { workflowPanelActions } from 'store/workflow-panel/workflow-panel-actions';
17 export class WorkflowMiddlewareService extends DataExplorerMiddlewareService {
18 constructor(private services: ServiceRepository, id: string) {
22 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
23 const state = api.getState();
24 const dataExplorer = getDataExplorer(state.dataExplorer, this.getId());
26 const response = await this.services.workflowService.list(getParams(dataExplorer));
27 api.dispatch(updateResources(response.items));
28 api.dispatch(setItems(response));
30 api.dispatch(couldNotFetchWorkflows());
35 export const getParams = (dataExplorer: DataExplorer) => ({
36 ...dataExplorerToListParams(dataExplorer),
37 order: getOrder<WorkflowResource>(dataExplorer),
38 filters: getFilters(dataExplorer)
41 export const getFilters = (dataExplorer: DataExplorer) => {
42 const filters = new FilterBuilder()
43 .addILike("name", dataExplorer.searchValue)
48 export const setItems = (listResults: ListResults<WorkflowResource>) =>
49 workflowPanelActions.SET_ITEMS({
50 ...listResultsToDataExplorerItemsMeta(listResults),
51 items: listResults.items.map(resource => resource.uuid),
54 const couldNotFetchWorkflows = () =>
55 snackbarActions.OPEN_SNACKBAR({
56 message: 'Could not fetch workflows.',
57 kind: SnackbarKind.ERROR