The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/packages/grafana-ui/src/components/Table/Table.story.tsx

82 lines
2.7 KiB

// import React from 'react';
7 years ago
import { storiesOf } from '@storybook/react';
import { Table } from './Table';
import { getTheme } from '../../themes';
7 years ago
import { migratedTestTable, migratedTestStyles, simpleTable } from './examples';
import { ScopedVars, TableData, GrafanaThemeType } from '../../types/index';
import { withFullSizeStory } from '../../utils/storybook/withFullSizeStory';
import { number, boolean } from '@storybook/addon-knobs';
7 years ago
const replaceVariables = (value: string, scopedVars?: ScopedVars) => {
if (scopedVars) {
// For testing variables replacement in link
for (const key in scopedVars) {
const val = scopedVars[key];
value = value.replace('$' + key, val.value);
}
}
7 years ago
return value;
};
export function makeDummyTable(columnCount: number, rowCount: number): TableData {
const A = 'A'.charCodeAt(0);
return {
columns: Array.from(new Array(columnCount), (x, i) => {
return {
text: String.fromCharCode(A + i),
};
}),
rows: Array.from(new Array(rowCount), (x, rowId) => {
const suffix = (rowId + 1).toString();
return Array.from(new Array(columnCount), (x, colId) => String.fromCharCode(A + colId) + suffix);
}),
type: 'table',
columnMap: {},
};
}
storiesOf('Alpha/Table', module)
7 years ago
.add('basic', () => {
const showHeader = boolean('Show Header', true);
const fixedRowCount = number('Fixed Rows', 1, { min: 0, max: 50, step: 1, range: false });
const fixedColumnCount = number('Fixed Columns', 1, { min: 0, max: 50, step: 1, range: false });
return withFullSizeStory(Table, {
7 years ago
styles: [],
data: simpleTable,
replaceVariables,
fixedRowCount,
fixedColumnCount,
showHeader,
theme: getTheme(GrafanaThemeType.Light),
7 years ago
});
})
.add('variable size', () => {
const columnCount = number('Column Count', 20, { min: 2, max: 50, step: 1, range: false });
const rowCount = number('Row Count', 20, { min: 0, max: 100, step: 1, range: false });
const showHeader = boolean('Show Header', true);
const fixedRowCount = number('Fixed Rows', 1, { min: 0, max: 50, step: 1, range: false });
const fixedColumnCount = number('Fixed Columns', 1, { min: 0, max: 50, step: 1, range: false });
return withFullSizeStory(Table, {
styles: [],
data: makeDummyTable(columnCount, rowCount),
7 years ago
replaceVariables,
fixedRowCount,
fixedColumnCount,
showHeader,
theme: getTheme(GrafanaThemeType.Light),
});
})
.add('Old tests configuration', () => {
return withFullSizeStory(Table, {
styles: migratedTestStyles,
data: migratedTestTable,
replaceVariables,
showHeader: true,
theme: getTheme(GrafanaThemeType.Light),
7 years ago
});
});