Skip to content

Commit

Permalink
GeneralSettings: Edit general dashboards settings to scenes (grafana#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanortegaalba authored Dec 1, 2023
1 parent c354c7b commit e56a252
Show file tree
Hide file tree
Showing 30 changed files with 1,169 additions and 133 deletions.
9 changes: 7 additions & 2 deletions .betterer.results
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"],
[0, 0, 0, "Do not use any type assertions.", "5"]
[0, 0, 0, "Do not use any type assertions.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"]
],
"packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
Expand Down Expand Up @@ -2655,6 +2656,9 @@ exports[`better eslint`] = {
"public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
],
"public/app/features/dashboard-scene/scene/DashboardScene.test.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
Expand All @@ -2680,7 +2684,8 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
Expand Down
24 changes: 12 additions & 12 deletions docs/sources/developers/kinds/core/dashboard/schema-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extraFields is reserved for any fields that are pulled from the API server metad
| `tags` | string[] | No | | Tags associated with dashboard. |
| `templating` | [object](#templating) | No | | Configured template variables |
| `time` | [object](#time) | No | | Time range for dashboard.<br/>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'}. |
| `timepicker` | [object](#timepicker) | No | | Configuration of the time picker shown at the top of a dashboard. |
| `timepicker` | [TimePickerConfig](#timepickerconfig) | No | | Time picker configuration<br/>It defines the default config for the time picker and the refresh picker for the specific dashboard. |
| `timezone` | string | No | `browser` | Timezone of dashboard. Accepted values are IANA TZDB zone ID or "browser" or "utc". |
| `title` | string | No | | Title of dashboard. |
| `uid` | string | No | | Unique dashboard identifier that can be generated by anyone. string (8-40) |
Expand Down Expand Up @@ -190,6 +190,17 @@ Sensitive information stripped: queries (metric, template,annotation) and panel
| `userId` | uint32 | **Yes** | | user id of the snapshot creator |
| `url` | string | No | | url of the snapshot, if snapshot was shared internally |

### TimePickerConfig

Time picker configuration
It defines the default config for the time picker and the refresh picker for the specific dashboard.

| Property | Type | Required | Default | Description |
|---------------------|----------|----------|---------------------------------------|---------------------------------------------------------------------------------------------------|
| `hidden` | boolean | **Yes** | `false` | Whether timepicker is visible or not. |
| `refresh_intervals` | string[] | **Yes** | `[5s 10s 30s 1m 5m 15m 30m 1h 2h 1d]` | Interval options available in the refresh picker dropdown. |
| `time_options` | string[] | **Yes** | `[5m 15m 1h 6h 12h 24h 2d 7d 30d]` | Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard. |

### Panels

| Property | Type | Required | Default | Description |
Expand Down Expand Up @@ -625,17 +636,6 @@ Accepted values are relative time strings like {from: 'now-6h', to: 'now'} or ab
| `from` | string | **Yes** | `now-6h` | |
| `to` | string | **Yes** | `now` | |

### Timepicker

Configuration of the time picker shown at the top of a dashboard.

| Property | Type | Required | Default | Description |
|---------------------|----------|----------|---------------------------------------|---------------------------------------------------------------------------------------------------|
| `collapse` | boolean | **Yes** | `false` | Whether timepicker is collapsed or not. Has no effect on provisioned dashboard. |
| `hidden` | boolean | **Yes** | `false` | Whether timepicker is visible or not. |
| `refresh_intervals` | string[] | **Yes** | `[5s 10s 30s 1m 5m 15m 30m 1h 2h 1d]` | Interval options available in the refresh picker dropdown. |
| `time_options` | string[] | **Yes** | `[5m 15m 1h 6h 12h 24h 2d 7d 30d]` | Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard. |

### Status

| Property | Type | Required | Default | Description |
Expand Down
22 changes: 12 additions & 10 deletions kinds/dashboard/dashboard_kind.cue
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ lineage: schemas: [{
}

// Configuration of the time picker shown at the top of a dashboard.
timepicker?: {
// Whether timepicker is visible or not.
hidden: bool | *false
// Interval options available in the refresh picker dropdown.
refresh_intervals: [...string] | *["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"]
// Whether timepicker is collapsed or not. Has no effect on provisioned dashboard.
collapse: bool | *false
// Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard.
time_options: [...string] | *["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"]
}
timepicker?: #TimePickerConfig

// The month that the fiscal year starts on. 0 = January, 11 = December
fiscalYearStartMonth?: uint8 & <12 | *0
Expand Down Expand Up @@ -452,6 +443,17 @@ lineage: schemas: [{
options: _
} @cuetsy(kind="interface") @grafana(TSVeneer="type")

// Time picker configuration
// It defines the default config for the time picker and the refresh picker for the specific dashboard.
#TimePickerConfig: {
// Whether timepicker is visible or not.
hidden: bool | *false
// Interval options available in the refresh picker dropdown.
refresh_intervals: [...string] | *["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"]
// Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard.
time_options: [...string] | *["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"]
} @cuetsy(kind="interface") @grafana(TSVeneer="type")

// 0 for no shared crosshair or tooltip (default).
// 1 for shared crosshair.
// 2 for shared crosshair AND shared tooltip.
Expand Down
2 changes: 2 additions & 0 deletions packages/grafana-schema/src/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type {
VariableModel,
DataSourceRef,
DataTransformerConfig,
TimePickerConfig,
Panel,
FieldConfigSource,
MatcherConfig,
Expand All @@ -95,6 +96,7 @@ export {
defaultAnnotationQuery,
defaultVariableModel,
VariableHide,
defaultTimePickerConfig,
defaultPanel,
defaultFieldConfigSource,
defaultMatcherConfig,
Expand Down
44 changes: 26 additions & 18 deletions packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,31 @@ export interface DataTransformerConfig {
options: unknown;
}

/**
* Time picker configuration
* It defines the default config for the time picker and the refresh picker for the specific dashboard.
*/
export interface TimePickerConfig {
/**
* Whether timepicker is visible or not.
*/
hidden: boolean;
/**
* Interval options available in the refresh picker dropdown.
*/
refresh_intervals: Array<string>;
/**
* Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard.
*/
time_options: Array<string>;
}

export const defaultTimePickerConfig: Partial<TimePickerConfig> = {
hidden: false,
refresh_intervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'],
time_options: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'],
};

/**
* 0 for no shared crosshair or tooltip (default).
* 1 for shared crosshair.
Expand Down Expand Up @@ -1096,24 +1121,7 @@ export interface Dashboard {
/**
* Configuration of the time picker shown at the top of a dashboard.
*/
timepicker?: {
/**
* Whether timepicker is visible or not.
*/
hidden: boolean;
/**
* Interval options available in the refresh picker dropdown.
*/
refresh_intervals: Array<string>;
/**
* Whether timepicker is collapsed or not. Has no effect on provisioned dashboard.
*/
collapse: boolean;
/**
* Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard.
*/
time_options: Array<string>;
};
timepicker?: TimePickerConfig;
/**
* Timezone of dashboard. Accepted values are IANA TZDB zone ID or "browser" or "utc".
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/grafana-schema/src/veneer/dashboard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ export interface DataTransformerConfig<TOptions = any> extends raw.DataTransform
options: TOptions;
}

export interface TimePickerConfig extends raw.TimePickerConfig {}

export const defaultDashboard = raw.defaultDashboard as Dashboard;
export const defaultVariableModel = {
...raw.defaultVariableModel,
} as VariableModel;
export const defaultTimePickerConfig = raw.defaultTimePickerConfig as TimePickerConfig;
export const defaultPanel: Partial<Panel> = raw.defaultPanel;
export const defaultRowPanel: Partial<Panel> = raw.defaultRowPanel;
export const defaultFieldConfig: Partial<FieldConfig> = raw.defaultFieldConfig;
Expand Down
30 changes: 16 additions & 14 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.

63 changes: 61 additions & 2 deletions public/app/features/dashboard-scene/scene/DashboardScene.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
sceneGraph,
SceneGridItem,
SceneGridLayout,
SceneRefreshPicker,
SceneTimeRange,
SceneQueryRunner,
SceneVariableSet,
TestVariable,
Expand All @@ -12,8 +14,11 @@ import appEvents from 'app/core/app_events';
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
import { VariablesChanged } from 'app/features/variables/types';

import { dashboardSceneGraph } from '../utils/dashboardSceneGraph';
import { djb2Hash } from '../utils/djb2Hash';

import { DashboardControls } from './DashboardControls';
import { DashboardLinksControls } from './DashboardLinksControls';
import { DashboardScene, DashboardSceneState } from './DashboardScene';

describe('DashboardScene', () => {
Expand Down Expand Up @@ -45,12 +50,54 @@ describe('DashboardScene', () => {

expect(scene.state.isDirty).toBe(true);

// verify can discard change
scene.onDiscard();

const gridItem2 = sceneGraph.findObject(scene, (p) => p.state.key === 'griditem-1') as SceneGridItem;
expect(gridItem2.state.x).toBe(0);
});

it.each`
prop | value
${'title'} | ${'new title'}
${'description'} | ${'new description'}
${'tags'} | ${['tag1', 'tag2']}
${'editable'} | ${false}
${'graphTooltip'} | ${1}
`(
'A change to $prop should set isDirty true',
({ prop, value }: { prop: keyof DashboardSceneState; value: any }) => {
scene.setState({ [prop]: value });

expect(scene.state.isDirty).toBe(true);

// TODO: Discard doesn't restore the previous state
// scene.onDiscard();
// expect(scene.state[prop]).toBe(prevState);
}
);

// TODO: Make the dashboard to restore the defaults on discard
it.skip('A change to refresh picker interval settings should set isDirty true', () => {
const refreshPicker = dashboardSceneGraph.getRefreshPicker(scene)!;
const prevState = refreshPicker.state.intervals;
refreshPicker.setState({ intervals: ['10s'] });

expect(scene.state.isDirty).toBe(true);

scene.onDiscard();
expect(refreshPicker.state.intervals).toEqual(prevState);
});

// TODO: Make the dashboard to restore the defaults on discard
it.skip('A change to time zone should set isDirty true', () => {
const timeRange = scene.state.$timeRange!;
const prevState = timeRange.state.timeZone;
timeRange.setState({ timeZone: 'UTC' });

expect(scene.state.isDirty).toBe(true);

scene.onDiscard();
expect(timeRange.state.timeZone).toBe(prevState);
});
});
});

Expand Down Expand Up @@ -101,6 +148,18 @@ function buildTestScene(overrides?: Partial<DashboardSceneState>) {
const scene = new DashboardScene({
title: 'hello',
uid: 'dash-1',
$timeRange: new SceneTimeRange({}),
controls: [
new DashboardControls({
variableControls: [],
linkControls: new DashboardLinksControls({}),
timeControls: [
new SceneRefreshPicker({
intervals: ['1s'],
}),
],
}),
],
body: new SceneGridLayout({
children: [
new SceneGridItem({
Expand Down
Loading

0 comments on commit e56a252

Please sign in to comment.