Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL field formatter (vis_type_table fix) #53573

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface Column {
title: string;
formatter?: {
convert?: (val: string) => string;
[key: string]: any;
};
sortable?: boolean;
}
Expand Down Expand Up @@ -94,15 +95,19 @@ describe('Table Vis - Paginated table', () => {

if (isNumber(colCount)) {
times(colCount, i => {
columns.push({ id: `${i}`, title: `column${i}`, formatter: { convert: identity } });
columns.push({
id: `${i}`,
title: `column${i}`,
formatter: { convert: identity, getConverterFor: () => identity },
});
});
} else {
columns = colCount.map(
(col, i) =>
({
id: `${i}`,
title: col.title,
formatter: col.formatter || { convert: identity },
formatter: col.formatter || { convert: identity, getConverterFor: () => identity },
} as Column)
);
}
Expand Down Expand Up @@ -678,6 +683,9 @@ describe('Table Vis - Paginated table', () => {
convert: val => {
return val === 'zzz' ? '<h1>hello</h1>' : val;
},
getConverterFor: () => (val: any) => {
return val === 'zzz' ? '<h1>hello</h1>' : val;
},
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import $ from 'jquery';
import _ from 'lodash';
import tableCellFilterHtml from './table_cell_filter.html';

function getFormattedValue(formatter, value) {
const parsedUrl = {
origin: window.location.origin,
pathname: window.location.pathname,
};

return formatter.getConverterFor('html')(value, false, false, parsedUrl);
}

export function KbnRows($compile) {
return {
restrict: 'A',
Expand Down Expand Up @@ -72,7 +81,7 @@ export function KbnRows($compile) {

// An AggConfigResult can "enrich" cell contents by applying a field formatter,
// which we want to do if possible.
contents = contentsIsDefined ? column.formatter.convert(contents, 'html') : '';
contents = contentsIsDefined ? getFormattedValue(column.formatter, contents) : '';

if (_.isObject(contents)) {
if (contents.attr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getFormat: FormatFactory = mapping => {
basePath: npStart.core.http.basePath,
};
// @ts-ignore
return format.convert(val, undefined, undefined, parsedUrl);
return format.getConverterFor(type)(val, false, false, parsedUrl);
};
},
convert: (val: string, type: string) => {
Expand All @@ -163,7 +163,7 @@ export const getFormat: FormatFactory = mapping => {
basePath: npStart.core.http.basePath,
};
// @ts-ignore
return format.convert(val, type, undefined, parsedUrl);
return format.getConverterFor(type)(val, false, false, parsedUrl);
},
} as FieldFormat;
} else {
Expand Down