X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/82db2694a5a0f54d4d8b07db08aecb0ca7d2f5ed..2a7fd99c212c33a1ec9911f8529fa5afc59a7bb2:/src/views-components/sharing-dialog/sharing-dialog.tsx

diff --git a/src/views-components/sharing-dialog/sharing-dialog.tsx b/src/views-components/sharing-dialog/sharing-dialog.tsx
index 63ee19a74b..1c9e4d0393 100644
--- a/src/views-components/sharing-dialog/sharing-dialog.tsx
+++ b/src/views-components/sharing-dialog/sharing-dialog.tsx
@@ -4,34 +4,77 @@
 
 import { compose, Dispatch } from 'redux';
 import { connect } from 'react-redux';
+import { RootState } from 'store/store';
+import { formValueSelector } from 'redux-form'
+import {
+    connectSharingDialog,
+    saveSharingDialogChanges,
+    connectSharingDialogProgress,
+    SharingDialogData,
+    createSharingToken,
+    initializeManagementForm
+} from 'store/sharing-dialog/sharing-dialog-actions';
+import { WithDialogProps } from 'store/dialog/with-dialog';
+import SharingDialogComponent, {
+    SharingDialogDataProps,
+    SharingDialogActionProps
+} from './sharing-dialog-component';
+import {
+    getSharingPublicAccessFormData,
+    hasChanges,
+    SHARING_DIALOG_NAME,
+    SHARING_MANAGEMENT_FORM_NAME,
+    VisibilityLevel
+} from 'store/sharing-dialog/sharing-dialog-types';
+import { WithProgressStateProps } from 'store/progress-indicator/with-progress';
+import { getDialog } from 'store/dialog/dialog-reducer';
+import { filterResources } from 'store/resources/resources';
+import { ApiClientAuthorization } from 'models/api-client-authorization';
+import { ResourceKind } from 'models/resource';
 
-import * as React from 'react';
-import { connectSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
-import { WithDialogProps } from '~/store/dialog/with-dialog';
-import { RootState } from '~/store/store';
+type Props = WithDialogProps<string> & WithProgressStateProps;
 
-import SharingDialogComponent, { SharingDialogDataProps, SharingDialogActionProps } from './sharing-dialog-component';
-import { SharingDialogContent } from './sharing-dialog-content';
-import { connectAdvancedViewSwitch, AdvancedViewSwitchInjectedProps } from './advanced-view-switch';
+const sharingManagementFormSelector = formValueSelector(SHARING_MANAGEMENT_FORM_NAME);
 
-const mapStateToProps = (_: RootState, { advancedViewOpen, ...props }: WithDialogProps<string> & AdvancedViewSwitchInjectedProps): SharingDialogDataProps => ({
-    ...props,
-    saveEnabled: false,
-    advancedEnabled: !advancedViewOpen,
-    children: <SharingDialogContent {...{ advancedViewOpen }} />,
-});
+const mapStateToProps = (state: RootState, { working, ...props }: Props): SharingDialogDataProps => {
+    const dialog = getDialog<SharingDialogData>(state.dialog, SHARING_DIALOG_NAME);
+    const sharedResourceUuid = dialog?.data.resourceUuid || '';
+    const sharingURLsDisabled = state.auth.config.clusterConfig.Workbench.DisableSharingURLsUI;
+    return ({
+        ...props,
+        permissions: sharingManagementFormSelector(state, 'permissions'),
+        saveEnabled: hasChanges(state),
+        loading: working,
+        sharedResourceUuid,
+        sharingURLsDisabled,
+        sharingURLsNr: !sharingURLsDisabled
+            ? (filterResources((resource: ApiClientAuthorization) =>
+                resource.kind === ResourceKind.API_CLIENT_AUTHORIZATION &&
+                resource.scopes.includes(`GET /arvados/v1/collections/${sharedResourceUuid}`) &&
+                resource.scopes.includes(`GET /arvados/v1/collections/${sharedResourceUuid}/`) &&
+                resource.scopes.includes('GET /arvados/v1/keep_services/accessible')
+            )(state.resources) as ApiClientAuthorization[]).length
+            : 0,
+        privateAccess: getSharingPublicAccessFormData(state)?.visibility === VisibilityLevel.PRIVATE,
+    })
+};
 
-const mapDispatchToProps = (_: Dispatch, { toggleAdvancedView, ...props }: WithDialogProps<string> & AdvancedViewSwitchInjectedProps): SharingDialogActionProps => ({
+const mapDispatchToProps = (dispatch: Dispatch, { ...props }: Props): SharingDialogActionProps => ({
     ...props,
     onClose: props.closeDialog,
-    onExited: toggleAdvancedView,
-    onSave: () => { console.log('save'); },
-    onAdvanced: toggleAdvancedView,
+    onSave: () => {
+        setTimeout(() => dispatch<any>(saveSharingDialogChanges), 0);
+    },
+    onCreateSharingToken: (d: Date) => () => {
+        dispatch<any>(createSharingToken(d));
+    },
+    refreshPermissions: () => {
+        dispatch<any>(initializeManagementForm);
+    }
 });
 
 export const SharingDialog = compose(
-    connectAdvancedViewSwitch,
     connectSharingDialog,
+    connectSharingDialogProgress,
     connect(mapStateToProps, mapDispatchToProps)
 )(SharingDialogComponent);
-
