From c97dc131f17edd04d19fe0e5f624a0660728aeef Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 8 Aug 2025 13:31:55 +0000 Subject: [PATCH] Update MetricToolbar to support preselected metric and improve modal handling Co-authored-by: nate --- .../elements/MetricElement/MetricElement.tsx | 2 +- .../elements/MetricElement/MetricToolbar.tsx | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/ui/report/elements/MetricElement/MetricElement.tsx b/apps/web/src/components/ui/report/elements/MetricElement/MetricElement.tsx index 899d9b804..c7d9d8ba4 100644 --- a/apps/web/src/components/ui/report/elements/MetricElement/MetricElement.tsx +++ b/apps/web/src/components/ui/report/elements/MetricElement/MetricElement.tsx @@ -32,7 +32,7 @@ export const MetricElement = withHOC( const readOnly = useReadOnly(); const content = metricId ? ( - + { + return selectedMetricId ? [{ id: selectedMetricId, name: '' }] : []; + }, [selectedMetricId]); + const onOpenEdit = React.useCallback(() => { editor.tf.select(); setOpenEditModal(true); @@ -33,6 +37,17 @@ export function MetricToolbar({ children }: { children: React.ReactNode }) { setOpenEditModal(false); }, []); + const handleAddMetrics = React.useCallback( + async (metrics: { id: string; name: string }[]) => { + const id = metrics?.[0]?.id; + const at = editor.api.findPath(element); + if (!id || !at) return onCloseEdit(); + plugin.api.metric.updateMetric(id, { at }); + onCloseEdit(); + }, + [editor, element, onCloseEdit, plugin.api.metric] + ); + return ( {children} @@ -50,18 +65,9 @@ export function MetricToolbar({ children }: { children: React.ReactNode }) { { - const selectedMetricId = metrics?.[0]?.id; - if (!selectedMetricId) return onCloseEdit(); - - const at = editor.api.findPath(element); - if (!at) return onCloseEdit(); - - plugin.api.metric.updateMetric(selectedMetricId, { at }); - onCloseEdit(); - }} + onAddMetrics={handleAddMetrics} selectionMode="single" saveButtonText="Update metric" />