Files
ComfyUI_frontend/src/storybook/mocks/useJobActions.ts
Benjamin Lu 818c5c32e5 [QPOv2] Add stories for list view and general job card (#7743)
Add stories for the media assets sidebar tab for easier prototyping.

Includes mocks for storybook.

Because some functions in the mocks are only used in the storybook
main.ts resolve, knip flags them as unused because it doesn't check that
path. So knipIgnoreUnusedButUsedByStorybook was added.

Part of the QPO v2 iteration, figma design can be found
[here](https://www.figma.com/design/LVilZgHGk5RwWOkVN6yCEK/Queue-Progress-Modal?node-id=3330-37286&m=dev).
This will be implemented in a series of stacked PRs that can be reviewed
and merged individually.

main <-- #7737, #7743, #7745

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7743-QPOv2-Add-stories-for-list-view-and-general-job-card-2d26d73d365081bca59afa925fb232d7)
by [Unito](https://www.unito.io)

---------

Co-authored-by: GitHub Action <action@github.com>
2026-01-10 22:34:37 -07:00

52 lines
1.3 KiB
TypeScript

import { computed, ref, toValue } from 'vue'
import type { MaybeRefOrGetter } from 'vue'
import type { JobAction } from '../../composables/queue/useJobActions'
import type { JobListItem } from '../../composables/queue/useJobList'
import type { JobState } from '../../types/queue'
const actionsByJobId = ref<Record<string, JobAction[]>>({})
const cancellableStates: JobState[] = ['pending', 'initialization', 'running']
const cancelAction: JobAction = {
icon: 'icon-[lucide--x]',
label: 'Cancel',
variant: 'destructive'
}
export function setMockJobActions(actions: Record<string, JobAction[]>) {
actionsByJobId.value = actions
}
export function useJobActions(
job?: MaybeRefOrGetter<JobListItem | null | undefined>
) {
const jobRef = computed(() => (job ? (toValue(job) ?? null) : null))
const canCancelJob = computed(() => {
const currentJob = jobRef.value
if (!currentJob) {
return false
}
const configuredActions = actionsByJobId.value[currentJob.id]
if (configuredActions) {
return configuredActions.length > 0
}
return (
currentJob.showClear !== false &&
cancellableStates.includes(currentJob.state)
)
})
async function runCancelJob() {
return undefined
}
return {
cancelAction,
canCancelJob,
runCancelJob
}
}