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 // Noop if data explorer refresh is triggered from another panel
31 const groupResource = await this.services.groupsService.get(groupUuid);
32 api.dispatch(updateResources([groupResource]));
34 const permissionsIn = await this.services.permissionService.list({
35 filters: new FilterBuilder()
36 .addEqual('head_uuid', groupUuid)
37 .addEqual('link_class', LinkClass.PERMISSION)
40 api.dispatch(updateResources(permissionsIn.items));
42 api.dispatch(GroupMembersPanelActions.SET_ITEMS({
43 ...listResultsToDataExplorerItemsMeta(permissionsIn),
44 items: permissionsIn.items.map(item => item.uuid),
47 const usersIn = await this.services.userService.list({
48 filters: new FilterBuilder()
49 .addIn('uuid', permissionsIn.items
50 .filter((item) => item.tailKind === ResourceKind.USER)
51 .map(item => item.tailUuid))
55 api.dispatch(updateResources(usersIn.items));
57 const projectsIn = await this.services.projectService.list({
58 filters: new FilterBuilder()
59 .addIn('uuid', permissionsIn.items
60 .filter((item) => item.tailKind === ResourceKind.PROJECT)
61 .map(item => item.tailUuid))
65 api.dispatch(updateResources(projectsIn.items));
67 api.dispatch(couldNotFetchGroupDetailsContents());
73 const couldNotFetchGroupDetailsContents = () =>
74 snackbarActions.OPEN_SNACKBAR({
75 message: 'Could not fetch group members.',
76 kind: SnackbarKind.ERROR