Skip to content

Commit

Permalink
Typed token action kind and improved getActionName logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ARADDCC012 committed May 21, 2024
1 parent a1ee321 commit a778cb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions frontend/pages/settings/personal-access-tokens/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Title from 'src/common/Title'
import Link from 'src/Link'
import MessageAlert from 'src/MessageAlert'
import TokenDialog from 'src/settings/authentication/TokenDialog'
import { TokenAction, TokenActionKeys, TokenInterface, TokenScope } from 'types/types'
import { TokenAction, TokenActionKeys, TokenActionKind, TokenInterface, TokenScope } from 'types/types'
import { getErrorMessage } from 'utils/fetcher'
import { plural } from 'utils/stringUtils'

Expand All @@ -33,10 +33,10 @@ const [TokenReadAction, TokenWriteAction] = Object.values(TokenAction).reduce<Re
let groupedActions = [readActions, writeActions]
const [name, kind] = action.split(':')

if (kind === 'read') {
if (kind === TokenActionKind.READ) {
groupedActions = [{ ...readActions, [name]: action }, writeActions]
}
if (kind === 'write') {
if (kind === TokenActionKind.WRITE) {
groupedActions = [readActions, { ...writeActions, [name]: action }]
}

Expand All @@ -54,7 +54,8 @@ const isReadAction = (action: TokenActionKeys) => {
}

const getActionName = (action: TokenActionKeys) => {
return action.split(':')[0]
const [name, _kind] = action.split(':')
return name
}

const actionOptions = Object.values(TokenAction)
Expand Down
7 changes: 7 additions & 0 deletions frontend/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ export const TokenScope = {

export type TokenScopeKeys = (typeof TokenScope)[keyof typeof TokenScope]

export const TokenActionKind = {
READ: 'read',
WRITE: 'write',
}

export type TokenActionKindKeys = (typeof TokenActionKind)[keyof typeof TokenActionKind]

export const TokenAction = {
MODEL_READ: 'model:read',
MODEL_WRITE: 'model:write',
Expand Down

0 comments on commit a778cb8

Please sign in to comment.