diff --git a/packages/grafana-ui/src/components/Table/Table.story.tsx b/packages/grafana-ui/src/components/Table/Table.story.tsx
new file mode 100644
index 00000000000..a494f01c56d
--- /dev/null
+++ b/packages/grafana-ui/src/components/Table/Table.story.tsx
@@ -0,0 +1,70 @@
+import React, { FunctionComponent } from 'react';
+import { storiesOf } from '@storybook/react';
+import { Table } from './Table';
+
+import { migratedTestTable, migratedTestStyles, simpleTable } from './examples';
+import { ScopedVars } from '../../types/index';
+
+import { renderComponentWithTheme } from '../../utils/storybook/withTheme';
+import { AutoSizer } from 'react-virtualized';
+
+const CenteredStory: FunctionComponent<{}> = ({ children }) => {
+ return (
+
+
+ {({ width, height }) => (
+
+
+ Need to pass {width}/{height} to the table?
+
+ {children}
+
+ )}
+
+
+ );
+};
+
+const replaceVariables = (value: any, scopedVars: ScopedVars | undefined) => {
+ // if (scopedVars) {
+ // // For testing variables replacement in link
+ // _.each(scopedVars, (val, key) => {
+ // value = value.replace('$' + key, val.value);
+ // });
+ // }
+ return value;
+};
+
+storiesOf('UI - Alpha/Table', module)
+ .addDecorator(story => {story()})
+ .add('basic', () => {
+ return renderComponentWithTheme(Table, {
+ styles: [],
+ data: simpleTable,
+ replaceVariables,
+ showHeader: true,
+ width: 500,
+ height: 300,
+ });
+ })
+ .add('Test Configuration', () => {
+ return renderComponentWithTheme(Table, {
+ styles: migratedTestStyles,
+ data: migratedTestTable,
+ replaceVariables,
+ showHeader: true,
+ width: 500,
+ height: 300,
+ });
+ });
diff --git a/packages/grafana-ui/src/components/Table/Table.test.ts b/packages/grafana-ui/src/components/Table/Table.test.ts
index 0e08473f149..93cf53b2adb 100644
--- a/packages/grafana-ui/src/components/Table/Table.test.ts
+++ b/packages/grafana-ui/src/components/Table/Table.test.ts
@@ -1,9 +1,11 @@
import _ from 'lodash';
import { getColorDefinitionByName } from '@grafana/ui';
-import { ScopedVars, TableData } from '@grafana/ui/src/types';
+import { ScopedVars } from '@grafana/ui/src/types';
import { getTheme } from '../../themes';
-import Table, { ColumnStyle } from './Table';
+import Table from './Table';
+
+import { migratedTestTable, migratedTestStyles } from './examples';
// TODO: this is commented out with *x* describe!
// Essentially all the elements need to replace the with
@@ -11,161 +13,6 @@ xdescribe('when rendering table', () => {
const SemiDarkOrange = getColorDefinitionByName('semi-dark-orange');
describe('given 13 columns', () => {
- const table = {
- type: 'table',
- columns: [
- { text: 'Time' },
- { text: 'Value' },
- { text: 'Colored' },
- { text: 'Undefined' },
- { text: 'String' },
- { text: 'United', unit: 'bps' },
- { text: 'Sanitized' },
- { text: 'Link' },
- { text: 'Array' },
- { text: 'Mapping' },
- { text: 'RangeMapping' },
- { text: 'MappingColored' },
- { text: 'RangeMappingColored' },
- ],
- rows: [[1388556366666, 1230, 40, undefined, '', '', 'my.host.com', 'host1', ['value1', 'value2'], 1, 2, 1, 2]],
- } as TableData;
-
- const styles: ColumnStyle[] = [
- {
- pattern: 'Time',
- type: 'date',
- alias: 'Timestamp',
- },
- {
- pattern: '/(Val)ue/',
- type: 'number',
- unit: 'ms',
- decimals: 3,
- alias: '$1',
- },
- {
- pattern: 'Colored',
- type: 'number',
- unit: 'none',
- decimals: 1,
- colorMode: 'value',
- thresholds: [50, 80],
- colors: ['#00ff00', SemiDarkOrange.name, 'rgb(1,0,0)'],
- },
- {
- pattern: 'String',
- type: 'string',
- },
- {
- pattern: 'String',
- type: 'string',
- },
- {
- pattern: 'United',
- type: 'number',
- unit: 'ms',
- decimals: 2,
- },
- {
- pattern: 'Sanitized',
- type: 'string',
- sanitize: true,
- },
- {
- pattern: 'Link',
- type: 'string',
- link: true,
- linkUrl: '/dashboard?param=$__cell¶m_1=$__cell_1¶m_2=$__cell_2',
- linkTooltip: '$__cell $__cell_1 $__cell_6',
- linkTargetBlank: true,
- },
- {
- pattern: 'Array',
- type: 'number',
- unit: 'ms',
- decimals: 3,
- },
- {
- pattern: 'Mapping',
- type: 'string',
- mappingType: 1,
- valueMaps: [
- {
- value: '1',
- text: 'on',
- },
- {
- value: '0',
- text: 'off',
- },
- {
- value: 'HELLO WORLD',
- text: 'HELLO GRAFANA',
- },
- {
- value: 'value1, value2',
- text: 'value3, value4',
- },
- ],
- },
- {
- pattern: 'RangeMapping',
- type: 'string',
- mappingType: 2,
- rangeMaps: [
- {
- from: '1',
- to: '3',
- text: 'on',
- },
- {
- from: '3',
- to: '6',
- text: 'off',
- },
- ],
- },
- {
- pattern: 'MappingColored',
- type: 'string',
- mappingType: 1,
- valueMaps: [
- {
- value: '1',
- text: 'on',
- },
- {
- value: '0',
- text: 'off',
- },
- ],
- colorMode: 'value',
- thresholds: [1, 2],
- colors: ['#00ff00', SemiDarkOrange.name, 'rgb(1,0,0)'],
- },
- {
- pattern: 'RangeMappingColored',
- type: 'string',
- mappingType: 2,
- rangeMaps: [
- {
- from: '1',
- to: '3',
- text: 'on',
- },
- {
- from: '3',
- to: '6',
- text: 'off',
- },
- ],
- colorMode: 'value',
- thresholds: [2, 5],
- colors: ['#00ff00', SemiDarkOrange.name, 'rgb(1,0,0)'],
- },
- ];
-
// const sanitize = value => {
// return 'sanitized';
// };
@@ -179,9 +26,11 @@ xdescribe('when rendering table', () => {
}
return value;
};
+
+ const table = migratedTestTable;
const renderer = new Table({
- styles,
- data: table,
+ styles: migratedTestStyles,
+ data: migratedTestTable,
replaceVariables,
showHeader: true,
width: 100,
diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx
index 63ff8e55a6a..f208b7651e8 100644
--- a/packages/grafana-ui/src/components/Table/Table.tsx
+++ b/packages/grafana-ui/src/components/Table/Table.tsx
@@ -450,6 +450,7 @@ export class Table extends Component {
if (!data) {
return NO Data ;
}
+
return (
|