1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { compose, Dispatch } from 'redux';
6 import { connect } from 'react-redux';
7 import { RootState } from 'store/store';
8 import { formValueSelector } from 'redux-form'
11 saveSharingDialogChanges,
12 connectSharingDialogProgress,
15 initializeManagementForm
16 } from 'store/sharing-dialog/sharing-dialog-actions';
17 import { WithDialogProps } from 'store/dialog/with-dialog';
19 SharingDialogComponent,
20 SharingDialogDataProps,
21 SharingDialogActionProps
22 } from './sharing-dialog-component';
24 getSharingPublicAccessFormData,
27 SHARING_MANAGEMENT_FORM_NAME,
29 } from 'store/sharing-dialog/sharing-dialog-types';
30 import { WithProgressStateProps } from 'store/progress-indicator/with-progress';
31 import { getDialog } from 'store/dialog/dialog-reducer';
32 import { filterResources } from 'store/resources/resources';
33 import { ApiClientAuthorization } from 'models/api-client-authorization';
34 import { ResourceKind } from 'models/resource';
36 type Props = WithDialogProps<string> & WithProgressStateProps;
38 const sharingManagementFormSelector = formValueSelector(SHARING_MANAGEMENT_FORM_NAME);
40 const mapStateToProps = (state: RootState, { working, ...props }: Props): SharingDialogDataProps => {
41 const dialog = getDialog<SharingDialogData>(state.dialog, SHARING_DIALOG_NAME);
42 const sharedResourceUuid = dialog?.data.resourceUuid || '';
43 const sharingURLsDisabled = state.auth.config.clusterConfig.Workbench.DisableSharingURLsUI;
46 permissions: sharingManagementFormSelector(state, 'permissions'),
47 saveEnabled: hasChanges(state),
51 sharingURLsNr: !sharingURLsDisabled
52 ? (filterResources((resource: ApiClientAuthorization) =>
53 resource.kind === ResourceKind.API_CLIENT_AUTHORIZATION &&
54 resource.scopes.includes(`GET /arvados/v1/collections/${sharedResourceUuid}`) &&
55 resource.scopes.includes(`GET /arvados/v1/collections/${sharedResourceUuid}/`) &&
56 resource.scopes.includes('GET /arvados/v1/keep_services/accessible')
57 )(state.resources) as ApiClientAuthorization[]).length
59 privateAccess: getSharingPublicAccessFormData(state)?.visibility === VisibilityLevel.PRIVATE,
63 const mapDispatchToProps = (dispatch: Dispatch, { ...props }: Props): SharingDialogActionProps => ({
65 onClose: props.closeDialog,
67 setTimeout(() => dispatch<any>(saveSharingDialogChanges), 0);
69 onCreateSharingToken: (d: Date) => () => {
70 dispatch<any>(createSharingToken(d));
72 refreshPermissions: () => {
73 dispatch<any>(initializeManagementForm);
77 export const SharingDialog = compose(
79 connectSharingDialogProgress,
80 connect(mapStateToProps, mapDispatchToProps)
81 )(SharingDialogComponent);