Refactor: move more files to @grafana/data (#17972)

This commit is contained in:
Ryan McKinley 2019-07-06 09:18:23 -07:00 committed by GitHub
parent fcdc29746f
commit bdaf0aa81a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 84 additions and 88 deletions

View File

@ -0,0 +1,5 @@
export interface DataLink {
url: string;
title: string;
targetBlank?: boolean;
}

View File

@ -1,5 +1,8 @@
export * from './data'; export * from './data';
export * from './dataLink';
export * from './logs'; export * from './logs';
export * from './navModel'; export * from './navModel';
export * from './time'; export * from './time';
export * from './threshold';
export * from './utils'; export * from './utils';
export * from './valueMapping';

View File

@ -0,0 +1,22 @@
export enum MappingType {
ValueToText = 1,
RangeToText = 2,
}
interface BaseMap {
id: number;
operator: string;
text: string;
type: MappingType;
}
export type ValueMapping = ValueMap | RangeMap;
export interface ValueMap extends BaseMap {
value: string;
}
export interface RangeMap extends BaseMap {
from: string;
to: string;
}

View File

@ -9,6 +9,9 @@ export * from './labels';
export * from './object'; export * from './object';
export * from './fieldCache'; export * from './fieldCache';
export * from './moment_wrapper'; export * from './moment_wrapper';
export * from './thresholds';
export { getMappedValue } from './valueMappings';
// Names are too general to export globally // Names are too general to export globally
import * as dateMath from './datemath'; import * as dateMath from './datemath';

View File

@ -1,5 +1,5 @@
import { getMappedValue } from './valueMappings'; import { getMappedValue } from './valueMappings';
import { ValueMapping, MappingType } from '../types/panel'; import { ValueMapping, MappingType } from '../types';
describe('Format value with value mappings', () => { describe('Format value with value mappings', () => {
it('should return undefined with no valuemappings', () => { it('should return undefined with no valuemappings', () => {

View File

@ -1,6 +1,6 @@
import { ValueMapping, MappingType, ValueMap, RangeMap } from '../types'; import { ValueMapping, MappingType, ValueMap, RangeMap } from '../types';
export type TimeSeriesValue = string | number | null; type TimeSeriesValue = string | number | null;
const addValueToTextMappingText = ( const addValueToTextMappingText = (
allValueMappings: ValueMapping[], allValueMappings: ValueMapping[],

View File

@ -3,11 +3,11 @@ import React, { PureComponent, CSSProperties, ReactNode } from 'react';
import tinycolor from 'tinycolor2'; import tinycolor from 'tinycolor2';
// Utils // Utils
import { getColorFromHexRgbOrName, getThresholdForValue } from '../../utils'; import { getColorFromHexRgbOrName } from '../../utils';
// Types // Types
import { DisplayValue, Themeable, Threshold, VizOrientation } from '../../types'; import { DisplayValue, Themeable, VizOrientation } from '../../types';
import { TimeSeriesValue } from '@grafana/data'; import { Threshold, TimeSeriesValue, getThresholdForValue } from '@grafana/data';
const MIN_VALUE_HEIGHT = 18; const MIN_VALUE_HEIGHT = 18;
const MAX_VALUE_HEIGHT = 50; const MAX_VALUE_HEIGHT = 50;

View File

@ -1,5 +1,5 @@
import React, { useState, ChangeEvent, useContext } from 'react'; import React, { useState, ChangeEvent, useContext } from 'react';
import { DataLink } from '../../index'; import { DataLink } from '@grafana/data';
import { FormField, Switch } from '../index'; import { FormField, Switch } from '../index';
import { VariableSuggestion } from './DataLinkSuggestions'; import { VariableSuggestion } from './DataLinkSuggestions';
import { css, cx } from 'emotion'; import { css, cx } from 'emotion';

View File

@ -4,7 +4,8 @@ import React, { FC, useContext } from 'react';
import Prism from 'prismjs'; import Prism from 'prismjs';
// Components // Components
import { css } from 'emotion'; import { css } from 'emotion';
import { DataLink, ThemeContext } from '../../index'; import { DataLink } from '@grafana/data';
import { ThemeContext } from '../../index';
import { Button } from '../index'; import { Button } from '../index';
import { DataLinkEditor } from './DataLinkEditor'; import { DataLinkEditor } from './DataLinkEditor';
import { VariableSuggestion } from './DataLinkSuggestions'; import { VariableSuggestion } from './DataLinkSuggestions';

View File

@ -1,8 +1,9 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import $ from 'jquery'; import $ from 'jquery';
import { getColorFromHexRgbOrName } from '../../utils'; import { getColorFromHexRgbOrName } from '../../utils';
import { DisplayValue, Threshold, Themeable } from '../../types'; import { DisplayValue, Themeable } from '../../types';
import { selectThemeVariant } from '../../themes'; import { selectThemeVariant } from '../../themes';
import { Threshold } from '@grafana/data';
export interface Props extends Themeable { export interface Props extends Themeable {
height: number; height: number;

View File

@ -1,5 +1,5 @@
import React, { PureComponent, ChangeEvent } from 'react'; import React, { PureComponent, ChangeEvent } from 'react';
import { Threshold } from '../../types'; import { Threshold } from '@grafana/data';
import { colors } from '../../utils'; import { colors } from '../../utils';
import { ThemeContext } from '../../themes'; import { ThemeContext } from '../../themes';
import { getColorFromHexRgbOrName } from '../../utils'; import { getColorFromHexRgbOrName } from '../../utils';

View File

@ -2,7 +2,7 @@ import React, { ChangeEvent, PureComponent } from 'react';
import { FormField, FormLabel, Input, Select } from '..'; import { FormField, FormLabel, Input, Select } from '..';
import { MappingType, ValueMapping } from '../../types'; import { MappingType, ValueMapping } from '@grafana/data';
export interface Props { export interface Props {
valueMapping: ValueMapping; valueMapping: ValueMapping;

View File

@ -2,7 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { ValueMappingsEditor, Props } from './ValueMappingsEditor'; import { ValueMappingsEditor, Props } from './ValueMappingsEditor';
import { MappingType } from '../../types'; import { MappingType } from '@grafana/data';
const setup = (propOverrides?: object) => { const setup = (propOverrides?: object) => {
const props: Props = { const props: Props = {

View File

@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import MappingRow from './MappingRow'; import MappingRow from './MappingRow';
import { MappingType, ValueMapping } from '../../types'; import { MappingType, ValueMapping } from '@grafana/data';
import { PanelOptionsGroup } from '../PanelOptionsGroup/PanelOptionsGroup'; import { PanelOptionsGroup } from '../PanelOptionsGroup/PanelOptionsGroup';
export interface Props { export interface Props {

View File

@ -4,6 +4,5 @@ export * from './app';
export * from './datasource'; export * from './datasource';
export * from './theme'; export * from './theme';
export * from './graph'; export * from './graph';
export * from './threshold';
export * from './input'; export * from './input';
export * from './displayValue'; export * from './displayValue';

View File

@ -123,35 +123,6 @@ export interface PanelMenuItem {
subMenu?: PanelMenuItem[]; subMenu?: PanelMenuItem[];
} }
export enum MappingType {
ValueToText = 1,
RangeToText = 2,
}
interface BaseMap {
id: number;
operator: string;
text: string;
type: MappingType;
}
export type ValueMapping = ValueMap | RangeMap;
export interface ValueMap extends BaseMap {
value: string;
}
export interface RangeMap extends BaseMap {
from: string;
to: string;
}
export interface DataLink {
url: string;
title: string;
targetBlank?: boolean;
}
export enum VizOrientation { export enum VizOrientation {
Auto = 'auto', Auto = 'auto',
Vertical = 'vertical', Vertical = 'vertical',

View File

@ -1,5 +1,6 @@
import { getDisplayProcessor, getColorFromThreshold, DisplayProcessor, getDecimalsForValue } from './displayValue'; import { getDisplayProcessor, getColorFromThreshold, DisplayProcessor, getDecimalsForValue } from './displayValue';
import { DisplayValue, MappingType, ValueMapping } from '../types'; import { DisplayValue } from '../types';
import { MappingType, ValueMapping } from '@grafana/data';
function assertSame(input: any, processors: DisplayProcessor[], match: DisplayValue) { function assertSame(input: any, processors: DisplayProcessor[], match: DisplayValue) {
processors.forEach(processor => { processors.forEach(processor => {

View File

@ -3,20 +3,11 @@ import _ from 'lodash';
// Utils // Utils
import { getValueFormat } from './valueFormats/valueFormats'; import { getValueFormat } from './valueFormats/valueFormats';
import { getMappedValue } from './valueMappings';
import { getColorFromHexRgbOrName } from './namedColorsPalette'; import { getColorFromHexRgbOrName } from './namedColorsPalette';
// Types // Types
import { import { DecimalInfo, DisplayValue, GrafanaTheme, GrafanaThemeType, DecimalCount } from '../types';
Threshold, import { DateTime, dateTime, Threshold, ValueMapping, getMappedValue, Field } from '@grafana/data';
ValueMapping,
DecimalInfo,
DisplayValue,
GrafanaTheme,
GrafanaThemeType,
DecimalCount,
} from '../types';
import { DateTime, dateTime, Field } from '@grafana/data';
export type DisplayProcessor = (value: any) => DisplayValue; export type DisplayProcessor = (value: any) => DisplayValue;

View File

@ -1,18 +1,19 @@
import toNumber from 'lodash/toNumber'; import toNumber from 'lodash/toNumber';
import toString from 'lodash/toString'; import toString from 'lodash/toString';
import { DisplayValue, GrafanaTheme, InterpolateFunction, ScopedVars, GraphSeriesValue } from '../types/index';
import { getDisplayProcessor } from './displayValue';
import { getFlotPairs } from './flotPairs';
import { import {
ValueMapping, ValueMapping,
Threshold, Threshold,
DisplayValue, ReducerID,
GrafanaTheme, reduceField,
InterpolateFunction, FieldType,
ScopedVars, NullValueMode,
GraphSeriesValue, DataFrame,
} from '../types/index'; Field,
import { getDisplayProcessor } from './displayValue'; } from '@grafana/data';
import { getFlotPairs } from './flotPairs';
import { ReducerID, reduceField, FieldType, NullValueMode, DataFrame, Field } from '@grafana/data';
export interface FieldDisplayOptions { export interface FieldDisplayOptions {
values?: boolean; // If true show each row value values?: boolean; // If true show each row value

View File

@ -1,11 +1,9 @@
export * from './valueFormats/valueFormats'; export * from './valueFormats/valueFormats';
export * from './colors'; export * from './colors';
export * from './namedColorsPalette'; export * from './namedColorsPalette';
export * from './thresholds';
export * from './displayValue'; export * from './displayValue';
export * from './fieldDisplay'; export * from './fieldDisplay';
export * from './deprecationWarning'; export * from './deprecationWarning';
export { getMappedValue } from './valueMappings';
export * from './validate'; export * from './validate';
export { getFlotPairs } from './flotPairs'; export { getFlotPairs } from './flotPairs';
export * from './slate'; export * from './slate';

View File

@ -9,7 +9,8 @@ import templateSrv from 'app/features/templating/template_srv';
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
import { PanelModel } from 'app/features/dashboard/state/PanelModel'; import { PanelModel } from 'app/features/dashboard/state/PanelModel';
import { ClickOutsideWrapper, DataLink } from '@grafana/ui'; import { ClickOutsideWrapper } from '@grafana/ui';
import { DataLink } from '@grafana/data';
export interface Props { export interface Props {
panel: PanelModel; panel: PanelModel;

View File

@ -1,7 +1,8 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { renderMarkdown } from '@grafana/data'; import { renderMarkdown } from '@grafana/data';
import { Tooltip, ScopedVars, DataLink } from '@grafana/ui'; import { Tooltip, ScopedVars } from '@grafana/ui';
import { DataLink } from '@grafana/data';
import { PanelModel } from 'app/features/dashboard/state/PanelModel'; import { PanelModel } from 'app/features/dashboard/state/PanelModel';
import templateSrv from 'app/features/templating/template_srv'; import templateSrv from 'app/features/templating/template_srv';

View File

@ -8,7 +8,8 @@ import './../../panel/GeneralTabCtrl';
// Types // Types
import { PanelModel } from '../state/PanelModel'; import { PanelModel } from '../state/PanelModel';
import { DataLink, PanelOptionsGroup, DataLinksEditor } from '@grafana/ui'; import { DataLink } from '@grafana/data';
import { PanelOptionsGroup, DataLinksEditor } from '@grafana/ui';
import { getPanelLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv'; import { getPanelLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
interface Props { interface Props {

View File

@ -9,7 +9,7 @@ import kbn from 'app/core/utils/kbn';
// Types // Types
import { PanelModel } from './PanelModel'; import { PanelModel } from './PanelModel';
import { DashboardModel } from './DashboardModel'; import { DashboardModel } from './DashboardModel';
import { DataLink } from '@grafana/ui/src/types/panel'; import { DataLink } from '@grafana/data';
// Constants // Constants
import { import {

View File

@ -6,7 +6,9 @@ import { Emitter } from 'app/core/utils/emitter';
import { getNextRefIdChar } from 'app/core/utils/query'; import { getNextRefIdChar } from 'app/core/utils/query';
// Types // Types
import { DataQuery, ScopedVars, DataQueryResponseData, PanelPlugin, DataLink } from '@grafana/ui'; import { DataQuery, ScopedVars, DataQueryResponseData, PanelPlugin } from '@grafana/ui';
import { DataLink } from '@grafana/data';
import config from 'app/core/config'; import config from 'app/core/config';
import { PanelQueryRunner } from './PanelQueryRunner'; import { PanelQueryRunner } from './PanelQueryRunner';

View File

@ -3,9 +3,8 @@ import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import templateSrv, { TemplateSrv } from 'app/features/templating/template_srv'; import templateSrv, { TemplateSrv } from 'app/features/templating/template_srv';
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import { appendQueryToUrl, toUrlParams } from 'app/core/utils/url'; import { appendQueryToUrl, toUrlParams } from 'app/core/utils/url';
import { DataLink, VariableSuggestion, KeyValue, ScopedVars } from '@grafana/ui'; import { VariableSuggestion, KeyValue, ScopedVars, deprecationWarning, VariableOrigin } from '@grafana/ui';
import { TimeSeriesValue, DateTime, dateTime } from '@grafana/data'; import { TimeSeriesValue, DateTime, dateTime, DataLink } from '@grafana/data';
import { deprecationWarning, VariableOrigin } from '@grafana/ui';
export const DataLinkBuiltInVars = { export const DataLinkBuiltInVars = {
keepTime: '__url_time_range', keepTime: '__url_time_range',

View File

@ -1,7 +1,6 @@
// Libraries // Libraries
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
// Components
import { import {
ThresholdsEditor, ThresholdsEditor,
ValueMappingsEditor, ValueMappingsEditor,
@ -10,11 +9,13 @@ import {
FieldDisplayOptions, FieldDisplayOptions,
FieldPropertiesEditor, FieldPropertiesEditor,
PanelOptionsGroup, PanelOptionsGroup,
FormLabel,
PanelEditorProps,
Select,
} from '@grafana/ui'; } from '@grafana/ui';
import { Field } from '@grafana/data'; import { Field } from '@grafana/data';
// Types import { Threshold, ValueMapping } from '@grafana/data';
import { FormLabel, PanelEditorProps, Threshold, Select, ValueMapping } from '@grafana/ui';
import { BarGaugeOptions, orientationOptions, displayModes } from './types'; import { BarGaugeOptions, orientationOptions, displayModes } from './types';
export class BarGaugePanelEditor extends PureComponent<PanelEditorProps<BarGaugeOptions>> { export class BarGaugePanelEditor extends PureComponent<PanelEditorProps<BarGaugeOptions>> {

View File

@ -3,17 +3,15 @@ import React, { PureComponent } from 'react';
import { import {
PanelEditorProps, PanelEditorProps,
ThresholdsEditor, ThresholdsEditor,
Threshold,
PanelOptionsGrid, PanelOptionsGrid,
ValueMappingsEditor, ValueMappingsEditor,
ValueMapping,
FieldDisplayOptions, FieldDisplayOptions,
FieldDisplayEditor, FieldDisplayEditor,
FieldPropertiesEditor, FieldPropertiesEditor,
Switch, Switch,
PanelOptionsGroup, PanelOptionsGroup,
} from '@grafana/ui'; } from '@grafana/ui';
import { Field } from '@grafana/data'; import { Field, Threshold, ValueMapping } from '@grafana/data';
import { GaugeOptions } from './types'; import { GaugeOptions } from './types';

View File

@ -25,9 +25,9 @@ import ReactDOM from 'react-dom';
import { GraphLegendProps, Legend } from './Legend/Legend'; import { GraphLegendProps, Legend } from './Legend/Legend';
import { GraphCtrl } from './module'; import { GraphCtrl } from './module';
import { getValueFormat, ContextMenuItem, ContextMenuGroup, DataLink } from '@grafana/ui'; import { getValueFormat, ContextMenuItem, ContextMenuGroup } from '@grafana/ui';
import { provideTheme } from 'app/core/utils/ConfigProvider'; import { provideTheme } from 'app/core/utils/ConfigProvider';
import { toUtc } from '@grafana/data'; import { DataLink, toUtc } from '@grafana/data';
import { GraphContextMenuCtrl, FlotDataPoint } from './GraphContextMenuCtrl'; import { GraphContextMenuCtrl, FlotDataPoint } from './GraphContextMenuCtrl';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { ContextSrv } from 'app/core/services/context_srv'; import { ContextSrv } from 'app/core/services/context_srv';

View File

@ -11,8 +11,8 @@ import { DataProcessor } from './data_processor';
import { axesEditorComponent } from './axes_editor'; import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config'; import config from 'app/core/config';
import TimeSeries from 'app/core/time_series2'; import TimeSeries from 'app/core/time_series2';
import { DataFrame } from '@grafana/data'; import { DataFrame, DataLink } from '@grafana/data';
import { getColorFromHexRgbOrName, LegacyResponseData, DataLink, VariableSuggestion } from '@grafana/ui'; import { getColorFromHexRgbOrName, LegacyResponseData, VariableSuggestion } from '@grafana/ui';
import { getProcessedDataFrame } from 'app/features/dashboard/state/PanelQueryState'; import { getProcessedDataFrame } from 'app/features/dashboard/state/PanelQueryState';
import { PanelQueryRunnerFormat } from 'app/features/dashboard/state/PanelQueryRunner'; import { PanelQueryRunnerFormat } from 'app/features/dashboard/state/PanelQueryRunner';
import { GraphContextMenuCtrl } from './GraphContextMenuCtrl'; import { GraphContextMenuCtrl } from './GraphContextMenuCtrl';

View File

@ -3,13 +3,12 @@ import {
PanelEditorProps, PanelEditorProps,
PanelOptionsGrid, PanelOptionsGrid,
ValueMappingsEditor, ValueMappingsEditor,
ValueMapping,
FieldDisplayEditor, FieldDisplayEditor,
FieldDisplayOptions, FieldDisplayOptions,
FieldPropertiesEditor, FieldPropertiesEditor,
PanelOptionsGroup, PanelOptionsGroup,
} from '@grafana/ui'; } from '@grafana/ui';
import { Field } from '@grafana/data'; import { ValueMapping, Field } from '@grafana/data';
import { PieChartOptionsBox } from './PieChartOptionsBox'; import { PieChartOptionsBox } from './PieChartOptionsBox';
import { PieChartOptions } from './types'; import { PieChartOptions } from './types';

View File

@ -3,16 +3,14 @@ import React, { PureComponent } from 'react';
import { import {
PanelEditorProps, PanelEditorProps,
ThresholdsEditor, ThresholdsEditor,
Threshold,
PanelOptionsGrid, PanelOptionsGrid,
ValueMappingsEditor, ValueMappingsEditor,
ValueMapping,
FieldDisplayOptions, FieldDisplayOptions,
FieldDisplayEditor, FieldDisplayEditor,
FieldPropertiesEditor, FieldPropertiesEditor,
PanelOptionsGroup, PanelOptionsGroup,
} from '@grafana/ui'; } from '@grafana/ui';
import { Field } from '@grafana/data'; import { Threshold, ValueMapping, Field } from '@grafana/data';
import { SingleStatOptions, SparklineOptions } from './types'; import { SingleStatOptions, SparklineOptions } from './types';
import { ColoringEditor } from './ColoringEditor'; import { ColoringEditor } from './ColoringEditor';