fix(36): polish ScopePicker search collapse, unique panel IDs, and lazy catalog expand

This commit is contained in:
Jakub Zych
2026-11-25 01:29:28 +01:00
parent 51b60b94b8
commit bfb0bee809
7 changed files with 158 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, ref } from 'vue'
import { computed, nextTick, ref, useId, watch } from 'vue'
import { ChevronDown, ChevronRight, Lock, Search, X } from '@lucide/vue'
import type { AdminAPITokenScope } from '../../api/types'
import {
@@ -46,9 +46,12 @@ interface VisibleScopeGroup {
canClear: boolean
}
const pickerId = useId()
const query = ref('')
const filter = ref<ScopeFilter>('all')
const expanded = ref<Set<string>>(new Set())
const searchCollapsed = ref<Set<string>>(new Set())
let initializedExpanded = false
const searchInput = ref<HTMLInputElement | null>(null)
const partitioned = computed(() => partitionCatalog(props.catalog))
@@ -123,7 +126,7 @@ const visibleGroups = computed<VisibleScopeGroup[]>(() => {
result.push({
key: group.key,
panelId: `scope-group-panel-${index}`,
panelId: `${pickerId}-group-${index}`,
label: group.label,
allScopes: group.scopes,
visibleScopes,
@@ -182,11 +185,21 @@ const emptyState = computed(() => {
})
function isGroupExpanded(key: string): boolean {
return isSearching.value || expanded.value.has(key)
if (isSearching.value) {
return !searchCollapsed.value.has(key)
}
return expanded.value.has(key)
}
function toggleGroup(key: string): void {
if (isSearching.value) {
const next = new Set(searchCollapsed.value)
if (next.has(key)) {
next.delete(key)
} else {
next.add(key)
}
searchCollapsed.value = next
return
}
const next = new Set(expanded.value)
@@ -262,15 +275,28 @@ function focusSearch(): void {
searchInput.value?.focus()
}
onMounted(() => {
expanded.value = computeDefaultExpanded(
allGroups.value,
pluginScopes.value.length,
draftSelection.value,
false,
)
watch(query, () => {
if (searchCollapsed.value.size > 0) {
searchCollapsed.value = new Set()
}
})
watch(
() => allGroups.value.length,
(len) => {
if (!initializedExpanded && len > 0) {
initializedExpanded = true
expanded.value = computeDefaultExpanded(
allGroups.value,
pluginScopes.value.length,
draftSelection.value,
false,
)
}
},
{ immediate: true },
)
defineExpose({ focusSearch })
</script>