Merge branch '21720-material-ui-upgrade'
[arvados.git] / services / workbench2 / src / views-components / sharing-dialog / visibility-level-select.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { MenuItem, Select } from '@mui/material';
8 import withStyles from '@mui/styles/withStyles';
9 import Lock from '@mui/icons-material/Lock';
10 import People from '@mui/icons-material/People';
11 import Public from '@mui/icons-material/Public';
12 import { WithStyles } from '@mui/styles';
13 import { SelectProps } from '@mui/material/Select';
14 import { SelectItem } from './select-item';
15 import { VisibilityLevel } from 'store/sharing-dialog/sharing-dialog-types';
16
17
18 type VisibilityLevelSelectClasses = 'root';
19
20 const VisibilityLevelSelectStyles: CustomStyleRulesCallback<VisibilityLevelSelectClasses> = theme => ({
21     root: {
22     }
23 });
24 export const VisibilityLevelSelect = withStyles(VisibilityLevelSelectStyles)(
25     ({ classes, includePublic, ...props }: { includePublic: boolean } & SelectProps & WithStyles<VisibilityLevelSelectClasses>) =>
26         <Select
27             variant="standard"
28             {...props}
29             renderValue={renderPermissionItem}
30             inputProps={{ classes }}>
31             {includePublic && <MenuItem value={VisibilityLevel.PUBLIC}>
32                 {renderPermissionItem(VisibilityLevel.PUBLIC)}
33             </MenuItem>}
34             <MenuItem value={VisibilityLevel.ALL_USERS}>
35                 {renderPermissionItem(VisibilityLevel.ALL_USERS)}
36             </MenuItem>
37             <MenuItem value={VisibilityLevel.SHARED}>
38                 {renderPermissionItem(VisibilityLevel.SHARED)}
39             </MenuItem>
40             <MenuItem value={VisibilityLevel.PRIVATE}>
41                 {renderPermissionItem(VisibilityLevel.PRIVATE)}
42             </MenuItem>
43         </Select>);
44
45 const renderPermissionItem = (value: string) =>
46     <SelectItem {...{ value, icon: getIcon(value) }} />;
47
48 const getIcon = (value: string) => {
49     switch (value) {
50         case VisibilityLevel.PUBLIC:
51             return Public;
52         case VisibilityLevel.ALL_USERS:
53             return Public;
54         case VisibilityLevel.SHARED:
55             return People;
56         case VisibilityLevel.PRIVATE:
57             return Lock;
58         default:
59             return Lock;
60     }
61 };