Skip to content

Commit 911e68e

Browse files
Daniilkibanamachine
andauthored
[Data Table] Remove extra column in split mode (#83193) (#83807)
* Fix extra column in split table * Update table exports Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent a2c3b7e commit 911e68e

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

src/plugins/vis_type_table/public/legacy/agg_table/agg_table.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@ export function KbnAggTable(config, RecursionHelper) {
5858
};
5959

6060
self.toCsv = function (formatted) {
61-
const rows = formatted ? $scope.rows : $scope.table.rows;
62-
const columns = formatted ? [...$scope.formattedColumns] : [...$scope.table.columns];
63-
64-
if ($scope.splitRow && formatted) {
65-
columns.unshift($scope.splitRow);
66-
}
61+
const rows = $scope.rows;
62+
const columns = $scope.formattedColumns;
6763

6864
const nonAlphaNumRE = /[^a-zA-Z0-9]/;
6965
const allDoubleQuoteRE = /"/g;
@@ -77,7 +73,7 @@ export function KbnAggTable(config, RecursionHelper) {
7773
return val;
7874
}
7975

80-
let csvRows = [];
76+
const csvRows = [];
8177
for (const row of rows) {
8278
const rowArray = [];
8379
for (const col of columns) {
@@ -86,15 +82,11 @@ export function KbnAggTable(config, RecursionHelper) {
8682
formatted && col.formatter ? escape(col.formatter.convert(value)) : escape(value);
8783
rowArray.push(formattedValue);
8884
}
89-
csvRows = [...csvRows, rowArray];
85+
csvRows.push(rowArray);
9086
}
9187

9288
// add the columns to the rows
93-
csvRows.unshift(
94-
columns.map(function (col) {
95-
return escape(formatted ? col.title : col.name);
96-
})
97-
);
89+
csvRows.unshift(columns.map(({ title }) => escape(title)));
9890

9991
return csvRows
10092
.map(function (row) {
@@ -112,7 +104,6 @@ export function KbnAggTable(config, RecursionHelper) {
112104
if (!table) {
113105
$scope.rows = null;
114106
$scope.formattedColumns = null;
115-
$scope.splitRow = null;
116107
return;
117108
}
118109

@@ -122,19 +113,12 @@ export function KbnAggTable(config, RecursionHelper) {
122113

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

125-
const { buckets, metrics, splitColumn, splitRow } = $scope.dimensions;
116+
const { buckets, metrics } = $scope.dimensions;
126117

127118
$scope.formattedColumns = table.columns
128119
.map(function (col, i) {
129120
const isBucket = buckets.find((bucket) => bucket.accessor === i);
130-
const isSplitColumn = splitColumn
131-
? splitColumn.find((splitColumn) => splitColumn.accessor === i)
132-
: undefined;
133-
const isSplitRow = splitRow
134-
? splitRow.find((splitRow) => splitRow.accessor === i)
135-
: undefined;
136-
const dimension =
137-
isBucket || isSplitColumn || metrics.find((metric) => metric.accessor === i);
121+
const dimension = isBucket || metrics.find((metric) => metric.accessor === i);
138122

139123
const formatter = dimension
140124
? getFormatService().deserialize(dimension.format)
@@ -147,10 +131,6 @@ export function KbnAggTable(config, RecursionHelper) {
147131
filterable: !!isBucket,
148132
};
149133

150-
if (isSplitRow) {
151-
$scope.splitRow = formattedColumn;
152-
}
153-
154134
if (!dimension) return;
155135

156136
const last = i === table.columns.length - 1;

src/plugins/vis_type_table/public/legacy/agg_table/agg_table.test.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,12 @@ describe('Table Vis - AggTable Directive', function () {
262262

263263
const $tableScope = $el.isolateScope();
264264
const aggTable = $tableScope.aggTable;
265-
$tableScope.table = {
266-
columns: [
267-
{ id: 'a', name: 'one' },
268-
{ id: 'b', name: 'two' },
269-
{ id: 'c', name: 'with double-quotes(")' },
270-
],
271-
rows: [{ a: 1, b: 2, c: '"foobar"' }],
272-
};
265+
$tableScope.rows = [{ a: 1, b: 2, c: '"foobar"' }];
266+
$tableScope.formattedColumns = [
267+
{ id: 'a', title: 'one' },
268+
{ id: 'b', title: 'two' },
269+
{ id: 'c', title: 'with double-quotes(")' },
270+
];
273271

274272
expect(aggTable.toCsv()).toBe(
275273
'one,two,"with double-quotes("")"' + '\r\n' + '1,2,"""foobar"""' + '\r\n'
@@ -455,14 +453,12 @@ describe('Table Vis - AggTable Directive', function () {
455453
const aggTable = $tableScope.aggTable;
456454

457455
const saveAs = sinon.stub(aggTable, '_saveAs');
458-
$tableScope.table = {
459-
columns: [
460-
{ id: 'a', name: 'one' },
461-
{ id: 'b', name: 'two' },
462-
{ id: 'c', name: 'with double-quotes(")' },
463-
],
464-
rows: [{ a: 1, b: 2, c: '"foobar"' }],
465-
};
456+
$tableScope.rows = [{ a: 1, b: 2, c: '"foobar"' }];
457+
$tableScope.formattedColumns = [
458+
{ id: 'a', title: 'one' },
459+
{ id: 'b', title: 'two' },
460+
{ id: 'c', title: 'with double-quotes(")' },
461+
];
466462

467463
aggTable.csv.filename = 'somefilename.csv';
468464
aggTable.exportAsCsv();

0 commit comments

Comments
 (0)