Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor(web): open the prompt review dialog without a trigger wrapper (#19487)

cursor[bot]245c51c64189
diff --git a/web/src/features/prompts/components/NewPromptForm/NewPromptForm.tsx b/web/src/features/prompts/components/NewPromptForm/NewPromptForm.tsx
index fe60876460..eef12e0283 100644
--- a/web/src/features/prompts/components/NewPromptForm/NewPromptForm.tsx
+++ b/web/src/features/prompts/components/NewPromptForm/NewPromptForm.tsx
@@ -28,7 +28,7 @@ import {
getIsCharOrUnderscore,
} from "@langfuse/shared";
import { PromptChatMessages } from "./PromptChatMessages";
-import { ReviewPromptDialog } from "./ReviewPromptDialog";
+import { ReviewPromptDialogController } from "./ReviewPromptDialogController";
import {
NewPromptFormSchema,
type NewPromptFormSchemaType,
@@ -458,20 +458,24 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {
{initialPrompt ? (
<div className="flex flex-col gap-2">
- <ReviewPromptDialog
+ <ReviewPromptDialogController
initialPrompt={initialPrompt}
getNewPromptValues={form.getValues}
isLoading={createPromptMutation.isPending}
onConfirm={form.handleSubmit(onSubmit)}
>
- <Button
- disabled={!form.formState.isValid}
- variant="secondary"
- className="w-full"
- >
- Review changes
- </Button>
- </ReviewPromptDialog>
+ {({ openDialog }) => (
+ <Button
+ type="button"
+ disabled={!form.formState.isValid}
+ variant="secondary"
+ className="w-full"
+ onClick={openDialog}
+ >
+ Review changes
+ </Button>
+ )}
+ </ReviewPromptDialogController>
<Button
type="submit"
diff --git a/web/src/features/prompts/components/NewPromptForm/ReviewPromptDialog.tsx b/web/src/features/prompts/components/NewPromptForm/ReviewPromptDialog.tsx
deleted file mode 100644
index 2c0c555f72..0000000000
--- a/web/src/features/prompts/components/NewPromptForm/ReviewPromptDialog.tsx
+++ /dev/null
@@ -1,135 +0,0 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger, @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
-import React from "react";
-import { Button } from "@/src/components/ui/button";
-import {
- Dialog,
- DialogBody,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/src/components/ui/dialog";
-import { type Prompt } from "@langfuse/shared";
-import { type NewPromptFormSchemaType } from "./validation";
-import DiffViewer from "@/src/components/DiffViewer";
-
-type ReviewPromptDialogProps = {
- initialPrompt: Prompt;
- isLoading: boolean;
- children: React.ReactNode;
- onConfirm: () => void;
- getNewPromptValues: () => NewPromptFormSchemaType;
-};
-
-const formatMessages = (messages: any[], excludeKeys: string[] = []) => {
- return JSON.stringify(
- messages.map((m) =>
- Object.fromEntries(
- Object.entries(m)
- .filter(
- ([k]) =>
- !excludeKeys.includes(k) &&
- (k !== "type" || m.type === "placeholder"),
- )
- .sort(([a], [b]) => a.localeCompare(b)),
- ),
- ),
- null,
- 2,
- );
-};
-
-export const ReviewPromptDialog: React.FC<ReviewPromptDialogProps> = (
- props,
-) => {
- const { initialPrompt, children, getNewPromptValues, onConfirm, isLoading } =
- props;
- const [newPromptValue, setNewPromptValues] =
- React.useState<NewPromptFormSchemaType | null>(null);
- const [open, setOpen] = React.useState<boolean>(false);
-
- React.useEffect(() => {
- if (open) {
- setNewPromptValues(getNewPromptValues());
- }
- }, [open, setNewPromptValues, getNewPromptValues]);
-
- const initialPromptContent =
- initialPrompt.type === "text"
- ? (initialPrompt.prompt as string)
- : formatMessages(initialPrompt.prompt as any[]);
-
- const newPromptContent =
- initialPrompt.type === "text"
- ? (newPromptValue?.textPrompt ?? "")
- : formatMessages(newPromptValue?.chatPrompt ?? [], ["id"]);
-
- const newConfig = JSON.stringify(
- JSON.parse(newPromptValue?.config ?? "{}"),
- null,
- 2,
- );
-
- return (
- <Dialog open={open} onOpenChange={(open) => setOpen(open)}>
- <DialogTrigger asChild>{children}</DialogTrigger>
- <DialogContent size="xl">
- <DialogHeader>
- <DialogTitle>Review Prompt Changes</DialogTitle>
- <DialogDescription className="flex items-center gap-2">
- <span className="font-bold">{initialPrompt.name}</span>
- </DialogDescription>
- </DialogHeader>
-
- <DialogBody>
- <div className="max-h-[80vh] max-w-(--breakpoint-xl) space-y-6 overflow-y-auto">
- <div className="space-y-6">
- <div className="space-y-4">
- <div>
- <h3 className="mb-2 text-base font-bold">Content</h3>
- <DiffViewer
- oldString={initialPromptContent}
- newString={newPromptContent}
- oldLabel={`Previous content (v${initialPrompt.version})`}
- newLabel="New content (draft)"
- />
- </div>
- <div>
- <h3 className="mb-2 text-base font-bold">Config</h3>
- <DiffViewer
- oldString={JSON.stringify(initialPrompt.config, null, 2)}
- newString={newConfig ?? "failed"}
- oldLabel={`Previous config (v${initialPrompt.version})`}
- newLabel="New config (draft)"
- />
- </div>
- </div>
- </div>
- </div>
- </DialogBody>
-
- <DialogFooter className="flex flex-row">
- <Button
- type="button"
- variant="secondary"
- onClick={() => setOpen(false)}
- className="min-w-32"
- >
- Cancel
- </Button>
- <Button
- onClick={onConfirm}
- loading={isLoading}
- variant={newPromptValue?.isActive ? "destructive" : "default"}
- className="min-w-32"
- >
- Save new version
- {newPromptValue?.isActive ? " and promote to production" : ""}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
-};
diff --git a/web/src/features/prompts/components/NewPromptForm/ReviewPromptDialogController.tsx b/web/src/features/prompts/components/NewPromptForm/ReviewPromptDialogController.tsx
new file mode 100644
index 0000000000..807b442c51
--- /dev/null
+++ b/web/src/features/prompts/components/NewPromptForm/ReviewPromptDialogController.tsx
@@ -0,0 +1,103 @@
+import React from "react";
+import { type Prompt } from "@langfuse/shared";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+import DiffViewer from "@/src/components/DiffViewer";
+import { type NewPromptFormSchemaType } from "./validation";
+
+type ReviewPromptDialogControllerProps = {
+ initialPrompt: Prompt;
+ isLoading: boolean;
+ children: (control: { openDialog: () => void }) => React.ReactNode;
+ onConfirm: () => void;
+ getNewPromptValues: () => NewPromptFormSchemaType;
+};
+
+const formatMessages = (messages: any[], excludeKeys: string[] = []) => {
+ return JSON.stringify(
+ messages.map((m) =>
+ Object.fromEntries(
+ Object.entries(m)
+ .filter(
+ ([k]) =>
+ !excludeKeys.includes(k) &&
+ (k !== "type" || m.type === "placeholder"),
+ )
+ .sort(([a], [b]) => a.localeCompare(b)),
+ ),
+ ),
+ null,
+ 2,
+ );
+};
+
+export const ReviewPromptDialogController: React.FC<
+ ReviewPromptDialogControllerProps
+> = (props) => {
+ const { initialPrompt, children, getNewPromptValues, onConfirm, isLoading } =
+ props;
+
+ return (
+ <DialogController<NewPromptFormSchemaType>
+ renderDialog={({ state }) => {
+ const initialPromptContent =
+ initialPrompt.type === "text"
+ ? (initialPrompt.prompt as string)
+ : formatMessages(initialPrompt.prompt as any[]);
+
+ const newPromptContent =
+ initialPrompt.type === "text"
+ ? (state.textPrompt ?? "")
+ : formatMessages(state.chatPrompt ?? [], ["id"]);
+
+ const newConfig = JSON.stringify(JSON.parse(state.config), null, 2);
+
+ return (
+ <Dialog
+ size="xxl"
+ title="Review Prompt Changes"
+ closeLabel="Cancel"
+ actions={[
+ {
+ label: state.isActive
+ ? "Save new version and promote to production"
+ : "Save new version",
+ loading: isLoading,
+ onClick: onConfirm,
+ variant: state.isActive ? "destructive" : "default",
+ },
+ ]}
+ >
+ <Dialog.Body>
+ <p className="font-bold">{initialPrompt.name}</p>
+ <div>
+ <h3 className="mb-2 text-base font-bold">Content</h3>
+ <DiffViewer
+ oldString={initialPromptContent}
+ newString={newPromptContent}
+ oldLabel={`Previous content (v${initialPrompt.version})`}
+ newLabel="New content (draft)"
+ />
+ </div>
+ <div>
+ <h3 className="mb-2 text-base font-bold">Config</h3>
+ <DiffViewer
+ oldString={JSON.stringify(initialPrompt.config, null, 2)}
+ newString={newConfig ?? "failed"}
+ oldLabel={`Previous config (v${initialPrompt.version})`}
+ newLabel="New config (draft)"
+ />
+ </div>
+ </Dialog.Body>
+ </Dialog>
+ );
+ }}
+ >
+ {({ openDialog }) =>
+ children({
+ openDialog: () => openDialog(getNewPromptValues()),
+ })
+ }
+ </DialogController>
+ );
+};