Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/sidebar/tabs/BaseWorkflowsSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ const dummyExpandedKeys = ref<Record<string, boolean>>({})

const handleCloseWorkflow = async (workflow?: ComfyWorkflow) => {
if (workflow) {
await workflowService.closeWorkflow(workflow, {
warnIfUnsaved: !workspaceStore.shiftDown
await workflowService.closeWorkflows([workflow], {
warnIfUnsaved: !workspaceStore.shiftDown,
initiator: 'user'
})
}
}
Expand Down Expand Up @@ -342,7 +343,7 @@ const renderTreeNode = (
e: MouseEvent
) {
if (this.leaf && workflow) {
await workflowService.openWorkflow(workflow)
await workflowService.openWorkflow(workflow, { initiator: 'user' })
} else {
toggleNodeOnEvent(e, this)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/topbar/WorkflowOverflowMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ it('marks the agent target separately from the active overflow workflow', async
).toBeNull()

await user.click(targetItem)
expect(openWorkflow).toHaveBeenCalledWith(target)
expect(openWorkflow).toHaveBeenCalledWith(target, { initiator: 'user' })
})
2 changes: 1 addition & 1 deletion src/components/topbar/WorkflowOverflowMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const menuItems = computed(() =>
icon:
props.activeWorkflow?.key === workflow.key ? 'pi pi-check' : undefined,
command: () => {
void workflowService.openWorkflow(workflow)
void workflowService.openWorkflow(workflow, { initiator: 'user' })
}
}))
)
Expand Down
15 changes: 8 additions & 7 deletions src/components/topbar/WorkflowTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,16 @@ describe('WorkflowTab - close button', () => {
)
})

it('delegates close to workflow service with the tab workflow', async () => {
it('delegates close to workflow service as a user action', async () => {
renderTab()
const user = userEvent.setup()
await user.click(screen.getByTestId('close-workflow-button'))

expect(useWorkflowService().closeWorkflow).toHaveBeenCalledWith(
expect.objectContaining({ key: 'test-key' }),
expect.anything()
expect(useWorkflowService().closeWorkflows).toHaveBeenCalledWith(
[expect.objectContaining({ key: 'test-key' })],
expect.objectContaining({ initiator: 'user' })
)
expect(useWorkflowService().closeWorkflow).not.toHaveBeenCalled()
})
})

Expand Down Expand Up @@ -419,9 +420,9 @@ describe('WorkflowTab - Agent target', () => {
expect(screen.getByRole('img', { name: targetLabel })).toBeVisible()
expect(screen.getByTestId('workflow-dirty-indicator')).toBeVisible()
await userEvent.setup().click(screen.getByTestId('close-workflow-button'))
expect(useWorkflowService().closeWorkflow).toHaveBeenCalledWith(
workflowOption.workflow,
expect.anything()
expect(useWorkflowService().closeWorkflows).toHaveBeenCalledWith(
[workflowOption.workflow],
expect.objectContaining({ initiator: 'user' })
)
})
})
23 changes: 6 additions & 17 deletions src/components/topbar/WorkflowTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,12 @@ const handleClick = (event: Event) => {
popoverRef.value?.togglePopover(event)
}

const closeWorkflows = async (options: WorkflowOption[]) => {
for (const opt of options) {
if (
!(await useWorkflowService().closeWorkflow(opt.workflow, {
warnIfUnsaved: !workspaceStore.shiftDown,
hint: t('sideToolbar.workflowTab.dirtyCloseHint')
}))
) {
// User cancelled, or the replacement load failed
break
}
}
}

const onCloseWorkflow = async (option: WorkflowOption) => {
await closeWorkflows([option])
}
const onCloseWorkflow = (option: WorkflowOption) =>
useWorkflowService().closeWorkflows([option.workflow], {
warnIfUnsaved: !workspaceStore.shiftDown,
hint: t('sideToolbar.workflowTab.dirtyCloseHint'),
initiator: 'user'
})

const commandStore = useCommandStore()
const workflow = computed(() => workflowOption.workflow)
Expand Down
58 changes: 49 additions & 9 deletions src/components/topbar/WorkflowTabs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,20 @@ vi.mock(import('./WorkflowTab.vue'), () => ({
required: true
}
},
emits: ['closeOthers'],
render() {
return h(
TabsTrigger,
{ value: this.workflowOption.workflow.path },
() => this.workflowOption.workflow.filename
)
return [
h(
TabsTrigger,
{ value: this.workflowOption.workflow.path },
() => this.workflowOption.workflow.filename
),
h(
'button',
{ type: 'button', onClick: () => this.$emit('closeOthers') },
`Close tabs other than ${this.workflowOption.workflow.filename}`
)
]
}
})
}))
Expand Down Expand Up @@ -498,7 +506,10 @@ describe('WorkflowTabs selection and overflow', () => {

expect(useWorkflowService().openWorkflow).toHaveBeenCalledOnce()
expect(useWorkflowService().openWorkflow).toHaveBeenCalledWith(
firstWorkflow
firstWorkflow,
{
initiator: 'user'
}
)
expect(screen.getByRole('tab', { name: 'First workflow' })).toHaveAttribute(
'aria-selected',
Expand All @@ -513,7 +524,10 @@ describe('WorkflowTabs selection and overflow', () => {

expect(useWorkflowService().openWorkflow).toHaveBeenCalledOnce()
expect(useWorkflowService().openWorkflow).toHaveBeenCalledWith(
secondWorkflow
secondWorkflow,
{
initiator: 'user'
}
)
})

Expand All @@ -526,7 +540,10 @@ describe('WorkflowTabs selection and overflow', () => {

expect(useWorkflowService().openWorkflow).toHaveBeenCalledOnce()
expect(useWorkflowService().openWorkflow).toHaveBeenCalledWith(
secondWorkflow
secondWorkflow,
{
initiator: 'user'
}
)
})

Expand All @@ -539,8 +556,31 @@ describe('WorkflowTabs selection and overflow', () => {

expect(useWorkflowService().openWorkflow).toHaveBeenCalledOnce()
expect(useWorkflowService().openWorkflow).toHaveBeenCalledWith(
firstWorkflow
firstWorkflow,
{
initiator: 'user'
}
)
})

it('closes the other tabs as one user action', async () => {
const thirdWorkflow = await useWorkflowStore()
.createTemporary('Third workflow.json')
.load()
useWorkflowStore().attachWorkflow(thirdWorkflow, 2)
const { user } = renderComponent()

await user.click(
screen.getByRole('button', {
name: 'Close tabs other than Second workflow'
})
)

expect(useWorkflowService().closeWorkflows).toHaveBeenCalledExactlyOnceWith(
[thirdWorkflow, firstWorkflow],
{ warnIfUnsaved: true, initiator: 'user' }
)
expect(useWorkflowService().closeWorkflow).not.toHaveBeenCalled()
})

it('keeps the real workflow selected when another workflow fails to load', async () => {
Expand Down
19 changes: 6 additions & 13 deletions src/components/topbar/WorkflowTabs.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
:class="
cn(

Check warning on line 4 in src/components/topbar/WorkflowTabs.vue

View workflow job for this annotation

GitHub Actions / fallow / fallow

High cognitive complexity (moderate)

Function '<template>' is hard to understand (cognitive: 19, threshold: 15). • Severity: moderate • Cyclomatic: 15 • Cognitive: 19 • Lines: 276 High cognitive complexity means deeply nested or interleaved logic. Consider flattening control flow or extracting helper functions.
'workflow-tabs-container flex h-full flex-auto flex-row gap-1 overflow-hidden bg-comfy-menu-bg px-1',
isDesktop ? 'max-w-[env(titlebar-area-width,100vw)]' : 'max-w-full'
)
Expand Down Expand Up @@ -215,21 +215,14 @@
async function openWorkflowByPath(path: string | number) {
const option = options.value.find(({ value }) => value === path)
if (!option) return
await workflowService.openWorkflow(option.workflow)
await workflowService.openWorkflow(option.workflow, { initiator: 'user' })
}

const closeWorkflows = async (options: WorkflowOption[]) => {
for (const opt of options) {
if (
!(await workflowService.closeWorkflow(opt.workflow, {
warnIfUnsaved: !workspaceStore.shiftDown
}))
) {
// User cancelled, or the replacement load failed
break
}
}
}
const closeWorkflows = (options: WorkflowOption[]) =>
workflowService.closeWorkflows(
options.map(({ workflow }) => workflow),
{ warnIfUnsaved: !workspaceStore.shiftDown, initiator: 'user' }
)

const onCloseWorkflow = async (option: WorkflowOption) => {
await closeWorkflows([option])
Expand Down
9 changes: 6 additions & 3 deletions src/composables/useCoreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ export function useCoreCommands(): ComfyCommand[] {
label: 'Next Opened Workflow',
versionAdded: '1.3.9',
function: async () => {
await workflowService.loadNextOpenedWorkflow()
await workflowService.loadNextOpenedWorkflow({ initiator: 'user' })
}
},
{
Expand All @@ -646,7 +646,7 @@ export function useCoreCommands(): ComfyCommand[] {
label: 'Previous Opened Workflow',
versionAdded: '1.3.9',
function: async () => {
await workflowService.loadPreviousOpenedWorkflow()
await workflowService.loadPreviousOpenedWorkflow({ initiator: 'user' })
}
},
{
Expand Down Expand Up @@ -874,7 +874,10 @@ export function useCoreCommands(): ComfyCommand[] {
versionAdded: '1.7.3',
function: async () => {
if (workflowStore.activeWorkflow)
await workflowService.closeWorkflow(workflowStore.activeWorkflow)
await workflowService.closeWorkflows([workflowStore.activeWorkflow], {
warnIfUnsaved: true,
initiator: 'user'
})
}
},
{
Expand Down
6 changes: 4 additions & 2 deletions src/composables/useWorkflowActionsMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ describe('useWorkflowActionsMenu', () => {
await findItem(menuItems.value, 'g.rename').command?.()

expect(useWorkflowService().openWorkflow).toHaveBeenCalledWith(
customWorkflow.value
customWorkflow.value,
{ initiator: 'user' }
)
expect(startRename).toHaveBeenCalled()
})
Expand All @@ -450,7 +451,8 @@ describe('useWorkflowActionsMenu', () => {
).command?.()

expect(useWorkflowService().openWorkflow).toHaveBeenCalledWith(
customWorkflow.value
customWorkflow.value,
{ initiator: 'user' }
)
expect(
lazyDeployToComfyApiDialog.openDeployToComfyApiDialog
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useWorkflowActionsMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function useWorkflowActionsMenu(
/** Switch to the target workflow tab if it's not already active */
const ensureWorkflowActive = async (wf: ComfyWorkflow | null) => {
if (!wf || wf === workflowStore.activeWorkflow) return true
return await workflowService.openWorkflow(wf)
return await workflowService.openWorkflow(wf, { initiator: 'user' })
}

const menuItems = computed<WorkflowMenuItem[]>(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const workflowService: ReturnType<typeof realUseWorkflowService> = {
reloadCurrentWorkflow: vi.fn(async () => {}),
openWorkflow: vi.fn(async () => true),
closeWorkflow: vi.fn(async () => true),
closeWorkflows: vi.fn(async () => {}),
renameWorkflow: vi.fn(async () => {}),
deleteWorkflow: vi.fn(async () => true),
insertWorkflow: vi.fn(async () => {}),
Expand Down
Loading
Loading