Improve people select styles and behaviour
[arvados-workbench2.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, connectSharingDialogProgress } 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 import { hasChanges } from '~/store/sharing-dialog/sharing-dialog-types';
17 import { WithProgressStateProps } from '~/store/progress-indicator/with-progress';
18
19 type Props = WithDialogProps<string> & AdvancedViewSwitchInjectedProps & WithProgressStateProps;
20
21 const mapStateToProps = (state: RootState, { advancedViewOpen, working, ...props }: Props): SharingDialogDataProps => ({
22     ...props,
23     saveEnabled: hasChanges(state),
24     loading: working,
25     advancedEnabled: !advancedViewOpen,
26     children: <SharingDialogContent {...{ advancedViewOpen }} />,
27 });
28
29 const mapDispatchToProps = (dispatch: Dispatch, { toggleAdvancedView, ...props }: Props): SharingDialogActionProps => ({
30     ...props,
31     onClose: props.closeDialog,
32     onExited: toggleAdvancedView,
33     onSave: () => {
34         dispatch<any>(saveSharingDialogChanges);
35     },
36     onAdvanced: toggleAdvancedView,
37 });
38
39 export const SharingDialog = compose(
40     connectAdvancedViewSwitch,
41     connectSharingDialog,
42     connectSharingDialogProgress,
43     connect(mapStateToProps, mapDispatchToProps)
44 )(SharingDialogComponent);
45