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, GroupMembersPanelActions } from 'store/group-details-panel/group-details-panel-actions';
14 import { LinkClass } from 'models/link';
15 import { ResourceKind } from 'models/resource';
17 export class GroupDetailsPanelMembersMiddlewareService extends DataExplorerMiddlewareService {
19 constructor(private services: ServiceRepository, id: string) {
23 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
24 const dataExplorer = getDataExplorer(api.getState().dataExplorer, this.getId());
25 const groupUuid = getCurrentGroupDetailsPanelUuid(api.getState().properties);
26 if (!dataExplorer || !groupUuid) {
27 api.dispatch(groupsDetailsPanelDataExplorerIsNotSet());
30 const groupResource = await this.services.groupsService.get(groupUuid);
31 api.dispatch(updateResources([groupResource]));
33 const permissionsIn = await this.services.permissionService.list({
34 filters: new FilterBuilder()
35 .addEqual('head_uuid', groupUuid)
36 .addEqual('link_class', LinkClass.PERMISSION)
39 api.dispatch(updateResources(permissionsIn.items));
41 api.dispatch(GroupMembersPanelActions.SET_ITEMS({
42 ...listResultsToDataExplorerItemsMeta(permissionsIn),
43 items: permissionsIn.items.map(item => item.uuid),
46 const usersIn = await this.services.userService.list({
47 filters: new FilterBuilder()
48 .addIn('uuid', permissionsIn.items
49 .filter((item) => item.tailKind === ResourceKind.USER)
50 .map(item => item.tailUuid))
54 api.dispatch(updateResources(usersIn.items));
56 const projectsIn = await this.services.projectService.list({
57 filters: new FilterBuilder()
58 .addIn('uuid', permissionsIn.items
59 .filter((item) => item.tailKind === ResourceKind.PROJECT)
60 .map(item => item.tailUuid))
64 api.dispatch(updateResources(projectsIn.items));
66 api.dispatch(couldNotFetchGroupDetailsContents());
72 const groupsDetailsPanelDataExplorerIsNotSet = () =>
73 snackbarActions.OPEN_SNACKBAR({
74 message: 'Group members panel is not ready.',
75 kind: SnackbarKind.ERROR
78 const couldNotFetchGroupDetailsContents = () =>
79 snackbarActions.OPEN_SNACKBAR({
80 message: 'Could not fetch group members.',
81 kind: SnackbarKind.ERROR