mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(table): remove option to disable html encoding
This commit is contained in:
parent
d750908e36
commit
5775c0a341
@ -4,8 +4,6 @@ import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
|
||||
|
||||
|
||||
export class TableRenderer {
|
||||
formaters: any[];
|
||||
colorState: any;
|
||||
@ -26,27 +24,21 @@ export class TableRenderer {
|
||||
return _.first(style.colors);
|
||||
}
|
||||
|
||||
defaultCellFormater(escapeHtml = true) {
|
||||
return function(v) {
|
||||
if (v === null || v === void 0 || v === undefined) {
|
||||
return '';
|
||||
}
|
||||
defaultCellFormater(value) {
|
||||
if (value === null || value === void 0 || value === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (_.isArray(v)) {
|
||||
v = v.join(', ');
|
||||
}
|
||||
if (_.isArray(value)) {
|
||||
value = value.join(', ');
|
||||
}
|
||||
|
||||
if (_.isString(v) && escapeHtml) {
|
||||
v = encodeHtml(v);
|
||||
}
|
||||
|
||||
return v;
|
||||
};
|
||||
return value;
|
||||
}
|
||||
|
||||
createColumnFormater(style) {
|
||||
if (!style) {
|
||||
return this.defaultCellFormater();
|
||||
return this.defaultCellFormater;
|
||||
}
|
||||
|
||||
if (style.type === 'date') {
|
||||
@ -69,7 +61,7 @@ export class TableRenderer {
|
||||
}
|
||||
|
||||
if (_.isString(v)) {
|
||||
return encodeHtml(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
if (style.colorMode) {
|
||||
@ -80,11 +72,7 @@ export class TableRenderer {
|
||||
};
|
||||
}
|
||||
|
||||
if (style.type === 'string') {
|
||||
return this.defaultCellFormater(style.escapeHtml);
|
||||
}
|
||||
|
||||
return this.defaultCellFormater();
|
||||
return this.defaultCellFormater;
|
||||
}
|
||||
|
||||
formatColumnValue(colIndex, value) {
|
||||
@ -102,12 +90,13 @@ export class TableRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
this.formaters[colIndex] = this.defaultCellFormater();
|
||||
this.formaters[colIndex] = this.defaultCellFormater;
|
||||
return this.formaters[colIndex](value);
|
||||
}
|
||||
|
||||
renderCell(columnIndex, value, addWidthHack = false) {
|
||||
value = this.formatColumnValue(columnIndex, value);
|
||||
value = encodeHtml(value);
|
||||
var style = '';
|
||||
if (this.colorState.cell) {
|
||||
style = ' style="background-color:' + this.colorState.cell + ';color: white"';
|
||||
|
@ -41,12 +41,10 @@ describe('when rendering table', () => {
|
||||
{
|
||||
pattern: 'String',
|
||||
type: 'string',
|
||||
escapeHtml: true,
|
||||
},
|
||||
{
|
||||
pattern: 'UnescapedString',
|
||||
type: 'string',
|
||||
escapeHtml: false,
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
};
|
||||
@ -98,11 +96,6 @@ describe('when rendering table', () => {
|
||||
expect(html).to.be('<td>&breaking <br /> the <br /> row</td>');
|
||||
});
|
||||
|
||||
it('string style with escape html false should return html', () => {
|
||||
var html = renderer.renderCell(5, "&breaking <br /> the <br /> row");
|
||||
expect(html).to.be('<td>&breaking <br /> the <br /> row</td>');
|
||||
});
|
||||
|
||||
it('undefined value should render as -', () => {
|
||||
var html = renderer.renderCell(3, undefined);
|
||||
expect(html).to.be('<td></td>');
|
||||
|
Loading…
Reference in New Issue
Block a user