1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { Grid, Divider, IconButton, Typography, Tooltip } from '@mui/material';
11 WrappedFieldArrayProps,
13 FieldArrayFieldsProps,
16 import { PermissionSelect, formatPermissionLevel, parsePermissionLevel } from './permission-select';
17 import { WithStyles } from '@mui/styles';
18 import withStyles from '@mui/styles/withStyles';
19 import { CloseIcon } from 'components/icon/icon';
20 import { ArvadosTheme } from 'common/custom-theme';
22 export interface SaveProps {
26 const headerStyles: CustomStyleRulesCallback<'heading'> = (theme: ArvadosTheme) => ({
32 export const SharingManagementFormComponent = withStyles(headerStyles)(
33 ({ classes, onSave }: WithStyles<'heading'> & SaveProps & InjectedFormProps<{}, SaveProps>) =>
35 <Typography className={classes.heading}>People with access</Typography>
36 <FieldArray<{ onSave: () => void }> name='permissions' component={SharingManagementFieldArray as any} props={{ onSave }} />
39 export default SharingManagementFormComponent;
41 const SharingManagementFieldArray = ({ fields, onSave }: { onSave: () => void } & WrappedFieldArrayProps<{ email: string }>) =>
42 <div>{fields.map((field, index, fields) =>
43 <PermissionManagementRow key={field} {...{ field, index, fields }} onSave={onSave} />)}
46 const permissionManagementRowStyles: CustomStyleRulesCallback<'root'> = theme => ({
48 padding: `${theme.spacing(1)} 0`,
52 const PermissionManagementRow = withStyles(permissionManagementRowStyles)(
53 ({ field, index, fields, classes, onSave }: { field: string, index: number, fields: FieldArrayFieldsProps<{ email: string }>, onSave: () => void; } & WithStyles<'root'>) =>
55 <Grid container alignItems='center' spacing={1} wrap='nowrap' className={classes.root}>
57 <Typography noWrap variant='subtitle1'>{fields.get(index).email}</Typography>
59 <Grid item xs={1} container wrap='nowrap'>
60 <Tooltip title='Remove access'>
61 <IconButton onClick={() => { fields.remove(index); onSave(); }} size="large">
66 <Grid item xs={4} container wrap='nowrap'>
68 name={`${field}.permissions` as string}
69 component={PermissionSelectComponent}
70 format={formatPermissionLevel}
71 parse={parsePermissionLevel}
81 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
82 <PermissionSelect fullWidth disableUnderline {...input} />;