From c3c4a57c793d74fa8c5145d6a56d0862d3d8f831 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Thu, 29 Dec 2022 05:48:22 -0800 Subject: [PATCH] grafana/data: Move getPanelOptionsWithDefaults from core (#60813) * grafana/data: Move getPanelOptionsWithDefaults from core * Add internal comments --- .betterer.results | 42 +++---- packages/grafana-data/src/index.ts | 8 ++ .../getPanelOptionsWithDefaults.test.ts | 6 +- .../src/panel}/getPanelOptionsWithDefaults.ts | 37 ++++-- .../test}/__mocks__/pluginMocks.ts | 17 +-- .../grafana-data/test/helpers/fieldConfig.ts | 112 ++++++++++++++++++ packages/grafana-data/tsconfig.build.json | 2 +- .../DashboardPrompt/DashboardPrompt.test.tsx | 2 +- .../components/HelpWizard/HelpWizard.test.tsx | 2 +- .../PanelEditor/OptionsPaneOptions.test.tsx | 2 +- .../PanelEditor/state/actions.test.ts | 2 +- .../dashboard/state/DashboardMigrator.test.ts | 2 +- .../dashboard/state/PanelModel.test.ts | 4 +- .../features/dashboard/state/PanelModel.ts | 11 +- .../features/dashboard/utils/panel.test.ts | 2 +- .../datasources/state/buildCategories.test.ts | 2 +- public/app/features/datasources/utils.test.ts | 2 +- .../panel/components/PanelRenderer.tsx | 3 +- .../app/features/panel/state/actions.test.ts | 5 +- public/app/features/panel/state/actions.ts | 3 +- .../plugins/components/AppRootPage.test.tsx | 2 +- .../components/VizPanel/VizPanel.test.tsx | 2 +- .../scenes/components/VizPanel/VizPanel.tsx | 10 +- .../variants/DataSourceVariable.test.ts | 2 +- .../variables/datasource/actions.test.ts | 2 +- .../variables/datasource/reducer.test.ts | 2 +- public/test/helpers/fieldConfig.ts | 112 ------------------ 27 files changed, 215 insertions(+), 183 deletions(-) rename {public/app/features/dashboard/state => packages/grafana-data/src/panel}/getPanelOptionsWithDefaults.test.ts (98%) rename {public/app/features/dashboard/state => packages/grafana-data/src/panel}/getPanelOptionsWithDefaults.ts (88%) rename {public/app/features/plugins => packages/grafana-data/test}/__mocks__/pluginMocks.ts (87%) create mode 100644 packages/grafana-data/test/helpers/fieldConfig.ts diff --git a/.betterer.results b/.betterer.results index 5503228173f..5b994c6eb51 100644 --- a/.betterer.results +++ b/.betterer.results @@ -313,6 +313,23 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "6"], [0, 0, 0, "Do not use any type assertions.", "7"] ], + "packages/grafana-data/src/panel/getPanelOptionsWithDefaults.test.ts:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + ], + "packages/grafana-data/src/panel/getPanelOptionsWithDefaults.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, "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.", "6"], + [0, 0, 0, "Unexpected any. Specify a different type.", "7"], + [0, 0, 0, "Do not use any type assertions.", "8"], + [0, 0, 0, "Unexpected any. Specify a different type.", "9"], + [0, 0, 0, "Do not use any type assertions.", "10"] + ], "packages/grafana-data/src/panel/registryFactories.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -833,6 +850,10 @@ exports[`better eslint`] = { "packages/grafana-data/src/vector/SortedVector.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], + "packages/grafana-data/test/__mocks__/pluginMocks.ts:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + ], "packages/grafana-e2e/cypress/plugins/benchmark/formatting.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -3531,23 +3552,6 @@ exports[`better eslint`] = { "public/app/features/dashboard/state/actions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/dashboard/state/getPanelOptionsWithDefaults.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], - "public/app/features/dashboard/state/getPanelOptionsWithDefaults.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, "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.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Do not use any type assertions.", "10"] - ], "public/app/features/dashboard/state/initDashboard.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -4138,10 +4142,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], - "public/app/features/plugins/__mocks__/pluginMocks.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/app/features/plugins/admin/components/AppConfigWrapper.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] diff --git a/packages/grafana-data/src/index.ts b/packages/grafana-data/src/index.ts index e46409f4d65..0b4e525f30c 100644 --- a/packages/grafana-data/src/index.ts +++ b/packages/grafana-data/src/index.ts @@ -23,6 +23,14 @@ export { } from './transformations/matchers/valueMatchers/types'; export { LayoutModes, type LayoutMode } from './types/layout'; export { PanelPlugin, type SetFieldConfigOptionsArgs, type StandardOptionConfig } from './panel/PanelPlugin'; +export { + getPanelOptionsWithDefaults, + filterFieldConfigOverrides, + restoreCustomOverrideRules, + isCustomFieldProp, + isStandardFieldProp, + type OptionDefaults, +} from './panel/getPanelOptionsWithDefaults'; export { createFieldConfigRegistry } from './panel/registryFactories'; export { type QueryRunner, type QueryRunnerOptions } from './types/queryRunner'; export { type GroupingToMatrixTransformerOptions } from './transformations/transformers/groupingToMatrix'; diff --git a/public/app/features/dashboard/state/getPanelOptionsWithDefaults.test.ts b/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.test.ts similarity index 98% rename from public/app/features/dashboard/state/getPanelOptionsWithDefaults.test.ts rename to packages/grafana-data/src/panel/getPanelOptionsWithDefaults.test.ts index 07aa648d7ed..f4189f13181 100644 --- a/public/app/features/dashboard/state/getPanelOptionsWithDefaults.test.ts +++ b/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.test.ts @@ -1,5 +1,3 @@ -import { mockStandardFieldConfigOptions } from 'test/helpers/fieldConfig'; - import { ConfigOverrideRule, FieldColorModeId, @@ -12,7 +10,9 @@ import { StandardOptionConfig, ThresholdsMode, } from '@grafana/data'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; + +import { getPanelPlugin } from '../../test/__mocks__/pluginMocks'; +import { mockStandardFieldConfigOptions } from '../../test/helpers/fieldConfig'; import { getPanelOptionsWithDefaults, restoreCustomOverrideRules } from './getPanelOptionsWithDefaults'; diff --git a/public/app/features/dashboard/state/getPanelOptionsWithDefaults.ts b/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts similarity index 88% rename from public/app/features/dashboard/state/getPanelOptionsWithDefaults.ts rename to packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts index fadb6071164..b461d007d96 100644 --- a/public/app/features/dashboard/state/getPanelOptionsWithDefaults.ts +++ b/packages/grafana-data/src/panel/getPanelOptionsWithDefaults.ts @@ -1,18 +1,18 @@ import { mergeWith, isArray, isObject, unset, isEqual } from 'lodash'; +import { FieldConfigOptionsRegistry } from '../field/FieldConfigOptionsRegistry'; +import { fieldColorModeRegistry } from '../field/fieldColor'; +import { FieldColorConfigSettings } from '../field/overrides/processors'; +import { FieldColorModeId } from '../types/fieldColor'; import { ConfigOverrideRule, DynamicConfigValue, - FieldColorConfigSettings, - FieldColorModeId, - fieldColorModeRegistry, - FieldConfigOptionsRegistry, FieldConfigProperty, FieldConfigSource, - PanelPlugin, - ThresholdsConfig, - ThresholdsMode, -} from '@grafana/data'; +} from '../types/fieldOverrides'; +import { ThresholdsConfig, ThresholdsMode } from '../types/thresholds'; + +import { PanelPlugin } from './PanelPlugin'; export interface Props { plugin: PanelPlugin; @@ -26,6 +26,11 @@ export interface OptionDefaults { fieldConfig: FieldConfigSource; } +/** + * This will return the panel options with defaults applied. + * Used internally, not intended for external use. + * @internal + */ export function getPanelOptionsWithDefaults({ plugin, currentOptions, @@ -89,6 +94,10 @@ function applyFieldConfigDefaults(existingFieldConfig: FieldConfigSource, plugin return result; } +/** + * Used internally, not intended for external use. + * @internal + */ export function filterFieldConfigOverrides( overrides: ConfigOverrideRule[], condition: (value: DynamicConfigValue) => boolean @@ -194,6 +203,10 @@ function fixThresholds(thresholds: ThresholdsConfig) { } } +/** + * Used internally, not intended for external use. + * @internal + */ export function restoreCustomOverrideRules(current: FieldConfigSource, old: FieldConfigSource): FieldConfigSource { const result = { defaults: { @@ -221,10 +234,18 @@ export function restoreCustomOverrideRules(current: FieldConfigSource, old: Fiel return result; } +/** + * Used internally, not intended for external use. + * @internal + */ export function isCustomFieldProp(prop: DynamicConfigValue): boolean { return prop.id.startsWith('custom.'); } +/** + * Used internally, not intended for external use. + * @internal + */ export function isStandardFieldProp(prop: DynamicConfigValue): boolean { return !isCustomFieldProp(prop); } diff --git a/public/app/features/plugins/__mocks__/pluginMocks.ts b/packages/grafana-data/test/__mocks__/pluginMocks.ts similarity index 87% rename from public/app/features/plugins/__mocks__/pluginMocks.ts rename to packages/grafana-data/test/__mocks__/pluginMocks.ts index b59d49777b3..dcf80d0a589 100644 --- a/public/app/features/plugins/__mocks__/pluginMocks.ts +++ b/packages/grafana-data/test/__mocks__/pluginMocks.ts @@ -1,10 +1,10 @@ -import { ComponentType } from 'enzyme'; import { defaultsDeep } from 'lodash'; +import { ComponentType } from 'react'; -import { PanelPluginMeta, PluginMeta, PluginType, PanelPlugin, PanelProps } from '@grafana/data'; +import { PanelPluginMeta, PluginMeta, PluginType, PanelPlugin, PanelProps } from '../../src'; export const getMockPlugins = (amount: number): PluginMeta[] => { - const plugins = []; + const plugins: PluginMeta[] = []; for (let i = 0; i <= amount; i++) { plugins.push({ @@ -18,18 +18,19 @@ export const getMockPlugins = (amount: number): PluginMeta[] => { url: 'url/to/GrafanaLabs', }, description: 'pretty decent plugin', - links: ['one link'], + links: [{ name: 'one link', url: 'one link' }], logos: { small: 'small/logo', large: 'large/logo' }, - screenshots: [{ path: `screenshot/${i}` }], + screenshots: [{ path: `screenshot/${i}`, name: 'test' }], updated: '2018-09-26', version: '1', }, latestVersion: `1.${i}`, name: `pretty cool plugin-${i}`, pinned: false, - state: '', - type: '', - module: {}, + state: undefined, + type: PluginType.panel, + module: '', + baseUrl: '', }); } diff --git a/packages/grafana-data/test/helpers/fieldConfig.ts b/packages/grafana-data/test/helpers/fieldConfig.ts new file mode 100644 index 00000000000..1ea4a4b18ff --- /dev/null +++ b/packages/grafana-data/test/helpers/fieldConfig.ts @@ -0,0 +1,112 @@ +import { identityOverrideProcessor, ThresholdsMode } from '../../src'; + +export function mockStandardFieldConfigOptions() { + const category = ['Standard options']; + + const unit = { + category, + id: 'unit', + path: 'unit', + name: 'Unit', + description: 'Value units', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + }; + + const decimals = { + category, + id: 'decimals', + path: 'decimals', + name: 'Decimals', + description: 'Number of decimal to be shown for a value', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + }; + + const boolean = { + category, + id: 'boolean', + path: 'boolean', + name: 'Boolean', + description: '', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + }; + + const fieldColor = { + category, + id: 'color', + path: 'color', + name: 'color', + description: '', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + }; + + const text = { + category, + id: 'text', + path: 'text', + name: 'text', + description: '', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + }; + + const number = { + category, + id: 'number', + path: 'number', + name: 'number', + description: '', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + }; + + const thresholds = { + category: ['Thresholds'], + id: 'thresholds', + path: 'thresholds', + name: 'thresholds', + description: '', + // @ts-ignore + editor: () => null, + // @ts-ignore + override: () => null, + process: identityOverrideProcessor, + shouldApply: () => true, + defaultValue: { + mode: ThresholdsMode.Absolute, + steps: [ + { value: -Infinity, color: 'green' }, + { value: 80, color: 'red' }, + ], + }, + }; + + return [unit, decimals, boolean, fieldColor, text, number, thresholds]; +} diff --git a/packages/grafana-data/tsconfig.build.json b/packages/grafana-data/tsconfig.build.json index 9ec189c28ea..54309163ebc 100644 --- a/packages/grafana-data/tsconfig.build.json +++ b/packages/grafana-data/tsconfig.build.json @@ -1,4 +1,4 @@ { - "exclude": ["dist", "node_modules", "**/*.test.ts*"], + "exclude": ["dist", "node_modules", "test", "**/*.test.ts*"], "extends": "./tsconfig.json" } diff --git a/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx b/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx index cd5974264ef..9d30b556fb4 100644 --- a/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx +++ b/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx @@ -1,4 +1,4 @@ -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { setContextSrv } from '../../../../core/services/context_srv'; import { PanelModel } from '../../state/PanelModel'; diff --git a/public/app/features/dashboard/components/HelpWizard/HelpWizard.test.tsx b/public/app/features/dashboard/components/HelpWizard/HelpWizard.test.tsx index 7b5aca434c5..c2a059ba31e 100644 --- a/public/app/features/dashboard/components/HelpWizard/HelpWizard.test.tsx +++ b/public/app/features/dashboard/components/HelpWizard/HelpWizard.test.tsx @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react'; import React from 'react'; import { FieldType, getDefaultTimeRange, LoadingState, toDataFrame } from '@grafana/data'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { PanelModel } from '../../state/PanelModel'; diff --git a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx index bef989f789b..de347d3b897 100644 --- a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx +++ b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx @@ -12,9 +12,9 @@ import { standardFieldConfigEditorRegistry, toDataFrame, } from '@grafana/data'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { selectors } from '@grafana/e2e-selectors'; import { getAllOptionEditors, getAllStandardFieldConfigs } from 'app/core/components/OptionsUI/registry'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; import { PanelModel } from '../../state'; import { createDashboardModelFixture } from '../../state/__fixtures__/dashboardFixtures'; diff --git a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts index 21c5ee11372..bf5ffddd1eb 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts @@ -1,6 +1,6 @@ +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { createDashboardModelFixture } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures'; import { panelModelAndPluginReady, removePanel } from 'app/features/panel/state/reducers'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; import { thunkTester } from '../../../../../../test/core/thunk/thunkTester'; import { PanelModel } from '../../../state'; diff --git a/public/app/features/dashboard/state/DashboardMigrator.test.ts b/public/app/features/dashboard/state/DashboardMigrator.test.ts index 01d5330b7de..fcaa3be482a 100644 --- a/public/app/features/dashboard/state/DashboardMigrator.test.ts +++ b/public/app/features/dashboard/state/DashboardMigrator.test.ts @@ -1,11 +1,11 @@ import { each, map } from 'lodash'; import { DataLinkBuiltInVars, MappingType } from '@grafana/data'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { setDataSourceSrv } from '@grafana/runtime'; import { config } from 'app/core/config'; import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants'; import { mockDataSource, MockDataSourceSrv } from 'app/features/alerting/unified/mocks'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource'; import { VariableHide } from '../../variables/types'; diff --git a/public/app/features/dashboard/state/PanelModel.test.ts b/public/app/features/dashboard/state/PanelModel.test.ts index 7b81d663725..d45d097f438 100644 --- a/public/app/features/dashboard/state/PanelModel.test.ts +++ b/public/app/features/dashboard/state/PanelModel.test.ts @@ -10,11 +10,11 @@ import { dateTime, TimeRange, } from '@grafana/data'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; +import { mockStandardFieldConfigOptions } from '@grafana/data/test/helpers/fieldConfig'; import { setTemplateSrv } from '@grafana/runtime'; import { queryBuilder } from 'app/features/variables/shared/testing/builders'; -import { mockStandardFieldConfigOptions } from '../../../../test/helpers/fieldConfig'; -import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks'; import { PanelQueryRunner } from '../../query/state/PanelQueryRunner'; import { TemplateSrv } from '../../templating/template_srv'; import { variableAdapters } from '../../variables/adapters'; diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index f8b584b794f..6a1645da5fd 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -17,6 +17,10 @@ import { PanelModel as IPanelModel, DataSourceRef, CoreApp, + filterFieldConfigOverrides, + getPanelOptionsWithDefaults, + isStandardFieldProp, + restoreCustomOverrideRules, } from '@grafana/data'; import { getTemplateSrv, RefreshEvent } from '@grafana/runtime'; import config from 'app/core/config'; @@ -37,13 +41,6 @@ import { getVariablesUrlParams } from '../../variables/getAllVariableValuesForUr import { getTimeSrv } from '../services/TimeSrv'; import { TimeOverrideResult } from '../utils/panel'; -import { - filterFieldConfigOverrides, - getPanelOptionsWithDefaults, - isStandardFieldProp, - restoreCustomOverrideRules, -} from './getPanelOptionsWithDefaults'; - export interface GridPos { x: number; y: number; diff --git a/public/app/features/dashboard/utils/panel.test.ts b/public/app/features/dashboard/utils/panel.test.ts index a979c7ab1cc..16698ec3af4 100644 --- a/public/app/features/dashboard/utils/panel.test.ts +++ b/public/app/features/dashboard/utils/panel.test.ts @@ -2,9 +2,9 @@ import { advanceTo, clear } from 'jest-date-mock'; import { ComponentClass } from 'react'; import { dateTime, DateTime, PanelProps, TimeRange } from '@grafana/data'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { applyPanelTimeOverrides, calculateInnerPanelHeight } from 'app/features/dashboard/utils/panel'; -import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks'; import { PanelModel } from '../state'; const dashboardTimeRange: TimeRange = { diff --git a/public/app/features/datasources/state/buildCategories.test.ts b/public/app/features/datasources/state/buildCategories.test.ts index e8b86d228e0..4a4e8d44c2d 100644 --- a/public/app/features/datasources/state/buildCategories.test.ts +++ b/public/app/features/datasources/state/buildCategories.test.ts @@ -1,5 +1,5 @@ import { DataSourcePluginMeta } from '@grafana/data'; -import { getMockPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; +import { getMockPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { buildCategories } from './buildCategories'; diff --git a/public/app/features/datasources/utils.test.ts b/public/app/features/datasources/utils.test.ts index 0c41ef5c20e..bf3743b0994 100644 --- a/public/app/features/datasources/utils.test.ts +++ b/public/app/features/datasources/utils.test.ts @@ -1,4 +1,4 @@ -import { getMockPlugin, getMockPlugins } from 'app/features/plugins/__mocks__/pluginMocks'; +import { getMockPlugin, getMockPlugins } from '@grafana/data/test/__mocks__/pluginMocks'; import { nameExits, findNewName } from './utils'; diff --git a/public/app/features/panel/components/PanelRenderer.tsx b/public/app/features/panel/components/PanelRenderer.tsx index 6ac2e9cd377..dacaf743639 100644 --- a/public/app/features/panel/components/PanelRenderer.tsx +++ b/public/app/features/panel/components/PanelRenderer.tsx @@ -11,12 +11,13 @@ import { compareDataFrameStructures, PluginContextProvider, ScopedVars, + getPanelOptionsWithDefaults, + OptionDefaults, } from '@grafana/data'; import { getTemplateSrv, PanelRendererProps } from '@grafana/runtime'; import { ErrorBoundaryAlert, useTheme2 } from '@grafana/ui'; import { appEvents } from 'app/core/core'; -import { getPanelOptionsWithDefaults, OptionDefaults } from '../../dashboard/state/getPanelOptionsWithDefaults'; import { importPanelPlugin, syncGetPanelPlugin } from '../../plugins/importPanelPlugin'; const defaultFieldConfig = { defaults: {}, overrides: [] }; diff --git a/public/app/features/panel/state/actions.test.ts b/public/app/features/panel/state/actions.test.ts index beb0687757b..840e50647ca 100644 --- a/public/app/features/panel/state/actions.test.ts +++ b/public/app/features/panel/state/actions.test.ts @@ -1,8 +1,7 @@ -import { mockStandardFieldConfigOptions } from 'test/helpers/fieldConfig'; - import { standardEditorsRegistry, standardFieldConfigEditorRegistry } from '@grafana/data'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; +import { mockStandardFieldConfigOptions } from '@grafana/data/test/helpers/fieldConfig'; import { PanelModel } from 'app/features/dashboard/state'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; import { panelPluginLoaded } from 'app/features/plugins/admin/state/actions'; import { thunkTester } from '../../../../test/core/thunk/thunkTester'; diff --git a/public/app/features/panel/state/actions.ts b/public/app/features/panel/state/actions.ts index e440554fc25..efa00f419c1 100644 --- a/public/app/features/panel/state/actions.ts +++ b/public/app/features/panel/state/actions.ts @@ -1,6 +1,5 @@ -import { DataTransformerConfig, FieldConfigSource } from '@grafana/data'; +import { DataTransformerConfig, FieldConfigSource, getPanelOptionsWithDefaults } from '@grafana/data'; import { PanelModel } from 'app/features/dashboard/state/PanelModel'; -import { getPanelOptionsWithDefaults } from 'app/features/dashboard/state/getPanelOptionsWithDefaults'; import { getLibraryPanel } from 'app/features/library-panels/state/api'; import { LibraryElementDTO } from 'app/features/library-panels/types'; import { getPanelPluginNotFound } from 'app/features/panel/components/PanelPluginError'; diff --git a/public/app/features/plugins/components/AppRootPage.test.tsx b/public/app/features/plugins/components/AppRootPage.test.tsx index 0be95818648..d31cbe28759 100644 --- a/public/app/features/plugins/components/AppRootPage.test.tsx +++ b/public/app/features/plugins/components/AppRootPage.test.tsx @@ -5,13 +5,13 @@ import { Route, Router } from 'react-router-dom'; import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; import { AppPlugin, PluginType, AppRootProps, NavModelItem } from '@grafana/data'; +import { getMockPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { locationService, setEchoSrv } from '@grafana/runtime'; import { GrafanaContext } from 'app/core/context/GrafanaContext'; import { GrafanaRoute } from 'app/core/navigation/GrafanaRoute'; import { Echo } from 'app/core/services/echo/Echo'; import { configureStore } from 'app/store/configureStore'; -import { getMockPlugin } from '../__mocks__/pluginMocks'; import { getPluginSettings } from '../pluginSettings'; import { importAppPlugin } from '../plugin_loader'; diff --git a/public/app/features/scenes/components/VizPanel/VizPanel.test.tsx b/public/app/features/scenes/components/VizPanel/VizPanel.test.tsx index cdbe87edff6..75fce31a2be 100644 --- a/public/app/features/scenes/components/VizPanel/VizPanel.test.tsx +++ b/public/app/features/scenes/components/VizPanel/VizPanel.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { FieldConfigProperty, PanelPlugin } from '@grafana/data'; -import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; +import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { VizPanel } from './VizPanel'; diff --git a/public/app/features/scenes/components/VizPanel/VizPanel.tsx b/public/app/features/scenes/components/VizPanel/VizPanel.tsx index ee0773e6b5e..58a8e9f772f 100644 --- a/public/app/features/scenes/components/VizPanel/VizPanel.tsx +++ b/public/app/features/scenes/components/VizPanel/VizPanel.tsx @@ -1,12 +1,18 @@ import { DeepPartial } from '@reduxjs/toolkit'; import React from 'react'; -import { AbsoluteTimeRange, FieldConfigSource, PanelModel, PanelPlugin, toUtc } from '@grafana/data'; +import { + AbsoluteTimeRange, + FieldConfigSource, + PanelModel, + PanelPlugin, + toUtc, + getPanelOptionsWithDefaults, +} from '@grafana/data'; import { config } from '@grafana/runtime'; import { Field, Input } from '@grafana/ui'; import { importPanelPlugin, syncGetPanelPlugin } from 'app/features/plugins/importPanelPlugin'; -import { getPanelOptionsWithDefaults } from '../../../dashboard/state/getPanelOptionsWithDefaults'; import { SceneObjectBase } from '../../core/SceneObjectBase'; import { sceneGraph } from '../../core/sceneGraph'; import { SceneComponentProps, SceneLayoutChildState } from '../../core/types'; diff --git a/public/app/features/scenes/variables/variants/DataSourceVariable.test.ts b/public/app/features/scenes/variables/variants/DataSourceVariable.test.ts index 94f6fb6881d..cfe04693ae9 100644 --- a/public/app/features/scenes/variables/variants/DataSourceVariable.test.ts +++ b/public/app/features/scenes/variables/variants/DataSourceVariable.test.ts @@ -1,7 +1,7 @@ import { lastValueFrom } from 'rxjs'; import { DataSourceInstanceSettings, ScopedVars } from '@grafana/data'; -import { getMockPlugin } from 'app/features/plugins/__mocks__/pluginMocks'; +import { getMockPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { SceneObject } from '../../core/types'; import { CustomFormatterFn } from '../interpolation/sceneInterpolator'; diff --git a/public/app/features/variables/datasource/actions.test.ts b/public/app/features/variables/datasource/actions.test.ts index 3d4f669fce6..42864b95de4 100644 --- a/public/app/features/variables/datasource/actions.test.ts +++ b/public/app/features/variables/datasource/actions.test.ts @@ -1,7 +1,7 @@ import { DataSourceInstanceSettings } from '@grafana/data'; +import { getMockPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { reduxTester } from '../../../../test/core/redux/reduxTester'; -import { getMockPlugin } from '../../plugins/__mocks__/pluginMocks'; import { variableAdapters } from '../adapters'; import { changeVariableEditorExtended } from '../editor/reducer'; import { datasourceBuilder } from '../shared/testing/builders'; diff --git a/public/app/features/variables/datasource/reducer.test.ts b/public/app/features/variables/datasource/reducer.test.ts index 31a096eb3cc..9f775d9dd4d 100644 --- a/public/app/features/variables/datasource/reducer.test.ts +++ b/public/app/features/variables/datasource/reducer.test.ts @@ -1,9 +1,9 @@ import { cloneDeep } from 'lodash'; import { DataSourceInstanceSettings } from '@grafana/data'; +import { getMockPlugins } from '@grafana/data/test/__mocks__/pluginMocks'; import { reducerTester } from '../../../../test/core/redux/reducerTester'; -import { getMockPlugins } from '../../plugins/__mocks__/pluginMocks'; import { getDataSourceInstanceSetting } from '../shared/testing/helpers'; import { getVariableTestContext } from '../state/helpers'; import { VariablesState } from '../state/types'; diff --git a/public/test/helpers/fieldConfig.ts b/public/test/helpers/fieldConfig.ts index bc621b03f92..e69de29bb2d 100644 --- a/public/test/helpers/fieldConfig.ts +++ b/public/test/helpers/fieldConfig.ts @@ -1,112 +0,0 @@ -import { identityOverrideProcessor, ThresholdsMode } from '@grafana/data'; - -export function mockStandardFieldConfigOptions() { - const category = ['Standard options']; - - const unit = { - category, - id: 'unit', - path: 'unit', - name: 'Unit', - description: 'Value units', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - }; - - const decimals = { - category, - id: 'decimals', - path: 'decimals', - name: 'Decimals', - description: 'Number of decimal to be shown for a value', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - }; - - const boolean = { - category, - id: 'boolean', - path: 'boolean', - name: 'Boolean', - description: '', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - }; - - const fieldColor = { - category, - id: 'color', - path: 'color', - name: 'color', - description: '', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - }; - - const text = { - category, - id: 'text', - path: 'text', - name: 'text', - description: '', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - }; - - const number = { - category, - id: 'number', - path: 'number', - name: 'number', - description: '', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - }; - - const thresholds = { - category: ['Thresholds'], - id: 'thresholds', - path: 'thresholds', - name: 'thresholds', - description: '', - // @ts-ignore - editor: () => null, - // @ts-ignore - override: () => null, - process: identityOverrideProcessor, - shouldApply: () => true, - defaultValue: { - mode: ThresholdsMode.Absolute, - steps: [ - { value: -Infinity, color: 'green' }, - { value: 80, color: 'red' }, - ], - }, - }; - - return [unit, decimals, boolean, fieldColor, text, number, thresholds]; -}