From dbd2581f65f497326d32323b41fc0d59f327460a Mon Sep 17 00:00:00 2001 From: Maksym Yezhov Date: Sat, 6 Dec 2025 17:45:34 -0800 Subject: [PATCH] poc: new dialog system usage example --- src/components/Editor/PipelineDetails.tsx | 3 + src/components/shared/TmpTestDialog.tsx | 175 ++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/components/shared/TmpTestDialog.tsx diff --git a/src/components/Editor/PipelineDetails.tsx b/src/components/Editor/PipelineDetails.tsx index e2210c342..9aa55bd7e 100644 --- a/src/components/Editor/PipelineDetails.tsx +++ b/src/components/Editor/PipelineDetails.tsx @@ -18,6 +18,7 @@ import { getComponentFileFromList } from "@/utils/componentStore"; import { USER_PIPELINES_LIST_NAME } from "@/utils/constants"; import { TaskImplementation } from "../shared/TaskDetails"; +import { TestDialogButton } from "../shared/TmpTestDialog"; import { InputValueEditor } from "./IOEditor/InputValueEditor"; import { OutputNameEditor } from "./IOEditor/OutputNameEditor"; import RenamePipeline from "./RenamePipeline"; @@ -146,6 +147,8 @@ const PipelineDetails = () => { componentSpec={componentSpec} showInlineContent={false} /> + + {/* General Metadata */} diff --git a/src/components/shared/TmpTestDialog.tsx b/src/components/shared/TmpTestDialog.tsx new file mode 100644 index 000000000..df6917add --- /dev/null +++ b/src/components/shared/TmpTestDialog.tsx @@ -0,0 +1,175 @@ +import { useMutation } from "@tanstack/react-query"; +import { type ChangeEvent, useCallback, useState } from "react"; + +import { Button } from "@/components/ui/button"; +import { + DialogDescription, + DialogFooter, + DialogTitle, +} from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Spinner } from "@/components/ui/spinner"; +import { useDialog } from "@/hooks/useDialog"; +import useToastNotification from "@/hooks/useToastNotification"; +import { + DialogCancelledError, + type DialogProps, +} from "@/providers/DialogProvider/types"; + +import { InlineStack } from "../ui/layout"; + +interface DialogResult { + message: string; +} + +export function TestDialogButton() { + const { open: openDialog } = useDialog(); + const notify = useToastNotification(); + + const { mutate: showTestDialog, isPending } = useMutation({ + mutationFn: async () => { + const result = await openDialog({ + component: TestDialog, + routeKey: "test-dialog", + }); + + notify(`Dialog result: ${result?.message}`, "info"); + }, + onError: (error) => { + notify(`Error: ${error.message}`, "error"); + }, + }); + + return ( + + ); +} + +export function TestDialog({ close, cancel }: DialogProps) { + const [message, setMessage] = useState("Hello, world!"); + const notify = useToastNotification(); + const confirmationDialog = useConfirmationDialog(); + + const { mutate: confirmDialog, isPending: isConfirming } = useMutation({ + mutationFn: async () => { + const result = await confirmationDialog({ + title: "Nested Dialog", + description: + "This is a nested confirmation dialog. It will be automatically stacked and displayed", + }).catch((error) => { + /** + * Approach to detect "cancellation or closing" of the nested dialog + */ + if (error instanceof DialogCancelledError) { + return null; + } + throw error; + }); + + /** + * Reading results. Result is typed + */ + return result?.confirmed ? "confirmed" : "cancelled"; + }, + onSuccess: (result) => { + notify(`Confirmation dialog result: ${result}`, "info"); + }, + onError: (error) => { + notify(`Error: ${error.message}`, "error"); + }, + }); + + return ( + <> + Demo Dialog + + This is a demo dialog. It will pass the message to the parent component. + + + + ) => + setMessage(e.target.value) + } + /> + + + + + + + + + + ); +} + +export interface ConfirmationDialogResult { + confirmed: boolean; +} + +export function useConfirmationDialog() { + const { open: openDialog } = useDialog(); + return useCallback( + async ( + { + title, + description, + }: { + title: string; + description: string; + } = { + title: "Confirmation", + description: "Are you sure you want to proceed?", + }, + ) => { + return await openDialog< + ConfirmationDialogResult, + { title: string; description: string } + >({ + component: ConfirmationDialog, + props: { + title, + description, + }, + routeKey: "confirmation", + }); + }, + [openDialog], + ); +} + +export function ConfirmationDialog({ + close, + title, + description, +}: { title: string; description: string } & DialogProps) { + return ( + <> + {title} + {description} + + + + + + + ); +}