1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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 as any} />;
23 const SharingManagementFieldArray = ({ fields }: WrappedFieldArrayProps<{ email: string }>) =>
24 <div>{ fields.map((field, index, fields) =>
25 <PermissionManagementRow key={field} {...{ field, index, fields }} />) }
29 const permissionManagementRowStyles: StyleRulesCallback<'root'> = theme => ({
31 padding: `${theme.spacing.unit}px 0`,
34 const PermissionManagementRow = withStyles(permissionManagementRowStyles)(
35 ({ field, index, fields, classes }: { field: string, index: number, fields: FieldArrayFieldsProps<{ email: string }> } & WithStyles<'root'>) =>
38 <Grid container alignItems='center' spacing={8} wrap='nowrap' className={classes.root}>
40 <Typography noWrap variant='subtitle1'>{fields.get(index).email}</Typography>
42 <Grid item xs={4} container wrap='nowrap'>
44 name={`${field}.permissions` as string}
45 component={PermissionSelectComponent}
46 format={formatPermissionLevel}
47 parse={parsePermissionLevel} />
48 <IconButton onClick={() => fields.remove(index)}>
56 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
57 <PermissionSelect fullWidth disableUnderline {...input} />;