LCOV - code coverage report
Current view: top level - src/platform/workflowErrors/missingModel/components - MissingModelRow.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 64.6 % 113 73
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2           52 :   <div class="mb-1 flex w-full flex-col gap-0.5 last:mb-0">
       3              :     <div
       4              :       :aria-current="highlighted ? 'true' : undefined"
       5              :       :class="
       6              :         cn(
       7              :           'flex min-h-8 items-center gap-1',
       8              :           selectionEmphasisClass(highlighted)
       9              :         )
      10              :       "
      11              :     >
      12              :       <Button
      13              :         v-if="hasMultipleReferences"
      14              :         data-testid="missing-model-expand"
      15              :         variant="textonly"
      16              :         size="unset"
      17              :         :aria-label="
      18              :           expanded
      19              :             ? t('rightSidePanel.missingModels.collapseNodes')
      20              :             : t('rightSidePanel.missingModels.expandNodes')
      21              :         "
      22              :         :aria-expanded="expanded"
      23              :         class="h-8 w-4 shrink-0 p-0 hover:bg-transparent focus-visible:ring-inset"
      24              :         @click="handleToggleExpand"
      25              :       >
      26              :         <i
      27              :           aria-hidden="true"
      28              :           :class="
      29              :             cn(
      30              :               'icon-[lucide--chevron-right] text-muted-foreground transition-transform duration-200',
      31              :               expanded && 'rotate-90'
      32              :             )
      33              :           "
      34              :         />
      35              :       </Button>
      36              : 
      37              :       <span class="flex min-w-0 flex-1 flex-col gap-0">
      38              :         <span class="flex min-w-0 items-center gap-1 text-xs/tight">
      39              :           <button
      40              :             v-if="hasModelLabelControl"
      41              :             ref="modelLabelControl"
      42              :             type="button"
      43              :             class="m-0 min-w-0 cursor-pointer appearance-none rounded-sm border-0 bg-transparent p-0 text-left font-normal wrap-break-word outline-none hover:text-foreground focus:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-inset"
      44              :             :title="displayModelName"
      45              :             @click="handleModelLabelClick"
      46              :           >
      47              :             {{ displayModelName }}
      48              :           </button>
      49              :           <span
      50              :             v-else
      51              :             class="min-w-0 font-normal wrap-break-word"
      52              :             :title="displayModelName"
      53              :           >
      54              :             {{ displayModelName }}
      55              :           </span>
      56              :           <span
      57              :             v-if="hasMultipleReferences"
      58              :             data-testid="missing-model-reference-count"
      59              :             class="inline-flex h-4 min-w-4 shrink-0 items-center justify-center rounded-sm bg-accent px-1 text-2xs font-semibold"
      60              :           >
      61              :             {{ model.referencingNodes.length }}
      62              :           </span>
      63              :           <Button
      64              :             variant="muted-textonly"
      65              :             size="icon-sm"
      66              :             class="size-6 shrink-0 hover:bg-transparent hover:text-foreground focus-visible:ring-inset"
      67              :             :aria-label="linkLabel"
      68              :             :title="linkLabel"
      69              :             @click="copyModelLink"
      70              :           >
      71              :             <i aria-hidden="true" class="icon-[lucide--link]" />
      72              :           </Button>
      73              :         </span>
      74              :         <span
      75              :           v-if="modelMetadataLabel"
      76              :           class="block text-2xs/tight"
      77              :           :class="isUnknownCategory ? 'text-warning' : 'text-muted-foreground'"
      78              :         >
      79              :           {{ modelMetadataLabel }}
      80              :         </span>
      81              :       </span>
      82              : 
      83              :       <template v-if="isCloud && canCloudImport">
      84              :         <Button
      85              :           v-if="!isCloudImportDownloadActive"
      86              :           data-testid="missing-model-import"
      87              :           variant="secondary"
      88              :           size="sm"
      89              :           class="shrink-0 focus-visible:ring-inset"
      90              :           @click="showUploadDialog"
      91              :         >
      92              :           {{ t('g.import') }}
      93              :         </Button>
      94              :         <div
      95              :           v-else
      96              :           ref="cloudProgress"
      97              :           role="progressbar"
      98              :           :aria-label="t('rightSidePanel.missingModels.importing')"
      99              :           :aria-valuenow="cloudImportProgressPercent"
     100              :           aria-valuemin="0"
     101              :           aria-valuemax="100"
     102              :           tabindex="-1"
     103              :           class="flex h-8 w-16 shrink-0 items-center"
     104              :         >
     105              :           <span
     106              :             class="block h-1.5 w-full overflow-hidden rounded-full bg-muted"
     107              :           >
     108              :             <span
     109              :               class="block h-full rounded-full bg-primary transition-all duration-200 ease-linear"
     110              :               :style="{ width: `${cloudImportProgressPercent}%` }"
     111              :             />
     112              :           </span>
     113              :         </div>
     114              :         <span
     115              :           v-if="isCloudImportDownloadActive"
     116              :           role="status"
     117              :           aria-live="polite"
     118              :           class="sr-only"
     119              :         >
     120              :           {{ t('rightSidePanel.missingModels.importing') }}
     121              :         </span>
     122              :       </template>
     123              : 
     124              :       <template v-else>
     125              :         <Button
     126              :           v-if="showGatedRepoAction"
     127              :           :tooltip="t('rightSidePanel.missingModels.gatedModelTooltip')"
     128              :           :as="usesNativeModelAccess ? 'button' : 'a'"
     129              :           :type="usesNativeModelAccess ? 'button' : undefined"
     130              :           :href="usesNativeModelAccess ? undefined : gatedRepoUrl"
     131              :           :target="usesNativeModelAccess ? undefined : '_blank'"
     132              :           :rel="usesNativeModelAccess ? undefined : 'noopener noreferrer'"
     133              :           data-testid="missing-model-gated-access"
     134              :           variant="muted-textonly"
     135              :           size="icon"
     136              :           class="shrink-0 text-warning hover:text-warning focus-visible:ring-inset"
     137              :           :aria-label="
     138              :             t(
     139              :               usesNativeModelAccess
     140              :                 ? 'rightSidePanel.missingModels.openHuggingFaceRepoDesktop'
     141              :                 : 'rightSidePanel.missingModels.openHuggingFaceRepoNewTab',
     142              :               { model: model.name },
     143              :               { escapeParameter: false }
     144              :             )
     145              :           "
     146              :           @click="handleOpenGatedRepo"
     147              :         >
     148              :           <i aria-hidden="true" class="icon-[lucide--lock]" />
     149              :         </Button>
     150              :         <Button
     151              :           v-if="showDownloadAction && hostDownloadState.status === 'idle'"
     152              :           data-testid="missing-model-download"
     153              :           variant="secondary"
     154              :           size="sm"
     155              :           class="shrink-0 focus-visible:ring-inset"
     156              :           :aria-label="
     157              :             t(
     158              :               'rightSidePanel.missingModels.downloadModel',
     159              :               { model: model.name },
     160              :               { escapeParameter: false }
     161              :             )
     162              :           "
     163              :           :aria-describedby="
     164              :             showGatedRepoAction ? gatedDownloadDescriptionId : undefined
     165              :           "
     166              :           @click="handleDownload"
     167              :         >
     168              :           {{ t('g.download') }}
     169              :         </Button>
     170              :         <Button
     171              :           v-else-if="
     172              :             showDownloadAction && hostDownloadState.status === 'failed'
     173              :           "
     174              :           data-testid="missing-model-download-retry"
     175              :           variant="secondary"
     176              :           size="sm"
     177              :           class="shrink-0 focus-visible:ring-inset"
     178              :           :aria-label="
     179              :             t(
     180              :               'rightSidePanel.missingModels.retryDownloadModel',
     181              :               { model: model.name },
     182              :               { escapeParameter: false }
     183              :             )
     184              :           "
     185              :           :title="t('rightSidePanel.missingModels.downloadFailedHint')"
     186              :           @click="handleDownload"
     187              :         >
     188              :           {{ t('rightSidePanel.missingModels.retryDownload') }}
     189              :         </Button>
     190              :         <template
     191              :           v-else-if="showDownloadAction && (canToggleHostPause || canCancel)"
     192              :         >
     193              :           <Button
     194              :             v-if="canToggleHostPause"
     195              :             data-testid="missing-model-download-pause"
     196              :             variant="muted-textonly"
     197              :             size="icon-sm"
     198              :             class="size-8 shrink-0 hover:text-foreground focus-visible:ring-inset"
     199              :             :aria-label="
     200              :               t(
     201              :                 isHostDownloadPaused
     202              :                   ? 'rightSidePanel.missingModels.resumeDownloadModel'
     203              :                   : 'rightSidePanel.missingModels.pauseDownloadModel',
     204              :                 { model: model.name },
     205              :                 { escapeParameter: false }
     206              :               )
     207              :             "
     208              :             @click="toggleHostDownloadPause"
     209              :           >
     210              :             <i
     211              :               aria-hidden="true"
     212              :               :class="
     213              :                 isHostDownloadPaused
     214              :                   ? 'icon-[lucide--play]'
     215              :                   : 'icon-[lucide--pause]'
     216              :               "
     217              :             />
     218              :           </Button>
     219              :           <Button
     220              :             v-if="canCancel"
     221              :             data-testid="missing-model-download-cancel"
     222              :             variant="muted-textonly"
     223              :             size="icon-sm"
     224              :             class="size-8 shrink-0 hover:text-foreground focus-visible:ring-inset"
     225              :             :aria-label="
     226              :               t(
     227              :                 'rightSidePanel.missingModels.cancelDownloadModel',
     228              :                 { model: model.name },
     229              :                 { escapeParameter: false }
     230              :               )
     231              :             "
     232              :             @click="cancelHostDownload"
     233              :           >
     234              :             <i aria-hidden="true" class="icon-[lucide--x]" />
     235              :           </Button>
     236              :         </template>
     237              :         <Badge
     238              :           v-else-if="showDownloadAction && hostDownloadState.status === 'done'"
     239              :           data-testid="missing-model-downloaded"
     240              :           role="status"
     241              :           variant="compact"
     242              :           severity="success"
     243              :         >
     244              :           {{ t('rightSidePanel.missingModels.downloaded') }}
     245              :         </Badge>
     246              :         <span
     247              :           v-if="showGatedRepoAction"
     248              :           :id="gatedDownloadDescriptionId"
     249              :           hidden
     250              :         >
     251              :           {{ t('rightSidePanel.missingModels.gatedModelDownloadTooltip') }}
     252              :         </span>
     253              :       </template>
     254              : 
     255              :       <Button
     256              :         v-if="!hasMultipleReferences && !isUnknownCategory && primaryReference"
     257              :         data-testid="missing-model-locate"
     258              :         variant="muted-textonly"
     259              :         size="icon-sm"
     260              :         :aria-label="t('rightSidePanel.missingModels.locateNode')"
     261              :         class="size-8 shrink-0 hover:text-foreground focus-visible:ring-inset"
     262              :         @click="handleLocatePrimary"
     263              :       >
     264              :         <i aria-hidden="true" class="icon-[lucide--locate]" />
     265              :       </Button>
     266              :     </div>
     267              : 
     268              :     <MissingModelDownloadProgress
     269              :       v-if="showDownloadAction && activeHostDownload"
     270              :       :state="activeHostDownload"
     271              :       :model-name="model.name"
     272              :       :class="hasMultipleReferences && 'pl-5'"
     273              :     />
     274              : 
     275              :     <div
     276              :       v-if="model.replacements?.length"
     277              :       data-testid="missing-model-replacements"
     278              :       class="flex flex-col pl-5"
     279              :     >
     280              :       <span
     281              :         :id="replacementsLabelId"
     282              :         class="text-2xs/tight text-muted-foreground"
     283              :       >
     284              :         {{ t('rightSidePanel.missingModels.availableReplacements') }}
     285              :       </span>
     286              :       <ul :aria-labelledby="replacementsLabelId" class="m-0 list-none p-0">
     287            0 :         <li
     288              :           v-for="replacement in model.replacements"
     289              :           :key="replacement"
     290              :           class="flex min-h-8 min-w-0 items-center gap-2"
     291              :         >
     292              :           <span
     293              :             class="min-w-0 flex-1 text-xs/tight wrap-break-word"
     294              :             :title="replacement"
     295              :           >
     296              :             {{ replacement }}
     297              :           </span>
     298              :           <Button
     299              :             data-testid="missing-model-use-replacement"
     300              :             variant="secondary"
     301              :             size="sm"
     302              :             class="shrink-0 focus-visible:ring-inset"
     303              :             :aria-label="
     304              :               t(
     305              :                 'rightSidePanel.missingModels.useReplacement',
     306              :                 { model: replacement },
     307              :                 { escapeParameter: false }
     308              :               )
     309              :             "
     310              :             @click="
     311              :               replaceModelOnNodes(
     312              :                 model.name,
     313              :                 model.referencingNodes,
     314              :                 replacement
     315              :               )
     316              :             "
     317              :           >
     318              :             {{ t('rightSidePanel.missingModels.use') }}
     319              :           </Button>
     320              :         </li>
     321              :       </ul>
     322              :     </div>
     323              : 
     324              :     <TransitionCollapse>
     325              :       <ul
     326              :         v-if="showReferenceList"
     327              :         :class="
     328              :           cn(
     329              :             'm-0 list-none p-0',
     330              :             (hasMultipleReferences || isUnknownCategory) && 'pl-5'
     331              :           )
     332              :         "
     333              :       >
     334            2 :         <li
     335              :           v-for="ref in model.referencingNodes"
     336              :           :key="`${String(ref.nodeId)}::${ref.widgetName}`"
     337              :           class="min-w-0"
     338              :         >
     339              :           <div class="flex min-h-8 min-w-0 items-center gap-2">
     340              :             <button
     341              :               type="button"
     342              :               class="m-0 inline max-w-full cursor-pointer appearance-none rounded-sm border-0 bg-transparent p-0 text-left text-xs/tight font-normal wrap-break-word text-muted-foreground outline-none hover:text-foreground focus:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-inset"
     343              :               @click="emit('locateModel', String(ref.nodeId))"
     344              :             >
     345              :               {{
     346              :                 getNodeDisplayLabel(ref.nodeId, model.representative.nodeType)
     347              :               }}
     348              :             </button>
     349              :             <Button
     350              :               data-testid="missing-model-locate"
     351              :               variant="muted-textonly"
     352              :               size="icon-sm"
     353              :               :aria-label="t('rightSidePanel.missingModels.locateNode')"
     354              :               class="ml-auto size-8 shrink-0 hover:text-foreground focus-visible:ring-inset"
     355              :               @click="emit('locateModel', String(ref.nodeId))"
     356              :             >
     357              :               <i aria-hidden="true" class="icon-[lucide--locate]" />
     358              :             </Button>
     359              :           </div>
     360              :         </li>
     361              :       </ul>
     362              :     </TransitionCollapse>
     363              :   </div>
     364              : </template>
     365              : 
     366              : <script setup lang="ts">
     367              : import {
     368              :   computed,
     369              :   nextTick,
     370              :   onMounted,
     371              :   useId,
     372              :   useTemplateRef,
     373              :   watch
     374              : } from 'vue'
     375              : import { storeToRefs } from 'pinia'
     376              : import { useI18n } from 'vue-i18n'
     377              : import { cn } from '@comfyorg/tailwind-utils'
     378              : 
     379              : import { selectionEmphasisClass } from '@/platform/workflowErrors/panel/selectionEmphasis'
     380              : import Badge from '@comfyorg/design-system/badge/Badge'
     381              : import Button from '@comfyorg/design-system/button/Button'
     382              : import TransitionCollapse from '@comfyorg/design-system/transition/TransitionCollapse'
     383              : import type { MissingModelViewModel } from '@/platform/workflowErrors/missingModel/types'
     384              : import type { UploadModelDialogContext } from '@/platform/assets/composables/useUploadModelWizard'
     385              : 
     386              : import { useModelUpload } from '@/platform/assets/composables/useModelUpload'
     387              : import {
     388              :   useMissingModelInteractions,
     389              :   getModelStateKey,
     390              :   getNodeDisplayLabel
     391              : } from '@/platform/workflowErrors/missingModel/composables/useMissingModelInteractions'
     392              : import { useMissingModelDownload } from '@/platform/workflowErrors/missingModel/composables/useMissingModelDownload'
     393              : import { formatDownloadedBytes } from '@/platform/workflowErrors/missingModel/missingModelDownloadProgress'
     394              : import MissingModelDownloadProgress from '@/platform/workflowErrors/missingModel/components/MissingModelDownloadProgress.vue'
     395              : import { useMissingModelDownloadStore } from '@/platform/workflowErrors/missingModel/missingModelDownloadStore'
     396              : import { useMissingModelStore } from '@/platform/workflowErrors/missingModel/missingModelStore'
     397              : import { useCopyToClipboard } from '@/composables/useCopyToClipboard'
     398              : import { isCloud } from '@/platform/distribution/types'
     399              : import {
     400              :   isModelDownloadable,
     401              :   isTrustedHuggingFaceUrl,
     402              :   toBrowsableUrl
     403              : } from '@/platform/workflowErrors/missingModel/missingModelDownload'
     404              : import { formatSize } from '@/utils/formatUtil'
     405              : 
     406              : const {
     407              :   model,
     408              :   directory,
     409              :   isAssetSupported,
     410              :   canCloudImport = true,
     411              :   highlighted
     412              : } = defineProps<{
     413              :   model: MissingModelViewModel
     414              :   directory: string | null
     415              :   isAssetSupported: boolean
     416              :   canCloudImport?: boolean
     417              :   /** Emphasize the header row (model referenced by the canvas selection). */
     418              :   highlighted?: boolean
     419              : }>()
     420              : 
     421           35 : const emit = defineEmits<{
     422              :   locateModel: [nodeId: string]
     423              : }>()
     424              : 
     425           35 : const { t } = useI18n()
     426           35 : const { copyToClipboard } = useCopyToClipboard()
     427              : 
     428           35 : const modelKey = computed(() =>
     429              :   getModelStateKey(model.name, directory, isAssetSupported)
     430              : )
     431              : 
     432           35 : const downloadStatus = computed(() => getDownloadStatus(modelKey.value))
     433           35 : const isUnknownCategory = computed(() => directory === null)
     434           35 : const isDownloadActive = computed(
     435              :   () =>
     436              :     downloadStatus.value?.status === 'running' ||
     437              :     downloadStatus.value?.status === 'created'
     438              : )
     439           35 : const isCloudImportDownloadActive = computed(
     440              :   () => isCloud && canCloudImport && isDownloadActive.value
     441              : )
     442           35 : const cloudImportProgressPercent = computed(() =>
     443              :   Math.round((downloadStatus.value?.progress ?? 0) * 100)
     444              : )
     445           35 : const replacementsLabelId = useId()
     446           35 : const hasMultipleReferences = computed(() => model.referencingNodes.length > 1)
     447           35 : const primaryReference = computed(() => model.referencingNodes[0])
     448           35 : const hasModelLabelControl = computed(
     449              :   () =>
     450              :     hasMultipleReferences.value ||
     451              :     (!isUnknownCategory.value && !!primaryReference.value)
     452              : )
     453           35 : const linkLabel = computed(() =>
     454              :   model.representative.url
     455              :     ? t('rightSidePanel.missingModels.copyUrl')
     456              :     : t('rightSidePanel.missingModels.copyModelName')
     457              : )
     458              : 
     459           35 : const store = useMissingModelStore()
     460           35 : const { selectedLibraryModel } = storeToRefs(store)
     461           35 : const cloudProgress = useTemplateRef<HTMLElement>('cloudProgress')
     462           35 : const modelLabelControl = useTemplateRef<HTMLButtonElement>('modelLabelControl')
     463           35 : const {
     464              :   fileSizeFor,
     465              :   gatedRepoUrlFor,
     466              :   prefetchModelMetadata,
     467              :   downloadMissingModel,
     468              :   openModelAccessPage
     469              : } = useMissingModelDownload()
     470              : 
     471           35 : const expanded = computed(
     472              :   () =>
     473              :     store.modelExpandState[modelKey.value] ??
     474              :     (isUnknownCategory.value && hasMultipleReferences.value)
     475              : )
     476           35 : const showReferenceList = computed(
     477              :   () =>
     478              :     (isUnknownCategory.value && model.referencingNodes.length === 1) ||
     479              :     (hasMultipleReferences.value && expanded.value)
     480              : )
     481              : 
     482           35 : const displayModelName = computed(() => {
     483           37 :   if (!isCloudImportDownloadActive.value) return model.name
     484              : 
     485           37 :   return (
     486              :     downloadStatus.value?.assetName ??
     487              :     selectedLibraryModel.value[modelKey.value] ??
     488              :     model.name
     489              :   )
     490              : })
     491              : 
     492           35 : const downloadable = computed(() => {
     493           37 :   const rep = model.representative
     494           37 :   return !!(
     495              :     rep.url &&
     496              :     rep.directory &&
     497              :     isModelDownloadable({
     498              :       name: rep.name,
     499              :       url: rep.url,
     500              :       directory: rep.directory
     501              :     })
     502              :   )
     503              : })
     504              : 
     505           35 : const showDownloadAction = computed(() => !isCloud && downloadable.value)
     506           35 : const missingModelDownloadStore = useMissingModelDownloadStore()
     507           35 : const hostDownloadModel = computed(() => {
     508           33 :   const { name, url, directory } = model.representative
     509           33 :   return url && directory ? { name, url, directory } : undefined
     510              : })
     511           35 : const hostDownloadState = computed(() =>
     512              :   hostDownloadModel.value
     513              :     ? missingModelDownloadStore.stateFor(hostDownloadModel.value)
     514              :     : { status: 'idle' as const }
     515              : )
     516           35 : const isHostDownloadPaused = computed(
     517              :   () =>
     518              :     hostDownloadState.value.status === 'downloading' &&
     519              :     hostDownloadState.value.paused
     520              : )
     521           35 : const canToggleHostPause = computed(() => {
     522            0 :   const target = hostDownloadModel.value
     523            0 :   const state = hostDownloadState.value
     524            0 :   return (
     525              :     !!target &&
     526              :     state.status === 'downloading' &&
     527              :     missingModelDownloadStore.canControl(target, 'pauseDownload') &&
     528              :     missingModelDownloadStore.canControl(target, 'resumeDownload')
     529              :   )
     530              : })
     531           35 : const canCancel = computed(
     532              :   () =>
     533              :     !!hostDownloadModel.value &&
     534              :     missingModelDownloadStore.canControl(
     535              :       hostDownloadModel.value,
     536              :       'cancelDownload'
     537              :     )
     538              : )
     539              : 
     540            0 : function cancelHostDownload() {
     541            0 :   if (hostDownloadModel.value)
     542            0 :     missingModelDownloadStore.cancel(hostDownloadModel.value)
     543              : }
     544              : 
     545            0 : function toggleHostDownloadPause() {
     546            0 :   const target = hostDownloadModel.value
     547            0 :   const state = hostDownloadState.value
     548            0 :   if (!target || state.status !== 'downloading') return
     549            0 :   if (state.paused) missingModelDownloadStore.resume(target)
     550            0 :   else missingModelDownloadStore.pause(target)
     551              : }
     552           35 : const activeHostDownload = computed(() => {
     553           31 :   const state = hostDownloadState.value
     554           31 :   return state.status === 'requested' ||
     555              :     state.status === 'pending' ||
     556              :     state.status === 'downloading'
     557              :     ? state
     558              :     : undefined
     559              : })
     560           35 : const gatedRepoUrl = computed(() => {
     561           33 :   const url = model.representative.url
     562           33 :   const repoUrl = url ? gatedRepoUrlFor(url) : undefined
     563           33 :   return repoUrl && isTrustedHuggingFaceUrl(repoUrl) ? repoUrl : undefined
     564              : })
     565           35 : const showGatedRepoAction = computed(
     566              :   () => showDownloadAction.value && !!gatedRepoUrl.value
     567              : )
     568           35 : const usesNativeModelAccess = !!window.__comfyDesktop2?.openModelAccessPage
     569           35 : const gatedDownloadDescriptionId = useId()
     570              : 
     571           35 : const downloadSizeLabel = computed(() => {
     572           38 :   if (!showDownloadAction.value) return undefined
     573              : 
     574           34 :   const downloaded = formatDownloadedBytes(hostDownloadState.value)
     575           36 :   if (downloaded) return downloaded
     576              : 
     577           34 :   const url = model.representative.url
     578           38 :   const size = url ? fileSizeFor(url) : undefined
     579           38 :   return size ? formatSize(size) : undefined
     580              : })
     581           35 : const modelTypeLabel = computed(
     582              :   () => directory ?? t('rightSidePanel.missingModels.unknownCategory')
     583              : )
     584           35 : const modelMetadataLabel = computed(() =>
     585              :   [modelTypeLabel.value, downloadSizeLabel.value].filter(Boolean).join(' ยท ')
     586              : )
     587              : 
     588           35 : const missingModelUploadContext = computed<
     589              :   UploadModelDialogContext | undefined
     590              : >(() => {
     591            0 :   if (!canCloudImport || !directory) return undefined
     592              : 
     593            0 :   return {
     594              :     kind: 'missing-model-resolution',
     595              :     missingModelName: model.name,
     596              :     requiredModelType: directory,
     597              :     replacementTargets: model.referencingNodes.map((ref) => ({
     598              :       nodeId: String(ref.nodeId),
     599              :       nodeLabel: getNodeDisplayLabel(ref.nodeId, model.representative.nodeType),
     600              :       widgetName: ref.widgetName
     601              :     }))
     602              :   }
     603              : })
     604              : 
     605           35 : const { showUploadDialog } = useModelUpload(
     606              :   (result) => {
     607            0 :     handleUploadedModelImport(modelKey.value, result)
     608              : 
     609            0 :     if (result.status === 'success') {
     610            0 :       handleLibrarySelect()
     611              :     }
     612              :   },
     613              :   () => missingModelUploadContext.value
     614              : )
     615              : 
     616           35 : onMounted(() => {
     617              :   if (isCloud) return
     618              : 
     619           35 :   const url = model.representative.url
     620           35 :   if (url && downloadable.value) {
     621           31 :     void prefetchModelMetadata(url)
     622              :   }
     623              : })
     624              : 
     625            0 : function handleDownload() {
     626            0 :   const rep = model.representative
     627            0 :   if (rep.url && rep.directory) {
     628            0 :     downloadMissingModel({
     629              :       name: rep.name,
     630              :       url: rep.url,
     631              :       directory: rep.directory
     632              :     })
     633              :   } else {
     634            0 :     console.warn('[MissingModelRow] Cannot download: missing url or directory')
     635              :   }
     636              : }
     637              : 
     638            1 : function handleOpenGatedRepo() {
     639            1 :   if (!usesNativeModelAccess) return
     640              : 
     641            0 :   const repoUrl = gatedRepoUrl.value
     642            0 :   if (repoUrl) void openModelAccessPage(repoUrl)
     643              : }
     644              : 
     645            0 : function handleLocatePrimary() {
     646            0 :   const ref = primaryReference.value
     647            0 :   if (ref) emit('locateModel', String(ref.nodeId))
     648              : }
     649              : 
     650            1 : function copyModelLink() {
     651            1 :   const url = model.representative.url
     652            1 :   copyToClipboard(url ? toBrowsableUrl(url) : model.name)
     653              : }
     654              : 
     655           35 : const {
     656              :   confirmLibrarySelect,
     657              :   replaceModelOnNodes,
     658              :   getDownloadStatus,
     659              :   handleUploadedModelImport
     660              : } = useMissingModelInteractions()
     661              : 
     662            1 : function handleToggleExpand() {
     663            1 :   store.modelExpandState[modelKey.value] = !expanded.value
     664              : }
     665              : 
     666            0 : function handleModelLabelClick() {
     667            0 :   if (hasMultipleReferences.value) {
     668            0 :     handleToggleExpand()
     669            0 :     return
     670              :   }
     671              : 
     672            0 :   handleLocatePrimary()
     673              : }
     674              : 
     675           35 : watch(
     676              :   () => downloadStatus.value?.status,
     677              :   (status) => {
     678              :     if (!isCloud || status !== 'completed') return
     679              :     const completedAssetName = downloadStatus.value?.assetName
     680              :     if (completedAssetName) {
     681              :       selectedLibraryModel.value[modelKey.value] = completedAssetName
     682              :     }
     683              :     handleLibrarySelect()
     684              :   },
     685              :   { immediate: true }
     686              : )
     687              : 
     688           35 : watch(isCloudImportDownloadActive, async (isActive, wasActive) => {
     689            0 :   await nextTick()
     690            0 :   if (isActive) {
     691            0 :     cloudProgress.value?.focus()
     692            0 :   } else if (wasActive) {
     693            0 :     modelLabelControl.value?.focus()
     694              :   }
     695              : })
     696              : 
     697            0 : function handleLibrarySelect() {
     698            0 :   confirmLibrarySelect(
     699              :     modelKey.value,
     700              :     model.name,
     701              :     model.referencingNodes,
     702              :     directory
     703              :   )
     704              : }
     705              : </script>
        

Generated by: LCOV version 2.0-1