2024-10-23 16:55:45 +08:00
|
|
|
import { config } from '@grafana/runtime';
|
2024-09-27 21:11:28 +08:00
|
|
|
import {
|
|
|
|
SceneObjectState,
|
|
|
|
SceneGridLayout,
|
|
|
|
SceneObjectBase,
|
|
|
|
SceneGridRow,
|
|
|
|
VizPanel,
|
|
|
|
sceneGraph,
|
|
|
|
sceneUtils,
|
|
|
|
SceneComponentProps,
|
2025-01-22 21:57:45 +08:00
|
|
|
SceneGridItemLike,
|
2025-02-06 22:30:54 +08:00
|
|
|
useSceneObjectState,
|
2024-09-27 21:11:28 +08:00
|
|
|
} from '@grafana/scenes';
|
|
|
|
import { GRID_COLUMN_COUNT } from 'app/core/constants';
|
2025-02-05 19:14:03 +08:00
|
|
|
import { t } from 'app/core/internationalization';
|
2025-02-06 22:30:54 +08:00
|
|
|
import DashboardEmpty from 'app/features/dashboard/dashgrid/DashboardEmpty';
|
2024-09-27 21:11:28 +08:00
|
|
|
|
2025-03-10 15:03:55 +08:00
|
|
|
import { NewObjectAddedToCanvasEvent } from '../../edit-pane/shared';
|
2025-02-03 17:46:47 +08:00
|
|
|
import { isClonedKey, joinCloneKeys } from '../../utils/clone';
|
2025-02-06 17:57:08 +08:00
|
|
|
import { dashboardSceneGraph } from '../../utils/dashboardSceneGraph';
|
2024-09-27 21:11:28 +08:00
|
|
|
import {
|
|
|
|
forceRenderChildren,
|
|
|
|
getPanelIdForVizPanel,
|
|
|
|
NEW_PANEL_HEIGHT,
|
|
|
|
NEW_PANEL_WIDTH,
|
|
|
|
getVizPanelKeyForPanelId,
|
2025-02-03 17:46:47 +08:00
|
|
|
getGridItemKeyForPanelId,
|
2025-02-06 22:30:54 +08:00
|
|
|
getDashboardSceneFor,
|
2024-09-27 21:11:28 +08:00
|
|
|
} from '../../utils/utils';
|
2025-02-05 17:08:41 +08:00
|
|
|
import { DashboardLayoutManager } from '../types/DashboardLayoutManager';
|
2025-02-11 20:08:07 +08:00
|
|
|
import { LayoutRegistryItem } from '../types/LayoutRegistryItem';
|
2024-09-27 21:11:28 +08:00
|
|
|
|
2024-11-05 15:05:09 +08:00
|
|
|
import { DashboardGridItem } from './DashboardGridItem';
|
2025-02-03 17:46:47 +08:00
|
|
|
import { RowRepeaterBehavior } from './RowRepeaterBehavior';
|
|
|
|
import { RowActions } from './row-actions/RowActions';
|
2024-11-05 15:05:09 +08:00
|
|
|
|
2024-09-27 21:11:28 +08:00
|
|
|
interface DefaultGridLayoutManagerState extends SceneObjectState {
|
|
|
|
grid: SceneGridLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DefaultGridLayoutManager
|
|
|
|
extends SceneObjectBase<DefaultGridLayoutManagerState>
|
|
|
|
implements DashboardLayoutManager
|
|
|
|
{
|
2025-02-07 18:57:54 +08:00
|
|
|
public static Component = DefaultGridLayoutManagerRenderer;
|
|
|
|
|
2025-02-05 17:08:41 +08:00
|
|
|
public readonly isDashboardLayoutManager = true;
|
|
|
|
|
2025-02-11 20:08:07 +08:00
|
|
|
public static readonly descriptor: LayoutRegistryItem = {
|
2025-02-05 19:14:03 +08:00
|
|
|
get name() {
|
2025-03-06 18:39:45 +08:00
|
|
|
return t('dashboard.default-layout.name', 'Custom');
|
2025-02-05 19:14:03 +08:00
|
|
|
},
|
|
|
|
get description() {
|
2025-03-06 18:39:45 +08:00
|
|
|
return t('dashboard.default-layout.description', 'Manually size and position panels');
|
2025-02-05 19:14:03 +08:00
|
|
|
},
|
2025-02-05 17:08:41 +08:00
|
|
|
id: 'default-grid',
|
|
|
|
createFromLayout: DefaultGridLayoutManager.createFromLayout,
|
2025-02-11 20:08:07 +08:00
|
|
|
kind: 'GridLayout',
|
2025-02-05 17:08:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
public readonly descriptor = DefaultGridLayoutManager.descriptor;
|
2024-12-10 14:21:30 +08:00
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public addPanel(vizPanel: VizPanel) {
|
2025-02-06 17:57:08 +08:00
|
|
|
const panelId = dashboardSceneGraph.getNextPanelId(this);
|
2024-10-23 16:55:45 +08:00
|
|
|
|
|
|
|
vizPanel.setState({ key: getVizPanelKeyForPanelId(panelId) });
|
|
|
|
vizPanel.clearParent();
|
|
|
|
|
2024-09-27 21:11:28 +08:00
|
|
|
const newGridItem = new DashboardGridItem({
|
|
|
|
height: NEW_PANEL_HEIGHT,
|
|
|
|
width: NEW_PANEL_WIDTH,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
body: vizPanel,
|
2025-02-03 17:46:47 +08:00
|
|
|
key: getGridItemKeyForPanelId(panelId),
|
2024-09-27 21:11:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.state.grid.setState({
|
|
|
|
children: [newGridItem, ...this.state.grid.state.children],
|
|
|
|
});
|
2025-03-10 15:03:55 +08:00
|
|
|
|
|
|
|
this.publishEvent(new NewObjectAddedToCanvasEvent(vizPanel), true);
|
2024-09-27 21:11:28 +08:00
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public removePanel(panel: VizPanel) {
|
2024-09-27 21:11:28 +08:00
|
|
|
const gridItem = panel.parent!;
|
|
|
|
|
|
|
|
if (!(gridItem instanceof DashboardGridItem)) {
|
|
|
|
throw new Error('Trying to remove panel that is not inside a DashboardGridItem');
|
|
|
|
}
|
|
|
|
|
|
|
|
const layout = this.state.grid;
|
|
|
|
|
|
|
|
let row: SceneGridRow | undefined;
|
|
|
|
|
|
|
|
try {
|
|
|
|
row = sceneGraph.getAncestor(gridItem, SceneGridRow);
|
|
|
|
} catch {
|
|
|
|
row = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row) {
|
|
|
|
row.setState({ children: row.state.children.filter((child) => child !== gridItem) });
|
|
|
|
layout.forceRender();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state.grid.setState({
|
|
|
|
children: layout.state.children.filter((child) => child !== gridItem),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public duplicatePanel(vizPanel: VizPanel) {
|
2024-09-27 21:11:28 +08:00
|
|
|
const gridItem = vizPanel.parent;
|
|
|
|
if (!(gridItem instanceof DashboardGridItem)) {
|
|
|
|
console.error('Trying to duplicate a panel that is not inside a DashboardGridItem');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let panelState;
|
|
|
|
let panelData;
|
|
|
|
let newGridItem;
|
|
|
|
|
2025-02-06 17:57:08 +08:00
|
|
|
const newPanelId = dashboardSceneGraph.getNextPanelId(this);
|
2024-09-27 21:11:28 +08:00
|
|
|
const grid = this.state.grid;
|
|
|
|
|
|
|
|
if (gridItem instanceof DashboardGridItem) {
|
|
|
|
panelState = sceneUtils.cloneSceneObjectState(gridItem.state.body.state);
|
|
|
|
panelData = sceneGraph.getData(gridItem.state.body).clone();
|
|
|
|
} else {
|
|
|
|
panelState = sceneUtils.cloneSceneObjectState(vizPanel.state);
|
|
|
|
panelData = sceneGraph.getData(vizPanel).clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
// when we duplicate a panel we don't want to clone the alert state
|
|
|
|
delete panelData.state.data?.alertState;
|
|
|
|
|
2025-03-10 15:03:55 +08:00
|
|
|
const newPanel = new VizPanel({ ...panelState, $data: panelData, key: getVizPanelKeyForPanelId(newPanelId) });
|
|
|
|
|
2024-09-27 21:11:28 +08:00
|
|
|
newGridItem = new DashboardGridItem({
|
|
|
|
x: gridItem.state.x,
|
|
|
|
y: gridItem.state.y,
|
|
|
|
height: gridItem.state.height,
|
2024-12-12 18:57:42 +08:00
|
|
|
itemHeight: gridItem.state.height,
|
2024-09-27 21:11:28 +08:00
|
|
|
width: gridItem.state.width,
|
|
|
|
variableName: gridItem.state.variableName,
|
|
|
|
repeatDirection: gridItem.state.repeatDirection,
|
|
|
|
maxPerRow: gridItem.state.maxPerRow,
|
2025-02-07 18:57:54 +08:00
|
|
|
key: getGridItemKeyForPanelId(newPanelId),
|
2025-03-10 15:03:55 +08:00
|
|
|
body: newPanel,
|
2024-09-27 21:11:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (gridItem.parent instanceof SceneGridRow) {
|
|
|
|
const row = gridItem.parent;
|
|
|
|
|
|
|
|
row.setState({ children: [...row.state.children, newGridItem] });
|
|
|
|
grid.forceRender();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
grid.setState({ children: [...grid.state.children, newGridItem] });
|
2025-03-10 15:03:55 +08:00
|
|
|
|
|
|
|
this.publishEvent(new NewObjectAddedToCanvasEvent(newPanel), true);
|
2024-09-27 21:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public getVizPanels(): VizPanel[] {
|
|
|
|
const panels: VizPanel[] = [];
|
|
|
|
|
|
|
|
this.state.grid.forEachChild((child) => {
|
|
|
|
if (!(child instanceof DashboardGridItem) && !(child instanceof SceneGridRow)) {
|
|
|
|
throw new Error('Child is not a DashboardGridItem or SceneGridRow, invalid scene');
|
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
if (child instanceof DashboardGridItem && child.state.body instanceof VizPanel) {
|
|
|
|
panels.push(child.state.body);
|
2024-09-27 21:11:28 +08:00
|
|
|
} else if (child instanceof SceneGridRow) {
|
|
|
|
child.forEachChild((child) => {
|
2025-02-07 18:57:54 +08:00
|
|
|
if (child instanceof DashboardGridItem && child.state.body instanceof VizPanel) {
|
|
|
|
panels.push(child.state.body);
|
2024-09-27 21:11:28 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return panels;
|
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public addNewRow(): SceneGridRow {
|
|
|
|
const id = dashboardSceneGraph.getNextPanelId(this);
|
|
|
|
|
|
|
|
const row = new SceneGridRow({
|
|
|
|
key: getVizPanelKeyForPanelId(id),
|
|
|
|
title: 'Row title',
|
|
|
|
actions: new RowActions({}),
|
|
|
|
y: 0,
|
2024-09-27 21:11:28 +08:00
|
|
|
});
|
2025-02-07 18:57:54 +08:00
|
|
|
|
|
|
|
const sceneGridLayout = this.state.grid;
|
|
|
|
|
|
|
|
// find all panels until the first row and put them into the newly created row. If there are no other rows,
|
|
|
|
// add all panels to the row. If there are no panels just create an empty row
|
|
|
|
const indexTillNextRow = sceneGridLayout.state.children.findIndex((child) => child instanceof SceneGridRow);
|
|
|
|
const rowChildren = sceneGridLayout.state.children
|
|
|
|
.splice(0, indexTillNextRow === -1 ? sceneGridLayout.state.children.length : indexTillNextRow)
|
|
|
|
.map((child) => child.clone());
|
|
|
|
|
|
|
|
if (rowChildren) {
|
|
|
|
row.setState({ children: rowChildren });
|
|
|
|
}
|
|
|
|
|
|
|
|
sceneGridLayout.setState({ children: [row, ...sceneGridLayout.state.children] });
|
|
|
|
|
|
|
|
return row;
|
2024-09-27 21:11:28 +08:00
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public editModeChanged(isEditing: boolean) {
|
|
|
|
const updateResizeAndDragging = () => {
|
|
|
|
this.state.grid.setState({ isDraggable: isEditing, isResizable: isEditing });
|
|
|
|
forceRenderChildren(this.state.grid, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (config.featureToggles.dashboardNewLayouts) {
|
|
|
|
// We do this in a timeout to wait a bit with enabling dragging as dragging enables grid animations
|
|
|
|
// if we show the edit pane without animations it opens much faster and feels more responsive
|
|
|
|
setTimeout(updateResizeAndDragging, 10);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateResizeAndDragging();
|
2024-09-27 21:11:28 +08:00
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public activateRepeaters() {
|
2025-02-14 00:41:09 +08:00
|
|
|
if (!this.isActive) {
|
|
|
|
this.activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.state.grid.isActive) {
|
|
|
|
this.state.grid.activate();
|
|
|
|
}
|
|
|
|
|
2024-09-27 21:11:28 +08:00
|
|
|
this.state.grid.forEachChild((child) => {
|
|
|
|
if (child instanceof DashboardGridItem && !child.isActive) {
|
|
|
|
child.activate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child instanceof SceneGridRow && child.state.$behaviors) {
|
|
|
|
for (const behavior of child.state.$behaviors) {
|
|
|
|
if (behavior instanceof RowRepeaterBehavior && !child.isActive) {
|
|
|
|
child.activate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
child.state.children.forEach((child) => {
|
|
|
|
if (child instanceof DashboardGridItem && !child.isActive) {
|
|
|
|
child.activate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-03 17:46:47 +08:00
|
|
|
public cloneLayout(ancestorKey: string, isSource: boolean): DashboardLayoutManager {
|
|
|
|
return this.clone({
|
|
|
|
grid: this.state.grid.clone({
|
|
|
|
isResizable: isSource && this.state.grid.state.isResizable,
|
|
|
|
isDraggable: isSource && this.state.grid.state.isDraggable,
|
|
|
|
children: this.state.grid.state.children.reduce<{ panelId: number; children: SceneGridItemLike[] }>(
|
|
|
|
(childrenAcc, child) => {
|
|
|
|
if (child instanceof DashboardGridItem) {
|
|
|
|
const gridItemKey = joinCloneKeys(ancestorKey, getGridItemKeyForPanelId(childrenAcc.panelId));
|
|
|
|
|
|
|
|
const gridItem = child.clone({
|
|
|
|
key: gridItemKey,
|
|
|
|
body: child.state.body.clone({
|
|
|
|
key: joinCloneKeys(gridItemKey, getVizPanelKeyForPanelId(childrenAcc.panelId++)),
|
|
|
|
}),
|
|
|
|
isDraggable: isSource && child.state.isDraggable,
|
|
|
|
isResizable: isSource && child.state.isResizable,
|
|
|
|
});
|
|
|
|
|
|
|
|
childrenAcc.children.push(gridItem);
|
2025-02-07 18:57:54 +08:00
|
|
|
|
2025-02-03 17:46:47 +08:00
|
|
|
return childrenAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child instanceof SceneGridRow) {
|
|
|
|
const rowKey = joinCloneKeys(ancestorKey, getVizPanelKeyForPanelId(childrenAcc.panelId++));
|
|
|
|
|
|
|
|
const row = child.clone({
|
|
|
|
key: rowKey,
|
|
|
|
children: child.state.children.reduce<SceneGridItemLike[]>((rowAcc, rowChild) => {
|
|
|
|
if (isClonedKey(rowChild.state.key!)) {
|
|
|
|
return rowAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(rowChild instanceof DashboardGridItem)) {
|
|
|
|
rowAcc.push(rowChild.clone());
|
|
|
|
return rowAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gridItemKey = joinCloneKeys(rowKey, getGridItemKeyForPanelId(childrenAcc.panelId));
|
|
|
|
|
|
|
|
const gridItem = rowChild.clone({
|
|
|
|
key: gridItemKey,
|
|
|
|
isDraggable: isSource && rowChild.state.isDraggable,
|
|
|
|
isResizable: isSource && rowChild.state.isResizable,
|
|
|
|
body: rowChild.state.body.clone({
|
|
|
|
key: joinCloneKeys(gridItemKey, getVizPanelKeyForPanelId(childrenAcc.panelId++)),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
rowAcc.push(gridItem);
|
|
|
|
return rowAcc;
|
|
|
|
}, []),
|
|
|
|
isDraggable: isSource && child.state.isDraggable,
|
|
|
|
isResizable: isSource && child.state.isResizable,
|
|
|
|
});
|
|
|
|
|
|
|
|
childrenAcc.children.push(row);
|
|
|
|
|
|
|
|
return childrenAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
childrenAcc.children.push(child.clone());
|
2025-02-07 18:57:54 +08:00
|
|
|
|
2025-02-03 17:46:47 +08:00
|
|
|
return childrenAcc;
|
|
|
|
},
|
|
|
|
{ panelId: 0, children: [] }
|
|
|
|
).children,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
public removeRow(row: SceneGridRow, removePanels = false) {
|
|
|
|
const sceneGridLayout = this.state.grid;
|
|
|
|
|
|
|
|
const children = sceneGridLayout.state.children.filter((child) => child.state.key !== row.state.key);
|
|
|
|
|
|
|
|
if (!removePanels) {
|
|
|
|
const rowChildren = row.state.children.map((child) => child.clone());
|
|
|
|
const indexOfRow = sceneGridLayout.state.children.findIndex((child) => child.state.key === row.state.key);
|
|
|
|
|
|
|
|
children.splice(indexOfRow, 0, ...rowChildren);
|
|
|
|
}
|
|
|
|
|
|
|
|
sceneGridLayout.setState({ children });
|
|
|
|
}
|
|
|
|
|
|
|
|
public collapseAllRows() {
|
|
|
|
this.state.grid.state.children.forEach((child) => {
|
|
|
|
if (!(child instanceof SceneGridRow)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!child.state.isCollapsed) {
|
|
|
|
this.state.grid.toggleRow(child);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public expandAllRows() {
|
|
|
|
this.state.grid.state.children.forEach((child) => {
|
|
|
|
if (!(child instanceof SceneGridRow)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child.state.isCollapsed) {
|
|
|
|
this.state.grid.toggleRow(child);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-23 16:55:45 +08:00
|
|
|
public static createFromLayout(currentLayout: DashboardLayoutManager): DefaultGridLayoutManager {
|
|
|
|
const panels = currentLayout.getVizPanels();
|
|
|
|
return DefaultGridLayoutManager.fromVizPanels(panels);
|
|
|
|
}
|
|
|
|
|
2024-09-27 21:11:28 +08:00
|
|
|
public static fromVizPanels(panels: VizPanel[] = []): DefaultGridLayoutManager {
|
|
|
|
const children: DashboardGridItem[] = [];
|
|
|
|
const panelHeight = 10;
|
|
|
|
const panelWidth = GRID_COLUMN_COUNT / 3;
|
|
|
|
let currentY = 0;
|
|
|
|
let currentX = 0;
|
|
|
|
|
|
|
|
for (let panel of panels) {
|
2024-10-23 16:55:45 +08:00
|
|
|
panel.clearParent();
|
|
|
|
|
2024-09-27 21:11:28 +08:00
|
|
|
children.push(
|
|
|
|
new DashboardGridItem({
|
2025-02-07 18:57:54 +08:00
|
|
|
key: getGridItemKeyForPanelId(getPanelIdForVizPanel(panel)),
|
2024-09-27 21:11:28 +08:00
|
|
|
x: currentX,
|
|
|
|
y: currentY,
|
|
|
|
width: panelWidth,
|
|
|
|
height: panelHeight,
|
|
|
|
body: panel,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
currentX += panelWidth;
|
|
|
|
|
|
|
|
if (currentX + panelWidth >= GRID_COLUMN_COUNT) {
|
|
|
|
currentX = 0;
|
|
|
|
currentY += panelHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DefaultGridLayoutManager({
|
|
|
|
grid: new SceneGridLayout({
|
|
|
|
children: children,
|
2024-11-20 21:09:56 +08:00
|
|
|
isDraggable: true,
|
|
|
|
isResizable: true,
|
2024-09-27 21:11:28 +08:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-03 17:46:47 +08:00
|
|
|
public static fromGridItems(
|
|
|
|
gridItems: SceneGridItemLike[],
|
|
|
|
isDraggable?: boolean,
|
|
|
|
isResizable?: boolean
|
|
|
|
): DefaultGridLayoutManager {
|
2025-01-22 21:57:45 +08:00
|
|
|
const children = gridItems.reduce<SceneGridItemLike[]>((acc, gridItem) => {
|
|
|
|
gridItem.clearParent();
|
|
|
|
acc.push(gridItem);
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return new DefaultGridLayoutManager({
|
|
|
|
grid: new SceneGridLayout({
|
|
|
|
children,
|
2025-02-03 17:46:47 +08:00
|
|
|
isDraggable,
|
|
|
|
isResizable,
|
2025-01-22 21:57:45 +08:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
2025-02-07 18:57:54 +08:00
|
|
|
}
|
2025-01-22 21:57:45 +08:00
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
function DefaultGridLayoutManagerRenderer({ model }: SceneComponentProps<DefaultGridLayoutManager>) {
|
|
|
|
const { children } = useSceneObjectState(model.state.grid, { shouldActivateOrKeepAlive: true });
|
|
|
|
const dashboard = getDashboardSceneFor(model);
|
2025-02-06 22:30:54 +08:00
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
// If we are top level layout and have no children, show empty state
|
|
|
|
if (model.parent === dashboard && children.length === 0) {
|
|
|
|
return (
|
|
|
|
<DashboardEmpty dashboard={dashboard} canCreate={!!dashboard.state.meta.canEdit} key="dashboard-empty-state" />
|
|
|
|
);
|
|
|
|
}
|
2025-02-06 22:30:54 +08:00
|
|
|
|
2025-02-07 18:57:54 +08:00
|
|
|
return <model.state.grid.Component model={model.state.grid} />;
|
2024-09-27 21:11:28 +08:00
|
|
|
}
|