diff --git a/desktop/app/src/dispatcher/application.tsx b/desktop/app/src/dispatcher/application.tsx index c6e57c147..c201c7100 100644 --- a/desktop/app/src/dispatcher/application.tsx +++ b/desktop/app/src/dispatcher/application.tsx @@ -17,7 +17,7 @@ import { } from '../utils/exportData'; import {tryCatchReportPlatformFailures} from '../utils/metrics'; import {handleDeeplink} from '../deeplink'; -import {message} from 'antd'; +import {Dialog} from 'flipper-plugin'; export default (store: Store, _logger: Logger) => { const currentWindow = remote.getCurrentWindow(); @@ -59,7 +59,13 @@ export default (store: Store, _logger: Logger) => { (_event: IpcRendererEvent, query: string) => { handleDeeplink(store, query).catch((e) => { console.warn('Failed to handle deeplink', query, e); - message.error(`Failed to handle deeplink '${query}': ${e}`); + Dialog.alert({ + title: 'Failed to open deeplink', + type: 'error', + message: `Failed to handle deeplink '${query}': ${ + e.message ?? e.toString() + }`, + }); }); }, ); diff --git a/desktop/flipper-plugin/src/ui/Dialog.tsx b/desktop/flipper-plugin/src/ui/Dialog.tsx index feeab4c5f..679de22da 100644 --- a/desktop/flipper-plugin/src/ui/Dialog.tsx +++ b/desktop/flipper-plugin/src/ui/Dialog.tsx @@ -77,14 +77,33 @@ export const Dialog = { confirm({ message, + onConfirm, ...rest }: { message: React.ReactNode; + onConfirm?: () => Promise; } & BaseDialogOptions): DialogResult { return Dialog.show({ ...rest, children: message, - onConfirm: async () => true, + onConfirm: onConfirm ?? (async () => true), + }); + }, + + alert({ + message, + type, + ...rest + }: { + message: React.ReactNode; + type: 'info' | 'error' | 'warning' | 'success'; + } & BaseDialogOptions): Promise { + return new Promise((resolve) => { + Modal[type]({ + afterClose: resolve, + content: message, + ...rest, + }); }); }, diff --git a/docs/extending/flipper-plugin.mdx b/docs/extending/flipper-plugin.mdx index bf8c8641d..27a2bc3a1 100644 --- a/docs/extending/flipper-plugin.mdx +++ b/docs/extending/flipper-plugin.mdx @@ -914,7 +914,7 @@ Available utilities * `Dialog.confirm(options): Promise`. Show a confirmation dialog to the user. Options: * `message`: Description of what the user is confirming. -* `Dialog.prompt(options): Promise`. Prompt the user for some input. Options: +* `Dialog.prompt(options): Promise`. Inspired by `window.prompt`. Prompt the user for some input. Options: * `message`: Text accompanying the input * `defaultValue` * `onConfirm(value) => Promise`. Can be used to transform the inputted value before resolving the prompt promise. If the handler throws, this will be shown as validation error in the dialog. @@ -923,6 +923,9 @@ Available utilities * `Dialog.show(options): Promise Promise`. Handler to handle the OK button, which should produce the value the `Dialog.show` call will resolve to. +* `Dialog.alert(options)` show a small dialog, inspired by window.alert. Returns a `Promise`. Options: + * `type`, determines style. One of: `'info' | 'error' | 'warning' | 'success'`. + * `message` parameter to specificy the content of the dialog. ### Spinner