Centralize available scopes

This commit is contained in:
Gabe Kangas
2021-01-05 16:51:57 -08:00
parent 0012fbb4d1
commit a74dc31dd4

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { Table, Tag, Space, Button, Modal, Checkbox, Input, Typography } from 'antd'; import { Table, Tag, Space, Button, Modal, Checkbox, Input, Typography, Tooltip } from 'antd';
import { DeleteOutlined, EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons'; import { DeleteOutlined, EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons';
const { Title, Paragraph, Text } = Typography; const { Title, Paragraph, Text } = Typography;
@@ -12,34 +12,34 @@ import {
CREATE_ACCESS_TOKEN, CREATE_ACCESS_TOKEN,
} from "../utils/apis"; } from "../utils/apis";
const scopeMapping = { const availableScopes = {
'CAN_SEND_SYSTEM_MESSAGES': 'system chat', 'CAN_SEND_SYSTEM_MESSAGES': { name: 'System messages', description: 'You can send official messages on behalf of the system', color: 'purple' },
'CAN_SEND_MESSAGES': 'user chat', 'CAN_SEND_MESSAGES': { name: 'User chat messages', description: 'You can send messages on behalf of a username', color: 'green' },
}; };
function convertScopeStringToRenderString(scope) { function convertScopeStringToTag(scopeString) {
if (!scope || !scopeMapping[scope]) { if (!scopeString || !availableScopes[scopeString]) {
return "unknown"; return null;
} }
return scopeMapping[scope].toUpperCase(); const scope = availableScopes[scopeString];
return (
<Tooltip key={scopeString} title={scope.description}>
<Tag color={scope.color} >
{scope.name}
</Tag>
</Tooltip>
);
} }
function NewTokenModal(props) { function NewTokenModal(props) {
var selectedScopes = []; var selectedScopes = [];
const scopes = [
{ const scopes = Object.keys(availableScopes).map(function (key) {
value: 'CAN_SEND_SYSTEM_MESSAGES', return { value: key, label: availableScopes[key].description }
label: 'Can send system chat messages', });
description: 'Can send chat messages as the offical system user.'
},
{
value: 'CAN_SEND_MESSAGES',
label: 'Can send user chat messages',
description: 'Can send chat messages as any user name.'
},
]
function onChange(checkedValues) { function onChange(checkedValues) {
selectedScopes = checkedValues selectedScopes = checkedValues
@@ -97,13 +97,7 @@ export default function AccessTokens() {
render: scopes => ( render: scopes => (
<> <>
{scopes.map(scope => { {scopes.map(scope => {
const color = 'purple'; return convertScopeStringToTag(scope);
return (
<Tag color={color} key={scope}>
{convertScopeStringToRenderString(scope)}
</Tag>
);
})} })}
</> </>
), ),