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';
8 import React from 'react';
9 import { connectSharingDialog, saveSharingDialogChanges, connectSharingDialogProgress, sendSharingInvitations } from 'store/sharing-dialog/sharing-dialog-actions';
10 import { WithDialogProps } from 'store/dialog/with-dialog';
11 import { RootState } from 'store/store';
13 import SharingDialogComponent, { SharingDialogDataProps, SharingDialogActionProps } from './sharing-dialog-component';
14 import { SharingDialogContent } from './sharing-dialog-content';
15 import { connectAdvancedViewSwitch, AdvancedViewSwitchInjectedProps } from './advanced-view-switch';
16 import { hasChanges } from 'store/sharing-dialog/sharing-dialog-types';
17 import { WithProgressStateProps } from 'store/progress-indicator/with-progress';
19 type Props = WithDialogProps<string> & AdvancedViewSwitchInjectedProps & WithProgressStateProps;
21 const mapStateToProps = (state: RootState, { advancedViewOpen, working, ...props }: Props): SharingDialogDataProps => ({
23 saveEnabled: hasChanges(state),
25 advancedEnabled: !advancedViewOpen,
26 children: <SharingDialogContent {...{ advancedViewOpen }} />,
29 const mapDispatchToProps = (dispatch: Dispatch, { toggleAdvancedView, advancedViewOpen, ...props }: Props): SharingDialogActionProps => ({
31 onClose: props.closeDialog,
33 if (advancedViewOpen) {
38 if (advancedViewOpen) {
39 dispatch<any>(saveSharingDialogChanges);
41 dispatch<any>(sendSharingInvitations);
44 onAdvanced: toggleAdvancedView,
47 export const SharingDialog = compose(
48 connectAdvancedViewSwitch,
50 connectSharingDialogProgress,
51 connect(mapStateToProps, mapDispatchToProps)
52 )(SharingDialogComponent);