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, Typography } from '@mui/material';
8 import { Field, WrappedFieldProps } from 'redux-form';
9 import { WithStyles } from '@mui/styles';
10 import withStyles from '@mui/styles/withStyles';
11 import { VisibilityLevelSelect } from './visibility-level-select';
12 import { VisibilityLevel } from 'store/sharing-dialog/sharing-dialog-types';
14 const sharingPublicAccessStyles: CustomStyleRulesCallback<'root'> = theme => ({
16 padding: `${theme.spacing(2)} 0`,
23 interface AccessProps {
24 visibility: VisibilityLevel;
25 includePublic: boolean;
29 const SharingPublicAccessForm = withStyles(sharingPublicAccessStyles)(
30 ({ classes, visibility, includePublic, onSave }: WithStyles<'root' | 'heading'> & AccessProps) =>
32 <Typography className={classes.heading}>General access</Typography>
33 <Grid container alignItems='center' className={classes.root}>
35 <Typography variant='subtitle1'>
36 {renderVisibilityInfo(visibility)}
39 <Grid item xs={4} wrap='nowrap'>
40 <Field<{ includePublic: boolean }> name='visibility' component={VisibilityLevelSelectComponent} includePublic={includePublic} onChange={onSave} />
46 const renderVisibilityInfo = (visibility: VisibilityLevel) => {
48 case VisibilityLevel.PUBLIC:
49 return 'Shared with anyone on the Internet';
50 case VisibilityLevel.ALL_USERS:
51 return 'Shared with all users on this cluster';
52 case VisibilityLevel.SHARED:
53 return 'Shared with specific people';
54 case VisibilityLevel.PRIVATE:
61 const SharingPublicAccessFormComponent = ({ visibility, includePublic, onSave }: AccessProps) =>
62 <SharingPublicAccessForm {...{ visibility, includePublic, onSave }} />;
64 export default SharingPublicAccessFormComponent;
66 const VisibilityLevelSelectComponent = ({ input, includePublic }: { includePublic: boolean } & WrappedFieldProps) =>
67 <VisibilityLevelSelect fullWidth disableUnderline includePublic={includePublic} {...input} />;