Skip to content

Commit

Permalink
[Data Table] Formatting CSV properly (#54127)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Maja Grubic and elasticmachine authored Jan 10, 2020
1 parent 402322c commit e7e88d4
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export function KbnAggTable(config, RecursionHelper) {
// escape each cell in each row
const csvRows = rows.map(function(row) {
return Object.entries(row).map(([k, v]) => {
return escape(formatted ? columns.find(c => c.id === k).formatter.convert(v) : v);
const column = columns.find(c => c.id === k);
if (formatted && column) {
return escape(column.formatter.convert(v));
}
return escape(v);
});
});

Expand Down Expand Up @@ -110,12 +114,16 @@ export function KbnAggTable(config, RecursionHelper) {

if (typeof $scope.dimensions === 'undefined') return;

const { buckets, metrics } = $scope.dimensions;
const { buckets, metrics, splitColumn } = $scope.dimensions;

$scope.formattedColumns = table.columns
.map(function(col, i) {
const isBucket = buckets.find(bucket => bucket.accessor === i);
const dimension = isBucket || metrics.find(metric => metric.accessor === i);
const isSplitColumn = splitColumn
? splitColumn.find(splitColumn => splitColumn.accessor === i)
: undefined;
const dimension =
isBucket || isSplitColumn || metrics.find(metric => metric.accessor === i);

if (!dimension) return;

Expand Down

0 comments on commit e7e88d4

Please sign in to comment.