mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Schema v2: Express isNew dashboard through client annotations (#98408)
* Schema v2: Express isNew dashboard through client annotations
* Betterer update
* Revert "Betterer update"
This reverts commit e9d1fe3c4e
.
This commit is contained in:
parent
37e47d5b9a
commit
bc96da3a95
@ -46,6 +46,7 @@ export const AnnoKeyRepoHash = 'grafana.app/repoHash';
|
||||
export const AnnoKeyRepoTimestamp = 'grafana.app/repoTimestamp';
|
||||
|
||||
export const AnnoKeySavedFromUI = 'grafana.app/saved-from-ui';
|
||||
export const AnnoKeyDashboardIsNew = 'grafana.app/dashboard-is-new';
|
||||
|
||||
// Annotations provided by the API
|
||||
type GrafanaAnnotations = {
|
||||
@ -69,6 +70,7 @@ type GrafanaClientAnnotations = {
|
||||
[AnnoKeyFolderId]?: number;
|
||||
[AnnoKeyFolderId]?: number;
|
||||
[AnnoKeySavedFromUI]?: string;
|
||||
[AnnoKeyDashboardIsNew]?: boolean;
|
||||
};
|
||||
|
||||
export interface Resource<T = object, K = string> extends TypeMeta<K> {
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
defaultTimeSettingsSpec,
|
||||
GroupByVariableKind,
|
||||
} from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0/dashboard.gen';
|
||||
import { AnnoKeyFolder } from 'app/features/apiserver/types';
|
||||
import { AnnoKeyDashboardIsNew, AnnoKeyFolder } from 'app/features/apiserver/types';
|
||||
import { DashboardWithAccessInfo } from 'app/features/dashboard/api/types';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
import { DashboardDTO } from 'app/types';
|
||||
@ -122,8 +122,6 @@ export async function buildNewDashboardSaveModelV2(
|
||||
canStar: false,
|
||||
canShare: false,
|
||||
canDelete: false,
|
||||
// Not sure this should belong here or to metadata.annotations
|
||||
isNew: true,
|
||||
},
|
||||
metadata: {
|
||||
name: '',
|
||||
@ -131,6 +129,7 @@ export async function buildNewDashboardSaveModelV2(
|
||||
creationTimestamp: '0',
|
||||
annotations: {
|
||||
[AnnoKeyFolder]: '',
|
||||
[AnnoKeyDashboardIsNew]: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -26,6 +26,7 @@ import {
|
||||
TextVariableKind,
|
||||
} from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0/dashboard.gen';
|
||||
import { handyTestingSchema } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0/examples';
|
||||
import { AnnoKeyDashboardIsNew } from 'app/features/apiserver/types';
|
||||
import { DashboardWithAccessInfo } from 'app/features/dashboard/api/types';
|
||||
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource';
|
||||
|
||||
@ -305,4 +306,25 @@ describe('transformSaveModelSchemaV2ToScene', () => {
|
||||
expect(getQueryRunnerFor(vizPanels[0])?.state.datasource?.type).toBe('mixed');
|
||||
expect(getQueryRunnerFor(vizPanels[0])?.state.datasource?.uid).toBe(MIXED_DATASOURCE_NAME);
|
||||
});
|
||||
|
||||
describe('is new dashboard handling', () => {
|
||||
it('handles undefined is new dashbaord annotation', () => {
|
||||
const scene = transformSaveModelSchemaV2ToScene(defaultDashboard);
|
||||
expect(scene.state.meta.isNew).toBe(false);
|
||||
});
|
||||
it('handles defined is new dashbaord annotation', () => {
|
||||
const dashboard: DashboardWithAccessInfo<DashboardV2Spec> = {
|
||||
...defaultDashboard,
|
||||
metadata: {
|
||||
...defaultDashboard.metadata,
|
||||
annotations: {
|
||||
...defaultDashboard.metadata.annotations,
|
||||
[AnnoKeyDashboardIsNew]: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
const scene = transformSaveModelSchemaV2ToScene(dashboard);
|
||||
expect(scene.state.meta.isNew).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -51,6 +51,7 @@ import {
|
||||
QueryVariableKind,
|
||||
TextVariableKind,
|
||||
} from '@grafana/schema/src/schema/dashboard/v2alpha0/dashboard.gen';
|
||||
import { AnnoKeyDashboardIsNew } from 'app/features/apiserver/types';
|
||||
import { DashboardWithAccessInfo } from 'app/features/dashboard/api/types';
|
||||
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource';
|
||||
|
||||
@ -122,6 +123,7 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
|
||||
// TODO: Combine access and metadata to compose the V1 meta object
|
||||
meta: {
|
||||
version: parseInt(metadata.resourceVersion, 10),
|
||||
isNew: Boolean(dto.metadata.annotations?.[AnnoKeyDashboardIsNew]),
|
||||
},
|
||||
tags: dashboard.tags,
|
||||
title: dashboard.title,
|
||||
|
@ -26,6 +26,5 @@ export interface DashboardWithAccessInfo<T> extends Resource<T, 'DashboardWithAc
|
||||
canStar?: boolean;
|
||||
canAdmin?: boolean;
|
||||
annotationsPermissions?: AnnotationsPermissions;
|
||||
isNew?: boolean;
|
||||
}; // TODO...
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user