🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(dashboards): Migrate clone dialog to design-system (#19460)
Ben Bachem184a5c8c0d73
diff --git a/web/src/features/dashboard/DashboardDetailPage.tsx b/web/src/features/dashboard/DashboardDetailPage.tsxindex bd2a701ad0..fc8be5672f 100644--- a/web/src/features/dashboard/DashboardDetailPage.tsx+++ b/web/src/features/dashboard/DashboardDetailPage.tsx@@ -44,7 +44,7 @@ import {useClipboardWidgetProbe,} from "@/src/features/widgets";import { DashboardGrid } from "@/src/features/widgets/components/DashboardGrid";-import { CloneFirstDialogController } from "@/src/features/dashboard/components/CloneFirstDialogController";+import { ConnectedCloneDashboardDialogController } from "@/src/features/dashboard/components/ConnectedCloneDashboardDialogController";import { PageHeaderControlsPortal } from "@/src/components/layouts/page-header-controls-slot";import {DropdownMenu,@@ -178,8 +178,6 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {// gridResetKey remounts the grid to revert an attempted drag/resize when the// user cancels the clone-first flow.- const [cloneFirstPendingDefinition, setCloneFirstPendingDefinition] =- useState<{ widgets: DashboardPlacement[] } | null>(null);const [gridResetKey, setGridResetKey] = useState(0);// Filter state - use persistent filters from dashboard@@ -1199,16 +1197,7 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {});return (- <CloneFirstDialogController- projectId={projectId}- dashboardId={dashboardId}- dashboardName={dashboard.data?.name ?? "Dashboard"}- pendingDefinition={cloneFirstPendingDefinition}- onCancel={() => {- setCloneFirstPendingDefinition(null);- setGridResetKey((key) => key + 1);- }}- >+ <ConnectedCloneDashboardDialogController>{({ openDialog: openCloneFirstDialog }) => {const openCloneFirst = (attempt:@@ -1223,8 +1212,15 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {attempt,surface: "detail",});- setCloneFirstPendingDefinition(pendingDefinition ?? null);- openCloneFirstDialog();+ openCloneFirstDialog({+ projectId,+ dashboardId,+ dashboardName: dashboard.data?.name ?? "Dashboard",+ pendingDefinition,+ onCancel: () => {+ setGridResetKey((key) => key + 1);+ },+ });};const handleDeleteWidget = (tileId: string) => {@@ -1538,6 +1534,6 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {</DialogController>);}}- </CloneFirstDialogController>+ </ConnectedCloneDashboardDialogController>);}diff --git a/web/src/features/dashboard/components/CloneDashboardDialog.stories.tsx b/web/src/features/dashboard/components/CloneDashboardDialog.stories.tsxnew file mode 100644index 0000000000..12f420ec7a--- /dev/null+++ b/web/src/features/dashboard/components/CloneDashboardDialog.stories.tsx@@ -0,0 +1,55 @@+import { fn } from "storybook/test";++import preview from "../../../../.storybook/preview";+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";+import { CloneDashboardDialog } from "./CloneDashboardDialog";++const meta = preview.meta({+ component: CloneDashboardDialog,+ parameters: { layout: "fullscreen" },+ decorators: [+ (Story) => (+ <DialogController<null>+ initialState={() => null}+ renderDialog={() => <Story />}+ >+ {() => null}+ </DialogController>+ ),+ ],+ args: {+ dashboardName: "Overview",+ setAsHome: false,+ hasPendingChange: false,+ isPending: false,+ onConfirm: fn(),+ onOpenExisting: fn(),+ },+});++export default meta;++export const Default = meta.story({});++export const WithPendingChange = meta.story({+ args: { hasPendingChange: true },+});++export const SetAsHome = meta.story({+ args: { setAsHome: true },+});++export const ExistingCopy = meta.story({+ args: { existingCloneName: "Overview (Clone)" },+});++export const ExistingCopyWithPendingChange = meta.story({+ args: {+ existingCloneName: "Overview (Clone)",+ hasPendingChange: true,+ },+});++export const CreatingCopy = meta.story({+ args: { isPending: true, existingCloneName: "Overview (Clone)" },+});diff --git a/web/src/features/dashboard/components/CloneDashboardDialog.tsx b/web/src/features/dashboard/components/CloneDashboardDialog.tsxnew file mode 100644index 0000000000..a0827b2939--- /dev/null+++ b/web/src/features/dashboard/components/CloneDashboardDialog.tsx@@ -0,0 +1,73 @@+import { ExternalLinkIcon } from "@langfuse/icons";+import { Button } from "@/src/components/design-system/Button/Button";+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";++export function CloneDashboardDialog({+ dashboardName,+ setAsHome,+ hasPendingChange,+ existingCloneName,+ isPending,+ onConfirm,+ onOpenExisting,+}: {+ dashboardName: string;+ setAsHome: boolean;+ hasPendingChange: boolean;+ existingCloneName?: string;+ isPending: boolean;+ onConfirm: () => void;+ onOpenExisting: () => void;+}) {+ return (+ <Dialog+ title="Clone dashboard"+ actions={[+ {+ label: "Clone",+ loading: isPending,+ onClick: onConfirm,+ },+ ]}+ >+ <Dialog.Body>+ <p className="text-muted-foreground">+ The dashboard{" "}+ <span className="text-foreground font-bold">+ “{dashboardName}”+ </span>{" "}+ is maintained by Langfuse and can’t be edited directly. Clone it+ to create an editable version in this project.+ {hasPendingChange && " Your change will be applied to the clone."}+ {setAsHome && " The clone will become your Home dashboard."}+ </p>+ <p className="text-muted-foreground">+ You can rearrange or remove Langfuse-maintained tiles. Editing their+ content isn’t available yet.+ </p>+ {existingCloneName && (+ <div className="bg-muted/50 flex flex-wrap items-center justify-between gap-2 rounded-md border p-3">+ <span className="text-muted-foreground">+ This project already has a dashboard named{" "}+ <span className="text-foreground font-bold">+ “{existingCloneName}”+ </span>+ .+ {hasPendingChange+ ? " Opening it won’t apply your current change."+ : ""}+ </span>+ <Button+ variant="outline"+ size="sm"+ text="Open existing clone"+ icon={ExternalLinkIcon}+ disabled={isPending}+ onClick={onOpenExisting}+ />+ </div>+ )}+ </Dialog.Body>+ </Dialog>+ );+}diff --git a/web/src/features/dashboard/components/CloneFirstDialogController.tsx b/web/src/features/dashboard/components/ConnectedCloneDashboardDialogController.tsxsimilarity index 52%rename from web/src/features/dashboard/components/CloneFirstDialogController.tsxrename to web/src/features/dashboard/components/ConnectedCloneDashboardDialogController.tsxindex ffd0e3f2a6..1264ac1f70 100644--- a/web/src/features/dashboard/components/CloneFirstDialogController.tsx+++ b/web/src/features/dashboard/components/ConnectedCloneDashboardDialogController.tsx@@ -1,16 +1,8 @@-/* eslint-disable @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */import { type ReactNode, useMemo, useRef } from "react";import { useRouter } from "next/router";-import { ExternalLinkIcon } from "@langfuse/icons";import { api } from "@/src/utils/api";-import {- DialogController,- DialogHeader,- DialogTitle,- DialogFooter,- DialogBody,-} from "@/src/components/ui/dialog";-import { Button } from "@/src/components/ui/button";+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";+import { CloneDashboardDialog } from "./CloneDashboardDialog";import { showErrorToast, showSuccessToast } from "@/src/features/notifications";import { usePostHogClientCapture } from "@/src/features/posthog-analytics";import type { DashboardPlacement } from "@/src/features/widgets";@@ -23,7 +15,7 @@ import { classifyTrpcToastError } from "@/src/utils/trpcErrorClassification";* `pendingDefinition` and setting the clone as the project's Home) and* navigates to the editable copy.*/-type CloneFirstDialogControllerProps = {+type CloneDashboardDialogState = {projectId: string;dashboardId: string;dashboardName: string;@@ -35,36 +27,29 @@ type CloneFirstDialogControllerProps = {onCancel?: () => void;};-export function CloneFirstDialogController({+export function ConnectedCloneDashboardDialogController({children,- ...props-}: CloneFirstDialogControllerProps & {- children: (control: { openDialog: () => void }) => ReactNode;+}: {+ children: (control: {+ openDialog: (state: CloneDashboardDialogState) => void;+ }) => ReactNode;}) {const capture = usePostHogClientCapture();const cloneInFlightRef = useRef(false);- const handleCancel = () => {- capture("dashboard:clone_first_cancelled", {- dashboard_id: props.dashboardId,- had_pending_change: Boolean(props.pendingDefinition),- });- props.onCancel?.();- };+ const onDismissRef = useRef<(() => void) | undefined>(undefined);return (- <DialogController- closeOnInteractionOutside={false}+ <DialogController<CloneDashboardDialogState>onBeforeClose={() => !cloneInFlightRef.current}- onDismiss={handleCancel}- size="default"- renderContent={({ closeDialog }) => (- <CloneFirstDialogContent- {...props}+ onDismiss={() => onDismissRef.current?.()}+ renderDialog={({ state, closeDialog }) => (+ <ConnectedCloneDashboardDialog+ {...state}closeDialog={closeDialog}cancelDialog={() => {if (cloneInFlightRef.current) return false;closeDialog();- handleCancel();+ onDismissRef.current?.();return true;}}onPendingChange={(isPending) => {@@ -73,12 +58,25 @@ export function CloneFirstDialogController({/>)}>- {({ openDialog }) => children({ openDialog })}+ {({ openDialog }) =>+ children({+ openDialog: (state) => {+ onDismissRef.current = () => {+ capture("dashboard:clone_first_cancelled", {+ dashboard_id: state.dashboardId,+ had_pending_change: Boolean(state.pendingDefinition),+ });+ state.onCancel?.();+ };+ openDialog(state);+ },+ })+ }</DialogController>);}-function CloneFirstDialogContent({+function ConnectedCloneDashboardDialog({closeDialog,cancelDialog,onPendingChange,@@ -87,7 +85,7 @@ function CloneFirstDialogContent({dashboardName,setAsHome = false,pendingDefinition,-}: Omit<CloneFirstDialogControllerProps, "onCancel"> & {+}: Omit<CloneDashboardDialogState, "onCancel"> & {closeDialog: () => void;cancelDialog: () => boolean;onPendingChange: (isPending: boolean) => void;@@ -168,88 +166,26 @@ function CloneFirstDialogContent({});};- const handleClose = () => {- cancelDialog();- };-return (- <>- <DialogHeader>- <DialogTitle>Create your editable copy</DialogTitle>- </DialogHeader>- <DialogBody>- <div className="text-muted-foreground grid gap-3 py-4 text-sm">- <p>- <span className="text-foreground font-bold">- “{dashboardName}”- </span>{" "}- is maintained by Langfuse and can’t be edited directly.- We’ll create your own editable copy in this project- {pendingDefinition ? " with your change applied" : ""}- {setAsHome ? " and show it on your Home page from now on" : ""}.- </p>- <p>- Langfuse-maintained tiles on the copy can be rearranged or removed;- editing their content will become available in a future release.- </p>- {existingClone && (- <div className="bg-muted/50 flex flex-wrap items-center justify-between gap-2 rounded-md border p-3">- <span>- You already have a copy:{" "}- <span className="text-foreground font-bold">- “{existingClone.name}”- </span>- {pendingDefinition- ? " — opening it will discard your attempted change"- : ""}- </span>- <Button- variant="outline"- size="sm"- type="button"- disabled={cloneDashboard.isPending}- onClick={() => {- capture("dashboard:clone_open_existing_click", {- dashboard_id: dashboardId,- existing_clone_id: existingClone.id,- had_pending_change: Boolean(pendingDefinition),- });- if (!cancelDialog()) return;- router.push(- `/project/${projectId}/dashboards/${encodeURIComponent(existingClone.id)}`,- );- }}- >- <ExternalLinkIcon- size="base"- color="default"- __rawClassName="mr-1"- />- Open it instead- </Button>- </div>- )}- </div>- </DialogBody>- <DialogFooter>- <div className="flex gap-2">- <Button- onClick={handleClose}- variant="outline"- type="button"- disabled={cloneDashboard.isPending}- >- Cancel- </Button>- <Button- onClick={handleConfirm}- type="button"- loading={cloneDashboard.isPending}- >- Create my copy- </Button>- </div>- </DialogFooter>- </>+ <CloneDashboardDialog+ dashboardName={dashboardName}+ setAsHome={setAsHome}+ hasPendingChange={Boolean(pendingDefinition)}+ existingCloneName={existingClone?.name}+ isPending={cloneDashboard.isPending}+ onConfirm={handleConfirm}+ onOpenExisting={() => {+ if (!existingClone) return;+ capture("dashboard:clone_open_existing_click", {+ dashboard_id: dashboardId,+ existing_clone_id: existingClone.id,+ had_pending_change: Boolean(pendingDefinition),+ });+ if (!cancelDialog()) return;+ router.push(+ `/project/${projectId}/dashboards/${encodeURIComponent(existingClone.id)}`,+ );+ }}+ />);}diff --git a/web/src/features/dashboard/components/DashboardTable/ConnectedDashboardTable.tsx b/web/src/features/dashboard/components/DashboardTable/ConnectedDashboardTable.tsxindex 3f6df02d93..b88c79b166 100644--- a/web/src/features/dashboard/components/DashboardTable/ConnectedDashboardTable.tsx+++ b/web/src/features/dashboard/components/DashboardTable/ConnectedDashboardTable.tsx@@ -10,7 +10,7 @@ import { safeExtract } from "@/src/utils/map-utils";import { useDetailPageLists } from "@/src/features/navigate-detail-pages";import { usePostHogClientCapture } from "@/src/features/posthog-analytics";import { EditDialogDashboardContent } from "@/src/features/dashboard/components/EditDialogDashboardContent";-import { CloneFirstDialogController } from "@/src/features/dashboard/components/CloneFirstDialogController";+import { ConnectedCloneDashboardDialogController } from "@/src/features/dashboard/components/ConnectedCloneDashboardDialogController";import { useRouter } from "next/router";import { DialogController } from "@/src/components/ui/dialog";import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";@@ -134,11 +134,7 @@ export function ConnectedDashboardTable() {}, [dashboardData, dashboardError, dashboardStatus]);return (- <CloneFirstDialogController- projectId={projectId}- dashboardId={selectedDashboard?.id ?? ""}- dashboardName={selectedDashboard?.name ?? "Dashboard"}- >+ <ConnectedCloneDashboardDialogController>{({ openDialog: openCloneFirstDialog }) => (<DialogControllercloseOnInteractionOutside={false}@@ -190,7 +186,11 @@ export function ConnectedDashboardTable() {attempt: "list_edit",surface: "list",});- openCloneFirstDialog();+ openCloneFirstDialog({+ projectId,+ dashboardId: dashboard.id,+ dashboardName: dashboard.name,+ });}}onClone={(dashboard) => {cloneDashboard.mutate(@@ -235,6 +235,6 @@ export function ConnectedDashboardTable() {)}</DialogController>)}- </CloneFirstDialogController>+ </ConnectedCloneDashboardDialogController>);}