LCOV - code coverage report
Current view: top level - src/platform/settings/composables - useSettingsUrlLoader.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 1 1
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { useRoute, useRouter } from 'vue-router'
       2              : 
       3              : import {
       4              :   clearPreservedQuery,
       5              :   hydratePreservedQuery,
       6              :   mergePreservedQueryIntoQuery
       7              : } from '@/platform/navigation/preservedQueryManager'
       8              : import { PRESERVED_QUERY_NAMESPACES } from '@/platform/navigation/preservedQueryNamespaces'
       9              : import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog'
      10              : import type { SettingPanelType } from '@comfyorg/settings-core/types'
      11              : 
      12         2355 : const NAMESPACE = PRESERVED_QUERY_NAMESPACES.SETTINGS
      13              : 
      14              : const DEEP_LINKABLE_PANELS: Record<string, SettingPanelType> = {
      15              :   'plan-credits': 'workspace',
      16              :   members: 'workspace-members'
      17              : }
      18              : 
      19              : /**
      20              :  * Opens the Settings dialog on a named panel from a `?settings=` deep link
      21              :  * (e.g. `?settings=plan-credits`), so external surfaces like platform.comfy.org
      22              :  * can land users directly on the tab where they complete billing actions.
      23              :  *
      24              :  * Only values in `DEEP_LINKABLE_PANELS` open a panel; any other value is a
      25              :  * silent no-op with the param stripped. Survives the login redirect via the
      26              :  * preserved-query system, like the top-up URL loader.
      27              :  */
      28              : export function useSettingsUrlLoader() {
      29              :   const route = useRoute()
      30              :   const router = useRouter()
      31              :   const settingsDialog = useSettingsDialog()
      32              : 
      33              :   /** Reads `?settings=`, strips it, and opens the mapped Settings panel.
      34              :    * Resolves once the strip has landed, so the loader that runs next reads a
      35              :    * query this one has already cleaned rather than restoring the param. */
      36              :   async function loadSettingsFromUrl() {
      37              :     hydratePreservedQuery(NAMESPACE)
      38              :     const query =
      39              :       mergePreservedQueryIntoQuery(NAMESPACE, route.query) ?? route.query
      40              :     const param = query.settings
      41              :     if (param === undefined) return
      42              : 
      43              :     // Strip any present settings param (even unrecognized or malformed values)
      44              :     // and write the clean URL in a single replace, so a clean URL is
      45              :     // guaranteed even if the replace rejects or no panel matches.
      46              :     const cleanQuery = { ...query }
      47              :     delete cleanQuery.settings
      48              :     const stripped = router.replace({ query: cleanQuery }).catch((error) => {
      49              :       console.warn('[useSettingsUrlLoader] Failed to clean URL params:', error)
      50              :     })
      51              :     clearPreservedQuery(NAMESPACE)
      52              : 
      53              :     if (
      54              :       typeof param === 'string' &&
      55              :       param &&
      56              :       Object.hasOwn(DEEP_LINKABLE_PANELS, param)
      57              :     ) {
      58              :       settingsDialog.show(DEEP_LINKABLE_PANELS[param])
      59              :     }
      60              : 
      61              :     await stripped
      62              :   }
      63              : 
      64              :   return {
      65              :     loadSettingsFromUrl
      66              :   }
      67              : }
        

Generated by: LCOV version 2.0-1