瀏覽代碼

fix type errors

ryan 6 年之前
父節點
當前提交
ca5d7c3510

+ 2 - 1
packages/grafana-ui/src/components/DataTable/DataTable.tsx

@@ -86,7 +86,8 @@ export class DataTable extends Component<Props, State> {
 
     // Update the data when data or sort changes
     if (dataChanged || sortBy !== prevState.sortBy || sortDirection !== prevState.sortDirection) {
-      this.setState({ data: sortTableData(data, sortBy, sortDirection === 'DESC') });
+      const sorted = data ? sortTableData(data, sortBy, sortDirection === 'DESC') : data;
+      this.setState({ data: sorted });
     }
   }
 

+ 0 - 1
packages/grafana-ui/src/components/DataTable/renderer.test.ts

@@ -3,7 +3,6 @@ import TableModel from 'app/core/table_model';
 
 import { getColorDefinitionByName } from '@grafana/ui';
 import { ScopedVars } from '@grafana/ui/src/types';
-import moment from 'moment';
 import { TableRenderer } from './renderer';
 import { Index } from 'react-virtualized';
 import { ColumnStyle } from './DataTable';

+ 2 - 2
packages/grafana-ui/src/components/DataTable/renderer.tsx

@@ -98,7 +98,7 @@ export class TableRenderer {
     }
   }
 
-  createColumnFormatter(header: Column, style?: ColumnStyle): CellFormatter {
+  createColumnFormatter(schema: Column, style?: ColumnStyle): CellFormatter {
     if (!style) {
       return this.defaultCellFormatter;
     }
@@ -181,7 +181,7 @@ export class TableRenderer {
     }
 
     if (style.type === 'number') {
-      const valueFormatter = getValueFormat(style.unit || header.unit);
+      const valueFormatter = getValueFormat(style.unit || schema.unit || 'none');
 
       return v => {
         if (v === null || v === void 0) {

+ 2 - 2
packages/grafana-ui/src/utils/processTimeSeries.ts

@@ -174,8 +174,8 @@ export function processTimeSeries({ timeSeries, nullValueMode }: Options): TimeS
   return vmSeries;
 }
 
-export function sortTableData(data?: TableData, sortIndex?: number, reverse = false): TableData {
-  if (data && isNumber(sortIndex)) {
+export function sortTableData(data: TableData, sortIndex?: number, reverse = false): TableData {
+  if (isNumber(sortIndex)) {
     const copy = {
       ...data,
       rows: [...data.rows].sort((a, b) => {