Transforms: Fix schema definition (#62619)

pull/56097/head
Ryan McKinley 2 years ago committed by GitHub
parent 91221bc436
commit 4186871390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .betterer.results
  2. 19
      kinds/dashboard/dashboard_kind.cue
  3. 24
      packages/grafana-data/src/types/transformations.ts
  4. 3
      packages/grafana-schema/src/index.gen.ts
  5. 25
      packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts
  6. 4
      packages/grafana-schema/src/veneer/dashboard.types.ts
  7. 27
      pkg/kinds/dashboard/dashboard_types_gen.go
  8. 2
      public/app/features/dashboard/state/DashboardMigrator.ts
  9. 10
      public/app/features/sandbox/TestStuffPage.tsx

@ -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.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"], [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.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"]
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
], ],
"packages/grafana-data/src/types/variables.ts:5381": [ "packages/grafana-data/src/types/variables.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"] [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": [ "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.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"], [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.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"]
], ],
"packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [ "packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],

@ -283,13 +283,18 @@ lineage: seqs: [
} @cuetsy(kind="interface") } @cuetsy(kind="interface")
// TODO docs // TODO docs
// FIXME this is extremely underspecfied; wasn't obvious which typescript types corresponded to it #DataTransformerConfig: {
#Transformation: { @grafana(TSVeneer="type")
id: string
hide: bool | *false // Unique identifier of transformer
// only apply to some frames id: string
// Disabled transformations are skipped
disabled?: bool
// Optional frame matcher. When missing it will be applied to all results
filter?: #MatcherConfig filter?: #MatcherConfig
options: {...} // Options to be passed to the transformer
// Valid options depend on the transformer id
options: _
} @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview)
// 0 for no shared crosshair or tooltip (default). // 0 for no shared crosshair or tooltip (default).
@ -386,7 +391,7 @@ lineage: seqs: [
// TODO docs // TODO docs
timeRegions?: [...] @grafanamaturity(NeedsExpertReview) timeRegions?: [...] @grafanamaturity(NeedsExpertReview)
transformations: [...#Transformation] @grafanamaturity(NeedsExpertReview) transformations: [...#DataTransformerConfig] @grafanamaturity(NeedsExpertReview)
// TODO docs // TODO docs
// TODO tighter constraint // TODO tighter constraint

@ -1,6 +1,6 @@
import { MonoTypeOperatorFunction } from 'rxjs'; import { MonoTypeOperatorFunction } from 'rxjs';
import { MatcherConfig } from '@grafana/schema'; import { MatcherConfig, DataTransformerConfig } from '@grafana/schema';
import { RegistryItemWithOptions } from '../utils/Registry'; import { RegistryItemWithOptions } from '../utils/Registry';
@ -41,27 +41,9 @@ export interface SynchronousDataTransformerInfo<TOptions = any> extends DataTran
} }
/** /**
* @public * @deprecated use TransformationConfig from schema
*/ */
export interface DataTransformerConfig<TOptions = any> { export type { 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 FrameMatcher = (frame: DataFrame) => boolean; export type FrameMatcher = (frame: DataFrame) => boolean;
export type FieldMatcher = (field: Field, frame: DataFrame, allFrames: DataFrame[]) => boolean; export type FieldMatcher = (field: Field, frame: DataFrame, allFrames: DataFrame[]) => boolean;

@ -25,7 +25,6 @@ export type {
RegexMap, RegexMap,
SpecialValueMap, SpecialValueMap,
ValueMappingResult, ValueMappingResult,
Transformation,
LibraryPanelRef, LibraryPanelRef,
RowPanel, RowPanel,
GraphPanel, GraphPanel,
@ -44,7 +43,6 @@ export {
defaultThresholdsConfig, defaultThresholdsConfig,
MappingType, MappingType,
SpecialValueMatch, SpecialValueMatch,
defaultTransformation,
DashboardCursorSync, DashboardCursorSync,
defaultDashboardCursorSync, defaultDashboardCursorSync,
defaultRowPanel defaultRowPanel
@ -63,6 +61,7 @@ export type {
Dashboard, Dashboard,
VariableModel, VariableModel,
DataSourceRef, DataSourceRef,
DataTransformerConfig,
Panel, Panel,
FieldConfigSource, FieldConfigSource,
MatcherConfig, MatcherConfig,

@ -353,22 +353,27 @@ export interface ValueMappingResult {
/** /**
* TODO docs * 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; filter?: MatcherConfig;
hide: boolean; /**
* Unique identifier of transformer
*/
id: string; id: string;
options: Record<string, unknown>; /**
* Options to be passed to the transformer
* Valid options depend on the transformer id
*/
options: unknown;
} }
export const defaultTransformation: Partial<Transformation> = {
hide: false,
};
/** /**
* 0 for no shared crosshair or tooltip (default). * 0 for no shared crosshair or tooltip (default).
* 1 for shared crosshair. * 1 for shared crosshair.
@ -479,7 +484,7 @@ export interface Panel {
* Panel title. * Panel title.
*/ */
title?: string; title?: string;
transformations: Array<Transformation>; transformations: Array<DataTransformerConfig>;
/** /**
* Whether to display the panel without a background. * Whether to display the panel without a background.
*/ */

@ -47,6 +47,10 @@ export interface MatcherConfig<TConfig = any> extends raw.MatcherConfig {
options?: TConfig; options?: TConfig;
} }
export interface DataTransformerConfig<TOptions = any> extends raw.DataTransformerConfig {
options: TOptions;
}
export const defaultDashboard = raw.defaultDashboard as Dashboard; export const defaultDashboard = raw.defaultDashboard as Dashboard;
export const defaultVariableModel = { export const defaultVariableModel = {
...raw.defaultVariableModel, ...raw.defaultVariableModel,

@ -334,6 +334,20 @@ type DataSourceRef struct {
Uid *string `json:"uid,omitempty"` 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. // DynamicConfigValue defines model for DynamicConfigValue.
type DynamicConfigValue struct { type DynamicConfigValue struct {
Id string `json:"id"` Id string `json:"id"`
@ -545,8 +559,8 @@ type Panel struct {
TimeShift *string `json:"timeShift,omitempty"` TimeShift *string `json:"timeShift,omitempty"`
// Panel title. // Panel title.
Title *string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
Transformations []Transformation `json:"transformations"` Transformations []DataTransformerConfig `json:"transformations"`
// Whether to display the panel without a background. // Whether to display the panel without a background.
Transparent bool `json:"transparent"` Transparent bool `json:"transparent"`
@ -707,15 +721,6 @@ type ThresholdsConfig struct {
// ThresholdsMode defines model for ThresholdsMode. // ThresholdsMode defines model for ThresholdsMode.
type ThresholdsMode string 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 // TODO docs
type ValueMap struct { type ValueMap struct {
Options map[string]ValueMappingResult `json:"options"` Options map[string]ValueMappingResult `json:"options"`

@ -6,7 +6,6 @@ import {
DataLinkBuiltInVars, DataLinkBuiltInVars,
DataQuery, DataQuery,
DataSourceRef, DataSourceRef,
DataTransformerConfig,
FieldConfigSource, FieldConfigSource,
FieldMatcherID, FieldMatcherID,
FieldType, FieldType,
@ -26,6 +25,7 @@ import {
import { labelsToFieldsTransformer } from '@grafana/data/src/transformations/transformers/labelsToFields'; import { labelsToFieldsTransformer } from '@grafana/data/src/transformations/transformers/labelsToFields';
import { mergeTransformer } from '@grafana/data/src/transformations/transformers/merge'; import { mergeTransformer } from '@grafana/data/src/transformations/transformers/merge';
import { getDataSourceSrv, setDataSourceSrv } from '@grafana/runtime'; import { getDataSourceSrv, setDataSourceSrv } from '@grafana/runtime';
import { DataTransformerConfig } from '@grafana/schema';
import { AxisPlacement, GraphFieldConfig } from '@grafana/ui'; import { AxisPlacement, GraphFieldConfig } from '@grafana/ui';
import { migrateTableDisplayModeToCellOptions } from '@grafana/ui/src/components/Table/utils'; import { migrateTableDisplayModeToCellOptions } from '@grafana/ui/src/components/Table/utils';
import { getAllOptionEditors, getAllStandardFieldConfigs } from 'app/core/components/OptionsUI/registry'; import { getAllOptionEditors, getAllStandardFieldConfigs } from 'app/core/components/OptionsUI/registry';

@ -2,14 +2,8 @@ import React, { useMemo, useState } from 'react';
import { useObservable } from 'react-use'; import { useObservable } from 'react-use';
import AutoSizer from 'react-virtualized-auto-sizer'; import AutoSizer from 'react-virtualized-auto-sizer';
import { import { ApplyFieldOverrideOptions, dateMath, FieldColorModeId, NavModelItem, PanelData } from '@grafana/data';
ApplyFieldOverrideOptions, import { DataTransformerConfig } from '@grafana/schema';
DataTransformerConfig,
dateMath,
FieldColorModeId,
NavModelItem,
PanelData,
} from '@grafana/data';
import { Button, Table } from '@grafana/ui'; import { Button, Table } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page'; import { Page } from 'app/core/components/Page/Page';
import { config } from 'app/core/config'; import { config } from 'app/core/config';

Loading…
Cancel
Save