1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Grid, StyleRulesCallback, Divider, IconButton, Typography } from '@material-ui/core';
10 WrappedFieldArrayProps,
14 import { PermissionSelect, formatPermissionLevel, parsePermissionLevel } from './permission-select';
15 import { WithStyles } from '@material-ui/core/styles';
16 import withStyles from '@material-ui/core/styles/withStyles';
17 import { CloseIcon } from '~/components/icon/icon';
21 <FieldArray name='permissions' component={SharingManagementFieldArray} />;
23 const SharingManagementFieldArray = ({ fields }: WrappedFieldArrayProps<{ email: string }>) =>
26 fields.map((field, index, fields) =>
27 <PermissionManagementRow key={field} {...{ field, index, fields }} />)
32 const permissionManagementRowStyles: StyleRulesCallback<'root'> = theme => ({
34 padding: `${theme.spacing.unit}px 0`,
37 const PermissionManagementRow = withStyles(permissionManagementRowStyles)(
38 ({ field, index, fields, classes }: { field: string, index: number, fields: FieldArrayFieldsProps<{ email: string }> } & WithStyles<'root'>) =>
41 <Grid container alignItems='center' spacing={8} wrap='nowrap' className={classes.root}>
43 <Typography noWrap variant='subheading'>{fields.get(index).email}</Typography>
45 <Grid item xs={4} container wrap='nowrap'>
47 name={`${field}.permissions`}
48 component={PermissionSelectComponent}
49 format={formatPermissionLevel}
50 parse={parsePermissionLevel} />
51 <IconButton onClick={() => fields.remove(index)}>
59 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
60 <PermissionSelect fullWidth disableUnderline {...input} />;