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 { apiClientAuthorizationsActions } from 'store/api-client-authorizations/api-client-authorizations-actions';
13 import { ListArguments, ListResults } from 'services/common-service/common-service';
14 import { ApiClientAuthorization } from 'models/api-client-authorization';
16 export class ApiClientAuthorizationMiddlewareService extends DataExplorerMiddlewareService {
17 constructor(private services: ServiceRepository, id: string) {
21 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
22 const state = api.getState();
23 const dataExplorer = getDataExplorer(state.dataExplorer, this.getId());
25 const response = await this.services.apiClientAuthorizationService.list(getParams(dataExplorer));
26 api.dispatch(updateResources(response.items));
27 api.dispatch(setItems(response));
29 api.dispatch(couldNotFetchLinks());
34 const getParams = (dataExplorer: DataExplorer): ListArguments => ({
35 ...dataExplorerToListParams(dataExplorer),
36 order: getOrder<ApiClientAuthorization>(dataExplorer)
39 export const setItems = (listResults: ListResults<ApiClientAuthorization>) =>
40 apiClientAuthorizationsActions.SET_ITEMS({
41 ...listResultsToDataExplorerItemsMeta(listResults),
42 items: listResults.items.map(resource => resource.uuid),
45 const couldNotFetchLinks = () =>
46 snackbarActions.OPEN_SNACKBAR({
47 message: 'Could not fetch api client authorizations.',
48 kind: SnackbarKind.ERROR