From a74dc31dd4389cfb1ce0854338584e0cd4d742cc Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 5 Jan 2021 16:51:57 -0800 Subject: [PATCH] Centralize available scopes --- web/pages/access-tokens.tsx | 48 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/web/pages/access-tokens.tsx b/web/pages/access-tokens.tsx index 58288665f..79e096f47 100644 --- a/web/pages/access-tokens.tsx +++ b/web/pages/access-tokens.tsx @@ -1,5 +1,5 @@ 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'; const { Title, Paragraph, Text } = Typography; @@ -12,34 +12,34 @@ import { CREATE_ACCESS_TOKEN, } from "../utils/apis"; -const scopeMapping = { - 'CAN_SEND_SYSTEM_MESSAGES': 'system chat', - 'CAN_SEND_MESSAGES': 'user chat', +const availableScopes = { + 'CAN_SEND_SYSTEM_MESSAGES': { name: 'System messages', description: 'You can send official messages on behalf of the system', color: 'purple' }, + 'CAN_SEND_MESSAGES': { name: 'User chat messages', description: 'You can send messages on behalf of a username', color: 'green' }, }; -function convertScopeStringToRenderString(scope) { - if (!scope || !scopeMapping[scope]) { - return "unknown"; +function convertScopeStringToTag(scopeString) { + if (!scopeString || !availableScopes[scopeString]) { + return null; } - return scopeMapping[scope].toUpperCase(); + const scope = availableScopes[scopeString]; + + return ( + + + {scope.name} + + + ); } function NewTokenModal(props) { var selectedScopes = []; - const scopes = [ - { - value: 'CAN_SEND_SYSTEM_MESSAGES', - 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.' - }, - ] + + const scopes = Object.keys(availableScopes).map(function (key) { + return { value: key, label: availableScopes[key].description } + }); function onChange(checkedValues) { selectedScopes = checkedValues @@ -97,13 +97,7 @@ export default function AccessTokens() { render: scopes => ( <> {scopes.map(scope => { - const color = 'purple'; - - return ( - - {convertScopeStringToRenderString(scope)} - - ); + return convertScopeStringToTag(scope); })} ),