|
|
|
@ -36,6 +36,7 @@ import { |
|
|
|
AdhocVariableKind, |
|
|
|
AdhocVariableKind, |
|
|
|
AnnotationQueryKind, |
|
|
|
AnnotationQueryKind, |
|
|
|
DataLink, |
|
|
|
DataLink, |
|
|
|
|
|
|
|
RepeatOptions, |
|
|
|
} from '../../../../../packages/grafana-schema/src/schema/dashboard/v2alpha0/dashboard.gen'; |
|
|
|
} from '../../../../../packages/grafana-schema/src/schema/dashboard/v2alpha0/dashboard.gen'; |
|
|
|
import { DashboardDataLayerSet } from '../scene/DashboardDataLayerSet'; |
|
|
|
import { DashboardDataLayerSet } from '../scene/DashboardDataLayerSet'; |
|
|
|
import { DashboardScene, DashboardSceneState } from '../scene/DashboardScene'; |
|
|
|
import { DashboardScene, DashboardSceneState } from '../scene/DashboardScene'; |
|
|
|
@ -43,7 +44,13 @@ import { PanelTimeRange } from '../scene/PanelTimeRange'; |
|
|
|
import { DashboardGridItem } from '../scene/layout-default/DashboardGridItem'; |
|
|
|
import { DashboardGridItem } from '../scene/layout-default/DashboardGridItem'; |
|
|
|
import { DefaultGridLayoutManager } from '../scene/layout-default/DefaultGridLayoutManager'; |
|
|
|
import { DefaultGridLayoutManager } from '../scene/layout-default/DefaultGridLayoutManager'; |
|
|
|
import { dashboardSceneGraph } from '../utils/dashboardSceneGraph'; |
|
|
|
import { dashboardSceneGraph } from '../utils/dashboardSceneGraph'; |
|
|
|
import { getPanelIdForVizPanel, getQueryRunnerFor, getVizPanelKeyForPanelId } from '../utils/utils'; |
|
|
|
import { |
|
|
|
|
|
|
|
getPanelIdForVizPanel, |
|
|
|
|
|
|
|
getQueryRunnerFor, |
|
|
|
|
|
|
|
getVizPanelKeyForPanelId, |
|
|
|
|
|
|
|
isLibraryPanel, |
|
|
|
|
|
|
|
calculateGridItemDimensions, |
|
|
|
|
|
|
|
} from '../utils/utils'; |
|
|
|
|
|
|
|
|
|
|
|
import { sceneVariablesSetToSchemaV2Variables } from './sceneVariablesSetToVariables'; |
|
|
|
import { sceneVariablesSetToSchemaV2Variables } from './sceneVariablesSetToVariables'; |
|
|
|
import { transformCursorSynctoEnum } from './transformToV2TypesUtils'; |
|
|
|
import { transformCursorSynctoEnum } from './transformToV2TypesUtils'; |
|
|
|
@ -107,7 +114,7 @@ export function transformSceneToSaveModelSchemaV2(scene: DashboardScene, isSnaps |
|
|
|
layout: { |
|
|
|
layout: { |
|
|
|
kind: 'GridLayout', |
|
|
|
kind: 'GridLayout', |
|
|
|
spec: { |
|
|
|
spec: { |
|
|
|
items: getGridLayoutItems(oldDash), |
|
|
|
items: getGridLayoutItems(oldDash, isSnapshot), |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// EOF layout
|
|
|
|
// EOF layout
|
|
|
|
@ -142,16 +149,16 @@ function getLiveNow(state: DashboardSceneState) { |
|
|
|
|
|
|
|
|
|
|
|
function getGridLayoutItems(state: DashboardSceneState, isSnapshot?: boolean): GridLayoutItemKind[] { |
|
|
|
function getGridLayoutItems(state: DashboardSceneState, isSnapshot?: boolean): GridLayoutItemKind[] { |
|
|
|
const body = state.body; |
|
|
|
const body = state.body; |
|
|
|
const elements: GridLayoutItemKind[] = []; |
|
|
|
let elements: GridLayoutItemKind[] = []; |
|
|
|
if (body instanceof DefaultGridLayoutManager) { |
|
|
|
if (body instanceof DefaultGridLayoutManager) { |
|
|
|
for (const child of body.state.grid.state.children) { |
|
|
|
for (const child of body.state.grid.state.children) { |
|
|
|
if (child instanceof DashboardGridItem) { |
|
|
|
if (child instanceof DashboardGridItem) { |
|
|
|
// TODO: handle panel repeater scenario
|
|
|
|
// TODO: handle panel repeater scenario
|
|
|
|
// if (child.state.variableName) {
|
|
|
|
if (child.state.variableName) { |
|
|
|
// panels = panels.concat(panelRepeaterToPanels(child, isSnapshot));
|
|
|
|
elements = elements.concat(repeaterToLayoutItems(child, isSnapshot)); |
|
|
|
// } else {
|
|
|
|
} else { |
|
|
|
elements.push(gridItemToGridLayoutItemKind(child, isSnapshot)); |
|
|
|
elements.push(gridItemToGridLayoutItemKind(child, isSnapshot)); |
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: OLD transformer code
|
|
|
|
// TODO: OLD transformer code
|
|
|
|
@ -164,6 +171,7 @@ function getGridLayoutItems(state: DashboardSceneState, isSnapshot?: boolean): G |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return elements; |
|
|
|
return elements; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -185,6 +193,7 @@ export function gridItemToGridLayoutItemKind(gridItem: DashboardGridItem, isSnap |
|
|
|
x = gridItem_.state.x ?? 0; |
|
|
|
x = gridItem_.state.x ?? 0; |
|
|
|
y = gridItem_.state.y ?? 0; |
|
|
|
y = gridItem_.state.y ?? 0; |
|
|
|
width = gridItem_.state.width ?? 0; |
|
|
|
width = gridItem_.state.width ?? 0; |
|
|
|
|
|
|
|
const repeatVar = gridItem_.state.variableName; |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: which name should we use for the element reference, key or something else ?
|
|
|
|
// FIXME: which name should we use for the element reference, key or something else ?
|
|
|
|
const elementName = gridItem_.state.body.state.key ?? 'DefaultName'; |
|
|
|
const elementName = gridItem_.state.body.state.key ?? 'DefaultName'; |
|
|
|
@ -202,6 +211,23 @@ export function gridItemToGridLayoutItemKind(gridItem: DashboardGridItem, isSnap |
|
|
|
}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (repeatVar) { |
|
|
|
|
|
|
|
const repeat: RepeatOptions = { |
|
|
|
|
|
|
|
mode: 'variable', |
|
|
|
|
|
|
|
value: repeatVar, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gridItem_.state.maxPerRow) { |
|
|
|
|
|
|
|
repeat.maxPerRow = gridItem_.getMaxPerRow(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gridItem_.state.repeatDirection) { |
|
|
|
|
|
|
|
repeat.direction = gridItem_.getRepeatDirection(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elementGridItem.spec.repeat = repeat; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!elementGridItem) { |
|
|
|
if (!elementGridItem) { |
|
|
|
throw new Error('Unsupported grid item type'); |
|
|
|
throw new Error('Unsupported grid item type'); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -367,6 +393,60 @@ function createElements(panels: PanelKind[]): Record<string, PanelKind> { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function repeaterToLayoutItems(repeater: DashboardGridItem, isSnapshot = false): GridLayoutItemKind[] { |
|
|
|
|
|
|
|
if (!isSnapshot) { |
|
|
|
|
|
|
|
return [gridItemToGridLayoutItemKind(repeater)]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (repeater.state.body instanceof VizPanel && isLibraryPanel(repeater.state.body)) { |
|
|
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
// const { x = 0, y = 0, width: w = 0, height: h = 0 } = repeater.state;
|
|
|
|
|
|
|
|
// return [vizPanelToPanel(repeater.state.body, { x, y, w, h }, isSnapshot)];
|
|
|
|
|
|
|
|
return []; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (repeater.state.repeatedPanels) { |
|
|
|
|
|
|
|
const { h, w, columnCount } = calculateGridItemDimensions(repeater); |
|
|
|
|
|
|
|
const panels = repeater.state.repeatedPanels!.map((panel, index) => { |
|
|
|
|
|
|
|
let x = 0, |
|
|
|
|
|
|
|
y = 0; |
|
|
|
|
|
|
|
if (repeater.state.repeatDirection === 'v') { |
|
|
|
|
|
|
|
x = repeater.state.x!; |
|
|
|
|
|
|
|
y = index * h; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
x = (index % columnCount) * w; |
|
|
|
|
|
|
|
y = repeater.state.y! + Math.floor(index / columnCount) * h; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const gridPos = { x, y, w, h }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result: GridLayoutItemKind = { |
|
|
|
|
|
|
|
kind: 'GridLayoutItem', |
|
|
|
|
|
|
|
spec: { |
|
|
|
|
|
|
|
x: gridPos.x, |
|
|
|
|
|
|
|
y: gridPos.y, |
|
|
|
|
|
|
|
width: gridPos.w, |
|
|
|
|
|
|
|
height: gridPos.h, |
|
|
|
|
|
|
|
repeat: { |
|
|
|
|
|
|
|
mode: 'variable', |
|
|
|
|
|
|
|
value: repeater.state.variableName!, |
|
|
|
|
|
|
|
maxPerRow: repeater.getMaxPerRow(), |
|
|
|
|
|
|
|
direction: repeater.state.repeatDirection, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
element: { |
|
|
|
|
|
|
|
kind: 'ElementReference', |
|
|
|
|
|
|
|
name: panel.state.key!, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return panels; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return []; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getVariables(oldDash: DashboardSceneState) { |
|
|
|
function getVariables(oldDash: DashboardSceneState) { |
|
|
|
const variablesSet = oldDash.$variables; |
|
|
|
const variablesSet = oldDash.$variables; |
|
|
|
|
|
|
|
|
|
|
|
|