Ver código fonte

Moving a couple of types to @grafana/ui

Torkel Ödegaard 7 anos atrás
pai
commit
a02b4b47b6
33 arquivos alterados com 137 adições e 159 exclusões
  1. 2 0
      packages/grafana-ui/src/types/index.ts
  2. 31 0
      packages/grafana-ui/src/types/panel.ts
  3. 45 5
      packages/grafana-ui/src/types/series.ts
  4. 17 0
      packages/grafana-ui/src/types/time.ts
  5. 2 1
      public/app/core/utils/explore.ts
  6. 1 1
      public/app/core/utils/rangeutil.ts
  7. 2 2
      public/app/features/dashboard/dashgrid/DataPanel.tsx
  8. 2 1
      public/app/features/dashboard/dashgrid/PanelChrome.tsx
  9. 1 1
      public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx
  10. 1 1
      public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx
  11. 5 1
      public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx
  12. 2 2
      public/app/features/dashboard/time_srv.ts
  13. 1 1
      public/app/features/dashboard/utils/getPanelMenu.ts
  14. 1 1
      public/app/features/dashboard/utils/panel.ts
  15. 2 1
      public/app/features/explore/Explore.tsx
  16. 1 1
      public/app/features/explore/Graph.tsx
  17. 1 1
      public/app/features/explore/Logs.tsx
  18. 1 1
      public/app/features/explore/QueryEditor.tsx
  19. 1 1
      public/app/features/explore/QueryRows.tsx
  20. 1 1
      public/app/features/explore/TimePicker.tsx
  21. 2 1
      public/app/plugins/panel/gauge/Threshold.test.tsx
  22. 2 9
      public/app/plugins/panel/gauge/module.tsx
  23. 1 1
      public/app/plugins/panel/graph2/GraphOptions.tsx
  24. 1 1
      public/app/plugins/panel/graph2/GraphPanel.tsx
  25. 1 1
      public/app/plugins/panel/text2/module.tsx
  26. 2 1
      public/app/types/explore.ts
  27. 2 22
      public/app/types/index.ts
  28. 0 32
      public/app/types/panel.ts
  29. 1 1
      public/app/types/plugins.ts
  30. 1 64
      public/app/types/series.ts
  31. 2 1
      public/app/viz/Gauge.tsx
  32. 1 1
      public/app/viz/Graph.tsx
  33. 1 1
      public/app/viz/state/timeSeries.ts

+ 2 - 0
packages/grafana-ui/src/types/index.ts

@@ -1 +1,3 @@
 export * from './series';
+export * from './time';
+export * from './panel';

+ 31 - 0
packages/grafana-ui/src/types/panel.ts

@@ -0,0 +1,31 @@
+import { TimeSeries, LoadingState } from './series';
+import { TimeRange } from './time';
+
+export interface PanelProps<T = any> {
+  timeSeries: TimeSeries[];
+  timeRange: TimeRange;
+  loading: LoadingState;
+  options: T;
+  renderCounter: number;
+  width: number;
+  height: number;
+}
+
+export interface PanelOptionsProps<T = any> {
+  options: T;
+  onChange: (options: T) => void;
+}
+
+export interface PanelSize {
+  width: number;
+  height: number;
+}
+
+export interface PanelMenuItem {
+  type?: 'submenu' | 'divider';
+  text?: string;
+  iconClassName?: string;
+  onClick?: () => void;
+  shortcut?: string;
+  subMenu?: PanelMenuItem[];
+}

+ 45 - 5
packages/grafana-ui/src/types/series.ts

@@ -1,5 +1,3 @@
-import { Moment } from 'moment';
-
 export enum LoadingState {
   NotStarted = 'NotStarted',
   Loading = 'Loading',
@@ -7,7 +5,49 @@ export enum LoadingState {
   Error = 'Error',
 }
 
-export interface RawTimeRange {
-  from: Moment | string;
-  to: Moment | string;
+export type TimeSeriesValue = string | number | null;
+
+export type TimeSeriesPoints = TimeSeriesValue[][];
+
+export interface TimeSeries {
+  target: string;
+  datapoints: TimeSeriesPoints;
+  unit?: string;
+}
+
+/** View model projection of a time series */
+export interface TimeSeriesVM {
+  label: string;
+  color: string;
+  data: TimeSeriesValue[][];
+  stats: TimeSeriesStats;
+}
+
+export interface TimeSeriesStats {
+  total: number;
+  max: number;
+  min: number;
+  logmin: number;
+  avg: number | null;
+  current: number | null;
+  first: number | null;
+  delta: number;
+  diff: number | null;
+  range: number | null;
+  timeStep: number;
+  count: number;
+  allIsNull: boolean;
+  allIsZero: boolean;
+}
+
+export enum NullValueMode {
+  Null = 'null',
+  Ignore = 'connected',
+  AsZero = 'null as zero',
+}
+
+/** View model projection of many time series */
+export interface TimeSeriesVMs {
+  [index: number]: TimeSeriesVM;
+  length: number;
 }

+ 17 - 0
packages/grafana-ui/src/types/time.ts

@@ -0,0 +1,17 @@
+import { Moment } from 'moment';
+
+export interface RawTimeRange {
+  from: Moment | string;
+  to: Moment | string;
+}
+
+export interface TimeRange {
+  from: Moment;
+  to: Moment;
+  raw: RawTimeRange;
+}
+
+export interface IntervalValues {
+  interval: string; // 10s,5m
+  intervalMs: number;
+}

+ 2 - 1
public/app/core/utils/explore.ts

@@ -9,7 +9,8 @@ import { parse as parseDate } from 'app/core/utils/datemath';
 import TimeSeries from 'app/core/time_series2';
 import TableModel, { mergeTablesIntoModel } from 'app/core/table_model';
 import { ExploreState, ExploreUrlState, HistoryItem, QueryTransaction } from 'app/types/explore';
-import { DataQuery, RawTimeRange, IntervalValues, DataSourceApi } from 'app/types/series';
+import { DataQuery, DataSourceApi } from 'app/types/series';
+import { RawTimeRange, IntervalValues } from '@grafana/ui';
 
 export const DEFAULT_RANGE = {
   from: 'now-6h',

+ 1 - 1
public/app/core/utils/rangeutil.ts

@@ -1,7 +1,7 @@
 import _ from 'lodash';
 import moment from 'moment';
 
-import { RawTimeRange } from 'app/types/series';
+import { RawTimeRange } from '@grafana/ui';
 
 import * as dateMath from './datemath';
 

+ 2 - 2
public/app/features/dashboard/dashgrid/DataPanel.tsx

@@ -8,8 +8,8 @@ import { getDatasourceSrv, DatasourceSrv } from 'app/features/plugins/datasource
 import kbn from 'app/core/utils/kbn';
 
 // Types
-import { TimeRange, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types';
-import { LoadingState } from '@grafana/ui';
+import { DataQueryOptions, DataQueryResponse } from 'app/types';
+import { TimeRange, TimeSeries, LoadingState } from '@grafana/ui';
 
 interface RenderProps {
   loading: LoadingState;

+ 2 - 1
public/app/features/dashboard/dashgrid/PanelChrome.tsx

@@ -16,7 +16,8 @@ import { PANEL_HEADER_HEIGHT } from 'app/core/constants';
 // Types
 import { PanelModel } from '../panel_model';
 import { DashboardModel } from '../dashboard_model';
-import { PanelPlugin, TimeRange } from 'app/types';
+import { PanelPlugin } from 'app/types';
+import { TimeRange } from '@grafana/ui';
 
 export interface Props {
   panel: PanelModel;

+ 1 - 1
public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx

@@ -3,7 +3,7 @@ import { DashboardModel } from 'app/features/dashboard/dashboard_model';
 import { PanelModel } from 'app/features/dashboard/panel_model';
 import { PanelHeaderMenuItem } from './PanelHeaderMenuItem';
 import { getPanelMenu } from 'app/features/dashboard/utils/getPanelMenu';
-import { PanelMenuItem } from 'app/types/panel';
+import { PanelMenuItem } from '@grafana/ui';
 
 export interface Props {
   panel: PanelModel;

+ 1 - 1
public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx

@@ -1,5 +1,5 @@
 import React, { SFC } from 'react';
-import { PanelMenuItem } from 'app/types/panel';
+import { PanelMenuItem } from '@grafana/ui';
 
 interface Props {
   children: any;

+ 5 - 1
public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx

@@ -1,6 +1,10 @@
+// Libraries
 import _ from 'lodash';
 import React, { PureComponent } from 'react';
-import { PanelPlugin, PanelProps } from 'app/types';
+
+// Types
+import { PanelProps } from '@grafana/ui';
+import { PanelPlugin } from 'app/types';
 
 interface Props {
   pluginId: string;

+ 2 - 2
public/app/features/dashboard/time_srv.ts

@@ -6,9 +6,9 @@ import _ from 'lodash';
 import kbn from 'app/core/utils/kbn';
 import coreModule from 'app/core/core_module';
 import * as dateMath from 'app/core/utils/datemath';
-// Types
 
-import { TimeRange } from 'app/types';
+// Types
+import { TimeRange } from '@grafana/ui';
 
 export class TimeSrv {
   time: any;

+ 1 - 1
public/app/features/dashboard/utils/getPanelMenu.ts

@@ -4,7 +4,7 @@ import { store } from 'app/store/store';
 import { removePanel, duplicatePanel, copyPanel, editPanelJson, sharePanel } from 'app/features/dashboard/utils/panel';
 import { PanelModel } from 'app/features/dashboard/panel_model';
 import { DashboardModel } from 'app/features/dashboard/dashboard_model';
-import { PanelMenuItem } from 'app/types/panel';
+import { PanelMenuItem } from '@grafana/ui';
 
 export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
   const onViewPanel = () => {

+ 1 - 1
public/app/features/dashboard/utils/panel.ts

@@ -4,7 +4,7 @@ import store from 'app/core/store';
 // Models
 import { DashboardModel } from 'app/features/dashboard/dashboard_model';
 import { PanelModel } from 'app/features/dashboard/panel_model';
-import { TimeRange } from 'app/types/series';
+import { TimeRange } from '@grafana/ui';
 
 // Utils
 import { isString as _isString } from 'lodash';

+ 2 - 1
public/app/features/explore/Explore.tsx

@@ -11,7 +11,8 @@ import {
   QueryHintGetter,
   QueryHint,
 } from 'app/types/explore';
-import { TimeRange, DataQuery } from 'app/types/series';
+import { TimeRange } from '@grafana/ui';
+import { DataQuery } from 'app/types/series';
 import store from 'app/core/store';
 import {
   DEFAULT_RANGE,

+ 1 - 1
public/app/features/explore/Graph.tsx

@@ -8,7 +8,7 @@ import 'vendor/flot/jquery.flot.time';
 import 'vendor/flot/jquery.flot.selection';
 import 'vendor/flot/jquery.flot.stack';
 
-import { RawTimeRange } from 'app/types/series';
+import { RawTimeRange } from '@grafana/ui';
 import * as dateMath from 'app/core/utils/datemath';
 import TimeSeries from 'app/core/time_series2';
 

+ 1 - 1
public/app/features/explore/Logs.tsx

@@ -4,7 +4,7 @@ import Highlighter from 'react-highlight-words';
 import classnames from 'classnames';
 
 import * as rangeUtil from 'app/core/utils/rangeutil';
-import { RawTimeRange } from 'app/types/series';
+import { RawTimeRange } from '@grafana/ui';
 import {
   LogsDedupDescription,
   LogsDedupStrategy,

+ 1 - 1
public/app/features/explore/QueryEditor.tsx

@@ -3,7 +3,7 @@ import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoa
 import { Emitter } from 'app/core/utils/emitter';
 import { getIntervals } from 'app/core/utils/explore';
 import { DataQuery } from 'app/types';
-import { RawTimeRange } from 'app/types/series';
+import { RawTimeRange } from '@grafana/ui';
 import { getTimeSrv } from 'app/features/dashboard/time_srv';
 import 'app/features/plugins/plugin_loader';
 

+ 1 - 1
public/app/features/explore/QueryRows.tsx

@@ -7,7 +7,7 @@ import { Emitter } from 'app/core/utils/emitter';
 import QueryEditor from './QueryEditor';
 import QueryTransactionStatus from './QueryTransactionStatus';
 import { DataSource, DataQuery } from 'app/types';
-import { RawTimeRange } from 'app/types/series';
+import { RawTimeRange } from '@grafana/ui';
 
 function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint {
   const transaction = transactions.find(qt => qt.hints && qt.hints.length > 0);

+ 1 - 1
public/app/features/explore/TimePicker.tsx

@@ -3,7 +3,7 @@ import moment from 'moment';
 
 import * as dateMath from 'app/core/utils/datemath';
 import * as rangeUtil from 'app/core/utils/rangeutil';
-import { RawTimeRange, TimeRange } from 'app/types/series';
+import { RawTimeRange, TimeRange } from '@grafana/ui';
 
 const DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';
 export const DEFAULT_RANGE = {

+ 2 - 1
public/app/plugins/panel/gauge/Threshold.test.tsx

@@ -2,7 +2,8 @@ import React from 'react';
 import { shallow } from 'enzyme';
 import Thresholds from './Thresholds';
 import { defaultProps, OptionsProps } from './module';
-import { BasicGaugeColor, PanelOptionsProps } from 'app/types';
+import { BasicGaugeColor } from 'app/types';
+import { PanelOptionsProps } from '@grafana/ui';
 
 const setup = (propOverrides?: object) => {
   const props: PanelOptionsProps<OptionsProps> = {

+ 2 - 9
public/app/plugins/panel/gauge/module.tsx

@@ -5,15 +5,8 @@ import ValueOptions from './ValueOptions';
 import GaugeOptions from './GaugeOptions';
 import Thresholds from './Thresholds';
 import ValueMappings from './ValueMappings';
-import {
-  BasicGaugeColor,
-  NullValueMode,
-  PanelOptionsProps,
-  PanelProps,
-  RangeMap,
-  Threshold,
-  ValueMap,
-} from 'app/types';
+import { PanelOptionsProps, PanelProps, NullValueMode } from '@grafana/ui';
+import { BasicGaugeColor, RangeMap, Threshold, ValueMap } from 'app/types';
 
 export interface OptionsProps {
   baseColor: string;

+ 1 - 1
public/app/plugins/panel/graph2/GraphOptions.tsx

@@ -6,7 +6,7 @@ import React, { PureComponent } from 'react';
 import { Switch } from 'app/core/components/Switch/Switch';
 
 // Types
-import { PanelOptionsProps } from 'app/types';
+import { PanelOptionsProps } from '@grafana/ui';
 import { Options } from './types';
 
 export class GraphOptions extends PureComponent<PanelOptionsProps<Options>> {

+ 1 - 1
public/app/plugins/panel/graph2/GraphPanel.tsx

@@ -9,7 +9,7 @@ import Graph from 'app/viz/Graph';
 import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
 
 // Types
-import { PanelProps, NullValueMode } from 'app/types';
+import { PanelProps, NullValueMode } from '@grafana/ui';
 import { Options } from './types';
 
 interface Props extends PanelProps<Options> {}

+ 1 - 1
public/app/plugins/panel/text2/module.tsx

@@ -1,5 +1,5 @@
 import React, { PureComponent } from 'react';
-import { PanelProps } from 'app/types';
+import { PanelProps } from '@grafana/ui';
 
 export class Text2 extends PureComponent<PanelProps> {
   constructor(props) {

+ 2 - 1
public/app/types/explore.ts

@@ -1,6 +1,7 @@
 import { Value } from 'slate';
 
-import { DataQuery, RawTimeRange } from './series';
+import { DataQuery } from './series';
+import { RawTimeRange } from '@grafana/ui';
 import TableModel from 'app/core/table_model';
 import { LogsModel } from 'app/core/logs_model';
 import { DataSourceSelectItem } from 'app/types/datasources';

+ 2 - 22
public/app/types/index.ts

@@ -8,19 +8,8 @@ import { DashboardAcl, OrgRole, PermissionLevel } from './acl';
 import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
 import { Invitee, OrgUser, User, UsersState, UserState } from './user';
 import { DataSource, DataSourceSelectItem, DataSourcesState } from './datasources';
-import {
-  TimeRange,
-  TimeSeries,
-  TimeSeriesVM,
-  TimeSeriesVMs,
-  TimeSeriesStats,
-  NullValueMode,
-  DataQuery,
-  DataQueryResponse,
-  DataQueryOptions,
-  IntervalValues,
-} from './series';
-import { BasicGaugeColor, MappingType, PanelProps, PanelOptionsProps, RangeMap, Threshold, ValueMap } from './panel';
+import { DataQuery, DataQueryResponse, DataQueryOptions } from './series';
+import { BasicGaugeColor, MappingType, RangeMap, Threshold, ValueMap } from './panel';
 import { PluginDashboard, PluginMeta, Plugin, PanelPlugin, PluginsState } from './plugins';
 import { Organization, OrganizationState } from './organization';
 import {
@@ -67,15 +56,7 @@ export {
   OrgUser,
   User,
   UsersState,
-  TimeRange,
   PanelPlugin,
-  PanelProps,
-  PanelOptionsProps,
-  TimeSeries,
-  TimeSeriesVM,
-  TimeSeriesVMs,
-  NullValueMode,
-  TimeSeriesStats,
   DataQuery,
   DataQueryResponse,
   DataQueryOptions,
@@ -93,7 +74,6 @@ export {
   ValidationRule,
   ValueMap,
   RangeMap,
-  IntervalValues,
   MappingType,
   BasicGaugeColor,
 };

+ 0 - 32
public/app/types/panel.ts

@@ -1,35 +1,3 @@
-import { TimeSeries, TimeRange } from './series';
-import { LoadingState } from '@grafana/ui';
-
-export interface PanelProps<T = any> {
-  timeSeries: TimeSeries[];
-  timeRange: TimeRange;
-  loading: LoadingState;
-  options: T;
-  renderCounter: number;
-  width: number;
-  height: number;
-}
-
-export interface PanelOptionsProps<T = any> {
-  options: T;
-  onChange: (options: T) => void;
-}
-
-export interface PanelSize {
-  width: number;
-  height: number;
-}
-
-export interface PanelMenuItem {
-  type?: 'submenu' | 'divider';
-  text?: string;
-  iconClassName?: string;
-  onClick?: () => void;
-  shortcut?: string;
-  subMenu?: PanelMenuItem[];
-}
-
 export interface Threshold {
   index: number;
   value: number;

+ 1 - 1
public/app/types/plugins.ts

@@ -1,5 +1,5 @@
 import { ComponentClass } from 'react';
-import { PanelProps, PanelOptionsProps } from './panel';
+import { PanelProps, PanelOptionsProps } from '@grafana/ui';
 
 export interface PluginExports {
   Datasource?: any;

+ 1 - 64
public/app/types/series.ts

@@ -1,68 +1,5 @@
-import { Moment } from 'moment';
 import { PluginMeta } from './plugins';
-
-export interface RawTimeRange {
-  from: Moment | string;
-  to: Moment | string;
-}
-
-export interface TimeRange {
-  from: Moment;
-  to: Moment;
-  raw: RawTimeRange;
-}
-
-export interface IntervalValues {
-  interval: string; // 10s,5m
-  intervalMs: number;
-}
-
-export type TimeSeriesValue = string | number | null;
-
-export type TimeSeriesPoints = TimeSeriesValue[][];
-
-export interface TimeSeries {
-  target: string;
-  datapoints: TimeSeriesPoints;
-  unit?: string;
-}
-
-/** View model projection of a time series */
-export interface TimeSeriesVM {
-  label: string;
-  color: string;
-  data: TimeSeriesValue[][];
-  stats: TimeSeriesStats;
-}
-
-export interface TimeSeriesStats {
-  total: number;
-  max: number;
-  min: number;
-  logmin: number;
-  avg: number | null;
-  current: number | null;
-  first: number | null;
-  delta: number;
-  diff: number | null;
-  range: number | null;
-  timeStep: number;
-  count: number;
-  allIsNull: boolean;
-  allIsZero: boolean;
-}
-
-export enum NullValueMode {
-  Null = 'null',
-  Ignore = 'connected',
-  AsZero = 'null as zero',
-}
-
-/** View model projection of many time series */
-export interface TimeSeriesVMs {
-  [index: number]: TimeSeriesVM;
-  length: number;
-}
+import { TimeSeries, TimeRange, RawTimeRange } from '@grafana/ui';
 
 export interface DataQueryResponse {
   data: TimeSeries[];

+ 2 - 1
public/app/viz/Gauge.tsx

@@ -1,6 +1,7 @@
 import React, { PureComponent } from 'react';
 import $ from 'jquery';
-import { BasicGaugeColor, MappingType, RangeMap, Threshold, TimeSeriesVMs, ValueMap } from 'app/types';
+import { BasicGaugeColor, MappingType, RangeMap, Threshold, ValueMap } from 'app/types';
+import { TimeSeriesVMs } from '@grafana/ui';
 import config from '../core/config';
 import kbn from '../core/utils/kbn';
 

+ 1 - 1
public/app/viz/Graph.tsx

@@ -5,7 +5,7 @@ import 'vendor/flot/jquery.flot';
 import 'vendor/flot/jquery.flot.time';
 
 // Types
-import { TimeRange, TimeSeriesVMs } from 'app/types';
+import { TimeRange, TimeSeriesVMs } from '@grafana/ui';
 
 interface GraphProps {
   timeSeries: TimeSeriesVMs;

+ 1 - 1
public/app/viz/state/timeSeries.ts

@@ -5,7 +5,7 @@ import _ from 'lodash';
 import colors from 'app/core/utils/colors';
 
 // Types
-import { TimeSeries, TimeSeriesVMs, NullValueMode } from 'app/types';
+import { TimeSeries, TimeSeriesVMs, NullValueMode } from '@grafana/ui';
 
 interface Options {
   timeSeries: TimeSeries[];