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 } 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 { FilterBuilder } from '~/services/api/filter-builder';
12 import { updateResources } from '~/store/resources/resources-actions';
13 import { getCurrentGroupDetailsPanelUuid, GroupDetailsPanelActions } from '~/store/group-details-panel/group-details-panel-actions';
14 import { LinkClass } from '~/models/link';
16 export class GroupDetailsPanelMiddlewareService extends DataExplorerMiddlewareService {
18 constructor(private services: ServiceRepository, id: string) {
22 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
24 const dataExplorer = getDataExplorer(api.getState().dataExplorer, this.getId());
25 const groupUuid = getCurrentGroupDetailsPanelUuid(api.getState().properties);
27 if (!dataExplorer || !groupUuid) {
29 api.dispatch(groupsDetailsPanelDataExplorerIsNotSet());
35 const permissions = await this.services.permissionService.list({
37 filters: new FilterBuilder()
38 .addEqual('tailUuid', groupUuid)
39 .addEqual('linkClass', LinkClass.PERMISSION)
44 api.dispatch(updateResources(permissions.items));
46 const users = await this.services.userService.list({
48 filters: new FilterBuilder()
49 .addIn('uuid', permissions.items.map(item => item.headUuid))
54 api.dispatch(GroupDetailsPanelActions.SET_ITEMS({
55 ...listResultsToDataExplorerItemsMeta(permissions),
56 items: users.items.map(item => item.uuid),
59 api.dispatch(updateResources(users.items));
63 api.dispatch(couldNotFetchGroupDetailsContents());
70 const groupsDetailsPanelDataExplorerIsNotSet = () =>
71 snackbarActions.OPEN_SNACKBAR({
72 message: 'Group details panel is not ready.',
73 kind: SnackbarKind.ERROR
76 const couldNotFetchGroupDetailsContents = () =>
77 snackbarActions.OPEN_SNACKBAR({
78 message: 'Could not fetch group details.',
79 kind: SnackbarKind.ERROR