21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / workbench2 / src / views-components / sharing-dialog / sharing-urls.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { RootState } from 'store/store';
6 import { connect } from 'react-redux';
7 import { Dispatch } from 'redux';
8 import { ApiClientAuthorization } from 'models/api-client-authorization';
9 import { filterResources } from 'store/resources/resources';
10 import { ResourceKind } from 'models/resource';
11 import {
12     SharingURLsComponent,
13     SharingURLsComponentActionProps,
14     SharingURLsComponentDataProps
15 } from './sharing-urls-component';
16 import {
17     snackbarActions,
18     SnackbarKind
19 } from 'store/snackbar/snackbar-actions';
20 import { deleteSharingToken } from 'store/sharing-dialog/sharing-dialog-actions';
21
22 const mapStateToProps =
23     (state: RootState, ownProps: { uuid: string }): SharingURLsComponentDataProps => {
24         const sharingTokens = filterResources(
25             (resource: ApiClientAuthorization) =>
26                 resource.kind === ResourceKind.API_CLIENT_AUTHORIZATION  &&
27                 resource.scopes.includes(`GET /arvados/v1/collections/${ownProps.uuid}`) &&
28                 resource.scopes.includes(`GET /arvados/v1/collections/${ownProps.uuid}/`) &&
29                 resource.scopes.includes('GET /arvados/v1/keep_services/accessible')
30             )(state.resources) as ApiClientAuthorization[];
31         const sharingURLsPrefix = state.auth.config.keepWebInlineServiceUrl;
32         return {
33             collectionUuid: ownProps.uuid,
34             sharingTokens,
35             sharingURLsPrefix,
36         }
37     }
38
39 const mapDispatchToProps = (dispatch: Dispatch): SharingURLsComponentActionProps => ({
40     onDeleteSharingToken(uuid: string) {
41         dispatch<any>(deleteSharingToken(uuid));
42     },
43     onCopy(message: string) {
44         dispatch(snackbarActions.OPEN_SNACKBAR({
45             message,
46             hideDuration: 2000,
47             kind: SnackbarKind.SUCCESS
48         }));
49     },
50 })
51
52 export const SharingURLsContent = connect(mapStateToProps, mapDispatchToProps)(SharingURLsComponent)
53