mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Add ScopeMeta to DashboardModel (#99475)
This commit is contained in:
parent
d5d8abcd64
commit
de1df2f4e9
@ -34,7 +34,7 @@ import store from 'app/core/store';
|
|||||||
import { DashboardWithAccessInfo } from 'app/features/dashboard/api/types';
|
import { DashboardWithAccessInfo } from 'app/features/dashboard/api/types';
|
||||||
import { SaveDashboardAsOptions } from 'app/features/dashboard/components/SaveDashboard/types';
|
import { SaveDashboardAsOptions } from 'app/features/dashboard/components/SaveDashboard/types';
|
||||||
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
import { DashboardModel, ScopeMeta } from 'app/features/dashboard/state/DashboardModel';
|
||||||
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
||||||
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
||||||
import { getClosestScopesFacade, ScopesFacade } from 'app/features/scopes';
|
import { getClosestScopesFacade, ScopesFacade } from 'app/features/scopes';
|
||||||
@ -99,6 +99,8 @@ export interface DashboardSceneState extends SceneObjectState {
|
|||||||
preload?: boolean;
|
preload?: boolean;
|
||||||
/** A uid when saved */
|
/** A uid when saved */
|
||||||
uid?: string;
|
uid?: string;
|
||||||
|
/** @experimental */
|
||||||
|
scopeMeta?: ScopeMeta;
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
id?: number | null;
|
id?: number | null;
|
||||||
/** Layout of panels */
|
/** Layout of panels */
|
||||||
|
@ -217,6 +217,14 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scopeMeta =
|
||||||
|
config.featureToggles.scopeFilters && oldModel.scopeMeta
|
||||||
|
? {
|
||||||
|
trait: oldModel.scopeMeta.trait,
|
||||||
|
groups: oldModel.scopeMeta.groups,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const behaviorList: SceneObjectState['$behaviors'] = [
|
const behaviorList: SceneObjectState['$behaviors'] = [
|
||||||
new behaviors.CursorSync({
|
new behaviors.CursorSync({
|
||||||
sync: oldModel.graphTooltip,
|
sync: oldModel.graphTooltip,
|
||||||
@ -249,6 +257,7 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel,
|
|||||||
tags: oldModel.tags || [],
|
tags: oldModel.tags || [],
|
||||||
title: oldModel.title,
|
title: oldModel.title,
|
||||||
version: oldModel.version,
|
version: oldModel.version,
|
||||||
|
scopeMeta,
|
||||||
body: new DefaultGridLayoutManager({
|
body: new DefaultGridLayoutManager({
|
||||||
grid: new SceneGridLayout({
|
grid: new SceneGridLayout({
|
||||||
isLazy: !(dto.preload || contextSrv.user.authenticatedBy === 'render'),
|
isLazy: !(dto.preload || contextSrv.user.authenticatedBy === 'render'),
|
||||||
|
@ -140,6 +140,8 @@ export function transformSceneToSaveModel(scene: DashboardScene, isSnapshot = fa
|
|||||||
liveNow,
|
liveNow,
|
||||||
schemaVersion: DASHBOARD_SCHEMA_VERSION,
|
schemaVersion: DASHBOARD_SCHEMA_VERSION,
|
||||||
refresh: refreshPicker?.state.refresh,
|
refresh: refreshPicker?.state.refresh,
|
||||||
|
// @ts-expect-error not in dashboard schema because it's experimental
|
||||||
|
scopeMeta: state.scopeMeta,
|
||||||
};
|
};
|
||||||
|
|
||||||
return sortedDeepCloneWithoutNulls(dashboard);
|
return sortedDeepCloneWithoutNulls(dashboard);
|
||||||
|
@ -56,6 +56,12 @@ export interface CloneOptions {
|
|||||||
|
|
||||||
export type DashboardLinkType = 'link' | 'dashboards';
|
export type DashboardLinkType = 'link' | 'dashboards';
|
||||||
|
|
||||||
|
/** @experimental */
|
||||||
|
export interface ScopeMeta {
|
||||||
|
trait: string;
|
||||||
|
groups: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export class DashboardModel implements TimeModel {
|
export class DashboardModel implements TimeModel {
|
||||||
/** @deprecated use UID */
|
/** @deprecated use UID */
|
||||||
id: any;
|
id: any;
|
||||||
@ -87,6 +93,7 @@ export class DashboardModel implements TimeModel {
|
|||||||
panelInEdit?: PanelModel;
|
panelInEdit?: PanelModel;
|
||||||
panelInView?: PanelModel;
|
panelInView?: PanelModel;
|
||||||
fiscalYearStartMonth?: number;
|
fiscalYearStartMonth?: number;
|
||||||
|
scopeMeta?: ScopeMeta;
|
||||||
private panelsAffectedByVariableChange: number[] | null;
|
private panelsAffectedByVariableChange: number[] | null;
|
||||||
private appEventsSubscription: Subscription;
|
private appEventsSubscription: Subscription;
|
||||||
private lastRefresh: number;
|
private lastRefresh: number;
|
||||||
@ -155,6 +162,8 @@ export class DashboardModel implements TimeModel {
|
|||||||
this.links = data.links ?? [];
|
this.links = data.links ?? [];
|
||||||
this.gnetId = data.gnetId || null;
|
this.gnetId = data.gnetId || null;
|
||||||
this.panels = map(data.panels ?? [], (panelData) => new PanelModel(panelData));
|
this.panels = map(data.panels ?? [], (panelData) => new PanelModel(panelData));
|
||||||
|
// @ts-expect-error - experimental and it's not included in the schema
|
||||||
|
this.scopeMeta = data.scopeMeta;
|
||||||
// Deep clone original dashboard to avoid mutations by object reference
|
// Deep clone original dashboard to avoid mutations by object reference
|
||||||
this.originalDashboard = cloneDeep(data);
|
this.originalDashboard = cloneDeep(data);
|
||||||
this.originalTemplating = cloneDeep(this.templating);
|
this.originalTemplating = cloneDeep(this.templating);
|
||||||
|
Loading…
Reference in New Issue
Block a user