mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
Add default confirm dialog (#2114)
This commit is contained in:
33
README.md
33
README.md
@@ -230,11 +230,18 @@ https://github.com/user-attachments/assets/c142c43f-2fe9-4030-8196-b3bfd4c6977d
|
||||
### Developer APIs
|
||||
|
||||
<details>
|
||||
<summary>v1.6.13: Prompt dialog</summary>
|
||||
<summary>v1.6.13: prompt/confirm/alert replacements for ComfyUI desktop</summary>
|
||||
|
||||
`window.prompt` is not available in ComfyUI desktop's electron environment. Please use the following API to show a prompt dialog.
|
||||
Several browser-only APIs are not available in ComfyUI desktop's electron environment.
|
||||
|
||||
- `window.prompt`
|
||||
- `window.confirm`
|
||||
- `window.alert`
|
||||
|
||||
Please use the following APIs as replacements.
|
||||
|
||||
```js
|
||||
// window.prompt
|
||||
window['app'].extensionManager.dialog
|
||||
.prompt({
|
||||
title: 'Test Prompt',
|
||||
@@ -247,6 +254,28 @@ window['app'].extensionManager.dialog
|
||||
|
||||

|
||||
|
||||
```js
|
||||
// window.confirm
|
||||
window['app'].extensionManager.dialog
|
||||
.confirm({
|
||||
title: 'Test Confirm',
|
||||
message: 'Test Confirm Message'
|
||||
})
|
||||
.then((value: boolean) => {
|
||||
// Do something with the value user entered
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
```js
|
||||
// window.alert
|
||||
window['app'].extensionManager.toast
|
||||
.addAlert("Test Alert")
|
||||
```
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
@@ -177,5 +177,23 @@ test.describe('Topbar commands', () => {
|
||||
'Hello, world!'
|
||||
)
|
||||
})
|
||||
|
||||
test('Should allow showing a confirmation dialog', async ({
|
||||
comfyPage
|
||||
}) => {
|
||||
await comfyPage.page.evaluate(() => {
|
||||
window['app'].extensionManager.dialog
|
||||
.confirm({
|
||||
title: 'Test Confirm',
|
||||
message: 'Test Confirm Message'
|
||||
})
|
||||
.then((value: boolean) => {
|
||||
window['value'] = value
|
||||
})
|
||||
})
|
||||
|
||||
await comfyPage.confirmDialog.click('confirm')
|
||||
expect(await comfyPage.page.evaluate(() => window['value'])).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -91,11 +91,13 @@ class ConfirmDialog {
|
||||
public readonly delete: Locator
|
||||
public readonly overwrite: Locator
|
||||
public readonly reject: Locator
|
||||
public readonly confirm: 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"]')
|
||||
this.confirm = page.locator('button.p-button[aria-label="Confirm"]')
|
||||
}
|
||||
|
||||
async click(locator: KeysOfType<ConfirmDialog, Locator>) {
|
||||
|
||||
@@ -13,7 +13,14 @@
|
||||
autofocus
|
||||
/>
|
||||
<Button
|
||||
v-if="type === 'delete'"
|
||||
v-if="type === 'default'"
|
||||
:label="$t('g.confirm')"
|
||||
severity="primary"
|
||||
@click="onConfirm"
|
||||
icon="pi pi-check"
|
||||
/>
|
||||
<Button
|
||||
v-else-if="type === 'delete'"
|
||||
:label="$t('g.delete')"
|
||||
severity="danger"
|
||||
@click="onConfirm"
|
||||
|
||||
@@ -12,6 +12,7 @@ import type { ExecutionErrorWsMessage } from '@/types/apiTypes'
|
||||
import type { MissingNodeType } from '@/types/comfy'
|
||||
|
||||
export type ConfirmationDialogType =
|
||||
| 'default'
|
||||
| 'overwrite'
|
||||
| 'delete'
|
||||
| 'dirtyClose'
|
||||
@@ -121,16 +122,16 @@ export const useDialogService = () => {
|
||||
*/
|
||||
async function confirm({
|
||||
title,
|
||||
type,
|
||||
message,
|
||||
type = 'default',
|
||||
itemList = []
|
||||
}: {
|
||||
/** Dialog heading */
|
||||
title: string
|
||||
/** Pre-configured dialog type */
|
||||
type: ConfirmationDialogType
|
||||
/** The main message body */
|
||||
message: string
|
||||
/** Pre-configured dialog type */
|
||||
type?: ConfirmationDialogType
|
||||
/** Displayed as an unorderd list immediately below the message body */
|
||||
itemList?: string[]
|
||||
}): Promise<boolean | null> {
|
||||
|
||||
Reference in New Issue
Block a user