mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard Scene: Fix unnecessary diffing (#100158)
* Fix unnecessary diffing * use a diferent approach; update legacyId type * fix test
This commit is contained in:
parent
7b48670104
commit
f5d8f42635
@ -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> {
|
||||
|
@ -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 : [],
|
||||
};
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -134,7 +134,7 @@ export function ensureV2Response(
|
||||
};
|
||||
creationTimestamp = dto.meta.created;
|
||||
labelsMeta = {
|
||||
[DeprecatedInternalId]: dashboard.id ?? undefined,
|
||||
[DeprecatedInternalId]: dashboard.id?.toString() ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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]);
|
||||
|
@ -113,7 +113,7 @@ describe('v2 dashboard API - Save', () => {
|
||||
k8s: {
|
||||
name: 'test-dash',
|
||||
labels: {
|
||||
[DeprecatedInternalId]: 123,
|
||||
[DeprecatedInternalId]: '123',
|
||||
},
|
||||
|
||||
annotations: {
|
||||
|
@ -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: '',
|
||||
|
Loading…
Reference in New Issue
Block a user