From 735153886fb9fd5064085291512a6481f0f4ee25 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Thu, 5 Dec 2024 06:11:49 +1100 Subject: [PATCH] Confirm delete workflow (#1772) * Add confirm delete workflow prompt * Add confirm delete workflow setting * Add delete workflow tests * Change dialog to modal, set default cancel * Fix setting version key * Rename for clarity * Fix tests - Move into correct section - Add confirm control * Export type: ShowDialogOptions * Replace workflow overwrite with new dialog * Add delete workflow confirmation dialog * Update i18n * Add item list support to confirmation dialog * Prevent multiple dialogs for same action * Add confirm close file when dirty * Add i18n for overwrite dialog * Fix regression: confirm dialog setting ignored * Fix delete last workflow does not open replacement * Update tests --- browser_tests/fixtures/ComfyPage.ts | 28 +++++++- browser_tests/menu.spec.ts | 41 ++++++++++- .../content/ConfirmationDialogContent.vue | 64 +++++++++++++++++ .../sidebar/tabs/WorkflowsSidebarTab.vue | 12 +++- src/constants/coreSettings.ts | 7 ++ src/i18n.ts | 3 + src/locales/en.json | 21 +++++- src/locales/ja.json | 19 ++++++ src/locales/ru.json | 19 ++++++ src/locales/zh.json | 19 ++++++ src/services/dialogService.ts | 44 +++++++++++- src/services/workflowService.ts | 68 +++++++++++++------ src/stores/commandStore.ts | 4 ++ src/stores/dialogStore.ts | 18 ++--- src/types/apiTypes.ts | 3 +- 15 files changed, 333 insertions(+), 37 deletions(-) create mode 100644 src/components/dialog/content/ConfirmationDialogContent.vue diff --git a/browser_tests/fixtures/ComfyPage.ts b/browser_tests/fixtures/ComfyPage.ts index ce7ca8c2df..6428c9531b 100644 --- a/browser_tests/fixtures/ComfyPage.ts +++ b/browser_tests/fixtures/ComfyPage.ts @@ -75,6 +75,28 @@ type FolderStructure = { [key: string]: FolderStructure | string } +type KeysOfType = { + [K in keyof T]: T[K] extends Match ? K : never +}[keyof T] + +class ConfirmDialog { + public readonly delete: Locator + public readonly overwrite: Locator + public readonly reject: Locator + + constructor(public readonly page: Page) { + this.delete = page.locator('button.p-button[aria-label="Delete"]') + this.overwrite = page.locator('button.p-button[aria-label="Overwrite"]') + this.reject = page.locator('button.p-button[aria-label="Cancel"]') + } + + async click(locator: KeysOfType) { + const loc = this[locator] + await expect(loc).toBeVisible() + await loc.click() + } +} + export class ComfyPage { public readonly url: string // All canvas position operations are based on default view of canvas. @@ -94,6 +116,7 @@ export class ComfyPage { public readonly actionbar: ComfyActionbar public readonly templates: ComfyTemplates public readonly settingDialog: SettingDialog + public readonly confirmDialog: ConfirmDialog /** Worker index to test user ID */ public readonly userIds: string[] = [] @@ -118,6 +141,7 @@ export class ComfyPage { this.actionbar = new ComfyActionbar(page) this.templates = new ComfyTemplates(page) this.settingDialog = new SettingDialog(page) + this.confirmDialog = new ConfirmDialog(page) } convertLeafToContent(structure: FolderStructure): FolderStructure { @@ -740,14 +764,14 @@ export class ComfyPage { ) } - async confirmDialog(prompt: string, text: string = 'Yes') { + async clickDialogButton(prompt: string, buttonText: string = 'Yes') { const modal = this.page.locator( `.comfy-modal-content:has-text("${prompt}")` ) await expect(modal).toBeVisible() await modal .locator('.comfyui-button', { - hasText: text + hasText: buttonText }) .click() await expect(modal).toBeHidden() diff --git a/browser_tests/menu.spec.ts b/browser_tests/menu.spec.ts index bc79e7e42b..5e67c4fa8e 100644 --- a/browser_tests/menu.spec.ts +++ b/browser_tests/menu.spec.ts @@ -442,7 +442,7 @@ test.describe('Menu', () => { ).toEqual(['workflow5.json']) await comfyPage.menu.topbar.saveWorkflowAs('workflow5.json') - await comfyPage.confirmDialog('Overwrite existing file?', 'Yes') + await comfyPage.confirmDialog.click('overwrite') expect( await comfyPage.menu.workflowsTab.getOpenedWorkflowNames() ).toEqual(['workflow5.json']) @@ -477,7 +477,7 @@ test.describe('Menu', () => { ) await topbar.saveWorkflowAs('workflow1.json') - await comfyPage.confirmDialog('Overwrite existing file?', 'Yes') + await comfyPage.confirmDialog.click('overwrite') // The old workflow1.json should be deleted and the new one should be saved. expect( await comfyPage.menu.workflowsTab.getOpenedWorkflowNames() @@ -519,6 +519,43 @@ test.describe('Menu', () => { await comfyPage.menu.workflowsTab.getOpenedWorkflowNames() ).toEqual(['*Unsaved Workflow.json']) }) + + test('Can delete workflows (confirm disabled)', async ({ comfyPage }) => { + await comfyPage.setSetting('Comfy.Workflow.ConfirmDelete', false) + + const { topbar, workflowsTab } = comfyPage.menu + + const filename = 'workflow18.json' + await topbar.saveWorkflow(filename) + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([filename]) + + await workflowsTab.getOpenedItem(filename).click({ button: 'right' }) + await comfyPage.nextFrame() + await comfyPage.clickContextMenuItem('Delete') + + await expect(workflowsTab.getOpenedItem(filename)).not.toBeVisible() + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([ + '*Unsaved Workflow.json' + ]) + }) + + test('Can delete workflows', async ({ comfyPage }) => { + const { topbar, workflowsTab } = comfyPage.menu + + const filename = 'workflow18.json' + await topbar.saveWorkflow(filename) + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([filename]) + + await workflowsTab.getOpenedItem(filename).click({ button: 'right' }) + await comfyPage.clickContextMenuItem('Delete') + + await comfyPage.confirmDialog.click('delete') + + await expect(workflowsTab.getOpenedItem(filename)).not.toBeVisible() + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([ + '*Unsaved Workflow.json' + ]) + }) }) test.describe('Workflows topbar tabs', () => { diff --git a/src/components/dialog/content/ConfirmationDialogContent.vue b/src/components/dialog/content/ConfirmationDialogContent.vue new file mode 100644 index 0000000000..81feebd9c0 --- /dev/null +++ b/src/components/dialog/content/ConfirmationDialogContent.vue @@ -0,0 +1,64 @@ + + + diff --git a/src/components/sidebar/tabs/WorkflowsSidebarTab.vue b/src/components/sidebar/tabs/WorkflowsSidebarTab.vue index 6a6263fc40..94526bc69e 100644 --- a/src/components/sidebar/tabs/WorkflowsSidebarTab.vue +++ b/src/components/sidebar/tabs/WorkflowsSidebarTab.vue @@ -123,6 +123,7 @@ +