1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { MenuItem, Select, withStyles, StyleRulesCallback } from '@material-ui/core';
7 import RemoveRedEye from '@material-ui/icons/RemoveRedEye';
8 import Edit from '@material-ui/icons/Edit';
9 import Computer from '@material-ui/icons/Computer';
10 import { WithStyles } from '@material-ui/core/styles';
11 import { SelectProps } from '@material-ui/core/Select';
12 import { SelectItem } from './select-item';
13 import { PermissionLevel } from '../../models/permission';
15 export enum PermissionSelectValue {
21 export const parsePermissionLevel = (value: PermissionSelectValue) => {
23 case PermissionSelectValue.READ:
24 return PermissionLevel.CAN_READ;
25 case PermissionSelectValue.WRITE:
26 return PermissionLevel.CAN_WRITE;
27 case PermissionSelectValue.MANAGE:
28 return PermissionLevel.CAN_MANAGE;
30 return PermissionLevel.NONE;
34 export const formatPermissionLevel = (value: PermissionLevel) => {
36 case PermissionLevel.CAN_READ:
37 return PermissionSelectValue.READ;
38 case PermissionLevel.CAN_WRITE:
39 return PermissionSelectValue.WRITE;
40 case PermissionLevel.CAN_MANAGE:
41 return PermissionSelectValue.MANAGE;
43 return PermissionSelectValue.READ;
48 export const PermissionSelect = (props: SelectProps) =>
51 renderValue={renderPermissionItem}>
52 <MenuItem value={PermissionSelectValue.READ}>
53 {renderPermissionItem(PermissionSelectValue.READ)}
55 <MenuItem value={PermissionSelectValue.WRITE}>
56 {renderPermissionItem(PermissionSelectValue.WRITE)}
58 <MenuItem value={PermissionSelectValue.MANAGE}>
59 {renderPermissionItem(PermissionSelectValue.MANAGE)}
63 const renderPermissionItem = (value: string) =>
64 <SelectItem {...{ value, icon: getIcon(value) }} />;
66 const getIcon = (value: string) => {
68 case PermissionSelectValue.READ:
70 case PermissionSelectValue.WRITE:
72 case PermissionSelectValue.MANAGE: