1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Field, WrappedFieldProps, FieldArray, WrappedFieldArrayProps } from 'redux-form';
7 import { Grid, FormControl, InputLabel, Tooltip, IconButton, StyleRulesCallback } from '@material-ui/core';
8 import { PermissionSelect, parsePermissionLevel, formatPermissionLevel } from './permission-select';
9 import { ParticipantSelect, Participant } from './participant-select';
10 import { AddIcon } from 'components/icon/icon';
11 import { WithStyles } from '@material-ui/core/styles';
12 import withStyles from '@material-ui/core/styles/withStyles';
13 import { ArvadosTheme } from 'common/custom-theme';
15 type SharingStyles = 'root' | 'addButtonRoot' | 'addButtonPrimary' | 'addButtonDisabled';
17 const styles: StyleRulesCallback<SharingStyles> = (theme: ArvadosTheme) => ({
19 padding: `${theme.spacing.unit}px 0`,
29 color: theme.palette.primary.contrastText,
30 background: theme.palette.primary.main,
32 background: theme.palette.primary.dark,
40 const SharingInvitationFormComponent = (props: { onSave: () => void, saveEnabled: boolean }) => <StyledSharingInvitationFormComponent onSave={props.onSave} saveEnabled={props.saveEnabled} />
42 export default SharingInvitationFormComponent;
44 const StyledSharingInvitationFormComponent = withStyles(styles)(
45 ({ onSave, saveEnabled, classes }: { onSave: () => void, saveEnabled: boolean } & WithStyles<SharingStyles>) =>
46 <Grid container spacing={8} wrap='nowrap' className={classes.root} >
47 <Grid data-cy="invite-people-field" item xs={8}>
48 <InvitedPeopleField />
50 <Grid data-cy="permission-select-field" item xs={4} container wrap='nowrap'>
51 <PermissionSelectField />
52 <IconButton onClick={onSave} disabled={!saveEnabled} color="primary" classes={{
53 root: classes.addButtonRoot,
54 colorPrimary: classes.addButtonPrimary,
55 disabled: classes.addButtonDisabled
57 data-cy='add-invited-people'>
58 <Tooltip title="Add authorization">
65 const InvitedPeopleField = () =>
68 component={InvitedPeopleFieldComponent as any} />;
71 const InvitedPeopleFieldComponent = ({ fields }: WrappedFieldArrayProps<Participant>) =>
73 items={fields.getAll() || []}
74 onSelect={fields.push}
75 onDelete={fields.remove} />;
77 const PermissionSelectField = () =>
80 component={PermissionSelectComponent}
81 format={formatPermissionLevel}
82 parse={parsePermissionLevel} />;
84 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
85 <FormControl fullWidth>
86 <InputLabel>Authorization</InputLabel>
87 <PermissionSelect {...input} />