diff --git a/.betterer.results b/.betterer.results index d061bee340f..2f0796eb0a0 100644 --- a/.betterer.results +++ b/.betterer.results @@ -575,8 +575,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [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.", "4"] ], "packages/grafana-data/src/types/variables.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -974,8 +973,9 @@ exports[`better eslint`] = { "packages/grafana-schema/src/veneer/dashboard.types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"], + [0, 0, 0, "Do not use any type assertions.", "3"], + [0, 0, 0, "Do not use any type assertions.", "4"] ], "packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], diff --git a/kinds/dashboard/dashboard_kind.cue b/kinds/dashboard/dashboard_kind.cue index 98ed1bb3f02..84f18a234c4 100644 --- a/kinds/dashboard/dashboard_kind.cue +++ b/kinds/dashboard/dashboard_kind.cue @@ -283,13 +283,18 @@ lineage: seqs: [ } @cuetsy(kind="interface") // TODO docs - // FIXME this is extremely underspecfied; wasn't obvious which typescript types corresponded to it - #Transformation: { - id: string - hide: bool | *false - // only apply to some frames + #DataTransformerConfig: { + @grafana(TSVeneer="type") + + // Unique identifier of transformer + id: string + // Disabled transformations are skipped + disabled?: bool + // Optional frame matcher. When missing it will be applied to all results filter?: #MatcherConfig - options: {...} + // Options to be passed to the transformer + // Valid options depend on the transformer id + options: _ } @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview) // 0 for no shared crosshair or tooltip (default). @@ -386,7 +391,7 @@ lineage: seqs: [ // TODO docs timeRegions?: [...] @grafanamaturity(NeedsExpertReview) - transformations: [...#Transformation] @grafanamaturity(NeedsExpertReview) + transformations: [...#DataTransformerConfig] @grafanamaturity(NeedsExpertReview) // TODO docs // TODO tighter constraint diff --git a/packages/grafana-data/src/types/transformations.ts b/packages/grafana-data/src/types/transformations.ts index 88968acc864..3f212a917ed 100644 --- a/packages/grafana-data/src/types/transformations.ts +++ b/packages/grafana-data/src/types/transformations.ts @@ -1,6 +1,6 @@ import { MonoTypeOperatorFunction } from 'rxjs'; -import { MatcherConfig } from '@grafana/schema'; +import { MatcherConfig, DataTransformerConfig } from '@grafana/schema'; import { RegistryItemWithOptions } from '../utils/Registry'; @@ -41,27 +41,9 @@ export interface SynchronousDataTransformerInfo extends DataTran } /** - * @public + * @deprecated use TransformationConfig from schema */ -export interface DataTransformerConfig { - /** - * Unique identifier of transformer - */ - id: string; - - /** - * Disabled transformations are skipped - */ - disabled?: boolean; - - /** Optional frame matcher. When missing it will be applied to all results */ - filter?: MatcherConfig; - - /** - * Options to be passed to the transformer - */ - options: TOptions; -} +export type { DataTransformerConfig }; export type FrameMatcher = (frame: DataFrame) => boolean; export type FieldMatcher = (field: Field, frame: DataFrame, allFrames: DataFrame[]) => boolean; diff --git a/packages/grafana-schema/src/index.gen.ts b/packages/grafana-schema/src/index.gen.ts index 1368bee47b1..cefd43cc220 100644 --- a/packages/grafana-schema/src/index.gen.ts +++ b/packages/grafana-schema/src/index.gen.ts @@ -25,7 +25,6 @@ export type { RegexMap, SpecialValueMap, ValueMappingResult, - Transformation, LibraryPanelRef, RowPanel, GraphPanel, @@ -44,7 +43,6 @@ export { defaultThresholdsConfig, MappingType, SpecialValueMatch, - defaultTransformation, DashboardCursorSync, defaultDashboardCursorSync, defaultRowPanel @@ -63,6 +61,7 @@ export type { Dashboard, VariableModel, DataSourceRef, + DataTransformerConfig, Panel, FieldConfigSource, MatcherConfig, diff --git a/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts b/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts index b7d2041a0e9..108118c5e95 100644 --- a/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts +++ b/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts @@ -353,22 +353,27 @@ export interface ValueMappingResult { /** * TODO docs - * FIXME this is extremely underspecfied; wasn't obvious which typescript types corresponded to it */ -export interface Transformation { +export interface DataTransformerConfig { /** - * only apply to some frames + * Disabled transformations are skipped + */ + disabled?: boolean; + /** + * Optional frame matcher. When missing it will be applied to all results */ filter?: MatcherConfig; - hide: boolean; + /** + * Unique identifier of transformer + */ id: string; - options: Record; + /** + * Options to be passed to the transformer + * Valid options depend on the transformer id + */ + options: unknown; } -export const defaultTransformation: Partial = { - hide: false, -}; - /** * 0 for no shared crosshair or tooltip (default). * 1 for shared crosshair. @@ -479,7 +484,7 @@ export interface Panel { * Panel title. */ title?: string; - transformations: Array; + transformations: Array; /** * Whether to display the panel without a background. */ diff --git a/packages/grafana-schema/src/veneer/dashboard.types.ts b/packages/grafana-schema/src/veneer/dashboard.types.ts index bab4aa4450d..bf7a5299cde 100644 --- a/packages/grafana-schema/src/veneer/dashboard.types.ts +++ b/packages/grafana-schema/src/veneer/dashboard.types.ts @@ -47,6 +47,10 @@ export interface MatcherConfig extends raw.MatcherConfig { options?: TConfig; } +export interface DataTransformerConfig extends raw.DataTransformerConfig { + options: TOptions; +} + export const defaultDashboard = raw.defaultDashboard as Dashboard; export const defaultVariableModel = { ...raw.defaultVariableModel, diff --git a/pkg/kinds/dashboard/dashboard_types_gen.go b/pkg/kinds/dashboard/dashboard_types_gen.go index 6c51c2af578..b99076b8c7a 100644 --- a/pkg/kinds/dashboard/dashboard_types_gen.go +++ b/pkg/kinds/dashboard/dashboard_types_gen.go @@ -334,6 +334,20 @@ type DataSourceRef struct { Uid *string `json:"uid,omitempty"` } +// TODO docs +type DataTransformerConfig struct { + // Disabled transformations are skipped + Disabled *bool `json:"disabled,omitempty"` + Filter *MatcherConfig `json:"filter,omitempty"` + + // Unique identifier of transformer + Id string `json:"id"` + + // Options to be passed to the transformer + // Valid options depend on the transformer id + Options interface{} `json:"options"` +} + // DynamicConfigValue defines model for DynamicConfigValue. type DynamicConfigValue struct { Id string `json:"id"` @@ -545,8 +559,8 @@ type Panel struct { TimeShift *string `json:"timeShift,omitempty"` // Panel title. - Title *string `json:"title,omitempty"` - Transformations []Transformation `json:"transformations"` + Title *string `json:"title,omitempty"` + Transformations []DataTransformerConfig `json:"transformations"` // Whether to display the panel without a background. Transparent bool `json:"transparent"` @@ -707,15 +721,6 @@ type ThresholdsConfig struct { // ThresholdsMode defines model for ThresholdsMode. type ThresholdsMode string -// TODO docs -// FIXME this is extremely underspecfied; wasn't obvious which typescript types corresponded to it -type Transformation struct { - Filter *MatcherConfig `json:"filter,omitempty"` - Hide bool `json:"hide"` - Id string `json:"id"` - Options map[string]interface{} `json:"options"` -} - // TODO docs type ValueMap struct { Options map[string]ValueMappingResult `json:"options"` diff --git a/public/app/features/dashboard/state/DashboardMigrator.ts b/public/app/features/dashboard/state/DashboardMigrator.ts index 51deeecd53c..c95dcc7c5c8 100644 --- a/public/app/features/dashboard/state/DashboardMigrator.ts +++ b/public/app/features/dashboard/state/DashboardMigrator.ts @@ -6,7 +6,6 @@ import { DataLinkBuiltInVars, DataQuery, DataSourceRef, - DataTransformerConfig, FieldConfigSource, FieldMatcherID, FieldType, @@ -26,6 +25,7 @@ import { import { labelsToFieldsTransformer } from '@grafana/data/src/transformations/transformers/labelsToFields'; import { mergeTransformer } from '@grafana/data/src/transformations/transformers/merge'; import { getDataSourceSrv, setDataSourceSrv } from '@grafana/runtime'; +import { DataTransformerConfig } from '@grafana/schema'; import { AxisPlacement, GraphFieldConfig } from '@grafana/ui'; import { migrateTableDisplayModeToCellOptions } from '@grafana/ui/src/components/Table/utils'; import { getAllOptionEditors, getAllStandardFieldConfigs } from 'app/core/components/OptionsUI/registry'; diff --git a/public/app/features/sandbox/TestStuffPage.tsx b/public/app/features/sandbox/TestStuffPage.tsx index ee68673a8a4..a1bfb33837b 100644 --- a/public/app/features/sandbox/TestStuffPage.tsx +++ b/public/app/features/sandbox/TestStuffPage.tsx @@ -2,14 +2,8 @@ import React, { useMemo, useState } from 'react'; import { useObservable } from 'react-use'; import AutoSizer from 'react-virtualized-auto-sizer'; -import { - ApplyFieldOverrideOptions, - DataTransformerConfig, - dateMath, - FieldColorModeId, - NavModelItem, - PanelData, -} from '@grafana/data'; +import { ApplyFieldOverrideOptions, dateMath, FieldColorModeId, NavModelItem, PanelData } from '@grafana/data'; +import { DataTransformerConfig } from '@grafana/schema'; import { Button, Table } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { config } from 'app/core/config';