Commit 494acddb by ryan

get field mapping to actually work

parent 1cb03670
...@@ -15,6 +15,7 @@ import { sortTableData } from '../../utils/processTimeSeries'; ...@@ -15,6 +15,7 @@ import { sortTableData } from '../../utils/processTimeSeries';
import { TableData, InterpolateFunction } from '@grafana/ui'; import { TableData, InterpolateFunction } from '@grafana/ui';
import { TableCellBuilder, ColumnStyle, getCellBuilder, TableCellBuilderOptions } from './TableCellBuilder'; import { TableCellBuilder, ColumnStyle, getCellBuilder, TableCellBuilderOptions } from './TableCellBuilder';
import { stringToJsRegex } from '../../utils/index';
interface ColumnInfo { interface ColumnInfo {
index: number; index: number;
...@@ -90,6 +91,8 @@ export class Table extends Component<Props, State> { ...@@ -90,6 +91,8 @@ export class Table extends Component<Props, State> {
initColumns(props: Props): ColumnInfo[] { initColumns(props: Props): ColumnInfo[] {
const { styles, data } = props; const { styles, data } = props;
console.log('STYLES', styles);
return data.columns.map((col, index) => { return data.columns.map((col, index) => {
let title = col.text; let title = col.text;
let style: ColumnStyle | null = null; // ColumnStyle let style: ColumnStyle | null = null; // ColumnStyle
...@@ -97,7 +100,7 @@ export class Table extends Component<Props, State> { ...@@ -97,7 +100,7 @@ export class Table extends Component<Props, State> {
// Find the style based on the text // Find the style based on the text
for (let i = 0; i < styles.length; i++) { for (let i = 0; i < styles.length; i++) {
const s = styles[i]; const s = styles[i];
const regex = 'XXX'; //kbn.stringToJsRegex(s.pattern); const regex = stringToJsRegex(s.pattern);
if (title.match(regex)) { if (title.match(regex)) {
style = s; style = s;
if (s.alias) { if (s.alias) {
...@@ -170,14 +173,22 @@ export class Table extends Component<Props, State> { ...@@ -170,14 +173,22 @@ export class Table extends Component<Props, State> {
const { rowIndex, columnIndex, key, parent } = props; const { rowIndex, columnIndex, key, parent } = props;
const { showHeader } = this.props; const { showHeader } = this.props;
const { data } = this.state; const { data } = this.state;
const column = this.columns[columnIndex]; const column = this.columns[columnIndex];
if (!column) { if (!column) {
return <div>XXX</div>; // NOT SURE HOW/WHY THIS HAPPENS! // NOT SURE HOW/WHY THIS HAPPENS!
// Without it it will crash in storybook when you cycle up/down the # of columns
// this cell is never visible in the output?
return (
<div key={key} style={props.style}>
XXXXX
</div>
);
} }
const realRowIndex = rowIndex - (showHeader ? 1 : 0); const realRowIndex = rowIndex - (showHeader ? 1 : 0);
const isHeader = realRowIndex < 0; const isHeader = realRowIndex < 0;
const row = isHeader ? (data.columns as any[]) : data.rows[realRowIndex]; const row = isHeader ? data.columns : data.rows[realRowIndex];
const value = row[columnIndex]; const value = row[columnIndex];
const builder = isHeader ? this.headerBuilder : column.builder; const builder = isHeader ? this.headerBuilder : column.builder;
......
...@@ -41,12 +41,9 @@ export const simpleCellBuilder: TableCellBuilder = (cell: TableCellBuilderOption ...@@ -41,12 +41,9 @@ export const simpleCellBuilder: TableCellBuilder = (cell: TableCellBuilderOption
// //
// *************************************************************************** // ***************************************************************************
// APP Imports!!!
// import kbn from 'app/core/utils/kbn';
// Made to match the existing (untyped) settings in the angular table // Made to match the existing (untyped) settings in the angular table
export interface ColumnStyle { export interface ColumnStyle {
pattern?: string; pattern: string;
alias?: string; alias?: string;
colorMode?: 'cell' | 'value'; colorMode?: 'cell' | 'value';
...@@ -89,6 +86,8 @@ export function getCellBuilder(schema: Column, style: ColumnStyle | null, props: ...@@ -89,6 +86,8 @@ export function getCellBuilder(schema: Column, style: ColumnStyle | null, props:
} }
if (style.type === 'date') { if (style.type === 'date') {
console.log('MAKE DATE Column', schema, style);
return new CellBuilderWithStyle( return new CellBuilderWithStyle(
(v: any) => { (v: any) => {
if (v === undefined || v === null) { if (v === undefined || v === null) {
......
...@@ -2,4 +2,5 @@ export * from './processTimeSeries'; ...@@ -2,4 +2,5 @@ export * from './processTimeSeries';
export * from './valueFormats/valueFormats'; export * from './valueFormats/valueFormats';
export * from './colors'; export * from './colors';
export * from './namedColorsPalette'; export * from './namedColorsPalette';
export * from './stringUtils';
export { getMappedValue } from './valueMappings'; export { getMappedValue } from './valueMappings';
export function stringToJsRegex(str: string): RegExp {
if (str[0] !== '/') {
return new RegExp('^' + str + '$');
}
const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
if (!match) {
throw new Error(`'${str}' is not a valid regular expression.`);
}
return new RegExp(match[1], match[2]);
}
import _ from 'lodash'; import _ from 'lodash';
import { getValueFormat, getValueFormatterIndex, getValueFormats } from '@grafana/ui'; import { getValueFormat, getValueFormatterIndex, getValueFormats, stringToJsRegex } from '@grafana/ui';
const kbn: any = {}; const kbn: any = {};
...@@ -229,17 +229,8 @@ kbn.slugifyForUrl = str => { ...@@ -229,17 +229,8 @@ kbn.slugifyForUrl = str => {
}; };
kbn.stringToJsRegex = str => { kbn.stringToJsRegex = str => {
if (str[0] !== '/') { console.warn('Use grafana/ui stringToJsRegex');
return new RegExp('^' + str + '$'); return stringToJsRegex(str);
}
const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
if (!match) {
throw new Error(`'${str}' is not a valid regular expression.`);
}
return new RegExp(match[1], match[2]);
}; };
kbn.toFixed = (value, decimals) => { kbn.toFixed = (value, decimals) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment