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 { CustomStyleRulesCallback } from 'common/custom-theme';
8 import { Grid, FormControl, InputLabel } from '@mui/material';
9 import { PermissionSelect, parsePermissionLevel, formatPermissionLevel } from './permission-select';
10 import { ParticipantSelect, Participant } from './participant-select';
11 import { WithStyles } from '@mui/styles';
12 import withStyles from '@mui/styles/withStyles';
13 import { ArvadosTheme } from 'common/custom-theme';
15 type SharingStyles = 'root';
17 const styles: CustomStyleRulesCallback<SharingStyles> = (theme: ArvadosTheme) => ({
19 padding: `${theme.spacing(1)} 0`,
23 const SharingInvitationFormComponent = (props: { onSave: () => void }) => <StyledSharingInvitationFormComponent onSave={props.onSave} />
25 export default SharingInvitationFormComponent;
27 const StyledSharingInvitationFormComponent = withStyles(styles)(
28 ({ classes }: { onSave: () => void } & WithStyles<SharingStyles>) =>
29 <Grid container spacing={1} wrap='nowrap' className={classes.root} >
30 <Grid data-cy="invite-people-field" item xs={8}>
31 <InvitedPeopleField />
33 <Grid data-cy="permission-select-field" item xs={4} container wrap='nowrap'>
34 <PermissionSelectField />
38 const InvitedPeopleField = () =>
41 component={InvitedPeopleFieldComponent as any} />;
44 const InvitedPeopleFieldComponent = ({ fields }: WrappedFieldArrayProps<Participant>) =>
46 items={fields.getAll() || []}
47 onSelect={fields.push}
48 onDelete={fields.remove} />;
50 const PermissionSelectField = () =>
53 component={PermissionSelectComponent}
54 format={formatPermissionLevel}
55 parse={parsePermissionLevel} />;
57 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
58 <FormControl variant="standard" fullWidth>
59 <InputLabel>Authorization</InputLabel>
60 <PermissionSelect {...input} />