Dashboard: Schema V2 - Remove Dashboard id from spec (#99590)

* Dashboard: Schema V2 - Remove Dashboard id from spec

* Fix issue with dashboard id used in examples and serializers for schema v2

* Fix snapshot test
This commit is contained in:
Alexa V 2025-01-29 10:13:56 +01:00 committed by GitHub
parent 8e5a4560e8
commit 30c8ac7108
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 22 additions and 26 deletions

View File

@ -5,10 +5,6 @@ import (
)
DashboardV2Spec: {
// Unique numeric identifier for the dashboard.
// `id` is internal to a specific Grafana instance. `uid` should be used to identify a dashboard across Grafana instances.
id?: int64
// Title of dashboard.
title: string
@ -43,7 +39,7 @@ DashboardV2Spec: {
// Configured template variables.
variables: [...VariableKind]
elements: [ElementReference.name]: Element
elements: [ElementReference.name]: Element
annotations: [...AnnotationQueryKind]
@ -68,7 +64,7 @@ LibraryPanelSpec: {
id: number
// Title for the library panel in the dashboard
title: string
libraryPanel: LibraryPanelRef
}

View File

@ -1,7 +1,6 @@
import { DashboardV2Spec } from './types.gen';
export const handyTestingSchema: DashboardV2Spec = {
id: 1,
title: 'Default Dashboard',
description: 'This is a default dashboard',
cursorSync: 'Off',

View File

@ -4,9 +4,6 @@ import * as common from '@grafana/schema';
export interface DashboardV2Spec {
// Unique numeric identifier for the dashboard.
// `id` is internal to a specific Grafana instance. `uid` should be used to identify a dashboard across Grafana instances.
id?: number;
// Title of dashboard.
title: string;
// Description of dashboard.

View File

@ -42,7 +42,6 @@ export const AnnoKeyFolderId = 'grafana.app/folderId';
export const AnnoKeyFolderUrl = 'grafana.app/folderUrl';
export const AnnoKeyMessage = 'grafana.app/message';
export const AnnoKeySlug = 'grafana.app/slug';
export const AnnoKeyDashboardId = 'grafana.app/dashboardId';
// Identify where values came from
export const AnnoKeyRepoName = 'grafana.app/repoName';
@ -66,7 +65,6 @@ type GrafanaAnnotations = {
[AnnoKeyUpdatedBy]?: string;
[AnnoKeyFolder]?: string;
[AnnoKeySlug]?: string;
[AnnoKeyDashboardId]?: number;
[AnnoKeyRepoName]?: string;
[AnnoKeyRepoPath]?: string;

View File

@ -138,7 +138,7 @@ export function SaveDashboardAsForm({ dashboard, changeInfo }: Props) {
// Old folder picker fields
value={formValues.folder?.uid}
initialTitle={defaultValues!.folder!.title}
dashboardId={changedSaveModel.id ?? undefined}
dashboardId={dashboard.state.id ?? undefined}
enableCreateNew
/>
</Field>

View File

@ -627,7 +627,6 @@ describe('DashboardSceneSerializer', () => {
expect(saveAsModel).toMatchObject({
title: baseOptions.title,
description: baseOptions.description,
id: undefined,
editable: true,
annotations: [],
cursorSync: 'Off',
@ -801,7 +800,6 @@ describe('DashboardSceneSerializer', () => {
expect(serializer.initialSaveModel).toEqual({
...saveModel,
id: response.id,
});
});

View File

@ -172,7 +172,6 @@ export class V2DashboardSerializer
onSaveComplete(saveModel: DashboardV2Spec, result: SaveDashboardResponseDTO): void {
this.initialSaveModel = {
...saveModel,
id: result.id,
};
}

View File

@ -89,7 +89,6 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
},
},
},
"id": 1,
"layout": {
"kind": "GridLayout",
"spec": {

View File

@ -59,6 +59,7 @@ import {
AnnoKeyUpdatedBy,
AnnoKeyUpdatedTimestamp,
AnnoKeyDashboardIsSnapshot,
DeprecatedInternalId,
} from 'app/features/apiserver/types';
import { DashboardWithAccessInfo } from 'app/features/dashboard/api/types';
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource';
@ -125,6 +126,7 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
const isDashboardEditable = Boolean(dashboard.editable);
const canSave = dto.access.canSave !== false;
const dashboardId = metadata.labels?.[DeprecatedInternalId];
const meta: DashboardMeta = {
canShare: dto.access.canShare !== false,
@ -162,7 +164,7 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
description: dashboard.description,
editable: dashboard.editable,
preload: dashboard.preload,
id: dashboard.id,
id: dashboardId,
isDirty: false,
links: dashboard.links,
meta,
@ -198,11 +200,11 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
addPanelsOnLoadBehavior,
new DashboardScopesFacade({
reloadOnParamsChange: config.featureToggles.reloadDashboardsOnParamsChange,
uid: dashboard.id?.toString(),
uid: dashboardId?.toString(),
}),
new DashboardReloadBehavior({
reloadOnParamsChange: config.featureToggles.reloadDashboardsOnParamsChange,
uid: dashboard.id?.toString(),
uid: dashboardId?.toString(),
version: 1,
}),
],

View File

@ -76,7 +76,6 @@ export function transformSceneToSaveModelSchemaV2(scene: DashboardScene, isSnaps
const dashboardSchemaV2: DeepPartial<DashboardV2Spec> = {
//dashboard settings
id: oldDash.id ? oldDash.id : undefined,
title: oldDash.title,
description: oldDash.description ?? '',
cursorSync: getCursorSync(oldDash),

View File

@ -4,11 +4,11 @@ import { handyTestingSchema } from '@grafana/schema/dist/esm/schema/dashboard/v2
import {
AnnoKeyCreatedBy,
AnnoKeyDashboardGnetId,
AnnoKeyDashboardId,
AnnoKeyFolder,
AnnoKeySlug,
AnnoKeyUpdatedBy,
AnnoKeyUpdatedTimestamp,
DeprecatedInternalId,
} from 'app/features/apiserver/types';
import { getDefaultDataSourceRef } from 'app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2';
import {
@ -353,6 +353,9 @@ describe('ResponseTransformers', () => {
[AnnoKeyFolder]: 'folder1',
[AnnoKeySlug]: 'dashboard-slug',
},
labels: {
[DeprecatedInternalId]: 123,
},
},
};
@ -366,8 +369,8 @@ describe('ResponseTransformers', () => {
expect(transformed.metadata.annotations?.[AnnoKeyUpdatedTimestamp]).toEqual('2023-01-02T00:00:00Z');
expect(transformed.metadata.annotations?.[AnnoKeyFolder]).toEqual('folder1');
expect(transformed.metadata.annotations?.[AnnoKeySlug]).toEqual('dashboard-slug');
expect(transformed.metadata.annotations?.[AnnoKeyDashboardId]).toBe(123);
expect(transformed.metadata.annotations?.[AnnoKeyDashboardGnetId]).toBe('something-like-a-uid');
expect(transformed.metadata.labels?.[DeprecatedInternalId]).toBe(123);
// Spec
const spec = transformed.spec;

View File

@ -39,13 +39,13 @@ import { DashboardLink, DataTransformerConfig } from '@grafana/schema/src/raw/da
import {
AnnoKeyCreatedBy,
AnnoKeyDashboardGnetId,
AnnoKeyDashboardId,
AnnoKeyDashboardIsSnapshot,
AnnoKeyDashboardSnapshotOriginalUrl,
AnnoKeyFolder,
AnnoKeySlug,
AnnoKeyUpdatedBy,
AnnoKeyUpdatedTimestamp,
DeprecatedInternalId,
} from 'app/features/apiserver/types';
import { TypedVariableModelV2 } from 'app/features/dashboard-scene/serialization/transformSaveModelSchemaV2ToScene';
import { getDefaultDataSourceRef } from 'app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2';
@ -91,6 +91,7 @@ export function ensureV2Response(
let accessMeta: DashboardWithAccessInfo<DashboardV2Spec>['access'];
let annotationsMeta: DashboardWithAccessInfo<DashboardV2Spec>['metadata']['annotations'];
let labelsMeta: DashboardWithAccessInfo<DashboardV2Spec>['metadata']['labels'];
let creationTimestamp;
if (isDashboardResource(dto)) {
@ -101,11 +102,13 @@ export function ensureV2Response(
[AnnoKeyUpdatedTimestamp]: dto.metadata.annotations?.[AnnoKeyUpdatedTimestamp],
[AnnoKeyFolder]: dto.metadata.annotations?.[AnnoKeyFolder],
[AnnoKeySlug]: dto.metadata.annotations?.[AnnoKeySlug],
[AnnoKeyDashboardId]: dashboard.id ?? undefined,
[AnnoKeyDashboardGnetId]: dashboard.gnetId ?? undefined,
[AnnoKeyDashboardIsSnapshot]: dto.metadata.annotations?.[AnnoKeyDashboardIsSnapshot],
};
creationTimestamp = dto.metadata.creationTimestamp;
labelsMeta = {
[DeprecatedInternalId]: dto.metadata.labels?.[DeprecatedInternalId],
};
} else {
accessMeta = {
url: dto.meta.url,
@ -124,11 +127,13 @@ export function ensureV2Response(
[AnnoKeyUpdatedTimestamp]: dto.meta.updated,
[AnnoKeyFolder]: dto.meta.folderUid,
[AnnoKeySlug]: dto.meta.slug,
[AnnoKeyDashboardId]: dashboard.id ?? undefined,
[AnnoKeyDashboardGnetId]: dashboard.gnetId ?? undefined,
[AnnoKeyDashboardIsSnapshot]: dto.meta.isSnapshot,
};
creationTimestamp = dto.meta.created;
labelsMeta = {
[DeprecatedInternalId]: dashboard.id ?? undefined,
};
}
if (annotationsMeta?.[AnnoKeyDashboardIsSnapshot]) {
@ -171,6 +176,7 @@ export function ensureV2Response(
name: dashboard.uid,
resourceVersion: dashboard.version?.toString() || '0',
annotations: annotationsMeta,
labels: labelsMeta,
},
spec,
access: accessMeta,