X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/49ad5cc761e56b7d2fb204e872ad956c6fc1c60c..f55d7e31aa315de4eece3139c4fa1df7d6eb929e:/src/views-components/sharing-dialog/permission-select.tsx

diff --git a/src/views-components/sharing-dialog/permission-select.tsx b/src/views-components/sharing-dialog/permission-select.tsx
index 0b839d586f..3c4471f648 100644
--- a/src/views-components/sharing-dialog/permission-select.tsx
+++ b/src/views-components/sharing-dialog/permission-select.tsx
@@ -2,14 +2,14 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { MenuItem, Select, withStyles, StyleRulesCallback } from '@material-ui/core';
+import React from 'react';
+import { MenuItem, Select } from '@material-ui/core';
 import RemoveRedEye from '@material-ui/icons/RemoveRedEye';
 import Edit from '@material-ui/icons/Edit';
 import Computer from '@material-ui/icons/Computer';
-import { WithStyles } from '@material-ui/core/styles';
 import { SelectProps } from '@material-ui/core/Select';
 import { SelectItem } from './select-item';
+import { PermissionLevel } from '../../models/permission';
 
 export enum PermissionSelectValue {
     READ = 'Read',
@@ -17,30 +17,47 @@ export enum PermissionSelectValue {
     MANAGE = 'Manage',
 }
 
-type PermissionSelectClasses = 'value';
+export const parsePermissionLevel = (value: PermissionSelectValue) => {
+    switch (value) {
+        case PermissionSelectValue.READ:
+            return PermissionLevel.CAN_READ;
+        case PermissionSelectValue.WRITE:
+            return PermissionLevel.CAN_WRITE;
+        case PermissionSelectValue.MANAGE:
+            return PermissionLevel.CAN_MANAGE;
+        default:
+            return PermissionLevel.NONE;
+    }
+};
 
-const PermissionSelectStyles: StyleRulesCallback<PermissionSelectClasses> = theme => ({
-    value: {
-        marginLeft: theme.spacing.unit,
+export const formatPermissionLevel = (value: PermissionLevel) => {
+    switch (value) {
+        case PermissionLevel.CAN_READ:
+            return PermissionSelectValue.READ;
+        case PermissionLevel.CAN_WRITE:
+            return PermissionSelectValue.WRITE;
+        case PermissionLevel.CAN_MANAGE:
+            return PermissionSelectValue.MANAGE;
+        default:
+            return PermissionSelectValue.READ;
     }
-});
-
-export const PermissionSelect = withStyles(PermissionSelectStyles)(
-    ({ classes, ...props }: SelectProps & WithStyles<PermissionSelectClasses>) =>
-        <Select
-            {...props}
-            renderValue={renderPermissionItem}
-            inputProps={{ classes }}>
-            <MenuItem value={PermissionSelectValue.READ}>
-                {renderPermissionItem(PermissionSelectValue.READ)}
-            </MenuItem>
-            <MenuItem value={PermissionSelectValue.WRITE}>
-                {renderPermissionItem(PermissionSelectValue.WRITE)}
-            </MenuItem>
-            <MenuItem value={PermissionSelectValue.MANAGE}>
-                {renderPermissionItem(PermissionSelectValue.MANAGE)}
-            </MenuItem>
-        </Select>);
+};
+
+
+export const PermissionSelect = (props: SelectProps) =>
+    <Select
+        {...props}
+        renderValue={renderPermissionItem}>
+        <MenuItem value={PermissionSelectValue.READ}>
+            {renderPermissionItem(PermissionSelectValue.READ)}
+        </MenuItem>
+        <MenuItem value={PermissionSelectValue.WRITE}>
+            {renderPermissionItem(PermissionSelectValue.WRITE)}
+        </MenuItem>
+        <MenuItem value={PermissionSelectValue.MANAGE}>
+            {renderPermissionItem(PermissionSelectValue.MANAGE)}
+        </MenuItem>
+    </Select>;
 
 const renderPermissionItem = (value: string) =>
     <SelectItem {...{ value, icon: getIcon(value) }} />;
