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 { SaveDashboardAsOptions } from 'app/features/dashboard/components/SaveDashboard/types';
|
||||
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 { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
||||
import { getClosestScopesFacade, ScopesFacade } from 'app/features/scopes';
|
||||
@ -99,6 +99,8 @@ export interface DashboardSceneState extends SceneObjectState {
|
||||
preload?: boolean;
|
||||
/** A uid when saved */
|
||||
uid?: string;
|
||||
/** @experimental */
|
||||
scopeMeta?: ScopeMeta;
|
||||
/** @deprecated */
|
||||
id?: number | null;
|
||||
/** 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'] = [
|
||||
new behaviors.CursorSync({
|
||||
sync: oldModel.graphTooltip,
|
||||
@ -249,6 +257,7 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel,
|
||||
tags: oldModel.tags || [],
|
||||
title: oldModel.title,
|
||||
version: oldModel.version,
|
||||
scopeMeta,
|
||||
body: new DefaultGridLayoutManager({
|
||||
grid: new SceneGridLayout({
|
||||
isLazy: !(dto.preload || contextSrv.user.authenticatedBy === 'render'),
|
||||
|
@ -140,6 +140,8 @@ export function transformSceneToSaveModel(scene: DashboardScene, isSnapshot = fa
|
||||
liveNow,
|
||||
schemaVersion: DASHBOARD_SCHEMA_VERSION,
|
||||
refresh: refreshPicker?.state.refresh,
|
||||
// @ts-expect-error not in dashboard schema because it's experimental
|
||||
scopeMeta: state.scopeMeta,
|
||||
};
|
||||
|
||||
return sortedDeepCloneWithoutNulls(dashboard);
|
||||
|
@ -56,6 +56,12 @@ export interface CloneOptions {
|
||||
|
||||
export type DashboardLinkType = 'link' | 'dashboards';
|
||||
|
||||
/** @experimental */
|
||||
export interface ScopeMeta {
|
||||
trait: string;
|
||||
groups: string[];
|
||||
}
|
||||
|
||||
export class DashboardModel implements TimeModel {
|
||||
/** @deprecated use UID */
|
||||
id: any;
|
||||
@ -87,6 +93,7 @@ export class DashboardModel implements TimeModel {
|
||||
panelInEdit?: PanelModel;
|
||||
panelInView?: PanelModel;
|
||||
fiscalYearStartMonth?: number;
|
||||
scopeMeta?: ScopeMeta;
|
||||
private panelsAffectedByVariableChange: number[] | null;
|
||||
private appEventsSubscription: Subscription;
|
||||
private lastRefresh: number;
|
||||
@ -155,6 +162,8 @@ export class DashboardModel implements TimeModel {
|
||||
this.links = data.links ?? [];
|
||||
this.gnetId = data.gnetId || null;
|
||||
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
|
||||
this.originalDashboard = cloneDeep(data);
|
||||
this.originalTemplating = cloneDeep(this.templating);
|
||||
|
Loading…
Reference in New Issue
Block a user