feat(36-02): integrate ScopeAccessControl and in-dialog ScopePicker swap into ApiTokenCreateDialog
This commit is contained in:
@@ -10,19 +10,25 @@ import {
|
|||||||
RadioGroupItem,
|
RadioGroupItem,
|
||||||
RadioGroupRoot,
|
RadioGroupRoot,
|
||||||
} from 'reka-ui'
|
} from 'reka-ui'
|
||||||
import { Check, CircleAlert, Copy, Info, LoaderCircle, TriangleAlert, X } from '@lucide/vue'
|
import { ArrowLeft, Check, CircleAlert, Copy, LoaderCircle, TriangleAlert, X } from '@lucide/vue'
|
||||||
import { api } from '../../api/client'
|
import { api } from '../../api/client'
|
||||||
import type { AdminAPITokenScope } from '../../api/types'
|
import type { AdminAPITokenScope } from '../../api/types'
|
||||||
import { shortcutHint } from '../../app/hotkeys'
|
import { shortcutHint } from '../../app/hotkeys'
|
||||||
import { t } from '../../app/i18n'
|
import { t } from '../../app/i18n'
|
||||||
|
import type { AccessTier } from '../../app/scopeCatalog'
|
||||||
import { controlClass } from '../form/control'
|
import { controlClass } from '../form/control'
|
||||||
import { fieldErrors, focusField } from '../form/formState'
|
import { fieldErrors, focusField } from '../form/formState'
|
||||||
|
import ScopeAccessControl from '../scopes/ScopeAccessControl.vue'
|
||||||
|
import ScopePicker from '../scopes/ScopePicker.vue'
|
||||||
|
import { useScopeSelection } from '../scopes/useScopeSelection'
|
||||||
import Button from '../ui/Button.vue'
|
import Button from '../ui/Button.vue'
|
||||||
import { useConfirm } from '../ui/confirm'
|
import { useConfirm } from '../ui/confirm'
|
||||||
import { showToast } from '../../state/useToasts'
|
import { showToast } from '../../state/useToasts'
|
||||||
|
|
||||||
// Two-step create dialog (16.3 UI-SPEC §4-5): form, then show-once plaintext.
|
// Two-step create dialog (16.3 UI-SPEC §4-5 + Phase 36 UI-SPEC C5): form
|
||||||
// The plaintext lives only in a local ref and is cleared on close and unmount.
|
// (with in-dialog ScopePicker view swap at fixed max-w-[560px]), then
|
||||||
|
// show-once plaintext. The plaintext lives only in a local ref and is cleared
|
||||||
|
// on close and unmount.
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
open: boolean
|
open: boolean
|
||||||
confirm: ReturnType<typeof useConfirm>
|
confirm: ReturnType<typeof useConfirm>
|
||||||
@@ -44,7 +50,6 @@ const EXPIRY_OPTIONS = [
|
|||||||
const step = ref<1 | 2>(1)
|
const step = ref<1 | 2>(1)
|
||||||
const name = ref('')
|
const name = ref('')
|
||||||
const expires = ref('90d')
|
const expires = ref('90d')
|
||||||
const checked = ref<Set<string>>(new Set())
|
|
||||||
const scopes = ref<AdminAPITokenScope[]>([])
|
const scopes = ref<AdminAPITokenScope[]>([])
|
||||||
const scopesLoading = ref(false)
|
const scopesLoading = ref(false)
|
||||||
const scopesFailed = ref(false)
|
const scopesFailed = ref(false)
|
||||||
@@ -60,10 +65,32 @@ let copyTimer: ReturnType<typeof setTimeout> | null = null
|
|||||||
const nameInput = ref<HTMLInputElement | null>(null)
|
const nameInput = ref<HTMLInputElement | null>(null)
|
||||||
const plaintextInput = ref<HTMLInputElement | null>(null)
|
const plaintextInput = ref<HTMLInputElement | null>(null)
|
||||||
const copyButton = ref<HTMLElement | null>(null)
|
const copyButton = ref<HTMLElement | null>(null)
|
||||||
|
const scopeAccessRef = ref<InstanceType<typeof ScopeAccessControl> | null>(null)
|
||||||
|
const scopePickerRef = ref<InstanceType<typeof ScopePicker> | null>(null)
|
||||||
|
|
||||||
|
const {
|
||||||
|
availableTiers,
|
||||||
|
tier,
|
||||||
|
custom,
|
||||||
|
pickerOpen,
|
||||||
|
draftAdminRead,
|
||||||
|
draftScopes,
|
||||||
|
submittedScopes,
|
||||||
|
canSubmitScopes,
|
||||||
|
reset: resetScopeSelection,
|
||||||
|
selectTier,
|
||||||
|
openPicker,
|
||||||
|
applyPicker,
|
||||||
|
discardPicker,
|
||||||
|
} = useScopeSelection(scopes, 'token')
|
||||||
|
|
||||||
const starChecked = computed(() => checked.value.has('*'))
|
|
||||||
const canSubmit = computed(
|
const canSubmit = computed(
|
||||||
() => !scopesLoading.value && !scopesFailed.value && scopes.value.length > 0 && checked.value.size > 0 && !busy.value,
|
() =>
|
||||||
|
!scopesLoading.value &&
|
||||||
|
!scopesFailed.value &&
|
||||||
|
scopes.value.length > 0 &&
|
||||||
|
canSubmitScopes.value &&
|
||||||
|
!busy.value,
|
||||||
)
|
)
|
||||||
|
|
||||||
function pad(value: number): string {
|
function pad(value: number): string {
|
||||||
@@ -100,7 +127,7 @@ function resetForm(): void {
|
|||||||
step.value = 1
|
step.value = 1
|
||||||
name.value = ''
|
name.value = ''
|
||||||
expires.value = '90d'
|
expires.value = '90d'
|
||||||
checked.value = new Set()
|
resetScopeSelection([])
|
||||||
errors.value = {}
|
errors.value = {}
|
||||||
busy.value = false
|
busy.value = false
|
||||||
scopesFailed.value = false
|
scopesFailed.value = false
|
||||||
@@ -115,11 +142,13 @@ async function loadScopes(): Promise<void> {
|
|||||||
scopesLoading.value = true
|
scopesLoading.value = true
|
||||||
scopesFailed.value = false
|
scopesFailed.value = false
|
||||||
scopes.value = []
|
scopes.value = []
|
||||||
|
resetScopeSelection([])
|
||||||
try {
|
try {
|
||||||
const result = await api.GET('/account/tokens/scopes')
|
const result = await api.GET('/account/tokens/scopes')
|
||||||
if (result.data) {
|
if (result.data) {
|
||||||
const list = result.data.data ?? []
|
const list = result.data.data ?? []
|
||||||
scopes.value = list
|
scopes.value = list
|
||||||
|
resetScopeSelection(list)
|
||||||
scopesFailed.value = list.length === 0
|
scopesFailed.value = list.length === 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -139,28 +168,13 @@ watch(
|
|||||||
void loadScopes()
|
void loadScopes()
|
||||||
} else {
|
} else {
|
||||||
clearPlaintext()
|
clearPlaintext()
|
||||||
|
resetScopeSelection([])
|
||||||
step.value = 1
|
step.value = 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
function toggleScope(scopeName: string, on: boolean): void {
|
function clearScopeError(): void {
|
||||||
const next = new Set(checked.value)
|
|
||||||
if (scopeName === '*') {
|
|
||||||
if (on) {
|
|
||||||
next.clear()
|
|
||||||
next.add('*')
|
|
||||||
} else {
|
|
||||||
next.delete('*')
|
|
||||||
}
|
|
||||||
} else if (!starChecked.value) {
|
|
||||||
if (on) {
|
|
||||||
next.add(scopeName)
|
|
||||||
} else {
|
|
||||||
next.delete(scopeName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checked.value = next
|
|
||||||
if (errors.value.scopes) {
|
if (errors.value.scopes) {
|
||||||
const nextErrors = { ...errors.value }
|
const nextErrors = { ...errors.value }
|
||||||
delete nextErrors.scopes
|
delete nextErrors.scopes
|
||||||
@@ -168,15 +182,39 @@ function toggleScope(scopeName: string, on: boolean): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function scopeDisabled(scopeName: string): boolean {
|
async function onSelectTier(next: AccessTier): Promise<void> {
|
||||||
return starChecked.value && scopeName !== '*'
|
if (busy.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const wasOpen = pickerOpen.value
|
||||||
|
selectTier(next)
|
||||||
|
clearScopeError()
|
||||||
|
if (!wasOpen && pickerOpen.value) {
|
||||||
|
await nextTick()
|
||||||
|
scopePickerRef.value?.focusSearch()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectedScopes(): string[] {
|
async function onPickerOpen(): Promise<void> {
|
||||||
if (starChecked.value) {
|
if (busy.value) {
|
||||||
return ['*']
|
return
|
||||||
}
|
}
|
||||||
return scopes.value.map((scope) => scope.name).filter((scopeName) => checked.value.has(scopeName))
|
openPicker()
|
||||||
|
await nextTick()
|
||||||
|
scopePickerRef.value?.focusSearch()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onPickerApply(): Promise<void> {
|
||||||
|
applyPicker()
|
||||||
|
clearScopeError()
|
||||||
|
await nextTick()
|
||||||
|
scopeAccessRef.value?.focusPrimaryControl()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onPickerCancel(): Promise<void> {
|
||||||
|
discardPicker()
|
||||||
|
await nextTick()
|
||||||
|
scopeAccessRef.value?.focusPrimaryControl()
|
||||||
}
|
}
|
||||||
|
|
||||||
function nameDescribedBy(): string | undefined {
|
function nameDescribedBy(): string | undefined {
|
||||||
@@ -194,11 +232,7 @@ async function focusFirstInvalid(): Promise<void> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (errors.value.scopes) {
|
if (errors.value.scopes) {
|
||||||
const first = scopes.value.find((scope) => !scopeDisabled(scope.name))
|
scopeAccessRef.value?.focusPrimaryControl()
|
||||||
const el = first
|
|
||||||
? document.querySelector<HTMLInputElement>(`[data-scope="${CSS.escape(first.name)}"] input[type="checkbox"]`)
|
|
||||||
: null
|
|
||||||
el?.focus()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (errors.value.expires) {
|
if (errors.value.expires) {
|
||||||
@@ -207,14 +241,15 @@ async function focusFirstInvalid(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onSubmit(): Promise<void> {
|
async function onSubmit(): Promise<void> {
|
||||||
if (busy.value || !canSubmit.value || step.value !== 1) {
|
if (busy.value || !canSubmit.value || step.value !== 1 || pickerOpen.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
busy.value = true
|
busy.value = true
|
||||||
errors.value = {}
|
errors.value = {}
|
||||||
|
let invalid = false
|
||||||
try {
|
try {
|
||||||
const result = await api.POST('/account/tokens', {
|
const result = await api.POST('/account/tokens', {
|
||||||
body: { name: name.value, expires: expires.value, scopes: selectedScopes() },
|
body: { name: name.value, expires: expires.value, scopes: submittedScopes.value },
|
||||||
})
|
})
|
||||||
if (result.data) {
|
if (result.data) {
|
||||||
plaintext.value = result.data.data.token
|
plaintext.value = result.data.data.token
|
||||||
@@ -226,15 +261,18 @@ async function onSubmit(): Promise<void> {
|
|||||||
}
|
}
|
||||||
if (result.response.status === 422) {
|
if (result.response.status === 422) {
|
||||||
errors.value = fieldErrors(result.error?.error.details)
|
errors.value = fieldErrors(result.error?.error.details)
|
||||||
await focusFirstInvalid()
|
invalid = true
|
||||||
return
|
} else {
|
||||||
|
showToast(t('backend::lang.api_tokens.create_failed'), 'danger')
|
||||||
}
|
}
|
||||||
showToast(t('backend::lang.api_tokens.create_failed'), 'danger')
|
|
||||||
} catch {
|
} catch {
|
||||||
showToast(t('backend::lang.api_tokens.create_failed'), 'danger')
|
showToast(t('backend::lang.api_tokens.create_failed'), 'danger')
|
||||||
} finally {
|
} finally {
|
||||||
busy.value = false
|
busy.value = false
|
||||||
}
|
}
|
||||||
|
if (invalid) {
|
||||||
|
await focusFirstInvalid()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function markCopied(): void {
|
function markCopied(): void {
|
||||||
@@ -280,6 +318,7 @@ function onPlaintextFocus(event: FocusEvent): void {
|
|||||||
|
|
||||||
async function closeDialog(): Promise<void> {
|
async function closeDialog(): Promise<void> {
|
||||||
clearPlaintext()
|
clearPlaintext()
|
||||||
|
resetScopeSelection([])
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +353,10 @@ function onOpenAutoFocus(event: Event): void {
|
|||||||
copyButton.value?.querySelector('button')?.focus() ?? copyButton.value?.focus()
|
copyButton.value?.querySelector('button')?.focus() ?? copyButton.value?.focus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (pickerOpen.value) {
|
||||||
|
scopePickerRef.value?.focusSearch()
|
||||||
|
return
|
||||||
|
}
|
||||||
nameInput.value?.focus()
|
nameInput.value?.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,6 +376,11 @@ function onEscapeKey(event: Event): void {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (step.value === 1 && pickerOpen.value) {
|
||||||
|
event.preventDefault()
|
||||||
|
void onPickerCancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
if (step.value === 2) {
|
if (step.value === 2) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
void requestClose()
|
void requestClose()
|
||||||
@@ -356,261 +404,279 @@ onBeforeUnmount(() => {
|
|||||||
data-token-dialog
|
data-token-dialog
|
||||||
data-dialog-content
|
data-dialog-content
|
||||||
aria-modal="true"
|
aria-modal="true"
|
||||||
class="fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100vh-32px)] w-[calc(100%-32px)] max-w-[560px] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 rounded-modal bg-surface p-6 text-text shadow-pop"
|
class="fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100vh-32px)] w-[calc(100%-32px)] max-w-[560px] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-modal bg-surface text-text shadow-pop"
|
||||||
@open-auto-focus="onOpenAutoFocus"
|
@open-auto-focus="onOpenAutoFocus"
|
||||||
@close-auto-focus="onCloseAutoFocus"
|
@close-auto-focus="onCloseAutoFocus"
|
||||||
@pointer-down-outside="onPointerOutside"
|
@pointer-down-outside="onPointerOutside"
|
||||||
@interact-outside="onPointerOutside"
|
@interact-outside="onPointerOutside"
|
||||||
@escape-key-down="onEscapeKey"
|
@escape-key-down="onEscapeKey"
|
||||||
>
|
>
|
||||||
<div class="flex items-start gap-3">
|
<!-- Swapped in-dialog ScopePicker view (D-02, D-13): fixed max-w-[560px], zero nested overlay. -->
|
||||||
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
<template v-if="step === 1 && pickerOpen">
|
||||||
<DialogTitle class="text-[20px] font-bold tracking-[-0.01em]">{{
|
<div class="flex shrink-0 items-start gap-4 border-b border-border bg-surface p-4">
|
||||||
step === 1
|
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
||||||
? t('backend::lang.api_tokens.create_title')
|
<button
|
||||||
: t('backend::lang.api_tokens.created_title')
|
type="button"
|
||||||
}}</DialogTitle>
|
data-action="scope-picker-back"
|
||||||
<DialogDescription v-if="step === 1" class="text-muted">{{
|
:disabled="busy"
|
||||||
t('backend::lang.api_tokens.create_description')
|
class="inline-flex h-[34px] self-start items-center gap-1 rounded-tab px-2 text-[14px] font-semibold text-muted transition-colors duration-150 ease-out hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
}}</DialogDescription>
|
@click="onPickerCancel"
|
||||||
<DialogDescription
|
|
||||||
v-else
|
|
||||||
data-token-notice
|
|
||||||
role="note"
|
|
||||||
class="flex items-start gap-2 rounded-inner bg-sel px-4 py-3.5 text-text"
|
|
||||||
>
|
|
||||||
<TriangleAlert :size="16" class="mt-0.5 shrink-0" aria-hidden="true" />
|
|
||||||
<span>{{ t('backend::lang.api_tokens.created_notice') }}</span>
|
|
||||||
</DialogDescription>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
data-action="close"
|
|
||||||
:disabled="busy"
|
|
||||||
:aria-label="t('backend::lang.form.close')"
|
|
||||||
class="flex size-[34px] shrink-0 items-center justify-center rounded-tab bg-subtle text-muted hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-60"
|
|
||||||
@click="requestClose"
|
|
||||||
>
|
|
||||||
<X :size="16" aria-hidden="true" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form v-if="step === 1" novalidate class="flex min-h-0 flex-col gap-4" @submit.prevent="onSubmit">
|
|
||||||
<fieldset :disabled="busy" class="flex min-h-0 flex-col gap-[18px] overflow-y-auto">
|
|
||||||
<div class="flex min-w-0 flex-col gap-1.5" data-field="name">
|
|
||||||
<label :for="`${ID_PREFIX}-name`" class="font-semibold">{{
|
|
||||||
t('backend::lang.api_tokens.name')
|
|
||||||
}}</label>
|
|
||||||
<input
|
|
||||||
:id="`${ID_PREFIX}-name`"
|
|
||||||
ref="nameInput"
|
|
||||||
v-model="name"
|
|
||||||
name="name"
|
|
||||||
type="text"
|
|
||||||
maxlength="100"
|
|
||||||
autocomplete="off"
|
|
||||||
:placeholder="t('backend::lang.api_tokens.name_placeholder')"
|
|
||||||
:aria-invalid="errors.name ? 'true' : undefined"
|
|
||||||
:aria-describedby="nameDescribedBy()"
|
|
||||||
:class="controlClass(!!errors.name)"
|
|
||||||
class="h-input"
|
|
||||||
/>
|
|
||||||
<p :id="`${ID_PREFIX}-name-comment`" class="text-[13px] text-muted">
|
|
||||||
{{ t('backend::lang.api_tokens.name_comment') }}
|
|
||||||
</p>
|
|
||||||
<div
|
|
||||||
v-if="errors.name"
|
|
||||||
:id="`${ID_PREFIX}-name-error`"
|
|
||||||
class="flex flex-col gap-0.5 text-[13px] text-danger"
|
|
||||||
>
|
>
|
||||||
<p v-for="(text, index) in errors.name" :key="index" class="flex items-center gap-1.5">
|
<ArrowLeft :size="16" aria-hidden="true" />
|
||||||
<CircleAlert :size="14" class="shrink-0" aria-hidden="true" />
|
<span>{{ t('backend::lang.api_tokens.scope_picker_back') }}</span>
|
||||||
<span>{{ text }}</span>
|
</button>
|
||||||
</p>
|
<DialogTitle class="text-[20px] font-bold tracking-[-0.01em]">{{
|
||||||
</div>
|
t('backend::lang.api_tokens.scope_picker_title')
|
||||||
|
}}</DialogTitle>
|
||||||
|
<DialogDescription class="text-[13px] text-muted">{{
|
||||||
|
t('backend::lang.api_tokens.scope_picker_description')
|
||||||
|
}}</DialogDescription>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
<div class="flex min-w-0 flex-col gap-1.5" data-field="expires">
|
type="button"
|
||||||
<span id="api-token-expires-label" class="font-semibold">{{
|
data-action="close"
|
||||||
t('backend::lang.api_tokens.expires')
|
|
||||||
}}</span>
|
|
||||||
<RadioGroupRoot
|
|
||||||
v-model="expires"
|
|
||||||
orientation="horizontal"
|
|
||||||
aria-labelledby="api-token-expires-label"
|
|
||||||
class="inline-flex flex-wrap gap-1 rounded-inner border border-border bg-subtle p-1"
|
|
||||||
>
|
|
||||||
<RadioGroupItem
|
|
||||||
v-for="option in EXPIRY_OPTIONS"
|
|
||||||
:key="option.value"
|
|
||||||
:value="option.value"
|
|
||||||
data-expiry-segment
|
|
||||||
class="inline-flex h-pager items-center rounded-tab px-4 text-[13px] whitespace-nowrap text-muted transition-colors duration-150 ease-out hover:text-text data-[state=checked]:bg-surface data-[state=checked]:text-text data-[state=checked]:shadow-tab data-[state=checked]:text-[14px] data-[state=checked]:font-semibold"
|
|
||||||
>
|
|
||||||
{{ t(option.label) }}
|
|
||||||
</RadioGroupItem>
|
|
||||||
</RadioGroupRoot>
|
|
||||||
<p class="text-[13px] text-muted tabular-nums">{{ expiryPreview }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex min-w-0 flex-col gap-1.5" data-field="scopes">
|
|
||||||
<span id="api-token-scopes-label" class="font-semibold">{{
|
|
||||||
t('backend::lang.api_tokens.scopes')
|
|
||||||
}}</span>
|
|
||||||
<div
|
|
||||||
v-if="scopesLoading"
|
|
||||||
role="group"
|
|
||||||
aria-labelledby="api-token-scopes-label"
|
|
||||||
data-scope-picker
|
|
||||||
class="overflow-hidden rounded-inner border border-border"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
v-for="index in 3"
|
|
||||||
:key="index"
|
|
||||||
class="flex min-h-[56px] items-center gap-3 border-t border-border px-4 py-3 first:border-t-0"
|
|
||||||
aria-hidden="true"
|
|
||||||
>
|
|
||||||
<span class="size-5 shrink-0 rounded-[6px] bg-skel" />
|
|
||||||
<span class="h-3 w-40 rounded-[6px] bg-skel" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-else-if="scopesFailed"
|
|
||||||
role="alert"
|
|
||||||
class="flex items-start gap-2 rounded-inner bg-danger-soft px-[18px] py-3.5 text-danger"
|
|
||||||
>
|
|
||||||
<CircleAlert :size="16" class="mt-0.5 shrink-0" aria-hidden="true" />
|
|
||||||
<span>{{ t('backend::lang.api_tokens.scopes_failed') }}</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
role="group"
|
|
||||||
aria-labelledby="api-token-scopes-label"
|
|
||||||
data-scope-picker
|
|
||||||
:aria-invalid="errors.scopes ? 'true' : undefined"
|
|
||||||
:class="errors.scopes ? 'border-danger' : 'border-border'"
|
|
||||||
class="overflow-hidden rounded-inner border"
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
v-for="scope in scopes"
|
|
||||||
:key="scope.name"
|
|
||||||
:data-scope="scope.name"
|
|
||||||
:class="scopeDisabled(scope.name) ? 'cursor-not-allowed opacity-60' : 'cursor-pointer'"
|
|
||||||
class="flex min-h-[56px] items-start gap-3 border-t border-border px-4 py-3 first:border-t-0"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
class="mt-0.5 size-5 shrink-0 rounded-[6px] accent-primary"
|
|
||||||
:checked="checked.has(scope.name)"
|
|
||||||
:disabled="scopeDisabled(scope.name)"
|
|
||||||
@change="toggleScope(scope.name, ($event.target as HTMLInputElement).checked)"
|
|
||||||
/>
|
|
||||||
<span class="flex min-w-0 flex-col">
|
|
||||||
<span class="flex flex-wrap items-center gap-1">
|
|
||||||
<span class="font-semibold">{{ scope.label }}</span>
|
|
||||||
<span class="font-mono text-[13px] text-muted">{{ scope.name }}</span>
|
|
||||||
<span
|
|
||||||
v-if="scope.read_only"
|
|
||||||
class="inline-flex h-6 items-center rounded-pill bg-subtle px-2.5 text-[13px] font-semibold whitespace-nowrap text-muted"
|
|
||||||
>{{ t('backend::lang.api_tokens.read_only') }}</span
|
|
||||||
>
|
|
||||||
</span>
|
|
||||||
<span class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ scope.description }}</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
v-if="starChecked"
|
|
||||||
class="flex items-center gap-2 text-[13px] text-muted"
|
|
||||||
>
|
|
||||||
<Info :size="14" class="shrink-0" aria-hidden="true" />
|
|
||||||
<span>{{ t('backend::lang.api_tokens.scope_all_includes') }}</span>
|
|
||||||
</p>
|
|
||||||
<div
|
|
||||||
v-if="errors.scopes"
|
|
||||||
:id="`${ID_PREFIX}-scopes-error`"
|
|
||||||
class="flex flex-col gap-0.5 text-[13px] text-danger"
|
|
||||||
>
|
|
||||||
<p v-for="(text, index) in errors.scopes" :key="index" class="flex items-center gap-1.5">
|
|
||||||
<CircleAlert :size="14" class="shrink-0" aria-hidden="true" />
|
|
||||||
<span>{{ text }}</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="flex gap-2.5">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
class="flex-1"
|
|
||||||
data-action="create-token-cancel"
|
|
||||||
:disabled="busy"
|
:disabled="busy"
|
||||||
|
:aria-label="t('backend::lang.form.close')"
|
||||||
|
class="flex size-[34px] shrink-0 items-center justify-center rounded-tab bg-subtle text-muted hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
@click="requestClose"
|
@click="requestClose"
|
||||||
>
|
>
|
||||||
{{ t('backend::lang.api_tokens.create_cancel') }}
|
<X :size="16" aria-hidden="true" />
|
||||||
</Button>
|
</button>
|
||||||
<Button
|
|
||||||
variant="primary"
|
|
||||||
type="submit"
|
|
||||||
class="flex-1"
|
|
||||||
data-action="create-token-submit"
|
|
||||||
hotkey="mod+s mod+enter"
|
|
||||||
:title="shortcutHint(t('backend::lang.api_tokens.create_submit'), 'mod+s')"
|
|
||||||
:disabled="!canSubmit"
|
|
||||||
>
|
|
||||||
<LoaderCircle v-if="busy" :size="16" class="animate-spin" aria-hidden="true" />
|
|
||||||
{{ busy ? t('backend::lang.api_tokens.creating') : t('backend::lang.api_tokens.create_submit') }}
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
<ScopePicker
|
||||||
|
ref="scopePickerRef"
|
||||||
|
:catalog="scopes"
|
||||||
|
v-model:draft-admin-read="draftAdminRead"
|
||||||
|
v-model:draft-scopes="draftScopes"
|
||||||
|
:cancel-label="t('backend::lang.api_tokens.scope_picker_back')"
|
||||||
|
:disabled="busy"
|
||||||
|
@apply="onPickerApply"
|
||||||
|
@cancel="onPickerCancel"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
<div v-else class="flex min-h-0 flex-col gap-4">
|
<!-- Token form (Step 1) and show-once plaintext (Step 2) -->
|
||||||
<div class="flex min-w-0 flex-col gap-2">
|
<div v-else class="flex min-h-0 flex-1 flex-col gap-4 p-6">
|
||||||
<label :for="`${ID_PREFIX}-plaintext`" class="sr-only">{{
|
<div class="flex items-start gap-3">
|
||||||
t('backend::lang.api_tokens.token_label')
|
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
||||||
}}</label>
|
<DialogTitle class="text-[20px] font-bold tracking-[-0.01em]">{{
|
||||||
<input
|
step === 1
|
||||||
:id="`${ID_PREFIX}-plaintext`"
|
? t('backend::lang.api_tokens.create_title')
|
||||||
ref="plaintextInput"
|
: t('backend::lang.api_tokens.created_title')
|
||||||
:value="plaintext"
|
}}</DialogTitle>
|
||||||
type="text"
|
<DialogDescription v-if="step === 1" class="text-muted">{{
|
||||||
readonly
|
t('backend::lang.api_tokens.create_description')
|
||||||
autocomplete="off"
|
}}</DialogDescription>
|
||||||
spellcheck="false"
|
<DialogDescription
|
||||||
data-token-plaintext
|
v-else
|
||||||
:class="controlClass(false)"
|
data-token-notice
|
||||||
class="h-input bg-subtle font-mono text-[14px]"
|
role="note"
|
||||||
@focus="onPlaintextFocus"
|
class="flex items-start gap-2 rounded-inner bg-sel px-4 py-3.5 text-text"
|
||||||
@click="onPlaintextFocus"
|
|
||||||
@copy="onPlaintextCopy"
|
|
||||||
/>
|
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
|
||||||
<span ref="copyButton">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
:icon="copyFlash ? Check : Copy"
|
|
||||||
data-action="copy-token"
|
|
||||||
@click="onCopy"
|
|
||||||
>
|
|
||||||
{{ copyFlash ? t('backend::lang.api_tokens.copied') : t('backend::lang.api_tokens.copy') }}
|
|
||||||
</Button>
|
|
||||||
</span>
|
|
||||||
<p
|
|
||||||
v-if="copyFailed"
|
|
||||||
role="alert"
|
|
||||||
class="flex items-center gap-1.5 text-[13px] text-danger"
|
|
||||||
>
|
>
|
||||||
<CircleAlert :size="14" class="shrink-0" aria-hidden="true" />
|
<TriangleAlert :size="16" class="mt-0.5 shrink-0" aria-hidden="true" />
|
||||||
<span>{{ t('backend::lang.api_tokens.copy_failed') }}</span>
|
<span>{{ t('backend::lang.api_tokens.created_notice') }}</span>
|
||||||
</p>
|
</DialogDescription>
|
||||||
<span class="sr-only" aria-live="polite">{{ announce }}</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-action="close"
|
||||||
|
:disabled="busy"
|
||||||
|
:aria-label="t('backend::lang.form.close')"
|
||||||
|
class="flex size-[34px] shrink-0 items-center justify-center rounded-tab bg-subtle text-muted hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
@click="requestClose"
|
||||||
|
>
|
||||||
|
<X :size="16" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end">
|
|
||||||
<Button variant="primary" data-action="hide-token" @click="onHide">
|
<form v-if="step === 1" novalidate class="flex min-h-0 flex-col gap-4" @submit.prevent="onSubmit">
|
||||||
{{ t('backend::lang.api_tokens.done') }}
|
<fieldset :disabled="busy" class="flex min-h-0 flex-col gap-[18px] overflow-y-auto">
|
||||||
</Button>
|
<div class="flex min-w-0 flex-col gap-1.5" data-field="name">
|
||||||
|
<label :for="`${ID_PREFIX}-name`" class="font-semibold">{{
|
||||||
|
t('backend::lang.api_tokens.name')
|
||||||
|
}}</label>
|
||||||
|
<input
|
||||||
|
:id="`${ID_PREFIX}-name`"
|
||||||
|
ref="nameInput"
|
||||||
|
v-model="name"
|
||||||
|
name="name"
|
||||||
|
type="text"
|
||||||
|
maxlength="100"
|
||||||
|
autocomplete="off"
|
||||||
|
:placeholder="t('backend::lang.api_tokens.name_placeholder')"
|
||||||
|
:aria-invalid="errors.name ? 'true' : undefined"
|
||||||
|
:aria-describedby="nameDescribedBy()"
|
||||||
|
:class="controlClass(!!errors.name)"
|
||||||
|
class="h-input"
|
||||||
|
/>
|
||||||
|
<p :id="`${ID_PREFIX}-name-comment`" class="text-[13px] text-muted">
|
||||||
|
{{ t('backend::lang.api_tokens.name_comment') }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-if="errors.name"
|
||||||
|
:id="`${ID_PREFIX}-name-error`"
|
||||||
|
class="flex flex-col gap-0.5 text-[13px] text-danger"
|
||||||
|
>
|
||||||
|
<p v-for="(text, index) in errors.name" :key="index" class="flex items-center gap-1.5">
|
||||||
|
<CircleAlert :size="14" class="shrink-0" aria-hidden="true" />
|
||||||
|
<span>{{ text }}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-col gap-1.5" data-field="expires">
|
||||||
|
<span id="api-token-expires-label" class="font-semibold">{{
|
||||||
|
t('backend::lang.api_tokens.expires')
|
||||||
|
}}</span>
|
||||||
|
<RadioGroupRoot
|
||||||
|
v-model="expires"
|
||||||
|
orientation="horizontal"
|
||||||
|
aria-labelledby="api-token-expires-label"
|
||||||
|
class="inline-flex flex-wrap gap-1 rounded-inner border border-border bg-subtle p-1"
|
||||||
|
>
|
||||||
|
<RadioGroupItem
|
||||||
|
v-for="option in EXPIRY_OPTIONS"
|
||||||
|
:key="option.value"
|
||||||
|
:value="option.value"
|
||||||
|
data-expiry-segment
|
||||||
|
class="inline-flex h-pager items-center rounded-tab px-4 text-[13px] whitespace-nowrap text-muted transition-colors duration-150 ease-out hover:text-text data-[state=checked]:bg-surface data-[state=checked]:text-text data-[state=checked]:shadow-tab data-[state=checked]:text-[14px] data-[state=checked]:font-semibold"
|
||||||
|
>
|
||||||
|
{{ t(option.label) }}
|
||||||
|
</RadioGroupItem>
|
||||||
|
</RadioGroupRoot>
|
||||||
|
<p class="text-[13px] text-muted tabular-nums">{{ expiryPreview }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-col gap-1.5" data-field="scopes">
|
||||||
|
<template v-if="scopesLoading">
|
||||||
|
<span id="api-token-scopes-label" class="font-semibold">{{
|
||||||
|
t('backend::lang.api_tokens.access_level')
|
||||||
|
}}</span>
|
||||||
|
<div
|
||||||
|
role="group"
|
||||||
|
aria-labelledby="api-token-scopes-label"
|
||||||
|
data-scope-loading
|
||||||
|
class="flex flex-col gap-2"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<span class="h-10 rounded-inner bg-skel" />
|
||||||
|
<div class="flex flex-col gap-2 rounded-inner border border-border bg-subtle p-4">
|
||||||
|
<span class="h-3 w-48 rounded-[6px] bg-skel" />
|
||||||
|
<span class="h-3 w-32 rounded-[6px] bg-skel" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="scopesFailed">
|
||||||
|
<span id="api-token-scopes-label" class="font-semibold">{{
|
||||||
|
t('backend::lang.api_tokens.access_level')
|
||||||
|
}}</span>
|
||||||
|
<div
|
||||||
|
role="alert"
|
||||||
|
class="flex items-start gap-2 rounded-inner bg-danger-soft px-[18px] py-3.5 text-danger"
|
||||||
|
>
|
||||||
|
<CircleAlert :size="16" class="mt-0.5 shrink-0" aria-hidden="true" />
|
||||||
|
<span>{{ t('backend::lang.api_tokens.scopes_failed') }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ScopeAccessControl
|
||||||
|
v-else
|
||||||
|
ref="scopeAccessRef"
|
||||||
|
:id-prefix="ID_PREFIX"
|
||||||
|
:catalog="scopes"
|
||||||
|
:available-tiers="availableTiers"
|
||||||
|
:tier="tier"
|
||||||
|
:custom="custom"
|
||||||
|
:disabled="busy"
|
||||||
|
:invalid="Boolean(errors.scopes)"
|
||||||
|
@update:tier="onSelectTier"
|
||||||
|
@customize="onPickerOpen"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="errors.scopes"
|
||||||
|
:id="`${ID_PREFIX}-scopes-error`"
|
||||||
|
class="flex flex-col gap-0.5 text-[13px] text-danger"
|
||||||
|
>
|
||||||
|
<p v-for="(text, index) in errors.scopes" :key="index" class="flex items-center gap-1.5">
|
||||||
|
<CircleAlert :size="14" class="shrink-0" aria-hidden="true" />
|
||||||
|
<span>{{ text }}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div class="flex gap-2.5">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
class="flex-1"
|
||||||
|
data-action="create-token-cancel"
|
||||||
|
:disabled="busy"
|
||||||
|
@click="requestClose"
|
||||||
|
>
|
||||||
|
{{ t('backend::lang.api_tokens.create_cancel') }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
type="submit"
|
||||||
|
class="flex-1"
|
||||||
|
data-action="create-token-submit"
|
||||||
|
hotkey="mod+s mod+enter"
|
||||||
|
:title="shortcutHint(t('backend::lang.api_tokens.create_submit'), 'mod+s')"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
>
|
||||||
|
<LoaderCircle v-if="busy" :size="16" class="animate-spin" aria-hidden="true" />
|
||||||
|
{{ busy ? t('backend::lang.api_tokens.creating') : t('backend::lang.api_tokens.create_submit') }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div v-else class="flex min-h-0 flex-col gap-4">
|
||||||
|
<div class="flex min-w-0 flex-col gap-2">
|
||||||
|
<label :for="`${ID_PREFIX}-plaintext`" class="sr-only">{{
|
||||||
|
t('backend::lang.api_tokens.token_label')
|
||||||
|
}}</label>
|
||||||
|
<input
|
||||||
|
:id="`${ID_PREFIX}-plaintext`"
|
||||||
|
ref="plaintextInput"
|
||||||
|
:value="plaintext"
|
||||||
|
type="text"
|
||||||
|
readonly
|
||||||
|
autocomplete="off"
|
||||||
|
spellcheck="false"
|
||||||
|
data-token-plaintext
|
||||||
|
:class="controlClass(false)"
|
||||||
|
class="h-input bg-subtle font-mono text-[14px]"
|
||||||
|
@focus="onPlaintextFocus"
|
||||||
|
@click="onPlaintextFocus"
|
||||||
|
@copy="onPlaintextCopy"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span ref="copyButton">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
:icon="copyFlash ? Check : Copy"
|
||||||
|
data-action="copy-token"
|
||||||
|
@click="onCopy"
|
||||||
|
>
|
||||||
|
{{ copyFlash ? t('backend::lang.api_tokens.copied') : t('backend::lang.api_tokens.copy') }}
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
<p
|
||||||
|
v-if="copyFailed"
|
||||||
|
role="alert"
|
||||||
|
class="flex items-center gap-1.5 text-[13px] text-danger"
|
||||||
|
>
|
||||||
|
<CircleAlert :size="14" class="shrink-0" aria-hidden="true" />
|
||||||
|
<span>{{ t('backend::lang.api_tokens.copy_failed') }}</span>
|
||||||
|
</p>
|
||||||
|
<span class="sr-only" aria-live="polite">{{ announce }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<Button variant="primary" data-action="hide-token" @click="onHide">
|
||||||
|
{{ t('backend::lang.api_tokens.done') }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
Reference in New Issue
Block a user