diff --git a/.betterer.results b/.betterer.results index 710e638b2ba..e96c38df1a7 100644 --- a/.betterer.results +++ b/.betterer.results @@ -242,7 +242,7 @@ exports[`no enzyme tests`] = { "public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.test.tsx:3424320489": [ [0, 19, 13, "RegExp match", "2409514259"] ], - "public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx:1597135392": [ + "public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx:3368730691": [ [0, 31, 13, "RegExp match", "2409514259"] ] }` diff --git a/pkg/cmd/grafana-cli/commands/cuetsify_command.go b/pkg/cmd/grafana-cli/commands/cuetsify_command.go index b66e8143c2f..ed8deb0f11a 100644 --- a/pkg/cmd/grafana-cli/commands/cuetsify_command.go +++ b/pkg/cmd/grafana-cli/commands/cuetsify_command.go @@ -39,10 +39,7 @@ var importMap = map[string]string{ // to rely on the TypeScript auto-generated by cuetsy for that particular file. var skipPaths = []string{ "public/app/plugins/panel/barchart/models.cue", - "public/app/plugins/panel/bargauge/models.cue", "public/app/plugins/panel/canvas/models.cue", - "public/app/plugins/panel/dashlist/models.cue", - "public/app/plugins/panel/gauge/models.cue", "public/app/plugins/panel/histogram/models.cue", "public/app/plugins/panel/heatmap-new/models.cue", "public/app/plugins/panel/candlestick/models.cue", diff --git a/public/app/plugins/panel/bargauge/BarGaugeMigrations.ts b/public/app/plugins/panel/bargauge/BarGaugeMigrations.ts index dd97201ac9f..ca4ade8cf7d 100644 --- a/public/app/plugins/panel/bargauge/BarGaugeMigrations.ts +++ b/public/app/plugins/panel/bargauge/BarGaugeMigrations.ts @@ -1,8 +1,8 @@ import { PanelModel } from '@grafana/data'; import { sharedSingleStatMigrationHandler } from '@grafana/ui'; -import { BarGaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; -export const barGaugePanelMigrationHandler = (panel: PanelModel): Partial => { +export const barGaugePanelMigrationHandler = (panel: PanelModel): Partial => { return sharedSingleStatMigrationHandler(panel); }; diff --git a/public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx b/public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx index 18f64bccbaa..e5946a60ee3 100644 --- a/public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx +++ b/public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx @@ -16,7 +16,7 @@ import { selectors } from '@grafana/e2e-selectors'; import { BarGaugeDisplayMode } from '@grafana/ui'; import { BarGaugePanel } from './BarGaugePanel'; -import { BarGaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; const valueSelector = selectors.components.Panels.Visualization.BarGauge.valueV2; @@ -64,10 +64,10 @@ function createTimeRange(): TimeRange { }; } -function createBarGaugePanelWithData(data: PanelData): ReactWrapper> { +function createBarGaugePanelWithData(data: PanelData): ReactWrapper> { const timeRange = createTimeRange(); - const options: BarGaugeOptions = { + const options: PanelOptions = { displayMode: BarGaugeDisplayMode.Lcd, reduceOptions: { calcs: ['mean'], diff --git a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx index 95ce378211c..3d8d04373a4 100644 --- a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx +++ b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx @@ -16,9 +16,9 @@ import { BarGauge, DataLinksContextMenu, VizRepeater, VizRepeaterRenderValueProp import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu'; import { config } from 'app/core/config'; -import { BarGaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; -export class BarGaugePanel extends PureComponent> { +export class BarGaugePanel extends PureComponent> { renderComponent = ( valueProps: VizRepeaterRenderValueProps, menuProps: DataLinksContextMenuApi diff --git a/public/app/plugins/panel/bargauge/models.cue b/public/app/plugins/panel/bargauge/models.cue index 30a7a4515f7..cffc96d6eac 100644 --- a/public/app/plugins/panel/bargauge/models.cue +++ b/public/app/plugins/panel/bargauge/models.cue @@ -22,8 +22,10 @@ Panel: { { PanelOptions: { ui.SingleStatBaseOptions - displayMode: ui.BarGaugeDisplayMode - showUnfilled: bool + displayMode: ui.BarGaugeDisplayMode | *"gradient" + showUnfilled: bool | *true + minVizWidth: uint32 | *0 + minVizHeight: uint32 | *10 } @cuetsy(kind="interface") } ] diff --git a/public/app/plugins/panel/bargauge/models.gen.ts b/public/app/plugins/panel/bargauge/models.gen.ts new file mode 100644 index 00000000000..e595e3cd0a2 --- /dev/null +++ b/public/app/plugins/panel/bargauge/models.gen.ts @@ -0,0 +1,22 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// This file was autogenerated by cuetsy. DO NOT EDIT! +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import * as ui from '@grafana/schema'; + +export const modelVersion = Object.freeze([0, 0]); + + +export interface PanelOptions extends ui.SingleStatBaseOptions { + displayMode: ui.BarGaugeDisplayMode; + minVizHeight: number; + minVizWidth: number; + showUnfilled: boolean; +} + +export const defaultPanelOptions: Partial = { + displayMode: ui.BarGaugeDisplayMode.Gradient, + minVizHeight: 10, + minVizWidth: 0, + showUnfilled: true, +}; diff --git a/public/app/plugins/panel/bargauge/module.tsx b/public/app/plugins/panel/bargauge/module.tsx index 07e8f3e6373..43295226fee 100644 --- a/public/app/plugins/panel/bargauge/module.tsx +++ b/public/app/plugins/panel/bargauge/module.tsx @@ -1,14 +1,15 @@ import { PanelPlugin, VizOrientation } from '@grafana/data'; +import { BarGaugeDisplayMode } from '@grafana/schema'; import { commonOptionsBuilder, sharedSingleStatPanelChangedHandler } from '@grafana/ui'; import { addOrientationOption, addStandardDataReduceOptions } from '../stat/common'; import { barGaugePanelMigrationHandler } from './BarGaugeMigrations'; import { BarGaugePanel } from './BarGaugePanel'; +import { PanelOptions, defaultPanelOptions } from './models.gen'; import { BarGaugeSuggestionsSupplier } from './suggestions'; -import { BarGaugeOptions, displayModes } from './types'; -export const plugin = new PanelPlugin(BarGaugePanel) +export const plugin = new PanelPlugin(BarGaugePanel) .useFieldConfig() .setPanelOptions((builder) => { addStandardDataReduceOptions(builder); @@ -20,30 +21,34 @@ export const plugin = new PanelPlugin(BarGaugePanel) path: 'displayMode', name: 'Display mode', settings: { - options: displayModes, + options: [ + { value: BarGaugeDisplayMode.Gradient, label: 'Gradient' }, + { value: BarGaugeDisplayMode.Lcd, label: 'Retro LCD' }, + { value: BarGaugeDisplayMode.Basic, label: 'Basic' }, + ], }, - defaultValue: 'gradient', + defaultValue: defaultPanelOptions.displayMode, }) .addBooleanSwitch({ path: 'showUnfilled', name: 'Show unfilled area', description: 'When enabled renders the unfilled region as gray', - defaultValue: true, - showIf: (options: BarGaugeOptions) => options.displayMode !== 'lcd', + defaultValue: defaultPanelOptions.showUnfilled, + showIf: (options) => options.displayMode !== 'lcd', }) .addNumberInput({ path: 'minVizWidth', name: 'Min width', description: 'Minimum column width', - defaultValue: 0, - showIf: (options: BarGaugeOptions) => options.orientation === VizOrientation.Vertical, + defaultValue: defaultPanelOptions.minVizWidth, + showIf: (options) => options.orientation === VizOrientation.Vertical, }) .addNumberInput({ path: 'minVizHeight', name: 'Min height', description: 'Minimum row height', - defaultValue: 10, - showIf: (options: BarGaugeOptions) => options.orientation === VizOrientation.Horizontal, + defaultValue: defaultPanelOptions.minVizHeight, + showIf: (options) => options.orientation === VizOrientation.Horizontal, }); }) .setPanelChangeHandler(sharedSingleStatPanelChangedHandler) diff --git a/public/app/plugins/panel/bargauge/suggestions.ts b/public/app/plugins/panel/bargauge/suggestions.ts index 2c905c9095a..31df170035e 100644 --- a/public/app/plugins/panel/bargauge/suggestions.ts +++ b/public/app/plugins/panel/bargauge/suggestions.ts @@ -2,7 +2,7 @@ import { VisualizationSuggestionsBuilder, VizOrientation } from '@grafana/data'; import { BarGaugeDisplayMode } from '@grafana/ui'; import { SuggestionName } from 'app/types/suggestions'; -import { BarGaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; export class BarGaugeSuggestionsSupplier { getSuggestionsForData(builder: VisualizationSuggestionsBuilder) { @@ -12,7 +12,7 @@ export class BarGaugeSuggestionsSupplier { return; } - const list = builder.getListAppender({ + const list = builder.getListAppender({ name: '', pluginId: 'bargauge', options: {}, diff --git a/public/app/plugins/panel/bargauge/types.ts b/public/app/plugins/panel/bargauge/types.ts deleted file mode 100644 index 5b31d9f8ec9..00000000000 --- a/public/app/plugins/panel/bargauge/types.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { SelectableValue } from '@grafana/data'; -import { SingleStatBaseOptions, BarGaugeDisplayMode } from '@grafana/ui'; - -export interface BarGaugeOptions extends SingleStatBaseOptions { - displayMode: BarGaugeDisplayMode; - showUnfilled: boolean; - minVizWidth: number; - minVizHeight: number; -} - -export const displayModes: Array> = [ - { value: BarGaugeDisplayMode.Gradient, label: 'Gradient' }, - { value: BarGaugeDisplayMode.Lcd, label: 'Retro LCD' }, - { value: BarGaugeDisplayMode.Basic, label: 'Basic' }, -]; diff --git a/public/app/plugins/panel/dashlist/models.cue b/public/app/plugins/panel/dashlist/models.cue index b13be7c61d0..860b45b1dea 100644 --- a/public/app/plugins/panel/dashlist/models.cue +++ b/public/app/plugins/panel/dashlist/models.cue @@ -18,8 +18,9 @@ Panel: { lineages: [ [ { + PanelLayout: "list" | "previews" @cuetsy(kind="enum") PanelOptions: { - layout?: *"list" | "previews" + layout?: PanelLayout | *"list" showStarred: bool | *true showRecentlyViewed: bool | *false showSearch: bool | *false diff --git a/public/app/plugins/panel/dashlist/models.gen.ts b/public/app/plugins/panel/dashlist/models.gen.ts index 013e89cdd44..bcfa4297921 100644 --- a/public/app/plugins/panel/dashlist/models.gen.ts +++ b/public/app/plugins/panel/dashlist/models.gen.ts @@ -1,17 +1,19 @@ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// This file was almost autogenerated by cuetsy. +// This file was autogenerated by cuetsy. DO NOT EDIT! //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + export const modelVersion = Object.freeze([0, 0]); + export enum PanelLayout { List = 'list', Previews = 'previews', } export interface PanelOptions { - layout?: PanelLayout; folderId?: number; + layout?: PanelLayout; maxItems: number; query: string; showHeadings: boolean; @@ -21,7 +23,7 @@ export interface PanelOptions { tags: string[]; } -export const defaultPanelOptions: PanelOptions = { +export const defaultPanelOptions: Partial = { layout: PanelLayout.List, maxItems: 10, query: '', diff --git a/public/app/plugins/panel/gauge/GaugeMigrations.ts b/public/app/plugins/panel/gauge/GaugeMigrations.ts index 343e4a00d36..2ca30ab73a9 100644 --- a/public/app/plugins/panel/gauge/GaugeMigrations.ts +++ b/public/app/plugins/panel/gauge/GaugeMigrations.ts @@ -1,21 +1,21 @@ import { PanelModel } from '@grafana/data'; import { sharedSingleStatPanelChangedHandler, sharedSingleStatMigrationHandler } from '@grafana/ui'; -import { GaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; // This is called when the panel first loads -export const gaugePanelMigrationHandler = (panel: PanelModel): Partial => { +export const gaugePanelMigrationHandler = (panel: PanelModel): Partial => { return sharedSingleStatMigrationHandler(panel); }; // This is called when the panel changes from another panel export const gaugePanelChangedHandler = ( - panel: PanelModel> | any, + panel: PanelModel> | any, prevPluginId: string, prevOptions: any ) => { // This handles most config changes - const opts = sharedSingleStatPanelChangedHandler(panel, prevPluginId, prevOptions) as GaugeOptions; + const opts = sharedSingleStatPanelChangedHandler(panel, prevPluginId, prevOptions) as PanelOptions; // Changing from angular singlestat if (prevPluginId === 'singlestat' && prevOptions.angular) { diff --git a/public/app/plugins/panel/gauge/GaugePanel.tsx b/public/app/plugins/panel/gauge/GaugePanel.tsx index c4b38b6b614..dcd70e76456 100644 --- a/public/app/plugins/panel/gauge/GaugePanel.tsx +++ b/public/app/plugins/panel/gauge/GaugePanel.tsx @@ -7,9 +7,9 @@ import { config } from 'app/core/config'; import { clearNameForSingleSeries } from '../bargauge/BarGaugePanel'; -import { GaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; -export class GaugePanel extends PureComponent> { +export class GaugePanel extends PureComponent> { renderComponent = ( valueProps: VizRepeaterRenderValueProps, menuProps: DataLinksContextMenuApi diff --git a/public/app/plugins/panel/gauge/models.cue b/public/app/plugins/panel/gauge/models.cue index b180c966220..5d7693e76d8 100644 --- a/public/app/plugins/panel/gauge/models.cue +++ b/public/app/plugins/panel/gauge/models.cue @@ -22,8 +22,8 @@ Panel: { { PanelOptions: { ui.SingleStatBaseOptions - showThresholdLabels: bool - showThresholdMarkers: bool + showThresholdLabels: bool | *false + showThresholdMarkers: bool | *true } @cuetsy(kind="interface") } ] diff --git a/public/app/plugins/panel/gauge/models.gen.ts b/public/app/plugins/panel/gauge/models.gen.ts new file mode 100644 index 00000000000..ce9b2ce4f67 --- /dev/null +++ b/public/app/plugins/panel/gauge/models.gen.ts @@ -0,0 +1,18 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// This file was autogenerated by cuetsy. DO NOT EDIT! +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import * as ui from '@grafana/schema'; + +export const modelVersion = Object.freeze([0, 0]); + + +export interface PanelOptions extends ui.SingleStatBaseOptions { + showThresholdLabels: boolean; + showThresholdMarkers: boolean; +} + +export const defaultPanelOptions: Partial = { + showThresholdLabels: false, + showThresholdMarkers: true, +}; diff --git a/public/app/plugins/panel/gauge/module.tsx b/public/app/plugins/panel/gauge/module.tsx index 3f256a87aa3..3a36fd460a2 100644 --- a/public/app/plugins/panel/gauge/module.tsx +++ b/public/app/plugins/panel/gauge/module.tsx @@ -5,10 +5,10 @@ import { addOrientationOption, addStandardDataReduceOptions } from '../stat/comm import { gaugePanelMigrationHandler, gaugePanelChangedHandler } from './GaugeMigrations'; import { GaugePanel } from './GaugePanel'; +import { PanelOptions, defaultPanelOptions } from './models.gen'; import { GaugeSuggestionsSupplier } from './suggestions'; -import { GaugeOptions } from './types'; -export const plugin = new PanelPlugin(GaugePanel) +export const plugin = new PanelPlugin(GaugePanel) .useFieldConfig() .setPanelOptions((builder) => { addStandardDataReduceOptions(builder); @@ -19,13 +19,13 @@ export const plugin = new PanelPlugin(GaugePanel) path: 'showThresholdLabels', name: 'Show threshold labels', description: 'Render the threshold values around the gauge bar', - defaultValue: false, + defaultValue: defaultPanelOptions.showThresholdLabels, }) .addBooleanSwitch({ path: 'showThresholdMarkers', name: 'Show threshold markers', description: 'Renders the thresholds as an outer bar', - defaultValue: true, + defaultValue: defaultPanelOptions.showThresholdMarkers, }); commonOptionsBuilder.addTextSizeOptions(builder); diff --git a/public/app/plugins/panel/gauge/suggestions.ts b/public/app/plugins/panel/gauge/suggestions.ts index edad77f745a..d0e075ffd91 100644 --- a/public/app/plugins/panel/gauge/suggestions.ts +++ b/public/app/plugins/panel/gauge/suggestions.ts @@ -1,7 +1,7 @@ import { ThresholdsMode, VisualizationSuggestionsBuilder } from '@grafana/data'; import { SuggestionName } from 'app/types/suggestions'; -import { GaugeOptions } from './types'; +import { PanelOptions } from './models.gen'; export class GaugeSuggestionsSupplier { getSuggestionsForData(builder: VisualizationSuggestionsBuilder) { @@ -16,7 +16,7 @@ export class GaugeSuggestionsSupplier { return; } - const list = builder.getListAppender({ + const list = builder.getListAppender({ name: SuggestionName.Gauge, pluginId: 'gauge', options: {}, diff --git a/public/app/plugins/panel/gauge/types.ts b/public/app/plugins/panel/gauge/types.ts deleted file mode 100644 index ba03c033403..00000000000 --- a/public/app/plugins/panel/gauge/types.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { VizOrientation, SelectableValue } from '@grafana/data'; -import { SingleStatBaseOptions } from '@grafana/ui/src/components/SingleStatShared/SingleStatBaseOptions'; - -export interface GaugeOptions extends SingleStatBaseOptions { - showThresholdLabels: boolean; - showThresholdMarkers: boolean; -} - -export const orientationOptions: Array> = [ - { value: VizOrientation.Auto, label: 'Auto' }, - { value: VizOrientation.Horizontal, label: 'Horizontal' }, - { value: VizOrientation.Vertical, label: 'Vertical' }, -];