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, Tooltip } from '@material-ui/core';
10 WrappedFieldArrayProps,
12 FieldArrayFieldsProps,
15 import { PermissionSelect, formatPermissionLevel, parsePermissionLevel } from './permission-select';
16 import { WithStyles } from '@material-ui/core/styles';
17 import withStyles from '@material-ui/core/styles/withStyles';
18 import { CloseIcon } from 'components/icon/icon';
19 import { ArvadosTheme } from 'common/custom-theme';
21 export interface SaveProps {
25 const headerStyles: StyleRulesCallback<'heading'> = (theme: ArvadosTheme) => ({
31 export const SharingManagementFormComponent = withStyles(headerStyles)(
32 ({ classes, onSave }: WithStyles<'heading'> & SaveProps & InjectedFormProps<{}, SaveProps>) =>
34 <Typography className={classes.heading}>People with access</Typography>
35 <FieldArray<{ onSave: () => void }> name='permissions' component={SharingManagementFieldArray as any} props={{ onSave }} />
38 export default SharingManagementFormComponent;
40 const SharingManagementFieldArray = ({ fields, onSave }: { onSave: () => void } & WrappedFieldArrayProps<{ email: string }>) =>
41 <div>{fields.map((field, index, fields) =>
42 <PermissionManagementRow key={field} {...{ field, index, fields }} onSave={onSave} />)}
45 const permissionManagementRowStyles: StyleRulesCallback<'root'> = theme => ({
47 padding: `${theme.spacing.unit}px 0`,
51 const PermissionManagementRow = withStyles(permissionManagementRowStyles)(
52 ({ field, index, fields, classes, onSave }: { field: string, index: number, fields: FieldArrayFieldsProps<{ email: string }>, onSave: () => void; } & WithStyles<'root'>) =>
54 <Grid container alignItems='center' spacing={8} wrap='nowrap' className={classes.root}>
56 <Typography noWrap variant='subtitle1'>{fields.get(index).email}</Typography>
58 <Grid item xs={1} container wrap='nowrap'>
59 <Tooltip title='Remove access'>
60 <IconButton onClick={() => { fields.remove(index); onSave(); }}>
65 <Grid item xs={4} container wrap='nowrap'>
67 name={`${field}.permissions` as string}
68 component={PermissionSelectComponent}
69 format={formatPermissionLevel}
70 parse={parsePermissionLevel}
80 const PermissionSelectComponent = ({ input }: WrappedFieldProps) =>
81 <PermissionSelect fullWidth disableUnderline {...input} />;