Skip to content

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

fix(web): Move dialogs outside table dropdowns (#16969)

Ben Bachem4d134f24af77
diff --git a/web/src/components/deleteButton.tsx b/web/src/components/deleteButton.tsx
index 9a66b534ae..dd0d06d178 100644
--- a/web/src/components/deleteButton.tsx
+++ b/web/src/components/deleteButton.tsx
@@ -312,49 +312,6 @@ export function DeleteDatasetButton(props: DeleteButtonProps) {
);
}
-export function DeleteDashboardButton(props: DeleteButtonProps) {
- const utils = api.useUtils();
- const {
- itemId,
- projectId,
- scope = "dashboards:CUD",
- invalidateFunc = () => utils.dashboard.invalidate(),
- } = props;
- const dashboardMutation = api.dashboard.delete.useMutation();
- const executeDeleteMutation = async (onSuccess: () => void) => {
- try {
- await dashboardMutation.mutateAsync({
- dashboardId: itemId,
- projectId,
- });
- } catch (error) {
- return Promise.reject(error);
- }
- showSuccessToast({
- title: "Dashboard deleted",
- description: "The dashboard has been deleted successfully",
- });
- onSuccess();
- };
-
- return (
- <DeleteButton
- {...props}
- scope={scope}
- invalidateFunc={invalidateFunc}
- captureDeleteOpen={(capture) =>
- capture("dashboard:delete_dashboard_form_open")
- }
- captureDeleteSuccess={(capture) =>
- capture("dashboard:delete_dashboard_button_click")
- }
- entityToDeleteName="dashboard"
- executeDeleteMutation={executeDeleteMutation}
- isDeleteMutationLoading={dashboardMutation.isPending}
- />
- );
-}
-
/** DeleteMonitorButton deletes a monitor through the shared confirm-then-delete pattern. */
export function DeleteMonitorButton(props: DeleteButtonProps) {
const utils = api.useUtils();
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index be6bab58eb..3f23267ca8 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -21,13 +21,7 @@ import { api } from "@/src/utils/api";
import { formatIntervalSeconds } from "@/src/utils/dates";
import { type RouterOutput } from "@/src/utils/types";
import { type RowSelectionState } from "@tanstack/react-table";
-import React, {
- useCallback,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { usePaginationState } from "@/src/hooks/usePaginationState";
import type Decimal from "decimal.js";
import {
@@ -35,7 +29,6 @@ import {
numberFormatter,
usdFormatter,
} from "@/src/utils/numbers";
-import { DeleteTraceButton } from "@/src/components/deleteButton";
import {
formatAsLabel,
LevelSymbols,
@@ -68,7 +61,7 @@ import { joinTableCoreAndMetrics } from "@/src/components/table/utils/joinTableC
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
import { BatchExportTableButton } from "@/src/components/BatchExportTableButton";
import { BreakdownTooltip } from "@/src/features/traces/components/BreakdownTooltip";
-import { InfoIcon } from "lucide-react";
+import { InfoIcon, Trash2 } from "lucide-react";
import { useHasEntitlement } from "@/src/features/entitlements/hooks";
import { TableActionMenu } from "@/src/features/table/components/TableActionMenu";
import { useSelectAll } from "@/src/features/table/hooks/useSelectAll";
@@ -105,6 +98,10 @@ import { usePeekTableState } from "@/src/components/table/peek/contexts/PeekTabl
import { useScoreColumns } from "@/src/features/scores/hooks/useScoreColumns";
import { scoreFilters } from "@/src/features/scores/lib/scoreColumns";
import { AddTracesToAnnotationQueueDialogController } from "@/src/features/annotation-queues/components/AddTracesToAnnotationQueueDialogController";
+import { DialogController } from "@/src/components/ui/dialog";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { DeleteTraceDialogContent } from "@/src/features/traces/components/DeleteTraceDialogContent";
export type TracesTableRow = {
// Shown by default
@@ -164,7 +161,7 @@ export type TracesTableProps = {
showControlsInPageHeader?: boolean;
};
-export default function TracesTable({
+function TracesTableInternal({
projectId,
userId,
omittedFilter = [],
@@ -173,8 +170,15 @@ export default function TracesTable({
externalDateRange,
limitRows,
showControlsInPageHeader = false,
-}: TracesTableProps) {
+ openDeleteTraceDialog,
+}: TracesTableProps & {
+ openDeleteTraceDialog: (traceId: string) => void;
+}) {
const peekContext = usePeekTableState();
+ const hasTraceDeleteAccess = useHasProjectAccess({
+ projectId,
+ scope: "traces:delete",
+ });
const tracesFilterConfig = useMemo(
() => getTraceFilterConfig(omittedFilter),
[omittedFilter],
@@ -1169,12 +1173,14 @@ export default function TracesTable({
isFixedPosition: true,
renderMenu: (traceId) =>
typeof traceId === "string" ? (
- <DropdownMenuItem asChild>
- <DeleteTraceButton
- itemId={traceId}
- projectId={projectId}
- isTableAction
- />
+ <DropdownMenuItem
+ disabled={
+ !hasTraceDeleteAccess || !hasTraceDeletionEntitlement
+ }
+ onSelect={() => openDeleteTraceDialog(traceId)}
+ >
+ <Trash2 className="mr-2 h-4 w-4" />
+ Delete
</DropdownMenuItem>
) : null,
}),
@@ -1529,3 +1535,37 @@ const TracesDynamicCell = ({
/>
);
};
+
+export default function TracesTable(props: TracesTableProps) {
+ const [traceIdToDelete, setTraceIdToDelete] = useState<string | null>(null);
+ const capture = usePostHogClientCapture();
+
+ return (
+ <DialogController
+ closeOnInteractionOutside
+ size="default"
+ renderContent={({ closeDialog }) =>
+ traceIdToDelete ? (
+ <DeleteTraceDialogContent
+ closeDialog={closeDialog}
+ projectId={props.projectId}
+ traceId={traceIdToDelete}
+ />
+ ) : null
+ }
+ >
+ {({ openDialog }) => (
+ <TracesTableInternal
+ {...props}
+ openDeleteTraceDialog={(traceId) => {
+ capture("trace:delete_form_open", {
+ source: "table-single-row",
+ });
+ setTraceIdToDelete(traceId);
+ openDialog();
+ }}
+ />
+ )}
+ </DialogController>
+ );
+}
diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx
index 41887c8bfc..6820c38334 100644
--- a/web/src/components/ui/dialog.tsx
+++ b/web/src/components/ui/dialog.tsx
@@ -184,6 +184,8 @@ type DialogControllerProps = {
Trigger: typeof DialogTrigger;
}) => React.ReactNode;
closeOnInteractionOutside: boolean;
+ onBeforeClose?: () => boolean;
+ onDismiss?: () => void;
renderContent: (control: { closeDialog: () => void }) => React.ReactNode;
size: React.ComponentProps<typeof DialogContent>["size"];
};
@@ -191,13 +193,29 @@ type DialogControllerProps = {
const DialogController = ({
children,
closeOnInteractionOutside,
+ onBeforeClose,
+ onDismiss,
renderContent,
size,
}: DialogControllerProps) => {
const [isOpen, setIsOpen] = React.useState(false);
+ const closeDialog = () => {
+ if (onBeforeClose?.() === false) return false;
+ setIsOpen(false);
+ return true;
+ };
return (
- <Dialog open={isOpen} onOpenChange={setIsOpen}>
+ <Dialog
+ open={isOpen}
+ onOpenChange={(open) => {
+ if (open) {
+ setIsOpen(true);
+ return;
+ }
+ if (closeDialog()) onDismiss?.();
+ }}
+ >
{children({
isOpen,
openDialog: () => setIsOpen(true),
@@ -207,7 +225,7 @@ const DialogController = ({
size={size}
closeOnInteractionOutside={closeOnInteractionOutside}
>
- {renderContent({ closeDialog: () => setIsOpen(false) })}
+ {renderContent({ closeDialog })}
</DialogContent>
</Dialog>
);
diff --git a/web/src/features/dashboard/components/CloneFirstDialog.tsx b/web/src/features/dashboard/components/CloneFirstDialog.tsx
deleted file mode 100644
index 297ee4721d..0000000000
--- a/web/src/features/dashboard/components/CloneFirstDialog.tsx
+++ /dev/null
@@ -1,205 +0,0 @@
-import React, { useMemo } from "react";
-import { useRouter } from "next/router";
-import { ExternalLinkIcon } from "lucide-react";
-import { api } from "@/src/utils/api";
-import {
- Dialog,
- DialogContent,
- DialogHeader,
- DialogTitle,
- DialogFooter,
- DialogBody,
-} from "@/src/components/ui/dialog";
-import { Button } from "@/src/components/ui/button";
-import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
-import { showErrorToast } from "@/src/features/notifications/showErrorToast";
-import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
-import { type DashboardPlacement } from "@/src/features/widgets/components/DashboardGrid";
-
-/**
- * Clone-first flow for Langfuse-managed (read-only) dashboards: any edit
- * attempt routes here instead of being blocked. Confirming clones the
- * dashboard into the project (optionally carrying the attempted change via
- * `pendingDefinition` and setting the clone as the project's Home) and
- * navigates to the editable copy.
- */
-export function CloneFirstDialog({
- open,
- onOpenChange,
- projectId,
- dashboardId,
- dashboardName,
- setAsHome = false,
- pendingDefinition,
- onCancel,
-}: {
- open: boolean;
- onOpenChange: (open: boolean) => void;
- projectId: string;
- dashboardId: string;
- dashboardName: string;
- /** Set the clone as this project's Home dashboard in the same gesture. */
- setAsHome?: boolean;
- /** The attempted edit (e.g. moved/removed tile) to apply to the clone. */
- pendingDefinition?: { widgets: DashboardPlacement[] } | null;
- /** Called when the user dismisses without cloning (revert the attempt). */
- onCancel?: () => void;
-}) {
- const router = useRouter();
- const utils = api.useUtils();
- const capture = usePostHogClientCapture();
-
- // Detect existing copies of this dashboard so we can offer navigating to
- // one instead of accumulating "(Clone)" duplicates.
- const dashboards = api.dashboard.allDashboards.useQuery(
- {
- projectId,
- page: 1,
- limit: 500,
- orderBy: { column: "updatedAt", order: "DESC" },
- },
- { enabled: open },
- );
- const existingClone = useMemo(() => {
- const clonePattern = new RegExp(
- `^${dashboardName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")} \\(Clone( \\d+)?\\)$`,
- );
- return dashboards.data?.dashboards.find(
- (d) => d.owner === "PROJECT" && clonePattern.test(d.name),
- );
- }, [dashboards.data?.dashboards, dashboardName]);
-
- const cloneDashboard = api.dashboard.cloneDashboard.useMutation({
- onSuccess: (data) => {
- utils.dashboard.invalidate();
- capture("dashboard:clone_dashboard", {
- source: "clone_first_dialog",
- set_as_home: setAsHome,
- had_pending_change: Boolean(pendingDefinition),
- dashboardId,
- // The clone-first flow only exists for locked Langfuse-owned dashboards.
- owner: "LANGFUSE",
- });
- showSuccessToast({
- title: "Editable copy created",
- description: setAsHome
- ? "The copy is now this project's Home dashboard"
- : "You are now working on your own copy",
- duration: 3000,
- });
- onOpenChange(false);
- if (data?.id) {
- router.push(
- `/project/${projectId}/dashboards/${encodeURIComponent(data.id)}`,
- );
- }
- },
- onError: (e) => {
- showErrorToast("Failed to create copy", e.message);
- },
- });
-
- const handleConfirm = () => {
- cloneDashboard.mutate({
- projectId,
- dashboardId,
- definition: pendingDefinition ?? undefined,
- setAsHome,
- });
- };
-
- const handleOpenChange = (nextOpen: boolean) => {
- // Keep the dialog open while the clone is in flight (it navigates on
- // success); closing mid-flight would revert the grid and then surprise-
- // navigate.
- if (!nextOpen && cloneDashboard.isPending) return;
- if (!nextOpen) {
- capture("dashboard:clone_first_cancelled", {
- dashboard_id: dashboardId,
- had_pending_change: Boolean(pendingDefinition),
- });
- onCancel?.();
- }
- onOpenChange(nextOpen);
- };
-
- return (
- <Dialog open={open} onOpenChange={handleOpenChange}>
- <DialogContent className="sm:max-w-[500px]">
- <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">
- &ldquo;{dashboardName}&rdquo;
- </span>{" "}
- is maintained by Langfuse and can&rsquo;t be edited directly.
- We&rsquo;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">
- &ldquo;{existingClone.name}&rdquo;
- </span>
- {pendingDefinition
- ? " — opening it will discard your attempted change"
- : ""}
- </span>
- <Button
- variant="outline"
- size="sm"
- type="button"
- onClick={() => {
- capture("dashboard:clone_open_existing_click", {
- dashboard_id: dashboardId,
- existing_clone_id: existingClone.id,
- had_pending_change: Boolean(pendingDefinition),
- });
- onOpenChange(false);
- onCancel?.();
- router.push(
- `/project/${projectId}/dashboards/${encodeURIComponent(existingClone.id)}`,
- );
- }}
- >
- <ExternalLinkIcon size={14} className="mr-1" />
- Open it instead
- </Button>
- </div>
- )}
- </div>
- </DialogBody>
- <DialogFooter>
- <div className="flex gap-2">
- <Button
- onClick={() => handleOpenChange(false)}
- variant="outline"
- type="button"
- disabled={cloneDashboard.isPending}
- >
- Cancel
- </Button>
- <Button
- onClick={handleConfirm}
- type="button"
- loading={cloneDashboard.isPending}
- >
- Create my copy
- </Button>
- </div>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
-}
diff --git a/web/src/features/dashboard/components/CloneFirstDialogController.tsx b/web/src/features/dashboard/components/CloneFirstDialogController.tsx
new file mode 100644
index 0000000000..e1206bd1b8
--- /dev/null
+++ b/web/src/features/dashboard/components/CloneFirstDialogController.tsx
@@ -0,0 +1,245 @@
+import { type ReactNode, useMemo, useRef } from "react";
+import { useRouter } from "next/router";
+import { ExternalLinkIcon } from "lucide-react";
+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 { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
+import { showErrorToast } from "@/src/features/notifications/showErrorToast";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { type DashboardPlacement } from "@/src/features/widgets/components/DashboardGrid";
+
+/**
+ * Clone-first flow for Langfuse-managed (read-only) dashboards: any edit
+ * attempt routes here instead of being blocked. Confirming clones the
+ * dashboard into the project (optionally carrying the attempted change via
+ * `pendingDefinition` and setting the clone as the project's Home) and
+ * navigates to the editable copy.
+ */
+type CloneFirstDialogControllerProps = {
+ projectId: string;
+ dashboardId: string;
+ dashboardName: string;
+ /** Set the clone as this project's Home dashboard in the same gesture. */
+ setAsHome?: boolean;
+ /** The attempted edit (e.g. moved/removed tile) to apply to the clone. */
+ pendingDefinition?: { widgets: DashboardPlacement[] } | null;
+ /** Called when the user dismisses without cloning (revert the attempt). */
+ onCancel?: () => void;
+};
+
+export function CloneFirstDialogController({
+ children,
+ ...props
+}: CloneFirstDialogControllerProps & {
+ children: (control: { openDialog: () => 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?.();
+ };
+
+ return (
+ <DialogController
+ closeOnInteractionOutside={false}
+ onBeforeClose={() => !cloneInFlightRef.current}
+ onDismiss={handleCancel}
+ size="default"
+ renderContent={({ closeDialog }) => (
+ <CloneFirstDialogContent
+ {...props}
+ closeDialog={closeDialog}
+ cancelDialog={() => {
+ if (cloneInFlightRef.current) return false;
+ closeDialog();
+ handleCancel();
+ return true;
+ }}
+ onPendingChange={(isPending) => {
+ cloneInFlightRef.current = isPending;
+ }}
+ />
+ )}
+ >
+ {({ openDialog }) => children({ openDialog })}
+ </DialogController>
+ );
+}
+
+function CloneFirstDialogContent({
+ closeDialog,
+ cancelDialog,
+ onPendingChange,
+ projectId,
+ dashboardId,
+ dashboardName,
+ setAsHome = false,
+ pendingDefinition,
+}: Omit<CloneFirstDialogControllerProps, "onCancel"> & {
+ closeDialog: () => void;
+ cancelDialog: () => boolean;
+ onPendingChange: (isPending: boolean) => void;
+}) {
+ const router = useRouter();
+ const utils = api.useUtils();
+ const capture = usePostHogClientCapture();
+
+ // Detect existing copies of this dashboard so we can offer navigating to
+ // one instead of accumulating "(Clone)" duplicates.
+ const dashboards = api.dashboard.allDashboards.useQuery(
+ {
+ projectId,
+ page: 1,
+ limit: 500,
+ orderBy: { column: "updatedAt", order: "DESC" },
+ },
+ { enabled: true },
+ );
+ const existingClone = useMemo(() => {
+ const cloneName = `${dashboardName} (Clone)`;
+ const numberedClonePrefix = `${dashboardName} (Clone `;
+ return dashboards.data?.dashboards.find((dashboard) => {
+ if (dashboard.owner !== "PROJECT") return false;
+ if (dashboard.name === cloneName) return true;
+ if (!dashboard.name.startsWith(numberedClonePrefix)) return false;
+ if (!dashboard.name.endsWith(")")) return false;
+
+ const cloneNumber = dashboard.name.slice(numberedClonePrefix.length, -1);
+ return /^\d+$/.test(cloneNumber);
+ });
+ }, [dashboards.data?.dashboards, dashboardName]);
+
+ const cloneDashboard = api.dashboard.cloneDashboard.useMutation({
+ onSuccess: (data) => {
+ onPendingChange(false);
+ utils.dashboard.invalidate();
+ capture("dashboard:clone_dashboard", {
+ source: "clone_first_dialog",
+ set_as_home: setAsHome,
+ had_pending_change: Boolean(pendingDefinition),
+ dashboardId,
+ // The clone-first flow only exists for locked Langfuse-owned dashboards.
+ owner: "LANGFUSE",
+ });
+ showSuccessToast({
+ title: "Editable copy created",
+ description: setAsHome
+ ? "The copy is now this project's Home dashboard"
+ : "You are now working on your own copy",
+ duration: 3000,
+ });
+ closeDialog();
+ if (data?.id) {
+ router.push(
+ `/project/${projectId}/dashboards/${encodeURIComponent(data.id)}`,
+ );
+ }
+ },
+ onError: (e) => {
+ onPendingChange(false);
+ showErrorToast("Failed to create copy", e.message);
+ },
+ });
+
+ const handleConfirm = () => {
+ onPendingChange(true);
+ cloneDashboard.mutate({
+ projectId,
+ dashboardId,
+ definition: pendingDefinition ?? undefined,
+ setAsHome,
+ });
+ };
+
+ 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">
+ &ldquo;{dashboardName}&rdquo;
+ </span>{" "}
+ is maintained by Langfuse and can&rsquo;t be edited directly.
+ We&rsquo;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">
+ &ldquo;{existingClone.name}&rdquo;
+ </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={14} className="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>
+ </>
+ );
+}
diff --git a/web/src/features/dashboard/components/DashboardTable.tsx b/web/src/features/dashboard/components/DashboardTable.tsx
index a8c4a24f9e..8213f39b0f 100644
--- a/web/src/features/dashboard/components/DashboardTable.tsx
+++ b/web/src/features/dashboard/components/DashboardTable.tsx
@@ -13,16 +13,16 @@ import { createDropdownTableColumn } from "@/src/components/design-system/table/
import { createLinkTableColumn } from "@/src/components/design-system/table/columns/createLinkTableColumn";
import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";
import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context";
-import { Button } from "@/src/components/ui/button";
-import { Copy, Edit, User as UserIcon } from "lucide-react";
+import { Copy, Edit, Trash2, User as UserIcon } from "lucide-react";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { showErrorToast } from "@/src/features/notifications/showErrorToast";
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
import { DropdownMenuItem } from "@/src/components/ui/dropdown-menu";
-import { DeleteDashboardButton } from "@/src/components/deleteButton";
-import { EditDashboardDialog } from "@/src/features/dashboard/components/EditDashboardDialog";
-import { CloneFirstDialog } from "@/src/features/dashboard/components/CloneFirstDialog";
+import { DeleteDialogDashboardContent } from "@/src/features/dashboard/components/DeleteDialogDashboardContent";
+import { EditDialogDashboardContent } from "@/src/features/dashboard/components/EditDialogDashboardContent";
+import { CloneFirstDialogController } from "@/src/features/dashboard/components/CloneFirstDialogController";
import { useRouter } from "next/router";
+import { DialogController } from "@/src/components/ui/dialog";
type DashboardTableRow = {
id: string;
@@ -33,156 +33,28 @@ type DashboardTableRow = {
owner: "PROJECT" | "LANGFUSE";
};
-const dashboardMenuButtonWrapperClassName = "w-full";
-const dashboardMenuButtonClassName = "w-full justify-start";
-
-function CloneDashboardButton({
- dashboardId,
- projectId,
- owner,
-}: {
- dashboardId: string;
- projectId: string;
- owner: DashboardTableRow["owner"];
-}) {
+export function DashboardTable() {
+ const projectId = useProjectIdFromURL() as string;
+ const { setDetailPageList } = useDetailPageLists();
+ const router = useRouter();
const utils = api.useUtils();
- const hasAccess = useHasProjectAccess({ projectId, scope: "dashboards:CUD" });
const capture = usePostHogClientCapture();
-
- const mutCloneDashboard = api.dashboard.cloneDashboard.useMutation({
+ const hasAccess = useHasProjectAccess({ projectId, scope: "dashboards:CUD" });
+ const [selectedDashboard, setSelectedDashboard] =
+ useState<DashboardTableRow | null>(null);
+ const cloneDashboard = api.dashboard.cloneDashboard.useMutation({
onSuccess: () => {
utils.dashboard.invalidate();
- capture("dashboard:clone_dashboard", {
- source: "list_clone_button",
- dashboardId,
- owner,
- });
showSuccessToast({
title: "Dashboard cloned",
description: "The dashboard has been cloned successfully",
});
},
- onError: (e) => {
- showErrorToast("Failed to clone dashboard", e.message);
+ onError: (error) => {
+ showErrorToast("Failed to clone dashboard", error.message);
},
});
- const handleCloneDashboard = () => {
- if (!projectId) {
- console.error("Project ID is missing");
- return;
- }
-
- mutCloneDashboard.mutateAsync({
- projectId,
- dashboardId,
- });
- };
-
- return (
- <div className={dashboardMenuButtonWrapperClassName}>
- <Button
- variant="ghost"
- size="default"
- className={dashboardMenuButtonClassName}
- disabled={!hasAccess}
- onClick={handleCloneDashboard}
- >
- <Copy className="mr-2 h-4 w-4" />
- Clone
- </Button>
- </div>
- );
-}
-
-function EditDashboardButton({
- dashboardId,
- projectId,
- dashboardName,
- dashboardDescription,
-}: {
- dashboardId: string;
- projectId: string;
- dashboardName: string;
- dashboardDescription: string;
-}) {
- const [isDialogOpen, setIsDialogOpen] = useState(false);
- const hasAccess = useHasProjectAccess({ projectId, scope: "dashboards:CUD" });
-
- return (
- <div className={dashboardMenuButtonWrapperClassName}>
- <Button
- variant="ghost"
- size="default"
- className={dashboardMenuButtonClassName}
- disabled={!hasAccess}
- onClick={() => setIsDialogOpen(true)}
- >
- <Edit className="mr-2 h-4 w-4" />
- Edit
- </Button>
-
- <EditDashboardDialog
- open={isDialogOpen}
- onOpenChange={setIsDialogOpen}
- projectId={projectId}
- dashboardId={dashboardId}
- initialName={dashboardName}
- initialDescription={dashboardDescription}
- />
- </div>
- );
-}
-
-function LockedEditDashboardButton({
- dashboardId,
- projectId,
- dashboardName,
-}: {
- dashboardId: string;
- projectId: string;
- dashboardName: string;
-}) {
- const [isDialogOpen, setIsDialogOpen] = useState(false);
- const hasAccess = useHasProjectAccess({ projectId, scope: "dashboards:CUD" });
- const capture = usePostHogClientCapture();
-
- return (
- <div className={dashboardMenuButtonWrapperClassName}>
- <Button
- variant="ghost"
- size="default"
- className={dashboardMenuButtonClassName}
- disabled={!hasAccess}
- onClick={() => {
- capture("dashboard:locked_edit_attempt", {
- dashboard_id: dashboardId,
- attempt: "list_edit",
- surface: "list",
- });
- setIsDialogOpen(true);
- }}
- >
- <Edit className="mr-2 h-4 w-4" />
- Edit
- </Button>
-
- <CloneFirstDialog
- open={isDialogOpen}
- onOpenChange={setIsDialogOpen}
- projectId={projectId}
- dashboardId={dashboardId}
- dashboardName={dashboardName}
- />
- </div>
- );
-}
-
-export function DashboardTable() {
- const projectId = useProjectIdFromURL() as string;
- const { setDetailPageList } = useDetailPageLists();
- const router = useRouter();
-
const [orderByState, setOrderByState] = useOrderByState({
column: "updatedAt",
order: "DESC",
@@ -276,96 +148,162 @@ export function DashboardTable() {
enableSorting: true,
size: 150,
}),
- createDropdownTableColumn<DashboardTableRow, string>({
- id: "actions",
- accessorFn: (row) => row.id,
- header: "Actions",
- size: 70,
- renderMenu: (id, { row }) => {
- if (!id) return null;
- const { name, description, owner } = row.original;
- return (
- <>
- {owner === "PROJECT" ? (
- <DropdownMenuItem className="w-full p-0">
- <EditDashboardButton
- dashboardId={id}
- projectId={projectId}
- dashboardName={name}
- dashboardDescription={description}
- />
- </DropdownMenuItem>
- ) : (
- <DropdownMenuItem className="w-full p-0">
- <LockedEditDashboardButton
- dashboardId={id}
- projectId={projectId}
- dashboardName={name}
- />
- </DropdownMenuItem>
- )}
- <DropdownMenuItem className="w-full p-0">
- <CloneDashboardButton
- dashboardId={id}
+ ] as LangfuseColumnDef<DashboardTableRow>[];
+
+ return (
+ <CloneFirstDialogController
+ projectId={projectId}
+ dashboardId={selectedDashboard?.id ?? ""}
+ dashboardName={selectedDashboard?.name ?? "Dashboard"}
+ >
+ {({ openDialog: openCloneFirstDialog }) => (
+ <DialogController
+ closeOnInteractionOutside={false}
+ size="default"
+ renderContent={({ closeDialog }) =>
+ selectedDashboard ? (
+ <EditDialogDashboardContent
+ closeDialog={closeDialog}
projectId={projectId}
- owner={owner}
+ dashboardId={selectedDashboard.id}
+ initialName={selectedDashboard.name}
+ initialDescription={selectedDashboard.description}
/>
- </DropdownMenuItem>
- {owner === "PROJECT" ? (
- <DropdownMenuItem
- className="w-full p-0"
- onSelect={(event) => {
- event.preventDefault();
- }}
- >
- <div className={dashboardMenuButtonWrapperClassName}>
- <DeleteDashboardButton
- itemId={id}
+ ) : null
+ }
+ >
+ {({ openDialog: openEditDialog }) => (
+ <DialogController
+ closeOnInteractionOutside={false}
+ size="default"
+ renderContent={({ closeDialog }) =>
+ selectedDashboard ? (
+ <DeleteDialogDashboardContent
+ closeDialog={closeDialog}
projectId={projectId}
- isTableAction
- className={dashboardMenuButtonClassName}
+ dashboardId={selectedDashboard.id}
/>
- </div>
- </DropdownMenuItem>
- ) : null}
- </>
- );
- },
- }),
- ] as LangfuseColumnDef<DashboardTableRow>[];
-
- return (
- <DataTable
- tableName="dashboards"
- columns={dashboardColumns}
- data={
- dashboards.isPending
- ? { isLoading: true, isError: false }
- : dashboards.isError
- ? {
- isLoading: false,
- isError: true,
- error: dashboards.error.message,
- }
- : {
- isLoading: false,
- isError: false,
- data: safeExtract(dashboards.data, "dashboards", []),
+ ) : null
}
- }
- orderBy={orderByState}
- setOrderBy={setOrderByState}
- pagination={{
- totalCount: dashboards.data?.totalCount ?? null,
- onChange: setPaginationState,
- state: paginationState,
- }}
- onRowClick={(row) => {
- router.push(
- `/project/${projectId}/dashboards/${encodeURIComponent(row.id)}`,
- );
- }}
- cellPadding="comfortable"
- />
+ >
+ {({ openDialog: openDeleteDialog }) => (
+ <DataTable
+ tableName="dashboards"
+ columns={[
+ ...dashboardColumns,
+ createDropdownTableColumn<DashboardTableRow, string>({
+ id: "actions",
+ accessorFn: (row) => row.id,
+ header: "Actions",
+ size: 70,
+ renderMenu: (id, { row }) => {
+ if (!id) return null;
+ const dashboard = row.original;
+
+ return (
+ <>
+ <DropdownMenuItem
+ disabled={!hasAccess}
+ onSelect={() => {
+ setSelectedDashboard(dashboard);
+ if (dashboard.owner === "PROJECT") {
+ openEditDialog();
+ return;
+ }
+
+ capture("dashboard:locked_edit_attempt", {
+ dashboard_id: dashboard.id,
+ attempt: "list_edit",
+ surface: "list",
+ });
+ openCloneFirstDialog();
+ }}
+ >
+ <Edit className="mr-2 h-4 w-4" />
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ disabled={!hasAccess}
+ onSelect={() => {
+ cloneDashboard.mutate(
+ {
+ projectId,
+ dashboardId: dashboard.id,
+ },
+ {
+ onSuccess: () => {
+ capture("dashboard:clone_dashboard", {
+ source: "list_clone_button",
+ dashboardId: dashboard.id,
+ owner: dashboard.owner,
+ });
+ },
+ },
+ );
+ }}
+ >
+ <Copy className="mr-2 h-4 w-4" />
+ Clone
+ </DropdownMenuItem>
+ {dashboard.owner === "PROJECT" ? (
+ <DropdownMenuItem
+ className="text-destructive"
+ disabled={!hasAccess}
+ onSelect={() => {
+ setSelectedDashboard(dashboard);
+ capture(
+ "dashboard:delete_dashboard_form_open",
+ );
+ openDeleteDialog();
+ }}
+ >
+ <Trash2 className="mr-2 h-4 w-4" />
+ Delete
+ </DropdownMenuItem>
+ ) : null}
+ </>
+ );
+ },
+ }),
+ ]}
+ data={
+ dashboards.isPending
+ ? { isLoading: true, isError: false }
+ : dashboards.isError
+ ? {
+ isLoading: false,
+ isError: true,
+ error: dashboards.error.message,
+ }
+ : {
+ isLoading: false,
+ isError: false,
+ data: safeExtract(
+ dashboards.data,
+ "dashboards",
+ [],
+ ),
+ }
+ }
+ orderBy={orderByState}
+ setOrderBy={setOrderByState}
+ pagination={{
+ totalCount: dashboards.data?.totalCount ?? null,
+ onChange: setPaginationState,
+ state: paginationState,
+ }}
+ onRowClick={(row) => {
+ router.push(
+ `/project/${projectId}/dashboards/${encodeURIComponent(row.id)}`,
+ );
+ }}
+ cellPadding="comfortable"
+ />
+ )}
+ </DialogController>
+ )}
+ </DialogController>
+ )}
+ </CloneFirstDialogController>
);
}
diff --git a/web/src/features/dashboard/components/DeleteDialogDashboardContent.tsx b/web/src/features/dashboard/components/DeleteDialogDashboardContent.tsx
new file mode 100644
index 0000000000..df027cdb75
--- /dev/null
+++ b/web/src/features/dashboard/components/DeleteDialogDashboardContent.tsx
@@ -0,0 +1,65 @@
+import { Button } from "@/src/components/ui/button";
+import {
+ DialogBody,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/src/components/ui/dialog";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { showErrorToast } from "@/src/features/notifications/showErrorToast";
+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
+import { api } from "@/src/utils/api";
+
+export function DeleteDialogDashboardContent({
+ closeDialog,
+ projectId,
+ dashboardId,
+}: {
+ closeDialog: () => void;
+ projectId: string;
+ dashboardId: string;
+}) {
+ const capture = usePostHogClientCapture();
+ const utils = api.useUtils();
+ const deleteDashboard = api.dashboard.delete.useMutation({
+ onSuccess: () => {
+ capture("dashboard:delete_dashboard_button_click");
+ showSuccessToast({
+ title: "Dashboard deleted",
+ description: "The dashboard has been deleted successfully",
+ });
+ utils.dashboard.invalidate();
+ closeDialog();
+ },
+ onError: (error) => {
+ showErrorToast("Failed to delete dashboard", error.message);
+ },
+ });
+
+ return (
+ <>
+ <DialogHeader>
+ <DialogTitle>Delete dashboard</DialogTitle>
+ </DialogHeader>
+ <DialogBody>
+ <p className="text-muted-foreground py-4 text-sm">
+ This action cannot be undone. It permanently deletes this dashboard.
+ </p>
+ </DialogBody>
+ <DialogFooter>
+ <div className="flex gap-2">
+ <Button variant="outline" onClick={closeDialog}>
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ loading={deleteDashboard.isPending}
+ onClick={() => deleteDashboard.mutate({ projectId, dashboardId })}
+ >
+ Delete dashboard
+ </Button>
+ </div>
+ </DialogFooter>
+ </>
+ );
+}
diff --git a/web/src/features/dashboard/components/EditDashboardDialog.tsx b/web/src/features/dashboard/components/EditDashboardDialog.tsx
deleted file mode 100644
index 71efa3e38e..0000000000
--- a/web/src/features/dashboard/components/EditDashboardDialog.tsx
+++ /dev/null
@@ -1,112 +0,0 @@
-import React, { useState } from "react";
-import { api } from "@/src/utils/api";
-import {
- Dialog,
- DialogContent,
- DialogHeader,
- DialogTitle,
- DialogFooter,
- DialogBody,
-} from "@/src/components/ui/dialog";
-import { Button } from "@/src/components/ui/button";
-import { Input } from "@/src/components/ui/input";
-import { Label } from "@/src/components/ui/label";
-import { Textarea } from "@/src/components/ui/textarea";
-import { showErrorToast } from "@/src/features/notifications/showErrorToast";
-
-interface EditDashboardDialogProps {
- open: boolean;
- onOpenChange: (open: boolean) => void;
- projectId: string;
- dashboardId: string;
- initialName: string;
- initialDescription: string;
-}
-
-export function EditDashboardDialog({
- open,
- onOpenChange,
- projectId,
- dashboardId,
- initialName,
- initialDescription,
-}: EditDashboardDialogProps) {
- const [name, setName] = useState(initialName);
- const [description, setDescription] = useState(initialDescription);
- const utils = api.useUtils();
-
- const updateDashboard = api.dashboard.updateDashboardMetadata.useMutation({
- onSuccess: () => {
- utils.dashboard.invalidate();
- onOpenChange(false);
- },
- onError: (e) => {
- showErrorToast("Failed to update dashboard", e.message);
- },
- });
-
- const handleSave = () => {
- if (!name.trim()) {
- showErrorToast("Validation error", "Dashboard name is required");
- return;
- }
-
- updateDashboard.mutate({
- projectId,
- dashboardId,
- name: name.trim(),
- description: description.trim(),
- });
- };
-
- return (
- <Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="sm:max-w-[500px]">
- <DialogHeader>
- <DialogTitle>Edit Dashboard</DialogTitle>
- </DialogHeader>
- <DialogBody>
- <div className="grid gap-4 py-4">
- <div className="grid gap-2">
- <Label htmlFor="name">Name</Label>
- <Input
- id="name"
- value={name}
- onChange={(e) => setName(e.target.value)}
- placeholder="Dashboard name"
- />
- </div>
- <div className="grid gap-2">
- <Label htmlFor="description">Description</Label>
- <Textarea
- id="description"
- value={description}
- onChange={(e) => setDescription(e.target.value)}
- placeholder="Dashboard description"
- rows={3}
- />
- </div>
- </div>
- </DialogBody>
- <DialogFooter>
- <div className="flex gap-2">
- <Button
- onClick={() => onOpenChange(false)}
- variant="outline"
- type="button"
- >
- Cancel
- </Button>
- <Button
- onClick={handleSave}
- type="button"
- loading={updateDashboard.isPending}
- >
- Save Changes
- </Button>
- </div>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
-}
diff --git a/web/src/features/dashboard/components/EditDialogDashboardContent.tsx b/web/src/features/dashboard/components/EditDialogDashboardContent.tsx
new file mode 100644
index 0000000000..19ed24e12f
--- /dev/null
+++ b/web/src/features/dashboard/components/EditDialogDashboardContent.tsx
@@ -0,0 +1,102 @@
+import React, { useState } from "react";
+import { api } from "@/src/utils/api";
+import {
+ DialogHeader,
+ DialogTitle,
+ DialogFooter,
+ DialogBody,
+} from "@/src/components/ui/dialog";
+import { Button } from "@/src/components/ui/button";
+import { Input } from "@/src/components/ui/input";
+import { Label } from "@/src/components/ui/label";
+import { Textarea } from "@/src/components/ui/textarea";
+import { showErrorToast } from "@/src/features/notifications/showErrorToast";
+
+interface EditDialogDashboardContentProps {
+ closeDialog: () => void;
+ projectId: string;
+ dashboardId: string;
+ initialName: string;
+ initialDescription: string;
+}
+
+export function EditDialogDashboardContent({
+ closeDialog,
+ projectId,
+ dashboardId,
+ initialName,
+ initialDescription,
+}: EditDialogDashboardContentProps) {
+ const [name, setName] = useState(initialName);
+ const [description, setDescription] = useState(initialDescription);
+ const utils = api.useUtils();
+
+ const updateDashboard = api.dashboard.updateDashboardMetadata.useMutation({
+ onSuccess: () => {
+ utils.dashboard.invalidate();
+ closeDialog();
+ },
+ onError: (e) => {
+ showErrorToast("Failed to update dashboard", e.message);
+ },
+ });
+
+ const handleSave = () => {
+ if (!name.trim()) {
+ showErrorToast("Validation error", "Dashboard name is required");
+ return;
+ }
+
+ updateDashboard.mutate({
+ projectId,
+ dashboardId,
+ name: name.trim(),
+ description: description.trim(),
+ });
+ };
+
+ return (
+ <>
+ <DialogHeader>
+ <DialogTitle>Edit Dashboard</DialogTitle>
+ </DialogHeader>
+ <DialogBody>
+ <div className="grid gap-4 py-4">
+ <div className="grid gap-2">
+ <Label htmlFor="name">Name</Label>
+ <Input
+ id="name"
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ placeholder="Dashboard name"
+ />
+ </div>
+ <div className="grid gap-2">
+ <Label htmlFor="description">Description</Label>
+ <Textarea
+ id="description"
+ value={description}
+ onChange={(e) => setDescription(e.target.value)}
+ placeholder="Dashboard description"
+ rows={3}
+ />
+ </div>
+ </div>
+ </DialogBody>
+ <DialogFooter>
+ <div className="flex gap-2">
+ <Button onClick={closeDialog} variant="outline" type="button">
+ Cancel
+ </Button>
+ <Button
+ onClick={handleSave}
+ type="button"
+ loading={updateDashboard.isPending}
+ >
+ Save Changes
+ </Button>
+ </div>
+ </DialogFooter>
+ </>
+ );
+}
diff --git a/web/src/features/datasets/components/DatasetRunsTable.tsx b/web/src/features/datasets/components/DatasetRunsTable.tsx
index e61a541ad0..1a699a4d7d 100644
--- a/web/src/features/datasets/components/DatasetRunsTable.tsx
+++ b/web/src/features/datasets/components/DatasetRunsTable.tsx
@@ -29,7 +29,6 @@ import {
DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
import { Button } from "@/src/components/ui/button";
-import { DeleteDatasetRunButton } from "@/src/features/datasets/components/DeleteDatasetRunButton";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
import { Checkbox } from "@/src/components/design-system/Checkbox/Checkbox";
import { type RowSelectionState } from "@tanstack/react-table";
@@ -53,6 +52,7 @@ import { createTextTableColumn } from "@/src/components/design-system/table/colu
import {
Dialog,
DialogContent,
+ DialogController,
DialogDescription,
DialogFooter,
DialogHeader,
@@ -72,8 +72,10 @@ import {
} from "@/src/features/scores/lib/scoreColumns";
import { getScoreLabelFromKey } from "@/src/features/scores/lib/aggregateScores";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import { DeleteDatasetRunDialogContent } from "@/src/features/datasets/components/DeleteDatasetRunDialogContent";
-export type DatasetRunRowData = {
+type DatasetRunRowData = {
id: string;
name: string;
createdAt: Date;
@@ -187,17 +189,27 @@ const DatasetRunTableMultiSelectAction = ({
);
};
-export function DatasetRunsTable(props: {
+type DatasetRunsTableProps = {
projectId: string;
datasetId: string;
selectedMetrics: string[];
setScoreOptions: (options: { key: string; value: string }[]) => void;
-}) {
+};
+
+function DatasetRunsTableInternal(
+ props: DatasetRunsTableProps & {
+ openDeleteDatasetRunDialog: (datasetRunId: string) => void;
+ },
+) {
const [paginationState, setPaginationState] = useQueryParams({
pageIndex: withDefault(NumberParam, 0),
pageSize: withDefault(NumberParam, 50),
});
const [selectedRows, setSelectedRows] = useState<RowSelectionState>({});
+ const hasDeleteAccess = useHasProjectAccess({
+ projectId: props.projectId,
+ scope: "datasets:CUD",
+ });
const [userFilterState, setUserFilterState] = useQueryFilterState(
[],
@@ -517,11 +529,13 @@ export function DatasetRunsTable(props: {
id ? (
<>
<DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DeleteDatasetRunButton
- projectId={props.projectId}
- datasetRunId={id}
- datasetId={props.datasetId}
- />
+ <DropdownMenuItem
+ disabled={!hasDeleteAccess}
+ onSelect={() => props.openDeleteDatasetRunDialog(id)}
+ >
+ <Trash className="mr-2 h-4 w-4" />
+ Delete
+ </DropdownMenuItem>
</>
) : null,
}),
@@ -799,3 +813,38 @@ export function DatasetRunsTable(props: {
</>
);
}
+
+export function DatasetRunsTable(props: DatasetRunsTableProps) {
+ const [datasetRunIdToDelete, setDatasetRunIdToDelete] = useState<
+ string | null
+ >(null);
+ const capture = usePostHogClientCapture();
+
+ return (
+ <DialogController
+ closeOnInteractionOutside
+ size="default"
+ renderContent={({ closeDialog }) =>
+ datasetRunIdToDelete ? (
+ <DeleteDatasetRunDialogContent
+ closeDialog={closeDialog}
+ projectId={props.projectId}
+ datasetId={props.datasetId}
+ datasetRunId={datasetRunIdToDelete}
+ />
+ ) : null
+ }
+ >
+ {({ openDialog }) => (
+ <DatasetRunsTableInternal
+ {...props}
+ openDeleteDatasetRunDialog={(datasetRunId) => {
+ capture("dataset_run:delete_form_open");
+ setDatasetRunIdToDelete(datasetRunId);
+ openDialog();
+ }}
+ />
+ )}
+ </DialogController>
+ );
+}
diff --git a/web/src/features/datasets/components/DeleteDatasetRunDialogContent.tsx b/web/src/features/datasets/components/DeleteDatasetRunDialogContent.tsx
new file mode 100644
index 0000000000..b6d790cd41
--- /dev/null
+++ b/web/src/features/datasets/components/DeleteDatasetRunDialogContent.tsx
@@ -0,0 +1,65 @@
+import { Button } from "@/src/components/ui/button";
+import {
+ DialogBody,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/src/components/ui/dialog";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { api } from "@/src/utils/api";
+
+export function DeleteDatasetRunDialogContent({
+ closeDialog,
+ projectId,
+ datasetId,
+ datasetRunId,
+}: {
+ closeDialog: () => void;
+ projectId: string;
+ datasetId: string;
+ datasetRunId: string;
+}) {
+ const capture = usePostHogClientCapture();
+ const utils = api.useUtils();
+ const deleteDatasetRun = api.datasets.deleteDatasetRuns.useMutation({
+ onSuccess: () => {
+ utils.datasets.invalidate();
+ closeDialog();
+ },
+ });
+
+ return (
+ <>
+ <DialogHeader>
+ <DialogTitle>Please confirm</DialogTitle>
+ </DialogHeader>
+ <DialogBody>
+ <p className="text-muted-foreground py-4 text-sm">
+ This action cannot be undone. Traces linked to this run must be
+ deleted manually.
+ </p>
+ </DialogBody>
+ <DialogFooter>
+ <div className="flex gap-2">
+ <Button variant="outline" onClick={closeDialog}>
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ loading={deleteDatasetRun.isPending}
+ onClick={() => {
+ capture("dataset_run:delete_form_submit");
+ deleteDatasetRun.mutate({
+ projectId,
+ datasetId,
+ datasetRunIds: [datasetRunId],
+ });
+ }}
+ >
+ Delete Dataset Run
+ </Button>
+ </div>
+ </DialogFooter>
+ </>
+ );
+}
diff --git a/web/src/features/traces/components/DeleteTraceDialogContent.tsx b/web/src/features/traces/components/DeleteTraceDialogContent.tsx
new file mode 100644
index 0000000000..e0157e3645
--- /dev/null
+++ b/web/src/features/traces/components/DeleteTraceDialogContent.tsx
@@ -0,0 +1,65 @@
+import { Button } from "@/src/components/ui/button";
+import {
+ DialogBody,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/src/components/ui/dialog";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
+import { api } from "@/src/utils/api";
+
+export function DeleteTraceDialogContent({
+ closeDialog,
+ projectId,
+ traceId,
+}: {
+ closeDialog: () => void;
+ projectId: string;
+ traceId: string;
+}) {
+ const capture = usePostHogClientCapture();
+ const utils = api.useUtils();
+ const traceMutation = api.traces.deleteMany.useMutation({
+ onSuccess: () => {
+ capture("trace:delete", { source: "table-single-row" });
+ showSuccessToast({
+ title: "Trace deleted",
+ description:
+ "Selected trace will be deleted. Traces are removed asynchronously and may continue to be visible for up to 24 hours.",
+ });
+ utils.traces.all.invalidate();
+ closeDialog();
+ },
+ });
+
+ return (
+ <>
+ <DialogHeader>
+ <DialogTitle>Please confirm</DialogTitle>
+ </DialogHeader>
+ <DialogBody>
+ <p className="text-muted-foreground py-4 text-sm">
+ This action cannot be undone. It removes all the data associated with
+ this trace.
+ </p>
+ </DialogBody>
+ <DialogFooter>
+ <div className="flex gap-2">
+ <Button variant="outline" onClick={closeDialog}>
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ loading={traceMutation.isPending}
+ onClick={() =>
+ traceMutation.mutate({ traceIds: [traceId], projectId })
+ }
+ >
+ Delete trace
+ </Button>
+ </div>
+ </DialogFooter>
+ </>
+ );
+}
diff --git a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx
index 3551bbd7ca..3e4ce53aec 100644
--- a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx
+++ b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx
@@ -39,7 +39,7 @@ import {
DashboardGrid,
type DashboardPlacement,
} from "@/src/features/widgets/components/DashboardGrid";
-import { CloneFirstDialog } from "@/src/features/dashboard/components/CloneFirstDialog";
+import { CloneFirstDialogController } from "@/src/features/dashboard/components/CloneFirstDialogController";
import { InlineEditText } from "@/src/components/design-system/InlineEditText/InlineEditText";
import { PageHeaderControlsPortal } from "@/src/components/layouts/page-header-controls-slot";
import {
@@ -48,7 +48,8 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
-import { EditDashboardDialog } from "@/src/features/dashboard/components/EditDashboardDialog";
+import { EditDialogDashboardContent } from "@/src/features/dashboard/components/EditDialogDashboardContent";
+import { DialogController } from "@/src/components/ui/dialog";
import { useDashboardDateRange } from "@/src/hooks/useDashboardDateRange";
import {
DASHBOARD_AGGREGATION_OPTIONS,
@@ -174,37 +175,12 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {
// Access for cloning (independent of dashboard owner)
const hasCloneAccess = hasRbacCUDAccess && isLockedDashboard;
- // Clone-first dialog state: open + the attempted change (if any) to carry
- // into the clone. gridResetKey remounts the grid to revert an attempted
- // drag/resize when the user cancels.
- const [cloneFirstState, setCloneFirstState] = useState<{
- open: boolean;
- pendingDefinition: { widgets: DashboardPlacement[] } | null;
- }>({ open: false, pendingDefinition: null });
+ // 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);
- const openCloneFirst = useCallback(
- (
- attempt:
- | "layout_change"
- | "delete_widget"
- | "add_widget"
- | "widget_pencil",
- pendingDefinition?: { widgets: DashboardPlacement[] },
- ) => {
- capture("dashboard:locked_edit_attempt", {
- dashboard_id: dashboardId,
- attempt,
- surface: "detail",
- });
- setCloneFirstState({
- open: true,
- pendingDefinition: pendingDefinition ?? null,
- });
- },
- [capture, dashboardId],
- );
-
// Filter state - use persistent filters from dashboard
const [savedFilters, setSavedFilters] = useState<FilterState>([]);
const [currentFilters, setCurrentFilters] = useState<FilterState>([]);
@@ -274,9 +250,6 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {
},
});
- // Dialog for editing name + description from the ... menu
- const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
-
// Mutation for renaming the dashboard inline from the page header
const updateDashboardMetadata =
api.dashboard.updateDashboardMetadata.useMutation({
@@ -942,6 +915,7 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {
// filters but never written into the dashboard's saved filters.
const { selectedEnvironments, setSelectedEnvironments } =
useEnvironmentFilter(environmentOptionsState.environmentOptions, projectId);
+ const setSelectedEnvironmentsDebounced = useDebounce(setSelectedEnvironments);
const environmentFilter = useMemo(
() =>
convertSelectedEnvironmentsToFilter(
@@ -1062,37 +1036,6 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {
router,
]);
- // Handle deleting a widget
- const handleDeleteWidget = (tileId: string) => {
- if (dashboardDefinition) {
- const updatedWidgets = dashboardDefinition.widgets.filter(
- (widget) => widget.id !== tileId,
- );
-
- const updatedDefinition = {
- ...dashboardDefinition,
- widgets: updatedWidgets,
- };
-
- if (isLockedEditable) {
- // Carry the removal into the clone instead of mutating.
- openCloneFirst("delete_widget", updatedDefinition);
- return;
- }
-
- applyDashboardDefinition(updatedDefinition);
- }
- };
-
- // Handle adding a widget
- const handleAddWidget = () => {
- if (isLockedEditable) {
- openCloneFirst("add_widget");
- return;
- }
- setIsWidgetDialogOpen(true);
- };
-
// Handle widget selection from dialog
const handleSelectWidget = (widget: WidgetItem) => {
addWidgetToDashboard(widget);
@@ -1159,284 +1102,340 @@ function DashboardDetailView({ readPath }: { readPath: ResolvedReadPath }) {
});
return (
- <DashboardQuerySchedulerProvider
- store={schedulerStore}
- shouldBucketQueriesByTimeRange={!("from" in timeRange)}
+ <CloneFirstDialogController
+ projectId={projectId}
+ dashboardId={dashboardId}
+ dashboardName={dashboard.data?.name ?? "Dashboard"}
+ pendingDefinition={cloneFirstPendingDefinition}
+ onCancel={() => {
+ setCloneFirstPendingDefinition(null);
+ setGridResetKey((key) => key + 1);
+ }}
>
- <Page
- withPadding
- scrollable
- headerProps={{
- title:
- (dashboard.data?.name || "Dashboard") +
- (dashboard.data?.owner === "LANGFUSE"
- ? " (Langfuse Maintained)"
- : ""),
- titleContent:
- hasCUDAccess && dashboard.data ? (
- <InlineEditText
- value={dashboard.data.name}
- required
- aria-label="Rename dashboard"
- onSave={(name) => {
- capture("dashboard:dashboard_renamed_inline", {
- dashboard_id: dashboardId,
- });
- updateDashboardMetadata.mutate({
- projectId,
- dashboardId,
- name,
- description: dashboard.data?.description ?? "",
- });
- }}
- />
- ) : undefined,
- breadcrumb: [
- {
- name: "Dashboards",
- href: `/project/${projectId}/dashboards`,
- },
- ],
- help: {
- description:
- dashboard.data?.description || "No description available",
- },
- actionButtonsLeft: (
- <>
- <MultiSelect
- title="Environment"
- label="Env"
- values={selectedEnvironments}
- onValueChange={useDebounce(setSelectedEnvironments)}
- options={environmentOptions}
- className="my-0 w-auto overflow-hidden"
- />
- <PopoverFilterBuilder
- columns={filterColumns}
- filterState={currentFilters}
- onChange={setCurrentFilters}
- // Analytics (LFE-10781): custom dashboard filter — a v3/legacy
- // surface (not the v4 events table).
- tableName="dashboard"
- isV4={false}
- />
- </>
- ),
- actionButtonsRight: (
- <>
- {(updateDashboardDefinition.isPending ||
- updateDashboardMetadata.isPending ||
- updateDashboardFilters.isPending ||
- setHomeDashboard.isPending) && (
- <span
- className="flex items-center"
- title="Saving..."
- role="status"
- aria-label="Saving"
- >
- <Loader2 className="text-muted-foreground h-4 w-4 animate-spin" />
- </span>
- )}
- {hasCUDAccess && hasUnsavedFilterChanges && (
- <Button
- onClick={handleSaveFilters}
- disabled={updateDashboardFilters.isPending}
- variant="outline"
- >
- {updateDashboardFilters.isPending
- ? "Saving..."
- : "Save Filters"}
- </Button>
- )}
- {hasRbacCUDAccess && (
- <Button onClick={handleAddWidget}>
- <PlusIcon size={16} className="mr-1 h-4 w-4" />
- Add Widget
- </Button>
- )}
- {hasCloneAccess && (
- <Button
- variant="outline"
- onClick={handleCloneDashboard}
- disabled={mutateCloneDashboard.isPending}
+ {({ openDialog: openCloneFirstDialog }) => {
+ const openCloneFirst = (
+ attempt:
+ | "layout_change"
+ | "delete_widget"
+ | "add_widget"
+ | "widget_pencil",
+ pendingDefinition?: { widgets: DashboardPlacement[] },
+ ) => {
+ capture("dashboard:locked_edit_attempt", {
+ dashboard_id: dashboardId,
+ attempt,
+ surface: "detail",
+ });
+ setCloneFirstPendingDefinition(pendingDefinition ?? null);
+ openCloneFirstDialog();
+ };
+
+ const handleDeleteWidget = (tileId: string) => {
+ if (!dashboardDefinition) return;
+
+ const updatedDefinition = {
+ ...dashboardDefinition,
+ widgets: dashboardDefinition.widgets.filter(
+ (widget) => widget.id !== tileId,
+ ),
+ };
+
+ if (isLockedEditable) {
+ openCloneFirst("delete_widget", updatedDefinition);
+ return;
+ }
+
+ applyDashboardDefinition(updatedDefinition);
+ };
+
+ const handleAddWidget = () => {
+ if (isLockedEditable) {
+ openCloneFirst("add_widget");
+ return;
+ }
+ setIsWidgetDialogOpen(true);
+ };
+
+ return (
+ <DialogController
+ closeOnInteractionOutside={false}
+ size="default"
+ renderContent={({ closeDialog }) =>
+ dashboard.data ? (
+ <EditDialogDashboardContent
+ closeDialog={closeDialog}
+ projectId={projectId}
+ dashboardId={dashboardId}
+ initialName={dashboard.data.name}
+ initialDescription={dashboard.data.description}
+ />
+ ) : null
+ }
+ >
+ {({ openDialog: openEditDialog }) => (
+ <DashboardQuerySchedulerProvider
+ store={schedulerStore}
+ shouldBucketQueriesByTimeRange={!("from" in timeRange)}
+ >
+ <Page
+ withPadding
+ scrollable
+ headerProps={{
+ title:
+ (dashboard.data?.name || "Dashboard") +
+ (dashboard.data?.owner === "LANGFUSE"
+ ? " (Langfuse Maintained)"
+ : ""),
+ titleContent:
+ hasCUDAccess && dashboard.data ? (
+ <InlineEditText
+ value={dashboard.data.name}
+ required
+ aria-label="Rename dashboard"
+ onSave={(name) => {
+ capture("dashboard:dashboard_renamed_inline", {
+ dashboard_id: dashboardId,
+ });
+ updateDashboardMetadata.mutate({
+ projectId,
+ dashboardId,
+ name,
+ description: dashboard.data?.description ?? "",
+ });
+ }}
+ />
+ ) : undefined,
+ breadcrumb: [
+ {
+ name: "Dashboards",
+ href: `/project/${projectId}/dashboards`,
+ },
+ ],
+ help: {
+ description:
+ dashboard.data?.description ||
+ "No description available",
+ },
+ actionButtonsLeft: (
+ <>
+ <MultiSelect
+ title="Environment"
+ label="Env"
+ values={selectedEnvironments}
+ onValueChange={setSelectedEnvironmentsDebounced}
+ options={environmentOptions}
+ className="my-0 w-auto overflow-hidden"
+ />
+ <PopoverFilterBuilder
+ columns={filterColumns}
+ filterState={currentFilters}
+ onChange={setCurrentFilters}
+ // Analytics (LFE-10781): custom dashboard filter — a v3/legacy
+ // surface (not the v4 events table).
+ tableName="dashboard"
+ isV4={false}
+ />
+ </>
+ ),
+ actionButtonsRight: (
+ <>
+ {(updateDashboardDefinition.isPending ||
+ updateDashboardMetadata.isPending ||
+ updateDashboardFilters.isPending ||
+ setHomeDashboard.isPending) && (
+ <span
+ className="flex items-center"
+ title="Saving..."
+ role="status"
+ aria-label="Saving"
+ >
+ <Loader2 className="text-muted-foreground h-4 w-4 animate-spin" />
+ </span>
+ )}
+ {hasCUDAccess && hasUnsavedFilterChanges && (
+ <Button
+ onClick={handleSaveFilters}
+ disabled={updateDashboardFilters.isPending}
+ variant="outline"
+ >
+ {updateDashboardFilters.isPending
+ ? "Saving..."
+ : "Save Filters"}
+ </Button>
+ )}
+ {hasRbacCUDAccess && (
+ <Button onClick={handleAddWidget}>
+ <PlusIcon size={16} className="mr-1 h-4 w-4" />
+ Add Widget
+ </Button>
+ )}
+ {hasCloneAccess && (
+ <Button
+ variant="outline"
+ onClick={handleCloneDashboard}
+ disabled={mutateCloneDashboard.isPending}
+ >
+ <Copy size={16} className="mr-1 h-4 w-4" />
+ Clone
+ </Button>
+ )}
+ {hasRbacCUDAccess && (
+ <DropdownMenu onOpenChange={setIsDashboardMenuOpen}>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ aria-label="More actions"
+ >
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {hasCUDAccess && (
+ <DropdownMenuItem
+ disabled={clipboardProbe === "no-widget"}
+ onClick={() =>
+ pasteWidgetFromClipboard("dashboard_menu")
+ }
+ >
+ <ClipboardPasteIcon className="mr-2 h-4 w-4" />
+ Paste widget
+ </DropdownMenuItem>
+ )}
+ <DropdownMenuItem
+ disabled={
+ isCurrentHome || setHomeDashboard.isPending
+ }
+ onClick={() => {
+ capture(
+ "dashboard:home_dashboard_set_default",
+ {
+ dashboard_id: dashboardId,
+ source: "detail_menu",
+ },
+ );
+ setHomeDashboard.mutate({
+ projectId,
+ dashboardId:
+ dashboardId === LANGFUSE_HOME_DASHBOARD_ID
+ ? null
+ : dashboardId,
+ });
+ }}
+ >
+ <HomeIcon className="mr-2 h-4 w-4" />
+ {isCurrentHome
+ ? "Shown on Home"
+ : "Use as Home"}
+ </DropdownMenuItem>
+ {hasCUDAccess && (
+ <DropdownMenuItem onSelect={openEditDialog}>
+ <PencilIcon className="mr-2 h-4 w-4" />
+ Edit name & description
+ </DropdownMenuItem>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
+ </>
+ ),
+ }}
>
- <Copy size={16} className="mr-1 h-4 w-4" />
- Clone
- </Button>
- )}
- {hasRbacCUDAccess && (
- <DropdownMenu onOpenChange={setIsDashboardMenuOpen}>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
- size="icon"
- aria-label="More actions"
- >
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {hasCUDAccess && (
- <DropdownMenuItem
- disabled={clipboardProbe === "no-widget"}
- onClick={() =>
- pasteWidgetFromClipboard("dashboard_menu")
+ <PageHeaderControlsPortal>
+ <TimeRangePicker
+ timeRange={timeRange}
+ onTimeRangeChange={setTimeRange}
+ timeRangePresets={dashboardTimeRangePresets}
+ className="my-0 max-w-full overflow-x-auto"
+ triggerClassName="px-2"
+ disabled={
+ lookbackLimit
+ ? {
+ before: new Date(
+ new Date().getTime() -
+ lookbackLimit * 24 * 60 * 60 * 1000,
+ ),
+ }
+ : undefined
+ }
+ />
+ </PageHeaderControlsPortal>
+ {isDraggingFile && (
+ <Layer name="modal">
+ <div className="bg-background/80 pointer-events-none fixed inset-0 flex items-center justify-center backdrop-blur-xs">
+ <div className="border-primary bg-background rounded-lg border-2 border-dashed px-8 py-6 text-center shadow-lg">
+ <p className="font-bold">Drop to import</p>
+ <p className="text-muted-foreground text-sm">
+ Langfuse dashboard or widget JSON
+ </p>
+ </div>
+ </div>
+ </Layer>
+ )}
+ <SelectWidgetDialog
+ open={isWidgetDialogOpen}
+ onOpenChange={setIsWidgetDialogOpen}
+ projectId={projectId}
+ onSelectWidget={handleSelectWidget}
+ onSelectPreset={addPresetToDashboard}
+ dashboardId={dashboardId}
+ />
+ {dashboard.isPending || !dashboardDefinition ? (
+ <NoDataOrLoading isLoading={true} />
+ ) : dashboard.isError ? (
+ <div className="flex h-64 items-center justify-center">
+ <div className="text-destructive">
+ Error: {dashboard.error.message}
+ </div>
+ </div>
+ ) : (
+ <div>
+ <DashboardGrid
+ key={gridResetKey}
+ readPath={readPath}
+ widgets={dashboardDefinition.widgets}
+ onChange={(updatedWidgets) => {
+ if (isLockedEditable) {
+ // Carry the attempted layout change into the clone.
+ openCloneFirst("layout_change", {
+ ...dashboardDefinition,
+ widgets: updatedWidgets,
+ });
+ return;
+ }
+ applyDashboardDefinition({
+ ...dashboardDefinition,
+ widgets: updatedWidgets,
+ });
+ }}
+ canEdit={hasRbacCUDAccess}
+ dashboardId={dashboardId}
+ projectId={projectId}
+ dateRange={absoluteTimeRange}
+ filterState={gridFilterState}
+ onDeleteWidget={handleDeleteWidget}
+ dashboardOwner={dashboard.data?.owner}
+ getWidgetSchedulerId={getWidgetSchedulerId}
+ onLockedEditAttempt={
+ isLockedEditable
+ ? () => openCloneFirst("widget_pencil")
+ : undefined
}
- >
- <ClipboardPasteIcon className="mr-2 h-4 w-4" />
- Paste widget
- </DropdownMenuItem>
- )}
- <DropdownMenuItem
- disabled={isCurrentHome || setHomeDashboard.isPending}
- onClick={() => {
- capture("dashboard:home_dashboard_set_default", {
- dashboard_id: dashboardId,
- source: "detail_menu",
- });
- setHomeDashboard.mutate({
- projectId,
- dashboardId:
- dashboardId === LANGFUSE_HOME_DASHBOARD_ID
- ? null
- : dashboardId,
- });
- }}
- >
- <HomeIcon className="mr-2 h-4 w-4" />
- {isCurrentHome ? "Shown on Home" : "Use as Home"}
- </DropdownMenuItem>
- {hasCUDAccess && (
- <DropdownMenuItem
- onClick={() => setIsEditDialogOpen(true)}
- >
- <PencilIcon className="mr-2 h-4 w-4" />
- Edit name & description
- </DropdownMenuItem>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
- )}
- </>
- ),
- }}
- >
- <PageHeaderControlsPortal>
- <TimeRangePicker
- timeRange={timeRange}
- onTimeRangeChange={setTimeRange}
- timeRangePresets={dashboardTimeRangePresets}
- className="my-0 max-w-full overflow-x-auto"
- triggerClassName="px-2"
- disabled={
- lookbackLimit
- ? {
- before: new Date(
- new Date().getTime() -
- lookbackLimit * 24 * 60 * 60 * 1000,
- ),
- }
- : undefined
- }
- />
- </PageHeaderControlsPortal>
- {isDraggingFile && (
- <Layer name="modal">
- <div className="bg-background/80 pointer-events-none fixed inset-0 flex items-center justify-center backdrop-blur-xs">
- <div className="border-primary bg-background rounded-lg border-2 border-dashed px-8 py-6 text-center shadow-lg">
- <p className="font-bold">Drop to import</p>
- <p className="text-muted-foreground text-sm">
- Langfuse dashboard or widget JSON
- </p>
- </div>
- </div>
- </Layer>
- )}
- <SelectWidgetDialog
- open={isWidgetDialogOpen}
- onOpenChange={setIsWidgetDialogOpen}
- projectId={projectId}
- onSelectWidget={handleSelectWidget}
- onSelectPreset={addPresetToDashboard}
- dashboardId={dashboardId}
- />
- {isEditDialogOpen && dashboard.data && (
- <EditDashboardDialog
- open={isEditDialogOpen}
- onOpenChange={setIsEditDialogOpen}
- projectId={projectId}
- dashboardId={dashboardId}
- initialName={dashboard.data.name}
- initialDescription={dashboard.data.description}
- />
- )}
- <CloneFirstDialog
- open={cloneFirstState.open}
- onOpenChange={(open) =>
- setCloneFirstState((prev) => ({ ...prev, open }))
- }
- projectId={projectId}
- dashboardId={dashboardId}
- dashboardName={dashboard.data?.name ?? "Dashboard"}
- pendingDefinition={cloneFirstState.pendingDefinition}
- onCancel={() => {
- // Revert the attempted drag/resize by remounting the grid with
- // the unchanged definition.
- setCloneFirstState({ open: false, pendingDefinition: null });
- setGridResetKey((key) => key + 1);
- }}
- />
- {dashboard.isPending || !dashboardDefinition ? (
- <NoDataOrLoading isLoading={true} />
- ) : dashboard.isError ? (
- <div className="flex h-64 items-center justify-center">
- <div className="text-destructive">
- Error: {dashboard.error.message}
- </div>
- </div>
- ) : (
- <div>
- <DashboardGrid
- key={gridResetKey}
- readPath={readPath}
- widgets={dashboardDefinition.widgets}
- onChange={(updatedWidgets) => {
- if (isLockedEditable) {
- // Carry the attempted layout change into the clone.
- openCloneFirst("layout_change", {
- ...dashboardDefinition,
- widgets: updatedWidgets,
- });
- return;
- }
- applyDashboardDefinition({
- ...dashboardDefinition,
- widgets: updatedWidgets,
- });
- }}
- canEdit={hasRbacCUDAccess}
- dashboardId={dashboardId}
- projectId={projectId}
- dateRange={absoluteTimeRange}
- filterState={gridFilterState}
- onDeleteWidget={handleDeleteWidget}
- dashboardOwner={dashboard.data?.owner}
- getWidgetSchedulerId={getWidgetSchedulerId}
- onLockedEditAttempt={
- isLockedEditable
- ? () => openCloneFirst("widget_pencil")
- : undefined
- }
- onDuplicateWidget={
- hasCUDAccess ? handleDuplicateWidget : undefined
- }
- onDuplicatePreset={
- hasCUDAccess ? handleDuplicatePreset : undefined
- }
- />
- </div>
- )}
- </Page>
- </DashboardQuerySchedulerProvider>
+ onDuplicateWidget={
+ hasCUDAccess ? handleDuplicateWidget : undefined
+ }
+ onDuplicatePreset={
+ hasCUDAccess ? handleDuplicatePreset : undefined
+ }
+ />
+ </div>
+ )}
+ </Page>
+ </DashboardQuerySchedulerProvider>
+ )}
+ </DialogController>
+ );
+ }}
+ </CloneFirstDialogController>
);
}