From dd23b87e4fa1416304749f170c2a939a90f02b90 Mon Sep 17 00:00:00 2001 From: Aleksandar Petrov <8142643+aleks-p@users.noreply.github.com> Date: Fri, 28 Nov 2025 17:19:48 -0400 Subject: [PATCH] Fix zoom reset, lint errors --- .../components/ExploreMapToolbar.tsx | 104 +++++++++++++----- 1 file changed, 74 insertions(+), 30 deletions(-) diff --git a/public/app/features/explore-map/components/ExploreMapToolbar.tsx b/public/app/features/explore-map/components/ExploreMapToolbar.tsx index a0993579ad2..0756ab2cd4b 100644 --- a/public/app/features/explore-map/components/ExploreMapToolbar.tsx +++ b/public/app/features/explore-map/components/ExploreMapToolbar.tsx @@ -1,8 +1,9 @@ import { css } from '@emotion/css'; -import { useCallback } from 'react'; +import { useCallback, useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; -import { Button, ButtonGroup, ToolbarButton, useStyles2 } from '@grafana/ui'; +import { t, Trans } from '@grafana/i18n'; +import { Button, ButtonGroup, ConfirmModal, ToolbarButton, useStyles2 } from '@grafana/ui'; import { useDispatch, useSelector } from 'app/types/store'; import { useTransformContext } from '../context/TransformContext'; @@ -14,6 +15,7 @@ export function ExploreMapToolbar() { const dispatch = useDispatch(); const { exportCanvas, importCanvas } = useCanvasPersistence(); const { transformRef } = useTransformContext(); + const [showResetConfirm, setShowResetConfirm] = useState(false); const panelCount = useSelector((state) => Object.keys(state.exploreMap.panels).length); const viewport = useSelector((state) => state.exploreMap.viewport); @@ -23,9 +25,12 @@ export function ExploreMapToolbar() { }, [dispatch]); const handleResetCanvas = useCallback(() => { - if (confirm('Are you sure you want to clear all panels? This cannot be undone.')) { - dispatch(resetCanvas()); - } + setShowResetConfirm(true); + }, []); + + const confirmResetCanvas = useCallback(() => { + dispatch(resetCanvas()); + setShowResetConfirm(false); }, [dispatch]); const handleZoomIn = useCallback(() => { @@ -42,7 +47,11 @@ export function ExploreMapToolbar() { const handleResetZoom = useCallback(() => { if (transformRef?.current) { - transformRef.current.resetTransform(); + console.log('[ExploreMapToolbar] Resetting zoom, transformRef:', transformRef.current); + // Reset both scale and position to initial values + transformRef.current.setTransform(0, 0, 1, 200); + } else { + console.log('[ExploreMapToolbar] transformRef is null or current is not set'); } }, [transformRef]); @@ -55,32 +64,67 @@ export function ExploreMapToolbar() { }, [importCanvas]); return ( -
-
- - {panelCount} panels + <> +
+
+ + + + {{ count: panelCount }} panels + + +
+ +
+ + + + {Math.round(viewport.zoom * 100)}% + + + +
+ +
+ + + + + +
-
- - - - {Math.round(viewport.zoom * 100)}% - - - -
- -
- - - - - -
-
+ setShowResetConfirm(false)} + /> + ); }