Skip to content

Commit

Permalink
Schema: Clean up / correct panel schema (grafana#76346)
Browse files Browse the repository at this point in the history
* Schema: Clean up / correct panel schema

* fixes
  • Loading branch information
torkelo authored Oct 11, 2023
1 parent bcf850f commit 72a1de8
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 114 deletions.
68 changes: 34 additions & 34 deletions docs/sources/developers/kinds/core/dashboard/schema-reference.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions kinds/dashboard/dashboard_kind.cue
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ lineage: schemas: [{
timezone?: string | *"browser"

// Whether a dashboard is editable or not.
editable: bool | *true
editable?: bool | *true

// Configuration of dashboard cursor sync behavior.
// Accepted values are 0 (sync turned off), 1 (shared crosshair), 2 (shared crosshair and tooltip).
graphTooltip: #DashboardCursorSync
graphTooltip?: #DashboardCursorSync

// Time range for dashboard.
// Accepted values are relative time strings like {from: 'now-6h', to: 'now'} or absolute time strings like {from: '2020-07-10T08:00:00.000Z', to: '2020-07-10T14:00:00.000Z'}.
Expand Down Expand Up @@ -515,7 +515,7 @@ lineage: schemas: [{
description?: string

// Whether to display the panel without a background.
transparent: bool | *false
transparent?: bool | *false

// The datasource used in all targets.
datasource?: #DataSourceRef
Expand Down Expand Up @@ -543,7 +543,7 @@ lineage: schemas: [{
// List of transformations that are applied to the panel data before rendering.
// When there are multiple transformations, Grafana applies them in the order they are listed.
// Each transformation creates a result set that then passes on to the next transformation in the processing pipeline.
transformations: [...#DataTransformerConfig]
transformations?: [...#DataTransformerConfig]

// The min time interval setting defines a lower limit for the $__interval and $__interval_ms variables.
// This value must be formatted as a number followed by a valid time
Expand Down Expand Up @@ -574,10 +574,10 @@ lineage: schemas: [{
libraryPanel?: #LibraryPanelRef

// It depends on the panel plugin. They are specified by the Options field in panel plugin schemas.
options: {...} @grafanamaturity(NeedsExpertReview)
options?: {...} @grafanamaturity(NeedsExpertReview)

// Field options allow you to change how the data is displayed in your visualizations.
fieldConfig: #FieldConfigSource
fieldConfig?: #FieldConfigSource
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview)

// The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export interface Panel {
/**
* Field options allow you to change how the data is displayed in your visualizations.
*/
fieldConfig: FieldConfigSource;
fieldConfig?: FieldConfigSource;
/**
* Grid position.
*/
Expand Down Expand Up @@ -684,7 +684,7 @@ export interface Panel {
/**
* It depends on the panel plugin. They are specified by the Options field in panel plugin schemas.
*/
options: Record<string, unknown>;
options?: Record<string, unknown>;
/**
* The version of the plugin that is used for this panel. This is used to find the plugin to display the panel and to migrate old panel configs.
*/
Expand Down Expand Up @@ -733,11 +733,11 @@ export interface Panel {
* When there are multiple transformations, Grafana applies them in the order they are listed.
* Each transformation creates a result set that then passes on to the next transformation in the processing pipeline.
*/
transformations: Array<DataTransformerConfig>;
transformations?: Array<DataTransformerConfig>;
/**
* Whether to display the panel without a background.
*/
transparent: boolean;
transparent?: boolean;
/**
* The panel plugin type id. This is used to find the plugin to display the panel.
*/
Expand Down Expand Up @@ -991,7 +991,7 @@ export interface Dashboard {
/**
* Whether a dashboard is editable or not.
*/
editable: boolean;
editable?: boolean;
/**
* The month that the fiscal year starts on. 0 = January, 11 = December
*/
Expand All @@ -1004,7 +1004,7 @@ export interface Dashboard {
* Configuration of dashboard cursor sync behavior.
* Accepted values are 0 (sync turned off), 1 (shared crosshair), 2 (shared crosshair and tooltip).
*/
graphTooltip: DashboardCursorSync;
graphTooltip?: DashboardCursorSync;
/**
* 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.
Expand Down
2 changes: 1 addition & 1 deletion packages/grafana-schema/src/veneer/dashboard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type { CommonDataSourceRef as DataSourceRef };

export interface Panel<TOptions = Record<string, unknown>, TCustomFieldConfig = Record<string, unknown>>
extends Omit<raw.Panel, 'fieldConfig'> {
fieldConfig: FieldConfigSource<TCustomFieldConfig>;
fieldConfig?: FieldConfigSource<TCustomFieldConfig>;
}

export interface RowPanel extends Omit<raw.RowPanel, 'panels'> {
Expand Down
12 changes: 6 additions & 6 deletions pkg/kinds/dashboard/dashboard_spec_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions public/app/features/alerting/TestRuleResult.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import React from 'react';

import { PanelModel } from '../dashboard/state';
import { createDashboardModelFixture, createPanelJSONFixture } from '../dashboard/state/__fixtures__/dashboardFixtures';
import { createDashboardModelFixture, createPanelSaveModel } from '../dashboard/state/__fixtures__/dashboardFixtures';

import { TestRuleResult } from './TestRuleResult';

Expand All @@ -22,7 +22,7 @@ jest.mock('@grafana/runtime', () => {
const props: React.ComponentProps<typeof TestRuleResult> = {
panel: new PanelModel({ id: 1 }),
dashboard: createDashboardModelFixture({
panels: [createPanelJSONFixture({ id: 1 })],
panels: [createPanelSaveModel({ id: 1 })],
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@grafana/scenes';
import { DashboardCursorSync, defaultDashboard, Panel, RowPanel, VariableType } from '@grafana/schema';
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
import { createPanelJSONFixture } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
import { createPanelSaveModel } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard';
import { DASHBOARD_DATASOURCE_PLUGIN_ID } from 'app/plugins/datasource/dashboard/types';

Expand Down Expand Up @@ -112,12 +112,12 @@ describe('transformSaveModelToScene', () => {

describe('when organizing panels as scene children', () => {
it('should create panels within collapsed rows', () => {
const panel = createPanelJSONFixture({
const panel = createPanelSaveModel({
title: 'test',
gridPos: { x: 1, y: 0, w: 12, h: 8 },
}) as Panel;

const row = createPanelJSONFixture({
const row = createPanelSaveModel({
title: 'test',
type: 'row',
gridPos: { x: 0, y: 0, w: 12, h: 1 },
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('transformSaveModelToScene', () => {
});

it('should create panels within expanded row', () => {
const panelOutOfRow = createPanelJSONFixture({
const panelOutOfRow = createPanelSaveModel({
title: 'Out of a row',
gridPos: {
h: 8,
Expand All @@ -155,7 +155,7 @@ describe('transformSaveModelToScene', () => {
y: 0,
},
});
const rowWithPanel = createPanelJSONFixture({
const rowWithPanel = createPanelSaveModel({
title: 'Row with panel',
type: 'row',
id: 10,
Expand All @@ -169,7 +169,7 @@ describe('transformSaveModelToScene', () => {
// This panels array is not used if the row is not collapsed
panels: [],
});
const panelInRow = createPanelJSONFixture({
const panelInRow = createPanelSaveModel({
gridPos: {
h: 8,
w: 12,
Expand All @@ -178,7 +178,7 @@ describe('transformSaveModelToScene', () => {
},
title: 'In row 1',
});
const emptyRow = createPanelJSONFixture({
const emptyRow = createPanelSaveModel({
collapsed: false,
gridPos: {
h: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('transformSceneToSaveModel', () => {

const result = gridItemToPanel(panel);

expect(result.transformations.length).toBe(1);
expect(result.transformations?.length).toBe(1);

expect(result.maxDataPoints).toBe(100);
expect(result.targets?.length).toBe(2);
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('transformSceneToSaveModel', () => {

const result = gridItemToPanel(panel);

expect(result.transformations.length).toBe(1);
expect(result.transformations?.length).toBe(1);

expect(result.targets?.length).toBe(1);
expect(result.targets?.[0]).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';

import { ContextSrv, setContextSrv } from '../../../../core/services/context_srv';
import { PanelModel } from '../../state/PanelModel';
import { createDashboardModelFixture, createPanelJSONFixture } from '../../state/__fixtures__/dashboardFixtures';
import { createDashboardModelFixture, createPanelSaveModel } from '../../state/__fixtures__/dashboardFixtures';

import { hasChanges, ignoreChanges } from './DashboardPrompt';

function getDefaultDashboardModel() {
return createDashboardModelFixture({
panels: [
createPanelJSONFixture({
createPanelSaveModel({
id: 1,
type: 'graph',
gridPos: { x: 0, y: 0, w: 24, h: 6 },
Expand Down
4 changes: 2 additions & 2 deletions public/app/features/dashboard/components/GenAI/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDashboardModelFixture, createPanelJSONFixture } from '../../state/__fixtures__/dashboardFixtures';
import { createDashboardModelFixture, createPanelSaveModel } from '../../state/__fixtures__/dashboardFixtures';

import { openai } from './llms';
import { getDashboardChanges, isLLMPluginEnabled, sanitizeReply } from './utils';
Expand All @@ -21,7 +21,7 @@ describe('getDashboardChanges', () => {
const deprecatedVersion = 37;
const dashboard = createDashboardModelFixture({
schemaVersion: deprecatedVersion,
panels: [createPanelJSONFixture({ title: 'Panel 1', options: deprecatedOptions })],
panels: [createPanelSaveModel({ title: 'Panel 1', options: deprecatedOptions })],
});

// Update title for the first panel
Expand Down
17 changes: 2 additions & 15 deletions public/app/features/dashboard/state/DashboardMigrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ describe('DashboardModel', () => {
{
type: 'row',
panels: [
// @ts-expect-error
{
id: 501,
type: 'table',
Expand Down Expand Up @@ -845,7 +844,6 @@ describe('DashboardModel', () => {
'# Angular Text Panel\n# $constant\n\nFor markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)\n\n## $text\n\n',
mode: 'markdown',
},
// @ts-expect-error
{
id: 3,
type: 'text2',
Expand All @@ -856,7 +854,6 @@ describe('DashboardModel', () => {
'# React Text Panel from scratch\n# $constant\n\nFor markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)\n\n## $text',
},
},
// @ts-expect-error
{
id: 4,
type: 'text2',
Expand Down Expand Up @@ -1594,7 +1591,6 @@ describe('DashboardModel', () => {
],
},
panels: [
// @ts-expect-error
{
gridPos: {
h: 8,
Expand Down Expand Up @@ -1717,7 +1713,6 @@ describe('DashboardModel', () => {
title: 'DynamoDB',
type: 'row',
panels: [
// @ts-expect-error
{
gridPos: {
h: 8,
Expand Down Expand Up @@ -1772,7 +1767,6 @@ describe('DashboardModel', () => {
title: 'Panel Title',
type: 'timeseries',
},
// @ts-expect-error
{
gridPos: {
h: 8,
Expand Down Expand Up @@ -1982,8 +1976,8 @@ describe('DashboardModel', () => {
describe('when migrating time series axis visibility', () => {
test('preserves x axis visibility', () => {
const model = new DashboardModel({
schemaVersion: 25,
panels: [
// @ts-expect-error
{
type: 'timeseries',
fieldConfig: {
Expand Down Expand Up @@ -2204,7 +2198,6 @@ describe('when migrating table cell display mode to cell options', () => {
beforeEach(() => {
model = new DashboardModel({
panels: [
// @ts-expect-error
{
id: 1,
type: 'table',
Expand All @@ -2216,9 +2209,8 @@ describe('when migrating table cell display mode to cell options', () => {
inspect: false,
},
},
} as unknown as FieldConfigSource, // missing overrides
} as unknown as FieldConfigSource, // missing overrides on purpose
},
// @ts-expect-error
{
id: 2,
type: 'table',
Expand All @@ -2233,7 +2225,6 @@ describe('when migrating table cell display mode to cell options', () => {
overrides: [],
},
},
// @ts-expect-error
{
id: 3,
type: 'table',
Expand All @@ -2248,7 +2239,6 @@ describe('when migrating table cell display mode to cell options', () => {
overrides: [],
},
},
// @ts-expect-error
{
id: 4,
type: 'table',
Expand All @@ -2263,7 +2253,6 @@ describe('when migrating table cell display mode to cell options', () => {
overrides: [],
},
},
// @ts-expect-error
{
id: 5,
type: 'table',
Expand All @@ -2278,7 +2267,6 @@ describe('when migrating table cell display mode to cell options', () => {
overrides: [],
},
},
// @ts-expect-error
{
id: 6,
type: 'table',
Expand Down Expand Up @@ -2346,7 +2334,6 @@ describe('when migrating table cell display mode to cell options', () => {
],
},
},
// @ts-expect-error
{
id: 7,
type: 'table',
Expand Down
Loading

0 comments on commit 72a1de8

Please sign in to comment.