From 621e7012dfd7c5a291360c1656dca6c97afd20f1 Mon Sep 17 00:00:00 2001 From: Bogdan Matei Date: Tue, 18 Mar 2025 14:34:14 +0200 Subject: [PATCH] Dynamic Dashboards: Fix some of the issues identified during bugbash (#102279) --- .../ElementSelectionContext.tsx | 6 + .../grafana-ui/src/components/Tabs/Tab.tsx | 23 ++- .../edit-pane/DashboardAddPane.tsx | 144 +++++++++--------- .../edit-pane/DashboardEditPane.tsx | 10 +- .../dashboard-scene/edit-pane/shared.ts | 4 + .../DefaultGridLayoutManager.tsx | 24 ++- .../scene/layout-rows/RowsLayoutManager.tsx | 8 +- .../scene/layout-tabs/TabItemRenderer.tsx | 2 + .../scene/layout-tabs/TabsLayoutManager.tsx | 10 +- public/locales/en-US/grafana.json | 32 ++-- 10 files changed, 175 insertions(+), 88 deletions(-) diff --git a/packages/grafana-ui/src/components/ElementSelectionContext/ElementSelectionContext.tsx b/packages/grafana-ui/src/components/ElementSelectionContext/ElementSelectionContext.tsx index 8ba48a7eeda..61627b0762c 100644 --- a/packages/grafana-ui/src/components/ElementSelectionContext/ElementSelectionContext.tsx +++ b/packages/grafana-ui/src/components/ElementSelectionContext/ElementSelectionContext.tsx @@ -45,6 +45,12 @@ export function useElementSelection(id: string | undefined): UseElementSelection // To prevent this click form clearing the selection evt.stopPropagation(); + // Prevent text selection caused by shift click + if (evt.shiftKey) { + evt.preventDefault(); + window.getSelection()?.empty(); + } + context.onSelect({ id }, evt.shiftKey); }, [context, id] diff --git a/packages/grafana-ui/src/components/Tabs/Tab.tsx b/packages/grafana-ui/src/components/Tabs/Tab.tsx index edbe71c965c..7b8cffdc428 100644 --- a/packages/grafana-ui/src/components/Tabs/Tab.tsx +++ b/packages/grafana-ui/src/components/Tabs/Tab.tsx @@ -24,10 +24,11 @@ export interface TabProps extends HTMLProps { counter?: number | null; /** Extra content, displayed after the tab label and counter */ suffix?: NavModelItem['tabSuffix']; + truncate?: boolean; } export const Tab = React.forwardRef( - ({ label, active, icon, onChangeTab, counter, suffix: Suffix, className, href, ...otherProps }, ref) => { + ({ label, active, icon, onChangeTab, counter, suffix: Suffix, className, href, truncate, ...otherProps }, ref) => { const tabsStyles = useStyles2(getStyles); const clearStyles = useStyles2(clearButtonStyles); @@ -40,7 +41,12 @@ export const Tab = React.forwardRef( ); - const linkClass = cx(clearStyles, tabsStyles.link, active ? tabsStyles.activeStyle : tabsStyles.notActive); + const linkClass = cx( + clearStyles, + tabsStyles.link, + active ? tabsStyles.activeStyle : tabsStyles.notActive, + truncate && tabsStyles.linkTruncate + ); const commonProps = { className: linkClass, @@ -53,7 +59,7 @@ export const Tab = React.forwardRef( if (href) { return ( -
+
( } return ( -
+