🪢 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
chore(dashboard): auto-save dashboard on any changes (#6820)
Steffen Schmitz10a3644dcfc4
diff --git a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsxindex 7d840538d4..dcbd61e3ec 100644--- a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx+++ b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx@@ -18,6 +18,7 @@ import {} from "@/src/features/widgets/components/SelectWidgetDialog";import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";import { v4 as uuidv4 } from "uuid";+import { useDebounce } from "@/src/hooks/useDebounce";interface WidgetPlacement {id: string;@@ -51,7 +52,6 @@ export default function DashboardDetail() {const [localDashboardDefinition, setLocalDashboardDefinition] = useState<{widgets: WidgetPlacement[];} | null>(null);- const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);// State for the widget selection dialogconst [isWidgetDialogOpen, setIsWidgetDialogOpen] = useState(false);@@ -62,9 +62,9 @@ export default function DashboardDetail() {onSuccess: () => {showSuccessToast({title: "Dashboard updated",- description: "Your changes have been saved successfully",+ description: "Your changes have been saved automatically",+ duration: 2000,});- setHasUnsavedChanges(false);// Invalidate the dashboard query to refetch the datadashboard.refetch();},@@ -73,6 +73,18 @@ export default function DashboardDetail() {},});+ const saveDashboardChanges = useDebounce(+ (definition: { widgets: WidgetPlacement[] }) => {+ updateDashboardDefinition.mutate({+ projectId,+ dashboardId,+ definition,+ });+ },+ 600,+ false,+ );+// Helper function to add a widget to the dashboardconst addWidgetToDashboard = useCallback((widget: WidgetItem) => {@@ -98,22 +110,17 @@ export default function DashboardDetail() {};// Add the widget to the local dashboard definition- setLocalDashboardDefinition({+ const updatedDefinition = {...localDashboardDefinition,widgets: [...localDashboardDefinition.widgets, newWidgetPlacement],- });-- setHasUnsavedChanges(true);-- showSuccessToast({- title: "Widget added",- description: `"${widget.name}" has been added to the dashboard. Click Save to apply changes.`,- });+ };+ setLocalDashboardDefinition(updatedDefinition);+ saveDashboardChanges(updatedDefinition);},[localDashboardDefinition,setLocalDashboardDefinition,- setHasUnsavedChanges,+ saveDashboardChanges,],);@@ -277,12 +284,12 @@ export default function DashboardDetail() {(widget) => widget.id !== tileId,);- setLocalDashboardDefinition({+ const updatedDefinition = {...localDashboardDefinition,widgets: updatedWidgets,- });-- setHasUnsavedChanges(true);+ };+ setLocalDashboardDefinition(updatedDefinition);+ saveDashboardChanges(updatedDefinition);}};@@ -296,17 +303,6 @@ export default function DashboardDetail() {addWidgetToDashboard(widget);};- // Handle saving the dashboard- const handleSaveDashboard = () => {- if (localDashboardDefinition && hasUnsavedChanges) {- updateDashboardDefinition.mutate({- projectId,- dashboardId,- definition: localDashboardDefinition,- });- }- };-return (<><SelectWidgetDialog@@ -332,17 +328,6 @@ export default function DashboardDetail() {<PlusIcon size={16} />Add Widget</Button>- <Button- onClick={handleSaveDashboard}- disabled={- !hasUnsavedChanges ||- updateDashboardDefinition.isLoading ||- !hasCUDAccess- }- loading={updateDashboardDefinition.isLoading}- >- Save- </Button></>),}}