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, StyleRulesCallback } from '@material-ui/core';
8 import { PermissionSelect, parsePermissionLevel, formatPermissionLevel } from './permission-select';
9 import { ParticipantSelect, Participant } from './participant-select';
10 import { WithStyles } from '@material-ui/core/styles';
11 import withStyles from '@material-ui/core/styles/withStyles';
12 import { ArvadosTheme } from 'common/custom-theme';
14 type SharingStyles = 'root';
16 const styles: StyleRulesCallback<SharingStyles> = (theme: ArvadosTheme) => ({
18 padding: `${theme.spacing.unit}px 0`,
22 const SharingInvitationFormComponent = (props: { onSave: () => void }) => <StyledSharingInvitationFormComponent onSave={props.onSave} />
24 export default SharingInvitationFormComponent;
26 const StyledSharingInvitationFormComponent = withStyles(styles)(
27 ({ classes }: { onSave: () => void } & WithStyles<SharingStyles>) =>
28 <Grid container spacing={8} wrap='nowrap' className={classes.root} >
29 <Grid data-cy="invite-people-field" item xs={8}>
30 <InvitedPeopleField />
32 <Grid data-cy="permission-select-field" item xs={4} container wrap='nowrap'>
33 <PermissionSelectField />
37 const InvitedPeopleField = () =>
40 component={InvitedPeopleFieldComponent as any} />;
43 const InvitedPeopleFieldComponent = ({ fields }: WrappedFieldArrayProps<Participant>) =>
45 items={fields.getAll() || []}
46 onSelect={fields.push}
47 onDelete={fields.remove} />;
49 const PermissionSelectField = () =>
52 component={PermissionSelectComponent}
53 format={formatPermissionLevel}
54 parse={parsePermissionLevel} />;
56 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
57 <FormControl fullWidth>
58 <InputLabel>Authorization</InputLabel>
59 <PermissionSelect {...input} />