LCOV - code coverage report
Current view: top level - src/components/actionbar/ComfyRunButton - ComfyQueueButton.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 76.8 % 69 53
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1           16 : <template>
       2              :   <ButtonGroup class="queue-button-group h-8 rounded-lg bg-secondary">
       3              :     <BatchCountEdit />
       4              :     <Button
       5              :       :tooltip="queueButtonTooltip"
       6              :       tooltip-side="bottom"
       7              :       :variant="queueButtonVariant"
       8              :       size="unset"
       9              :       :class="
      10              :         cn(
      11              :           'h-full gap-1.5 rounded-l-lg rounded-r-none px-4',
      12              :           !paymentRecoveryLock && 'font-light'
      13              :         )
      14              :       "
      15              :       data-testid="queue-button"
      16              :       @click="queuePrompt"
      17              :     >
      18              :       <i :class="iconClass" data-testid="queue-button-icon" />
      19              :       {{ queueButtonLabel }}
      20              :     </Button>
      21              : 
      22              :     <Menu side="bottom" :side-offset="4" class="min-w-44">
      23              :       <template #trigger>
      24              :         <Button
      25              :           :variant="queueMenuTriggerVariant"
      26              :           size="unset"
      27              :           :disabled="Boolean(paymentRecoveryLock)"
      28              :           :class="
      29              :             cn(
      30              :               queueMenuTriggerClass,
      31              :               queueMenuTriggerVariantClass[queueMenuTriggerVariant]
      32              :             )
      33              :           "
      34              :           :aria-label="t('menu.runOptions')"
      35              :           data-testid="queue-mode-menu-trigger"
      36              :         >
      37              :           <TinyChevronIcon />
      38              :         </Button>
      39              :       </template>
      40              :       <MenuRadioGroup
      41              :         :model-value="selectedQueueMode"
      42              :         :options="queueModeMenuItems"
      43              :         @select.prevent
      44              :       />
      45              :     </Menu>
      46              :   </ButtonGroup>
      47              : </template>
      48              : 
      49              : <script setup lang="ts">
      50              : import { storeToRefs } from 'pinia'
      51              : import { computed, watch } from 'vue'
      52              : import { useI18n } from 'vue-i18n'
      53              : 
      54              : import BatchCountEdit from '@/components/actionbar/BatchCountEdit.vue'
      55              : import TinyChevronIcon from '@comfyorg/design-system/icon/TinyChevronIcon'
      56              : import Button from '@comfyorg/design-system/button/Button'
      57              : import ButtonGroup from '@comfyorg/design-system/button-group/ButtonGroup'
      58              : import Menu from '@comfyorg/design-system/menu/Menu'
      59              : import MenuRadioGroup from '@comfyorg/design-system/menu/MenuRadioGroup'
      60              : import { isCloud } from '@/platform/distribution/types'
      61              : import { useTelemetry } from '@comfyorg/telemetry'
      62              : import { useCommandStore } from '@/platform/keybindings/commandStore'
      63              : import { useExecutionErrorStore } from '@/stores/executionErrorStore'
      64              : import {
      65              :   isInstantMode,
      66              :   isInstantRunningMode,
      67              :   useQueueSettingsStore
      68              : } from '@/stores/queueSettingsStore'
      69              : import { useWorkspaceStore } from '@/stores/workspaceStore'
      70              : import { cn } from '@comfyorg/tailwind-utils'
      71              : 
      72         2001 : const workspaceStore = useWorkspaceStore()
      73         2001 : const { mode: queueMode, batchCount } = storeToRefs(useQueueSettingsStore())
      74         2001 : const { hasMissingError } = storeToRefs(useExecutionErrorStore())
      75              : 
      76         2001 : const { t } = useI18n()
      77              : type QueueModeMenuKey = 'disabled' | 'change' | 'instant-idle'
      78              : type PaymentRecoveryLock = 'owner' | 'member'
      79              : 
      80              : const { paymentRecoveryLock = null } = defineProps<{
      81              :   paymentRecoveryLock?: PaymentRecoveryLock | null
      82              : }>()
      83         2001 : const emit = defineEmits<{
      84              :   paymentRecoveryClick: []
      85              : }>()
      86              : 
      87         2001 : watch(
      88              :   () => paymentRecoveryLock,
      89              :   (lock) => {
      90         2001 :     if (lock) queueMode.value = 'disabled'
      91              :   },
      92              :   { immediate: true }
      93              : )
      94              : 
      95              : interface QueueModeMenuItem {
      96              :   value: QueueModeMenuKey
      97              :   label: string
      98              :   tooltip: string
      99              :   command: () => void
     100              : }
     101              : 
     102         2001 : const selectedQueueMode = computed<QueueModeMenuKey>(() =>
     103              :   isInstantMode(queueMode.value) ? 'instant-idle' : queueMode.value
     104              : )
     105              : 
     106         2001 : const queueModeMenuItemLookup = computed<Record<string, QueueModeMenuItem>>(
     107              :   () => {
     108         2006 :     const items: Record<string, QueueModeMenuItem> = {
     109              :       disabled: {
     110              :         value: 'disabled',
     111              :         label: t('menu.run'),
     112              :         tooltip: t('menu.disabledTooltip'),
     113              :         command: () => {
     114            0 :           queueMode.value = 'disabled'
     115              :         }
     116              :       },
     117              :       change: {
     118              :         value: 'change',
     119              :         label: `${t('menu.run')} (${t('menu.onChange')})`,
     120              :         tooltip: t('menu.onChangeTooltip'),
     121              :         command: () => {
     122            1 :           useTelemetry()?.trackUiButtonClicked({
     123              :             button_id: 'queue_mode_option_run_on_change_selected',
     124              :             element_group: 'queue'
     125              :           })
     126            1 :           queueMode.value = 'change'
     127              :         }
     128              :       }
     129              :     }
     130              : 
     131              :     if (!isCloud) {
     132         2006 :       items['instant-idle'] = {
     133              :         value: 'instant-idle',
     134              :         label: `${t('menu.run')} (${t('menu.instant')})`,
     135              :         tooltip: t('menu.instantTooltip'),
     136              :         command: () => {
     137            0 :           useTelemetry()?.trackUiButtonClicked({
     138              :             button_id: 'queue_mode_option_run_instant_selected',
     139              :             element_group: 'queue'
     140              :           })
     141            0 :           queueMode.value = 'instant-idle'
     142              :         }
     143              :       }
     144              :     }
     145              : 
     146         2006 :     return items
     147              :   }
     148              : )
     149              : 
     150         2001 : const activeQueueModeMenuItem = computed(() => {
     151         2011 :   return (
     152              :     queueModeMenuItemLookup.value[selectedQueueMode.value] ||
     153              :     queueModeMenuItemLookup.value.disabled
     154              :   )
     155              : })
     156         2001 : const queueModeMenuItems = computed(() =>
     157              :   Object.values(queueModeMenuItemLookup.value)
     158              : )
     159              : 
     160         2001 : const isStopInstantAction = computed(() =>
     161              :   isInstantRunningMode(queueMode.value)
     162              : )
     163              : 
     164         2001 : const queueButtonLabel = computed(() =>
     165              :   paymentRecoveryLock === 'owner'
     166              :     ? t('subscription.paymentRecovery.ownerRunLabel')
     167              :     : paymentRecoveryLock === 'member'
     168              :       ? t('subscription.paymentRecovery.memberRunLabel')
     169              :       : isStopInstantAction.value
     170              :         ? t('menu.stopRunInstant')
     171              :         : String(activeQueueModeMenuItem.value?.label ?? '')
     172              : )
     173              : 
     174         2001 : const queueButtonVariant = computed<
     175              :   'destructive' | 'primary' | 'secondary' | 'subscribe'
     176              : >(() =>
     177              :   paymentRecoveryLock === 'owner'
     178              :     ? 'subscribe'
     179              :     : paymentRecoveryLock === 'member'
     180              :       ? 'secondary'
     181              :       : isStopInstantAction.value
     182              :         ? 'destructive'
     183              :         : 'primary'
     184              : )
     185         2001 : const queueMenuTriggerVariant = computed(() =>
     186              :   queueButtonVariant.value === 'subscribe'
     187              :     ? 'secondary'
     188              :     : queueButtonVariant.value
     189              : )
     190         2001 : const queueMenuTriggerVariantClass = {
     191              :   destructive: 'border-black/20 data-[state=open]:bg-destructive/90',
     192              :   primary: 'data-[state=open]:bg-primary/90',
     193              :   secondary: 'text-muted-foreground'
     194              : } satisfies Record<typeof queueMenuTriggerVariant.value, string>
     195         1966 : const queueMenuTriggerClass =
     196              :   'h-full w-6 rounded-l-none rounded-r-lg border-0 border-l border-solid border-current/25 p-0'
     197              : 
     198         2001 : const iconClass = computed(() => {
     199         3744 :   if (paymentRecoveryLock) {
     200            0 :     return 'icon-[lucide--lock]'
     201              :   }
     202         3744 :   if (isStopInstantAction.value) {
     203            0 :     return 'icon-[lucide--square]'
     204              :   }
     205         3744 :   if (hasMissingError.value) {
     206         2461 :     return 'icon-[lucide--triangle-alert]'
     207              :   }
     208         3744 :   if (workspaceStore.shiftDown) {
     209           19 :     return 'icon-[lucide--list-start]'
     210              :   }
     211         1265 :   if (queueMode.value === 'disabled') {
     212         1263 :     return 'icon-[lucide--play]'
     213              :   }
     214            2 :   if (isInstantMode(queueMode.value)) {
     215            0 :     return 'icon-[lucide--fast-forward]'
     216              :   }
     217            1 :   if (queueMode.value === 'change') {
     218            1 :     return 'icon-[lucide--step-forward]'
     219              :   }
     220            0 :   return 'icon-[lucide--play]'
     221              : })
     222              : 
     223         2001 : const queueButtonTooltip = computed(() => {
     224         3749 :   if (paymentRecoveryLock === 'owner') {
     225            0 :     return t('subscription.paymentRecovery.ownerRunTooltip')
     226              :   }
     227         3749 :   if (paymentRecoveryLock === 'member') {
     228            0 :     return t('subscription.paymentRecovery.memberRunTooltip')
     229              :   }
     230         3749 :   if (isStopInstantAction.value) {
     231            0 :     return t('menu.stopRunInstantTooltip')
     232              :   }
     233         3749 :   if (hasMissingError.value) {
     234         2466 :     return t('menu.runWorkflowMissingResources')
     235              :   }
     236         3749 :   if (workspaceStore.shiftDown) {
     237           19 :     return t('menu.runWorkflowFront')
     238              :   }
     239         1264 :   return t('menu.runWorkflow')
     240              : })
     241              : 
     242         2001 : const commandStore = useCommandStore()
     243         2001 : const queuePrompt = async (e: Event) => {
     244           52 :   if (paymentRecoveryLock) {
     245            0 :     emit('paymentRecoveryClick')
     246            0 :     return
     247              :   }
     248           52 :   if (isStopInstantAction.value) {
     249            0 :     queueMode.value = 'instant-idle'
     250            0 :     return
     251              :   }
     252              : 
     253              :   const isShiftPressed = 'shiftKey' in e && e.shiftKey
     254           52 :   const commandId = isShiftPressed
     255              :     ? 'Comfy.QueuePromptFront'
     256              :     : 'Comfy.QueuePrompt'
     257              : 
     258           52 :   if (isInstantMode(queueMode.value)) {
     259            0 :     queueMode.value = 'instant-running'
     260              :   }
     261              : 
     262           52 :   if (batchCount.value > 1) {
     263            0 :     useTelemetry()?.trackUiButtonClicked({
     264              :       button_id: 'queue_run_multiple_batches_submitted',
     265              :       element_group: 'queue'
     266              :     })
     267              :   }
     268              : 
     269           52 :   await commandStore.execute(commandId, {
     270              :     metadata: {
     271              :       subscribe_to_run: false,
     272              :       trigger_source: 'button'
     273              :     }
     274              :   })
     275              : }
     276              : </script>
        

Generated by: LCOV version 2.0-1