1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch, MiddlewareAPI } from "redux";
6 import { DataExplorerMiddlewareService, listResultsToDataExplorerItemsMeta, dataExplorerToListParams } from "~/store/data-explorer/data-explorer-middleware-service";
7 import { RootState } from "~/store/store";
8 import { ServiceRepository } from "~/services/services";
9 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
10 import { getDataExplorer } from "~/store/data-explorer/data-explorer-reducer";
11 import { GroupsPanelActions } from '~/store/groups-panel/groups-panel-actions';
12 import { FilterBuilder } from '~/services/api/filter-builder';
13 import { updateResources } from '~/store/resources/resources-actions';
15 export class GroupsPanelMiddlewareService extends DataExplorerMiddlewareService {
17 constructor(private services: ServiceRepository, id: string) {
21 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
23 const dataExplorer = getDataExplorer(api.getState().dataExplorer, this.getId());
27 api.dispatch(groupsPanelDataExplorerIsNotSet());
33 const filters = new FilterBuilder()
34 .addEqual('groupClass', null)
37 const response = await this.services.groupsService
39 ...dataExplorerToListParams(dataExplorer),
43 api.dispatch(updateResources(response.items));
45 api.dispatch(GroupsPanelActions.SET_ITEMS({
46 ...listResultsToDataExplorerItemsMeta(response),
47 items: response.items.map(item => item.uuid),
53 api.dispatch(couldNotFetchFavoritesContents());
60 const groupsPanelDataExplorerIsNotSet = () =>
61 snackbarActions.OPEN_SNACKBAR({
62 message: 'Groups panel is not ready.'
65 const couldNotFetchFavoritesContents = () =>
66 snackbarActions.OPEN_SNACKBAR({
67 message: 'Could not fetch groups.',
68 kind: SnackbarKind.ERROR