mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-23 07:50:15 +00:00
Road to No Explicit Any Part 6: Composables and Extensions (#8083)
## Summary - Type `onExecuted` callbacks with `NodeExecutionOutput` in saveMesh.ts and uploadAudio.ts - Type composable parameters and return values properly (useLoad3dViewer, useImageMenuOptions, useJobMenu, useResultGallery, useContextMenuTranslation) - Type `taskRef` as `TaskItemImpl` with updated test mocks - Fix error catch and index signature patterns without `any` - Add `NodeOutputWith<T>` generic helper for typed access to passthrough properties on `NodeExecutionOutput` ## Test plan - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes - [x] Unit tests pass for affected files - [x] Sourcegraph checks confirm no external usage of modified types ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8083-Road-to-No-Explicit-Any-Part-6-Composables-and-Extensions-2e96d73d3650810fb033d745bf88a22b) by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
0d5ca96a2b
commit
c56e8425d4
@@ -57,8 +57,8 @@ export const useCompletionSummary = () => {
|
||||
}
|
||||
if (prev && !active) {
|
||||
const start = lastActiveStartTs.value ?? 0
|
||||
const finished = queueStore.historyTasks.filter((t: any) => {
|
||||
const ts: number | undefined = t.executionEndTimestamp
|
||||
const finished = queueStore.historyTasks.filter((t) => {
|
||||
const ts = t.executionEndTimestamp
|
||||
return typeof ts === 'number' && ts >= start
|
||||
})
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export type JobListItem = {
|
||||
iconName?: string
|
||||
iconImageUrl?: string
|
||||
showClear?: boolean
|
||||
taskRef?: any
|
||||
taskRef?: TaskItemImpl
|
||||
progressTotalPercent?: number
|
||||
progressCurrentPercent?: number
|
||||
runningNodeName?: string
|
||||
|
||||
@@ -117,13 +117,24 @@ vi.mock('@/utils/formatUtil', () => ({
|
||||
}))
|
||||
|
||||
import { useJobMenu } from '@/composables/queue/useJobMenu'
|
||||
import type { TaskItemImpl } from '@/stores/queueStore'
|
||||
|
||||
const createJobItem = (overrides: Partial<JobListItem> = {}): JobListItem => ({
|
||||
type MockTaskRef = Record<string, unknown>
|
||||
|
||||
type TestJobListItem = Omit<JobListItem, 'taskRef'> & {
|
||||
taskRef?: MockTaskRef
|
||||
}
|
||||
|
||||
const createJobItem = (
|
||||
overrides: Partial<TestJobListItem> = {}
|
||||
): JobListItem => ({
|
||||
id: overrides.id ?? 'job-1',
|
||||
title: overrides.title ?? 'Test job',
|
||||
meta: overrides.meta ?? 'meta',
|
||||
state: overrides.state ?? 'completed',
|
||||
taskRef: overrides.taskRef,
|
||||
taskRef: overrides.taskRef as Partial<TaskItemImpl> | undefined as
|
||||
| TaskItemImpl
|
||||
| undefined,
|
||||
iconName: overrides.iconName,
|
||||
iconImageUrl: overrides.iconImageUrl,
|
||||
showClear: overrides.showClear,
|
||||
|
||||
@@ -12,7 +12,8 @@ import { useWorkflowStore } from '@/platform/workflow/management/stores/workflow
|
||||
import type {
|
||||
ExecutionErrorWsMessage,
|
||||
ResultItem,
|
||||
ResultItemType
|
||||
ResultItemType,
|
||||
TaskStatus
|
||||
} from '@/schemas/apiSchema'
|
||||
import { api } from '@/scripts/api'
|
||||
import { downloadBlob } from '@/scripts/utils'
|
||||
@@ -82,13 +83,20 @@ export function useJobMenu(
|
||||
await queueStore.update()
|
||||
}
|
||||
|
||||
const findExecutionError = (
|
||||
messages: TaskStatus['messages'] | undefined
|
||||
): ExecutionErrorWsMessage | undefined => {
|
||||
const errMessage = messages?.find((m) => m[0] === 'execution_error')
|
||||
if (errMessage && errMessage[0] === 'execution_error') {
|
||||
return errMessage[1]
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
const copyErrorMessage = async (item?: JobListItem | null) => {
|
||||
const target = resolveItem(item)
|
||||
if (!target) return
|
||||
const msgs = target.taskRef?.status?.messages as any[] | undefined
|
||||
const err = msgs?.find((m: any) => m?.[0] === 'execution_error')?.[1] as
|
||||
| ExecutionErrorWsMessage
|
||||
| undefined
|
||||
const err = findExecutionError(target.taskRef?.status?.messages)
|
||||
const message = err?.exception_message
|
||||
if (message) await copyToClipboard(String(message))
|
||||
}
|
||||
@@ -96,10 +104,7 @@ export function useJobMenu(
|
||||
const reportError = (item?: JobListItem | null) => {
|
||||
const target = resolveItem(item)
|
||||
if (!target) return
|
||||
const msgs = target.taskRef?.status?.messages as any[] | undefined
|
||||
const err = msgs?.find((m: any) => m?.[0] === 'execution_error')?.[1] as
|
||||
| ExecutionErrorWsMessage
|
||||
| undefined
|
||||
const err = findExecutionError(target.taskRef?.status?.messages)
|
||||
if (err) useDialogService().showExecutionErrorDialog(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
import { ref, shallowRef } from 'vue'
|
||||
|
||||
import type { JobListItem } from '@/composables/queue/useJobList'
|
||||
import type { ResultItemImpl } from '@/stores/queueStore'
|
||||
|
||||
/** Minimal preview item interface for gallery filtering. */
|
||||
interface PreviewItem {
|
||||
url: string
|
||||
supportsPreview: boolean
|
||||
}
|
||||
|
||||
/** Minimal task interface for gallery preview. */
|
||||
interface TaskWithPreview<T extends PreviewItem = PreviewItem> {
|
||||
previewOutput?: T
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages result gallery state and activation for queue items.
|
||||
*/
|
||||
export function useResultGallery(getFilteredTasks: () => any[]) {
|
||||
export function useResultGallery<T extends PreviewItem>(
|
||||
getFilteredTasks: () => TaskWithPreview<T>[]
|
||||
) {
|
||||
const galleryActiveIndex = ref(-1)
|
||||
const galleryItems = shallowRef<ResultItemImpl[]>([])
|
||||
const galleryItems = shallowRef<T[]>([])
|
||||
|
||||
const onViewItem = (item: JobListItem) => {
|
||||
const items: ResultItemImpl[] = getFilteredTasks().flatMap((t: any) => {
|
||||
const items: T[] = getFilteredTasks().flatMap((t) => {
|
||||
const preview = t.previewOutput
|
||||
return preview && preview.supportsPreview ? [preview] : []
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user