Line data Source code
1 : <template>
2 116 : <BaseModalLayout
3 : :labels="modalLayoutLabels"
4 : :content-title="$t('g.settings')"
5 : data-testid="settings-dialog"
6 : size="md"
7 : :content-padding="isWorkspaceCategoryActive ? 'none' : 'default'"
8 : header-padding="symmetric"
9 : :close-button-variant="closeButtonVariant"
10 : :close-icon="closeIcon"
11 : @close="onClose"
12 : >
13 : <template #leftPanelHeaderTitle>
14 : <i class="icon-[lucide--settings]" />
15 : <h2 class="text-base text-foreground">{{ $t('g.settings') }}</h2>
16 : </template>
17 :
18 : <template #leftPanel>
19 : <div class="px-3">
20 : <SearchInput
21 : v-model:model-value="searchQuery"
22 : :clear-label="$t('g.clear')"
23 : :accessible-label="$t('g.searchSettings') + '...'"
24 : size="md"
25 : class="rounded-lg ring-1 ring-border/50"
26 : :placeholder="$t('g.searchSettings') + '...'"
27 : :debounce-time="128"
28 : :autofocus="activeCategoryKey !== 'keybinding'"
29 : @search="handleSearch"
30 : />
31 : </div>
32 :
33 : <nav
34 : ref="navRef"
35 : class="flex scrollbar-hide flex-1 flex-col gap-1 overflow-y-auto px-3 pt-1 pb-4"
36 : >
37 252 : <div
38 : v-for="(group, index) in navGroups"
39 : :key="index"
40 : class="flex flex-col gap-2"
41 : >
42 : <NavTitle :title="group.title" />
43 1900 : <NavItem
44 : v-for="item in group.items"
45 : :key="item.id"
46 : :data-nav-id="item.id"
47 : :icon="item.icon"
48 : :badge="item.badge"
49 : :suffix-icon="item.suffixIcon"
50 : :active="activeCategoryKey === item.id"
51 : @click="onNavItemClick(item.id)"
52 : >
53 : {{ item.label }}
54 : </NavItem>
55 : </div>
56 : </nav>
57 : </template>
58 :
59 : <template #header>
60 : <div
61 : v-if="activeCategoryKey === 'keybinding'"
62 : id="keybinding-panel-header"
63 : class="flex-1"
64 : />
65 : <SettingsWorkspaceHeader
66 : v-else-if="isWorkspaceCategoryActive"
67 : :workspace-name="workspaceName"
68 : :subscription-tier="activeSummary?.subscriptionTier"
69 : :collapsed="isHeaderCollapsed"
70 : :large="unifiedBillingSettingsEnabled"
71 : />
72 : </template>
73 :
74 : <template #header-right-area>
75 : <div
76 : v-if="activeCategoryKey === 'keybinding'"
77 : id="keybinding-panel-actions"
78 : />
79 : </template>
80 :
81 : <template #content>
82 : <div
83 : :class="
84 : cn(
85 : 'flex min-h-0 flex-1 flex-col',
86 : isWorkspaceCategoryActive && 'px-6'
87 : )
88 : "
89 : @scroll.capture="handlePanelScroll"
90 : >
91 : <template v-if="activePanel">
92 : <Suspense>
93 : <component :is="activePanel.component" v-bind="activePanel.props" />
94 : <template #fallback>
95 : <div>
96 : {{ $t('g.loadingPanel', { panel: activePanel.node.label }) }}
97 : </div>
98 : </template>
99 : </Suspense>
100 : </template>
101 : <template v-else-if="inSearch">
102 : <SettingsPanel :setting-groups="searchResults" />
103 : </template>
104 : <template v-else-if="activeSettingCategory">
105 : <CurrentUserMessage v-if="activeSettingCategory.label === 'Comfy'" />
106 : <ThemePresetMessage
107 : v-if="activeSettingCategory.label === 'Appearance'"
108 : />
109 : <SettingsPanel
110 : :setting-groups="sortedGroups(activeSettingCategory)"
111 : />
112 : </template>
113 : </div>
114 : </template>
115 : </BaseModalLayout>
116 : </template>
117 :
118 : <script setup lang="ts">
119 : import { storeToRefs } from 'pinia'
120 : import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
121 :
122 : import SearchInput from '@comfyorg/design-system/search-input/SearchInput'
123 : import SettingsWorkspaceHeader from '@/platform/settings/components/SettingsWorkspaceHeader.vue'
124 : import CurrentUserMessage from '@/components/dialog/content/setting/CurrentUserMessage.vue'
125 : import BaseModalLayout from '@comfyorg/design-system/layout/BaseModalLayout'
126 : import NavItem from '@comfyorg/design-system/navigation/NavItem'
127 : import NavTitle from '@comfyorg/design-system/navigation/NavTitle'
128 : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
129 : import { refreshBalanceInBackground } from '@/platform/billing/refreshBalanceInBackground'
130 : import { useWorkspaceBillingStateStore } from '@/platform/billing/stores/workspaceBillingStateStore'
131 : import { useSettingsHeaderCollapse } from '@/platform/settings/composables/useSettingsHeaderCollapse'
132 : import { cn } from '@comfyorg/tailwind-utils'
133 : import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
134 : import ThemePresetMessage from '@/platform/theme/ThemePresetMessage.vue'
135 : import SettingsPanel from '@/platform/settings/components/SettingsPanel.vue'
136 : import { useSettingSearch } from '@/platform/settings/composables/useSettingSearch'
137 : import { useSettingUI } from '@/platform/settings/composables/useSettingUI'
138 : import { useSearchQueryTracking } from '@/platform/telemetry/searchQuery/useSearchQueryTracking'
139 : import type { SettingTreeNode } from '@/platform/settings/composables/useSettingSearch'
140 : import type {
141 : ISettingGroup,
142 : SettingDialogProps,
143 : SettingParams
144 : } from '@comfyorg/settings-core/types'
145 : import { useModalLayoutLabels } from '@/components/dialog/useModalLayoutLabels'
146 : import { flattenTree } from '@/utils/treeUtil'
147 :
148 : const { onClose, defaultPanel, scrollToSettingId, navigationRequestId } =
149 : defineProps<SettingDialogProps>()
150 :
151 107 : const modalLayoutLabels = useModalLayoutLabels()
152 :
153 107 : const {
154 : defaultCategory,
155 : settingCategories,
156 : navGroups,
157 : unifiedBillingSettingsEnabled,
158 : findCategoryByKey,
159 : findPanelByKey
160 : } = useSettingUI(defaultPanel, scrollToSettingId)
161 :
162 107 : const {
163 : searchQuery,
164 : inSearch,
165 : searchResultsCategories,
166 : matchedNavItemKeys,
167 : handleSearch: handleSearchBase,
168 : getSearchResults
169 : } = useSettingSearch()
170 :
171 107 : const { fetchBalance } = useBillingContext()
172 :
173 107 : const navRef = ref<HTMLElement | null>(null)
174 107 : const activeCategoryKey = ref<string | null>(defaultCategory.value?.key ?? null)
175 :
176 107 : const WORKSPACE_CATEGORY_KEYS = new Set([
177 : 'workspace',
178 : 'workspace-members',
179 : 'workspace-allowlist'
180 : ])
181 107 : const closeButtonVariant = computed(() =>
182 : unifiedBillingSettingsEnabled.value ? 'textonly' : undefined
183 : )
184 107 : const closeIcon = computed(() =>
185 : unifiedBillingSettingsEnabled.value ? 'icon-[lucide--x]' : undefined
186 : )
187 107 : const isWorkspaceCategoryActive = computed(
188 : () =>
189 : activeCategoryKey.value !== null &&
190 : WORKSPACE_CATEGORY_KEYS.has(activeCategoryKey.value)
191 : )
192 107 : const { workspaceName } = storeToRefs(useTeamWorkspaceStore())
193 107 : const { activeSummary } = storeToRefs(useWorkspaceBillingStateStore())
194 :
195 107 : const { isHeaderCollapsed, handlePanelScroll, resetHeaderCollapse } =
196 : useSettingsHeaderCollapse()
197 :
198 : // A panel change swaps the scroller out from under the collapse state, and the
199 : // state outlives the dialog, so a reopen would otherwise start collapsed.
200 107 : watch(activeCategoryKey, resetHeaderCollapse)
201 107 : onBeforeUnmount(resetHeaderCollapse)
202 :
203 107 : const navItems = computed(() => navGroups.value.flatMap((group) => group.items))
204 107 : const searchableNavItems = computed(() =>
205 : navItems.value.map((item) => ({
206 : key: item.id,
207 : label: item.label
208 : }))
209 : )
210 :
211 107 : watch(navItems, (items) => {
212 1 : const activeKey = activeCategoryKey.value
213 1 : if (!activeKey || items.some(({ id }) => id === activeKey)) return
214 1 : activeCategoryKey.value = items[0]?.id ?? null
215 : })
216 :
217 107 : watch([() => defaultPanel, () => navigationRequestId], ([panel]) => {
218 2 : if (!panel) return
219 2 : if (!findCategoryByKey(panel) && !findPanelByKey(panel)) return
220 2 : if (inSearch.value) {
221 0 : searchQuery.value = ''
222 0 : handleSearch('')
223 : }
224 2 : activeCategoryKey.value = panel
225 : })
226 :
227 107 : watch(
228 : [searchResultsCategories, matchedNavItemKeys],
229 : ([categories, navKeys]) => {
230 9 : if (!inSearch.value || (categories.size === 0 && navKeys.size === 0)) return
231 8 : const firstMatch = navGroups.value
232 : .flatMap((g) => g.items)
233 : .find((item) => {
234 56 : if (navKeys.has(item.id)) return true
235 52 : const node = findCategoryByKey(item.id)
236 56 : return node && categories.has(node.label)
237 : })
238 9 : activeCategoryKey.value = firstMatch?.id ?? null
239 : }
240 : )
241 :
242 107 : const activeSettingCategory = computed<SettingTreeNode | null>(() => {
243 116 : if (!activeCategoryKey.value) return null
244 116 : return (
245 : settingCategories.value.find((c) => c.key === activeCategoryKey.value) ??
246 : null
247 : )
248 : })
249 :
250 107 : const activePanel = computed(() => {
251 182 : if (!activeCategoryKey.value) return null
252 182 : return findPanelByKey(activeCategoryKey.value)
253 : })
254 :
255 107 : const getGroupSortOrder = (group: SettingTreeNode): number =>
256 : Math.max(0, ...flattenTree<SettingParams>(group).map((s) => s.sortOrder ?? 0))
257 :
258 136 : function sortedGroups(category: SettingTreeNode): ISettingGroup[] {
259 136 : return [...(category.children ?? [])]
260 : .sort((a, b) => {
261 8603 : const orderDiff = getGroupSortOrder(b) - getGroupSortOrder(a)
262 8603 : return orderDiff !== 0 ? orderDiff : a.label.localeCompare(b.label)
263 : })
264 : .map((group) => ({
265 : label: group.label,
266 : settings: flattenTree<SettingParams>(group).sort((a, b) => {
267 5697 : const sortOrderA = a.sortOrder ?? 0
268 : const sortOrderB = b.sortOrder ?? 0
269 5697 : return sortOrderB - sortOrderA
270 : })
271 : }))
272 : }
273 :
274 9 : function handleSearch(query: string) {
275 9 : handleSearchBase(query.trim(), searchableNavItems.value)
276 9 : if (query) {
277 8 : activeCategoryKey.value = null
278 1 : } else if (!activeCategoryKey.value) {
279 0 : activeCategoryKey.value = defaultCategory.value?.key ?? null
280 : }
281 : }
282 :
283 73 : function onNavItemClick(id: string) {
284 73 : activeCategoryKey.value = id
285 : }
286 :
287 107 : const searchResults = computed<ISettingGroup[]>(() => getSearchResults(null))
288 :
289 107 : useSearchQueryTracking('settings', searchQuery, searchResults)
290 :
291 : // Scroll to and highlight the target setting once the correct category renders.
292 107 : if (scrollToSettingId) {
293 0 : const stopScrollWatch = watch(
294 : activeCategoryKey,
295 : () => {
296 0 : void nextTick(() => {
297 0 : const el = document.querySelector(
298 : `[data-setting-id="${CSS.escape(scrollToSettingId)}"]`
299 : )
300 0 : if (!el) return
301 0 : stopScrollWatch()
302 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center' })
303 0 : el.classList.add('setting-highlight')
304 0 : el.addEventListener(
305 : 'animationend',
306 : () => el.classList.remove('setting-highlight'),
307 : { once: true }
308 : )
309 : })
310 : },
311 : { immediate: true }
312 : )
313 0 : onBeforeUnmount(stopScrollWatch)
314 : }
315 :
316 107 : watch(activeCategoryKey, (newKey, oldKey) => {
317 72 : if (!newKey && !inSearch.value) {
318 0 : activeCategoryKey.value = oldKey
319 : }
320 72 : if (newKey === 'credits') {
321 0 : void refreshBalanceInBackground(fetchBalance)
322 : }
323 72 : if (newKey) {
324 72 : void nextTick(() => {
325 72 : navRef.value
326 : ?.querySelector(`[data-nav-id="${newKey}"]`)
327 : ?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
328 : })
329 : }
330 : })
331 : </script>
332 :
333 : <style>
334 : @media (prefers-reduced-motion: no-preference) {
335 : .setting-highlight {
336 : animation: setting-highlight-pulse 1.5s ease-in-out;
337 : }
338 : }
339 :
340 : @keyframes setting-highlight-pulse {
341 : 0%,
342 : 100% {
343 : background-color: transparent;
344 : }
345 : 30% {
346 : background-color: color-mix(in srgb, var(--primary) 15%, transparent);
347 : }
348 : }
349 : </style>
|