Add visibility level select
[arvados.git] / src / views-components / sharing-dialog / sharing-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { compose, Dispatch } from 'redux';
6 import { connect } from 'react-redux';
7
8 import * as React from 'react';
9 import { connectSharingDialog, saveSharingDialogChanges, hasChanges } from '~/store/sharing-dialog/sharing-dialog-actions';
10 import { WithDialogProps } from '~/store/dialog/with-dialog';
11 import { RootState } from '~/store/store';
12
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
17 const mapStateToProps = (state: RootState, { advancedViewOpen, ...props }: WithDialogProps<string> & AdvancedViewSwitchInjectedProps): SharingDialogDataProps => ({
18     ...props,
19     saveEnabled: hasChanges(state),
20     advancedEnabled: !advancedViewOpen,
21     children: <SharingDialogContent {...{ advancedViewOpen }} />,
22 });
23
24 const mapDispatchToProps = (dispatch: Dispatch, { toggleAdvancedView, ...props }: WithDialogProps<string> & AdvancedViewSwitchInjectedProps): SharingDialogActionProps => ({
25     ...props,
26     onClose: props.closeDialog,
27     onExited: toggleAdvancedView,
28     onSave: () => {
29         dispatch<any>(saveSharingDialogChanges);
30     },
31     onAdvanced: toggleAdvancedView,
32 });
33
34 export const SharingDialog = compose(
35     connectAdvancedViewSwitch,
36     connectSharingDialog,
37     connect(mapStateToProps, mapDispatchToProps)
38 )(SharingDialogComponent);
39