[BugFix] Properly trigger onClose hook in dialogService (#2655)

This commit is contained in:
Chenlei Hu
2025-02-20 14:42:52 -05:00
committed by GitHub
parent 78146c86f4
commit 3e31045fbb
2 changed files with 23 additions and 12 deletions

View File

@@ -280,5 +280,22 @@ test.describe('Topbar commands', () => {
await comfyPage.confirmDialog.click('confirm')
expect(await comfyPage.page.evaluate(() => window['value'])).toBe(true)
})
test('Should allow dismissing a dialog', async ({ comfyPage }) => {
await comfyPage.page.evaluate(() => {
window['value'] = 'foo'
window['app'].extensionManager.dialog
.confirm({
title: 'Test Confirm',
message: 'Test Confirm Message'
})
.then((value: boolean) => {
window['value'] = value
})
})
await comfyPage.confirmDialog.click('reject')
expect(await comfyPage.page.evaluate(() => window['value'])).toBeNull()
})
})
})

View File

@@ -43,18 +43,13 @@ export const useDialogStore = defineStore('dialog', () => {
}
function closeDialog(options?: { key: string }) {
if (!options) {
dialogStack.value.pop()
return
}
const targetDialog = options
? dialogStack.value.find((d) => d.key === options.key)
: dialogStack.value[0]
if (!targetDialog) return
const dialogKey = options.key
const index = dialogStack.value.findIndex((d) => d.key === dialogKey)
if (index === -1) {
return
}
dialogStack.value.splice(index, 1)
targetDialog.dialogComponentProps?.onClose?.()
dialogStack.value.splice(dialogStack.value.indexOf(targetDialog), 1)
}
function createDialog(options: {
@@ -93,7 +88,6 @@ export const useDialogStore = defineStore('dialog', () => {
dialog.dialogComponentProps.maximized = false
},
onAfterHide: () => {
options.dialogComponentProps?.onClose?.()
closeDialog(dialog)
},
pt: {