From e1e9a570afdc2b917cb7ade4f756d7669e292cfd Mon Sep 17 00:00:00 2001 From: Sergej-Vlasov <37613182+Sergej-Vlasov@users.noreply.github.com> Date: Fri, 8 Aug 2025 13:42:51 +0100 Subject: [PATCH] TabsLayout: Rethinking tab repeats (#108134) * wip: rework tab repeat behaviour * wip: tab repeats rendering * wip: tab repeats rework * rework tab drag and drop to account for repeats * add TabItemRepeater tests * clean up * prevent canvas actions in cloned tabs and rows * add repeat name into tab title * prettier ffix * fix cloneLayout bug * remove experimental title adjustment on repeat --- .../scene/layout-rows/RowsLayoutManager.tsx | 5 +- .../layout-rows/RowsLayoutManagerRenderer.tsx | 5 +- .../scene/layout-tabs/TabItem.tsx | 24 +- .../scene/layout-tabs/TabItemEditor.tsx | 2 +- .../scene/layout-tabs/TabItemRenderer.tsx | 4 +- .../layout-tabs/TabItemRepeater.test.tsx | 165 +++++++++++ .../scene/layout-tabs/TabItemRepeater.tsx | 192 +++++++++++++ .../TabItemRepeaterBehavior.test.tsx | 272 ------------------ .../layout-tabs/TabItemRepeaterBehavior.ts | 161 ----------- .../scene/layout-tabs/TabsLayoutManager.tsx | 125 +++++--- .../layout-tabs/TabsLayoutManagerRenderer.tsx | 24 +- .../layoutSerializers/TabsLayoutSerializer.ts | 23 +- public/locales/en-US/grafana.json | 1 + 13 files changed, 481 insertions(+), 522 deletions(-) create mode 100644 public/app/features/dashboard-scene/scene/layout-tabs/TabItemRepeater.test.tsx create mode 100644 public/app/features/dashboard-scene/scene/layout-tabs/TabItemRepeater.tsx delete mode 100644 public/app/features/dashboard-scene/scene/layout-tabs/TabItemRepeaterBehavior.test.tsx delete mode 100644 public/app/features/dashboard-scene/scene/layout-tabs/TabItemRepeaterBehavior.ts diff --git a/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManager.tsx b/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManager.tsx index 1b04a9d6c23..1cdf72a480c 100644 --- a/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManager.tsx +++ b/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManager.tsx @@ -17,7 +17,6 @@ import { getDashboardSceneFor } from '../../utils/utils'; import { DashboardGridItem } from '../layout-default/DashboardGridItem'; import { DefaultGridLayoutManager } from '../layout-default/DefaultGridLayoutManager'; import { RowRepeaterBehavior } from '../layout-default/RowRepeaterBehavior'; -import { TabItemRepeaterBehavior } from '../layout-tabs/TabItemRepeaterBehavior'; import { TabsLayoutManager } from '../layout-tabs/TabsLayoutManager'; import { getRowFromClipboard } from '../layouts-shared/paste'; import { generateUniqueTitle, ungroupLayout } from '../layouts-shared/utils'; @@ -196,14 +195,12 @@ export class RowsLayoutManager extends SceneObjectBase i const conditionalRendering = tab.state.conditionalRendering; conditionalRendering?.clearParent(); - const behavior = tab.state.$behaviors?.find((b) => b instanceof TabItemRepeaterBehavior); - rows.push( new RowItem({ layout: tab.state.layout.clone(), title: tab.state.title, conditionalRendering, - repeatByVariable: behavior?.state.variableName, + repeatByVariable: tab.state.repeatByVariable, }) ); } diff --git a/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManagerRenderer.tsx b/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManagerRenderer.tsx index 17c19241f83..9c74a5b37a7 100644 --- a/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManagerRenderer.tsx +++ b/public/app/features/dashboard-scene/scene/layout-rows/RowsLayoutManagerRenderer.tsx @@ -7,6 +7,7 @@ import { Trans } from '@grafana/i18n'; import { MultiValueVariable, SceneComponentProps, sceneGraph, useSceneObjectState } from '@grafana/scenes'; import { Button, useStyles2 } from '@grafana/ui'; +import { isInCloneChain } from '../../utils/clone'; import { useDashboardState } from '../../utils/utils'; import { useClipboardState } from '../layouts-shared/useClipboardState'; @@ -20,6 +21,8 @@ export function RowLayoutManagerRenderer({ model }: SceneComponentProps model.forceSelectRow(start.draggableId)} @@ -42,7 +45,7 @@ export function RowLayoutManagerRenderer({ model }: SceneComponentProps ))} {dropProvided.placeholder} - {isEditing && ( + {isEditing && !isClone && (