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
|
// Labels
|
||||||
type GrafanaLabels = {
|
type GrafanaLabels = {
|
||||||
[DeprecatedInternalId]?: number;
|
[DeprecatedInternalId]?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface Resource<T = object, S = object, K = string> extends TypeMeta<K> {
|
export interface Resource<T = object, S = object, K = string> extends TypeMeta<K> {
|
||||||
|
@ -64,7 +64,7 @@ export class V1DashboardSerializer implements DashboardSceneSerializerLike<Dashb
|
|||||||
id: null,
|
id: null,
|
||||||
uid: '',
|
uid: '',
|
||||||
title: options.title || '',
|
title: options.title || '',
|
||||||
description: options.description || '',
|
description: options.description || undefined,
|
||||||
tags: options.isNew || options.copyTags ? saveModel.tags : [],
|
tags: options.isNew || options.copyTags ? saveModel.tags : [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,11 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
|
|||||||
|
|
||||||
const isDashboardEditable = Boolean(dashboard.editable);
|
const isDashboardEditable = Boolean(dashboard.editable);
|
||||||
const canSave = dto.access.canSave !== false;
|
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 = {
|
const meta: DashboardMeta = {
|
||||||
canShare: dto.access.canShare !== false,
|
canShare: dto.access.canShare !== false,
|
||||||
|
@ -428,7 +428,7 @@ describe('ResponseTransformers', () => {
|
|||||||
[AnnoKeySlug]: 'dashboard-slug',
|
[AnnoKeySlug]: 'dashboard-slug',
|
||||||
},
|
},
|
||||||
labels: {
|
labels: {
|
||||||
[DeprecatedInternalId]: 123,
|
[DeprecatedInternalId]: '123',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -444,7 +444,7 @@ describe('ResponseTransformers', () => {
|
|||||||
expect(transformed.metadata.annotations?.[AnnoKeyFolder]).toEqual('folder1');
|
expect(transformed.metadata.annotations?.[AnnoKeyFolder]).toEqual('folder1');
|
||||||
expect(transformed.metadata.annotations?.[AnnoKeySlug]).toEqual('dashboard-slug');
|
expect(transformed.metadata.annotations?.[AnnoKeySlug]).toEqual('dashboard-slug');
|
||||||
expect(transformed.metadata.annotations?.[AnnoKeyDashboardGnetId]).toBe('something-like-a-uid');
|
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
|
// Spec
|
||||||
const spec = transformed.spec;
|
const spec = transformed.spec;
|
||||||
|
@ -134,7 +134,7 @@ export function ensureV2Response(
|
|||||||
};
|
};
|
||||||
creationTimestamp = dto.meta.created;
|
creationTimestamp = dto.meta.created;
|
||||||
labelsMeta = {
|
labelsMeta = {
|
||||||
[DeprecatedInternalId]: dashboard.id ?? undefined,
|
[DeprecatedInternalId]: dashboard.id?.toString() ?? undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
AnnoKeyMessage,
|
AnnoKeyMessage,
|
||||||
AnnoKeyFolder,
|
AnnoKeyFolder,
|
||||||
Resource,
|
Resource,
|
||||||
|
DeprecatedInternalId,
|
||||||
} from 'app/features/apiserver/types';
|
} from 'app/features/apiserver/types';
|
||||||
import { getDashboardUrl } from 'app/features/dashboard-scene/utils/getDashboardUrl';
|
import { getDashboardUrl } from 'app/features/dashboard-scene/utils/getDashboardUrl';
|
||||||
import { DeleteDashboardResponse } from 'app/features/manage-dashboards/types';
|
import { DeleteDashboardResponse } from 'app/features/manage-dashboards/types';
|
||||||
@ -107,6 +108,10 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard> {
|
|||||||
dashboard: dash.spec,
|
dashboard: dash.spec,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (dash.metadata.labels?.[DeprecatedInternalId]) {
|
||||||
|
result.dashboard.id = parseInt(dash.metadata.labels[DeprecatedInternalId], 10);
|
||||||
|
}
|
||||||
|
|
||||||
if (dash.metadata.annotations?.[AnnoKeyFolder]) {
|
if (dash.metadata.annotations?.[AnnoKeyFolder]) {
|
||||||
try {
|
try {
|
||||||
const folder = await backendSrv.getFolderByUid(dash.metadata.annotations[AnnoKeyFolder]);
|
const folder = await backendSrv.getFolderByUid(dash.metadata.annotations[AnnoKeyFolder]);
|
||||||
|
@ -113,7 +113,7 @@ describe('v2 dashboard API - Save', () => {
|
|||||||
k8s: {
|
k8s: {
|
||||||
name: 'test-dash',
|
name: 'test-dash',
|
||||||
labels: {
|
labels: {
|
||||||
[DeprecatedInternalId]: 123,
|
[DeprecatedInternalId]: '123',
|
||||||
},
|
},
|
||||||
|
|
||||||
annotations: {
|
annotations: {
|
||||||
|
@ -143,10 +143,15 @@ export class K8sDashboardV2API
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let dashId = 0;
|
||||||
|
if (v.metadata.labels?.[DeprecatedInternalId]) {
|
||||||
|
dashId = parseInt(v.metadata.labels[DeprecatedInternalId], 10);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uid: v.metadata.name,
|
uid: v.metadata.name,
|
||||||
version: parseInt(v.metadata.resourceVersion, 10) ?? 0,
|
version: parseInt(v.metadata.resourceVersion, 10) ?? 0,
|
||||||
id: v.metadata.labels?.[DeprecatedInternalId] ?? 0,
|
id: dashId,
|
||||||
status: 'success',
|
status: 'success',
|
||||||
url,
|
url,
|
||||||
slug: '',
|
slug: '',
|
||||||
|
Loading…
Reference in New Issue
Block a user