Commit 61609780 by Daniel Lee

singlestat: with table data, support string values

If the selected table column is string then show that in the singlestat
parent a49ef90a
......@@ -174,10 +174,16 @@ class SingleStatCtrl extends MetricsPanelCtrl {
const datapoint = tableData[0][0];
data.value = datapoint[this.panel.tableColumn];
var decimalInfo = this.getDecimalsForValue(data.value);
var formatFunc = kbn.valueFormats[this.panel.format];
data.valueFormatted = formatFunc(datapoint[this.panel.tableColumn], decimalInfo.decimals, decimalInfo.scaledDecimals);
data.valueRounded = kbn.roundValue(data.value, this.panel.decimals || 0);
if (_.isString(data.value)) {
data.valueFormatted = _.escape(data.value);
data.value = 0;
data.valueRounded = 0;
} else {
const decimalInfo = this.getDecimalsForValue(data.value);
const formatFunc = kbn.valueFormats[this.panel.format];
data.valueFormatted = formatFunc(datapoint[this.panel.tableColumn], decimalInfo.decimals, decimalInfo.scaledDecimals);
data.valueRounded = kbn.roundValue(data.value, this.panel.decimals || 0);
}
this.setValueMapping(data);
}
......
......@@ -242,6 +242,18 @@ describe('SingleStatCtrl', function() {
expect(ctx.data.valueFormatted).to.be('NOT OK');
});
});
singleStatScenario('When value is string', function(ctx) {
ctx.setup(function() {
ctx.data = tableData;
ctx.data[0].rows[0] = [1492759673649,'ignore1', 65, 'ignore2'];
ctx.ctrl.panel.tableColumn = 'test1';
});
it('Should replace value with text NOT OK', function() {
expect(ctx.data.valueFormatted).to.be('ignore1');
});
});
});
});
......
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