1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { MenuItem, Select } from '@mui/material';
7 import RemoveRedEye from '@mui/icons-material/RemoveRedEye';
8 import Edit from '@mui/icons-material/Edit';
9 import Computer from '@mui/icons-material/Computer';
10 import { SelectProps } from '@mui/material/Select';
11 import { SelectItem } from './select-item';
12 import { PermissionLevel } from '../../models/permission';
14 export enum PermissionSelectValue {
20 export const parsePermissionLevel = (value: PermissionSelectValue) => {
22 case PermissionSelectValue.READ:
23 return PermissionLevel.CAN_READ;
24 case PermissionSelectValue.WRITE:
25 return PermissionLevel.CAN_WRITE;
26 case PermissionSelectValue.MANAGE:
27 return PermissionLevel.CAN_MANAGE;
29 return PermissionLevel.NONE;
33 export const formatPermissionLevel = (value: PermissionLevel) => {
35 case PermissionLevel.CAN_READ:
36 return PermissionSelectValue.READ;
37 case PermissionLevel.CAN_WRITE:
38 return PermissionSelectValue.WRITE;
39 case PermissionLevel.CAN_MANAGE:
40 return PermissionSelectValue.MANAGE;
42 return PermissionSelectValue.READ;
47 export const PermissionSelect = (props: SelectProps) =>
52 data-cy="permission-select"
53 renderValue={renderPermissionItem}>
54 <MenuItem value={PermissionSelectValue.READ}>
55 {renderPermissionItem(PermissionSelectValue.READ)}
57 <MenuItem value={PermissionSelectValue.WRITE}>
58 {renderPermissionItem(PermissionSelectValue.WRITE)}
60 <MenuItem value={PermissionSelectValue.MANAGE}>
61 {renderPermissionItem(PermissionSelectValue.MANAGE)}
65 const renderPermissionItem = (value: string) =>
66 <SelectItem {...{ value, icon: getIcon(value) }} />;
68 const getIcon = (value: string) => {
70 case PermissionSelectValue.READ:
72 case PermissionSelectValue.WRITE:
74 case PermissionSelectValue.MANAGE: