mirror of
https://github.com/grafana/grafana.git
synced 2025-12-22 12:44:34 +08:00
Compare commits
3 Commits
index-owne
...
KD/lazy-lo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19290cd0db | ||
|
|
375b791656 | ||
|
|
72472fa8b8 |
@@ -296,8 +296,8 @@
|
|||||||
"@grafana/plugin-ui": "^0.11.1",
|
"@grafana/plugin-ui": "^0.11.1",
|
||||||
"@grafana/prometheus": "workspace:*",
|
"@grafana/prometheus": "workspace:*",
|
||||||
"@grafana/runtime": "workspace:*",
|
"@grafana/runtime": "workspace:*",
|
||||||
"@grafana/scenes": "6.49.0",
|
"@grafana/scenes": "6.49.1--canary.1313.20102090431.0",
|
||||||
"@grafana/scenes-react": "6.49.0",
|
"@grafana/scenes-react": "6.49.1--canary.1313.20102090431.0",
|
||||||
"@grafana/schema": "workspace:*",
|
"@grafana/schema": "workspace:*",
|
||||||
"@grafana/sql": "workspace:*",
|
"@grafana/sql": "workspace:*",
|
||||||
"@grafana/ui": "workspace:*",
|
"@grafana/ui": "workspace:*",
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ import { DashboardGridItem } from './layout-default/DashboardGridItem';
|
|||||||
import { DefaultGridLayoutManager } from './layout-default/DefaultGridLayoutManager';
|
import { DefaultGridLayoutManager } from './layout-default/DefaultGridLayoutManager';
|
||||||
import { addNewRowTo } from './layouts-shared/addNew';
|
import { addNewRowTo } from './layouts-shared/addNew';
|
||||||
import { clearClipboard } from './layouts-shared/paste';
|
import { clearClipboard } from './layouts-shared/paste';
|
||||||
import { getIsLazy } from './layouts-shared/utils';
|
|
||||||
import { DashboardLayoutManager } from './types/DashboardLayoutManager';
|
import { DashboardLayoutManager } from './types/DashboardLayoutManager';
|
||||||
import { LayoutParent } from './types/LayoutParent';
|
import { LayoutParent } from './types/LayoutParent';
|
||||||
|
|
||||||
@@ -200,7 +199,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
|
|||||||
meta: {},
|
meta: {},
|
||||||
editable: true,
|
editable: true,
|
||||||
$timeRange: state.$timeRange ?? new SceneTimeRange({}),
|
$timeRange: state.$timeRange ?? new SceneTimeRange({}),
|
||||||
body: state.body ?? DefaultGridLayoutManager.fromVizPanels([], getIsLazy(state.preload)),
|
body: state.body ?? DefaultGridLayoutManager.fromVizPanels([]),
|
||||||
links: state.links ?? [],
|
links: state.links ?? [],
|
||||||
...state,
|
...state,
|
||||||
editPane: new DashboardEditPane(),
|
editPane: new DashboardEditPane(),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Trans } from '@grafana/i18n';
|
import { Trans } from '@grafana/i18n';
|
||||||
import { VizPanel } from '@grafana/scenes';
|
import { LazyLoader, VizPanel } from '@grafana/scenes';
|
||||||
import { Box, Spinner } from '@grafana/ui';
|
import { Box, Spinner } from '@grafana/ui';
|
||||||
|
|
||||||
import { DashboardScene } from './DashboardScene';
|
import { DashboardScene } from './DashboardScene';
|
||||||
@@ -51,11 +51,23 @@ export function useSoloPanelContext() {
|
|||||||
return useContext(SoloPanelContext);
|
return useContext(SoloPanelContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderMatchingSoloPanels(soloPanelContext: SoloPanelContextValue, panels: VizPanel[]) {
|
export function renderMatchingSoloPanels(
|
||||||
|
soloPanelContext: SoloPanelContextValue,
|
||||||
|
panels: VizPanel[],
|
||||||
|
isLazy?: boolean
|
||||||
|
) {
|
||||||
const matches: React.ReactNode[] = [];
|
const matches: React.ReactNode[] = [];
|
||||||
for (const panel of panels) {
|
for (const panel of panels) {
|
||||||
if (soloPanelContext.matches(panel)) {
|
if (soloPanelContext.matches(panel)) {
|
||||||
matches.push(<panel.Component model={panel} key={panel.state.key} />);
|
if (isLazy) {
|
||||||
|
matches.push(
|
||||||
|
<LazyLoader key={panel.state.key!}>
|
||||||
|
<panel.Component model={panel} />
|
||||||
|
</LazyLoader>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
matches.push(<panel.Component model={panel} key={panel.state.key} />);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export function AutoGridItemRenderer({ model }: SceneComponentProps<AutoGridItem
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (soloPanelContext) {
|
if (soloPanelContext) {
|
||||||
return renderMatchingSoloPanels(soloPanelContext, [body, ...repeatedPanels]);
|
return renderMatchingSoloPanels(soloPanelContext, [body, ...repeatedPanels], isLazy);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDragging = !!draggingKey;
|
const isDragging = !!draggingKey;
|
||||||
|
|||||||
@@ -2,16 +2,20 @@ import { css } from '@emotion/css';
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { SceneComponentProps } from '@grafana/scenes';
|
import { LazyLoader, SceneComponentProps, VizPanel } from '@grafana/scenes';
|
||||||
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
|
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
|
||||||
|
|
||||||
|
import { useDashboardState } from '../../utils/utils';
|
||||||
import { renderMatchingSoloPanels, useSoloPanelContext } from '../SoloPanelContext';
|
import { renderMatchingSoloPanels, useSoloPanelContext } from '../SoloPanelContext';
|
||||||
|
import { getIsLazy } from '../layouts-shared/utils';
|
||||||
|
|
||||||
import { DashboardGridItem, RepeatDirection } from './DashboardGridItem';
|
import { DashboardGridItem, RepeatDirection } from './DashboardGridItem';
|
||||||
|
|
||||||
export function DashboardGridItemRenderer({ model }: SceneComponentProps<DashboardGridItem>) {
|
export function DashboardGridItemRenderer({ model }: SceneComponentProps<DashboardGridItem>) {
|
||||||
const { repeatedPanels = [], itemHeight, variableName, body } = model.useState();
|
const { repeatedPanels = [], itemHeight, variableName, body } = model.useState();
|
||||||
const soloPanelContext = useSoloPanelContext();
|
const soloPanelContext = useSoloPanelContext();
|
||||||
|
const { preload } = useDashboardState(model);
|
||||||
|
const isLazy = useMemo(() => getIsLazy(preload), [preload]);
|
||||||
const layoutStyle = useLayoutStyle(
|
const layoutStyle = useLayoutStyle(
|
||||||
model.getRepeatDirection(),
|
model.getRepeatDirection(),
|
||||||
model.getChildCount(),
|
model.getChildCount(),
|
||||||
@@ -19,27 +23,35 @@ export function DashboardGridItemRenderer({ model }: SceneComponentProps<Dashboa
|
|||||||
itemHeight ?? 10
|
itemHeight ?? 10
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function LazyPanelWrapper({ item }: { item: VizPanel }) {
|
||||||
|
return isLazy ? (
|
||||||
|
<LazyLoader key={item.state.key!} className={panelWrapper}>
|
||||||
|
<item.Component model={item} />
|
||||||
|
</LazyLoader>
|
||||||
|
) : (
|
||||||
|
<div className={panelWrapper}>
|
||||||
|
<item.Component model={item} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (soloPanelContext) {
|
if (soloPanelContext) {
|
||||||
return renderMatchingSoloPanels(soloPanelContext, [body, ...repeatedPanels]);
|
return renderMatchingSoloPanels(soloPanelContext, [body, ...repeatedPanels], isLazy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!variableName) {
|
if (!variableName) {
|
||||||
return (
|
return (
|
||||||
<div className={panelWrapper} ref={model.containerRef}>
|
<div className={panelWrapper} ref={model.containerRef}>
|
||||||
<body.Component model={body} key={body.state.key} />
|
<LazyPanelWrapper item={body} key={body.state.key!} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={layoutStyle} ref={model.containerRef}>
|
<div className={layoutStyle} ref={model.containerRef}>
|
||||||
<div className={panelWrapper} key={body.state.key}>
|
<LazyPanelWrapper item={body} key={body.state.key!} />
|
||||||
<body.Component model={body} key={body.state.key} />
|
|
||||||
</div>
|
|
||||||
{repeatedPanels.map((panel) => (
|
{repeatedPanels.map((panel) => (
|
||||||
<div className={panelWrapper} key={panel.state.key}>
|
<LazyPanelWrapper item={panel} key={panel.state.key!} />
|
||||||
<panel.Component model={panel} key={panel.state.key} />
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import { AutoGridItem } from '../layout-auto-grid/AutoGridItem';
|
|||||||
import { CanvasGridAddActions } from '../layouts-shared/CanvasGridAddActions';
|
import { CanvasGridAddActions } from '../layouts-shared/CanvasGridAddActions';
|
||||||
import { clearClipboard, getDashboardGridItemFromClipboard } from '../layouts-shared/paste';
|
import { clearClipboard, getDashboardGridItemFromClipboard } from '../layouts-shared/paste';
|
||||||
import { dashboardCanvasAddButtonHoverStyles } from '../layouts-shared/styles';
|
import { dashboardCanvasAddButtonHoverStyles } from '../layouts-shared/styles';
|
||||||
import { getIsLazy } from '../layouts-shared/utils';
|
|
||||||
import { DashboardLayoutGrid } from '../types/DashboardLayoutGrid';
|
import { DashboardLayoutGrid } from '../types/DashboardLayoutGrid';
|
||||||
import { DashboardLayoutManager } from '../types/DashboardLayoutManager';
|
import { DashboardLayoutManager } from '../types/DashboardLayoutManager';
|
||||||
import { LayoutRegistryItem } from '../types/LayoutRegistryItem';
|
import { LayoutRegistryItem } from '../types/LayoutRegistryItem';
|
||||||
@@ -565,11 +564,10 @@ export class DefaultGridLayoutManager
|
|||||||
|
|
||||||
public static createFromLayout(currentLayout: DashboardLayoutManager): DefaultGridLayoutManager {
|
public static createFromLayout(currentLayout: DashboardLayoutManager): DefaultGridLayoutManager {
|
||||||
const panels = currentLayout.getVizPanels();
|
const panels = currentLayout.getVizPanels();
|
||||||
const isLazy = getIsLazy(getDashboardSceneFor(currentLayout).state.preload)!;
|
return DefaultGridLayoutManager.fromVizPanels(panels);
|
||||||
return DefaultGridLayoutManager.fromVizPanels(panels, isLazy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static fromVizPanels(panels: VizPanel[] = [], isLazy?: boolean | undefined): DefaultGridLayoutManager {
|
public static fromVizPanels(panels: VizPanel[] = []): DefaultGridLayoutManager {
|
||||||
const children: DashboardGridItem[] = [];
|
const children: DashboardGridItem[] = [];
|
||||||
const panelHeight = 10;
|
const panelHeight = 10;
|
||||||
const panelWidth = GRID_COLUMN_COUNT / 3;
|
const panelWidth = GRID_COLUMN_COUNT / 3;
|
||||||
@@ -607,7 +605,6 @@ export class DefaultGridLayoutManager
|
|||||||
children: children,
|
children: children,
|
||||||
isDraggable: true,
|
isDraggable: true,
|
||||||
isResizable: true,
|
isResizable: true,
|
||||||
isLazy,
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -615,8 +612,7 @@ export class DefaultGridLayoutManager
|
|||||||
public static fromGridItems(
|
public static fromGridItems(
|
||||||
gridItems: SceneGridItemLike[],
|
gridItems: SceneGridItemLike[],
|
||||||
isDraggable?: boolean,
|
isDraggable?: boolean,
|
||||||
isResizable?: boolean,
|
isResizable?: boolean
|
||||||
isLazy?: boolean | undefined
|
|
||||||
): DefaultGridLayoutManager {
|
): DefaultGridLayoutManager {
|
||||||
const children = gridItems.reduce<SceneGridItemLike[]>((acc, gridItem) => {
|
const children = gridItems.reduce<SceneGridItemLike[]>((acc, gridItem) => {
|
||||||
gridItem.clearParent();
|
gridItem.clearParent();
|
||||||
@@ -630,7 +626,6 @@ export class DefaultGridLayoutManager
|
|||||||
children,
|
children,
|
||||||
isDraggable,
|
isDraggable,
|
||||||
isResizable,
|
isResizable,
|
||||||
isLazy,
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,8 +358,7 @@ export class RowsLayoutManager extends SceneObjectBase<RowsLayoutManagerState> i
|
|||||||
layout: DefaultGridLayoutManager.fromGridItems(
|
layout: DefaultGridLayoutManager.fromGridItems(
|
||||||
rowConfig.children,
|
rowConfig.children,
|
||||||
rowConfig.isDraggable ?? layout.state.grid.state.isDraggable,
|
rowConfig.isDraggable ?? layout.state.grid.state.isDraggable,
|
||||||
rowConfig.isResizable ?? layout.state.grid.state.isResizable,
|
rowConfig.isResizable ?? layout.state.grid.state.isResizable
|
||||||
layout.state.grid.state.isLazy
|
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
22
yarn.lock
22
yarn.lock
@@ -3603,11 +3603,11 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@grafana/scenes-react@npm:6.49.0":
|
"@grafana/scenes-react@npm:6.49.1--canary.1313.20102090431.0":
|
||||||
version: 6.49.0
|
version: 6.49.1--canary.1313.20102090431.0
|
||||||
resolution: "@grafana/scenes-react@npm:6.49.0"
|
resolution: "@grafana/scenes-react@npm:6.49.1--canary.1313.20102090431.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@grafana/scenes": "npm:6.49.0"
|
"@grafana/scenes": "npm:6.49.1--canary.1313.20102090431.0"
|
||||||
lru-cache: "npm:^10.2.2"
|
lru-cache: "npm:^10.2.2"
|
||||||
react-use: "npm:^17.4.0"
|
react-use: "npm:^17.4.0"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -3619,7 +3619,7 @@ __metadata:
|
|||||||
react: ^18.0.0
|
react: ^18.0.0
|
||||||
react-dom: ^18.0.0
|
react-dom: ^18.0.0
|
||||||
react-router-dom: ^6.28.0
|
react-router-dom: ^6.28.0
|
||||||
checksum: 10/0f9ba2ccaf2c8a703f3c4867320852c07f640aea85491e6c1a35d7fd25b48e69740f7782b52280ab4d423a6e87659de41cf66904acc865c9ea1f934ded6c7e64
|
checksum: 10/275239e8f2458bebc70e895f6175a33b6199441d05b83caf2d2969fc772a12e19cdddc59b206b15f0c67bc1d250f817cf5075eb33eed0869d96076e2c1f9a730
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -3649,9 +3649,9 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@grafana/scenes@npm:6.49.0":
|
"@grafana/scenes@npm:6.49.1--canary.1313.20102090431.0":
|
||||||
version: 6.49.0
|
version: 6.49.1--canary.1313.20102090431.0
|
||||||
resolution: "@grafana/scenes@npm:6.49.0"
|
resolution: "@grafana/scenes@npm:6.49.1--canary.1313.20102090431.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@floating-ui/react": "npm:^0.26.16"
|
"@floating-ui/react": "npm:^0.26.16"
|
||||||
"@leeoniya/ufuzzy": "npm:^1.0.16"
|
"@leeoniya/ufuzzy": "npm:^1.0.16"
|
||||||
@@ -3671,7 +3671,7 @@ __metadata:
|
|||||||
react: ^18.0.0
|
react: ^18.0.0
|
||||||
react-dom: ^18.0.0
|
react-dom: ^18.0.0
|
||||||
react-router-dom: ^6.28.0
|
react-router-dom: ^6.28.0
|
||||||
checksum: 10/0e873ceac0834879ade41df56ced5a3e8f6a10e5aba15a6f271327aa804729402bcf44845e54614dd0fb1541a28efbb9a5499acceae04cb8be3b11bcdc230347
|
checksum: 10/4f2261cc19a4fe7c26b5113ffd940ecb478705c773ebd2fb7b26219ab53d6531a161136d2909847744ea22a5509a5de7fde5569b7fa35c6a00e874150031ac04
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -19441,8 +19441,8 @@ __metadata:
|
|||||||
"@grafana/plugin-ui": "npm:^0.11.1"
|
"@grafana/plugin-ui": "npm:^0.11.1"
|
||||||
"@grafana/prometheus": "workspace:*"
|
"@grafana/prometheus": "workspace:*"
|
||||||
"@grafana/runtime": "workspace:*"
|
"@grafana/runtime": "workspace:*"
|
||||||
"@grafana/scenes": "npm:6.49.0"
|
"@grafana/scenes": "npm:6.49.1--canary.1313.20102090431.0"
|
||||||
"@grafana/scenes-react": "npm:6.49.0"
|
"@grafana/scenes-react": "npm:6.49.1--canary.1313.20102090431.0"
|
||||||
"@grafana/schema": "workspace:*"
|
"@grafana/schema": "workspace:*"
|
||||||
"@grafana/sql": "workspace:*"
|
"@grafana/sql": "workspace:*"
|
||||||
"@grafana/test-utils": "workspace:*"
|
"@grafana/test-utils": "workspace:*"
|
||||||
|
|||||||
Reference in New Issue
Block a user