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 moment from 'moment';
|
||||||
import kbn from 'app/core/utils/kbn';
|
import kbn from 'app/core/utils/kbn';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export class TableRenderer {
|
export class TableRenderer {
|
||||||
formaters: any[];
|
formaters: any[];
|
||||||
colorState: any;
|
colorState: any;
|
||||||
@ -26,27 +24,21 @@ export class TableRenderer {
|
|||||||
return _.first(style.colors);
|
return _.first(style.colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultCellFormater(escapeHtml = true) {
|
defaultCellFormater(value) {
|
||||||
return function(v) {
|
if (value === null || value === void 0 || value === undefined) {
|
||||||
if (v === null || v === void 0 || v === undefined) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isArray(v)) {
|
if (_.isArray(value)) {
|
||||||
v = v.join(', ');
|
value = value.join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(v) && escapeHtml) {
|
return value;
|
||||||
v = encodeHtml(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createColumnFormater(style) {
|
createColumnFormater(style) {
|
||||||
if (!style) {
|
if (!style) {
|
||||||
return this.defaultCellFormater();
|
return this.defaultCellFormater;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.type === 'date') {
|
if (style.type === 'date') {
|
||||||
@ -69,7 +61,7 @@ export class TableRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(v)) {
|
if (_.isString(v)) {
|
||||||
return encodeHtml(v);
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.colorMode) {
|
if (style.colorMode) {
|
||||||
@ -80,11 +72,7 @@ export class TableRenderer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.type === 'string') {
|
return this.defaultCellFormater;
|
||||||
return this.defaultCellFormater(style.escapeHtml);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.defaultCellFormater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
formatColumnValue(colIndex, value) {
|
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);
|
return this.formaters[colIndex](value);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCell(columnIndex, value, addWidthHack = false) {
|
renderCell(columnIndex, value, addWidthHack = false) {
|
||||||
value = this.formatColumnValue(columnIndex, value);
|
value = this.formatColumnValue(columnIndex, value);
|
||||||
|
value = encodeHtml(value);
|
||||||
var style = '';
|
var style = '';
|
||||||
if (this.colorState.cell) {
|
if (this.colorState.cell) {
|
||||||
style = ' style="background-color:' + this.colorState.cell + ';color: white"';
|
style = ' style="background-color:' + this.colorState.cell + ';color: white"';
|
||||||
|
@ -41,12 +41,10 @@ describe('when rendering table', () => {
|
|||||||
{
|
{
|
||||||
pattern: 'String',
|
pattern: 'String',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
escapeHtml: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: 'UnescapedString',
|
pattern: 'UnescapedString',
|
||||||
type: 'string',
|
type: 'string'
|
||||||
escapeHtml: false,
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@ -98,11 +96,6 @@ describe('when rendering table', () => {
|
|||||||
expect(html).to.be('<td>&breaking <br /> the <br /> row</td>');
|
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 -', () => {
|
it('undefined value should render as -', () => {
|
||||||
var html = renderer.renderCell(3, undefined);
|
var html = renderer.renderCell(3, undefined);
|
||||||
expect(html).to.be('<td></td>');
|
expect(html).to.be('<td></td>');
|
||||||
|
Loading…
Reference in New Issue
Block a user