Dashboard Scene: Fix unnecessary diffing (#100158)

* Fix unnecessary diffing

* use a diferent approach; update legacyId type

* fix test
This commit is contained in:
Haris Rozajac 2025-02-07 10:47:07 -07:00 committed by GitHub
parent 7b48670104
commit f5d8f42635
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 22 additions and 8 deletions

View File

@ -90,7 +90,7 @@ type GrafanaClientAnnotations = {
// Labels
type GrafanaLabels = {
[DeprecatedInternalId]?: number;
[DeprecatedInternalId]?: string;
};
export interface Resource<T = object, S = object, K = string> extends TypeMeta<K> {

View File

@ -64,7 +64,7 @@ export class V1DashboardSerializer implements DashboardSceneSerializerLike<Dashb
id: null,
uid: '',
title: options.title || '',
description: options.description || '',
description: options.description || undefined,
tags: options.isNew || options.copyTags ? saveModel.tags : [],
};
}

View File

@ -141,7 +141,11 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
const isDashboardEditable = Boolean(dashboard.editable);
const canSave = dto.access.canSave !== false;
const dashboardId = metadata.labels?.[DeprecatedInternalId];
let dashboardId: number | undefined = undefined;
if (metadata.labels?.[DeprecatedInternalId]) {
dashboardId = parseInt(metadata.labels[DeprecatedInternalId], 10);
}
const meta: DashboardMeta = {
canShare: dto.access.canShare !== false,

View File

@ -428,7 +428,7 @@ describe('ResponseTransformers', () => {
[AnnoKeySlug]: 'dashboard-slug',
},
labels: {
[DeprecatedInternalId]: 123,
[DeprecatedInternalId]: '123',
},
},
};
@ -444,7 +444,7 @@ describe('ResponseTransformers', () => {
expect(transformed.metadata.annotations?.[AnnoKeyFolder]).toEqual('folder1');
expect(transformed.metadata.annotations?.[AnnoKeySlug]).toEqual('dashboard-slug');
expect(transformed.metadata.annotations?.[AnnoKeyDashboardGnetId]).toBe('something-like-a-uid');
expect(transformed.metadata.labels?.[DeprecatedInternalId]).toBe(123);
expect(transformed.metadata.labels?.[DeprecatedInternalId]).toBe('123');
// Spec
const spec = transformed.spec;

View File

@ -134,7 +134,7 @@ export function ensureV2Response(
};
creationTimestamp = dto.meta.created;
labelsMeta = {
[DeprecatedInternalId]: dashboard.id ?? undefined,
[DeprecatedInternalId]: dashboard.id?.toString() ?? undefined,
};
}

View File

@ -10,6 +10,7 @@ import {
AnnoKeyMessage,
AnnoKeyFolder,
Resource,
DeprecatedInternalId,
} from 'app/features/apiserver/types';
import { getDashboardUrl } from 'app/features/dashboard-scene/utils/getDashboardUrl';
import { DeleteDashboardResponse } from 'app/features/manage-dashboards/types';
@ -107,6 +108,10 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard> {
dashboard: dash.spec,
};
if (dash.metadata.labels?.[DeprecatedInternalId]) {
result.dashboard.id = parseInt(dash.metadata.labels[DeprecatedInternalId], 10);
}
if (dash.metadata.annotations?.[AnnoKeyFolder]) {
try {
const folder = await backendSrv.getFolderByUid(dash.metadata.annotations[AnnoKeyFolder]);

View File

@ -113,7 +113,7 @@ describe('v2 dashboard API - Save', () => {
k8s: {
name: 'test-dash',
labels: {
[DeprecatedInternalId]: 123,
[DeprecatedInternalId]: '123',
},
annotations: {

View File

@ -143,10 +143,15 @@ export class K8sDashboardV2API
})
);
let dashId = 0;
if (v.metadata.labels?.[DeprecatedInternalId]) {
dashId = parseInt(v.metadata.labels[DeprecatedInternalId], 10);
}
return {
uid: v.metadata.name,
version: parseInt(v.metadata.resourceVersion, 10) ?? 0,
id: v.metadata.labels?.[DeprecatedInternalId] ?? 0,
id: dashId,
status: 'success',
url,
slug: '',