mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Data Table] Remove extra column in split mode (#83193)
* Fix extra column in split table * Update table exports Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
5d05eeaab9
commit
b263145ba2
2 changed files with 19 additions and 43 deletions
|
@ -58,12 +58,8 @@ export function KbnAggTable(config, RecursionHelper) {
|
|||
};
|
||||
|
||||
self.toCsv = function (formatted) {
|
||||
const rows = formatted ? $scope.rows : $scope.table.rows;
|
||||
const columns = formatted ? [...$scope.formattedColumns] : [...$scope.table.columns];
|
||||
|
||||
if ($scope.splitRow && formatted) {
|
||||
columns.unshift($scope.splitRow);
|
||||
}
|
||||
const rows = $scope.rows;
|
||||
const columns = $scope.formattedColumns;
|
||||
|
||||
const nonAlphaNumRE = /[^a-zA-Z0-9]/;
|
||||
const allDoubleQuoteRE = /"/g;
|
||||
|
@ -77,7 +73,7 @@ export function KbnAggTable(config, RecursionHelper) {
|
|||
return val;
|
||||
}
|
||||
|
||||
let csvRows = [];
|
||||
const csvRows = [];
|
||||
for (const row of rows) {
|
||||
const rowArray = [];
|
||||
for (const col of columns) {
|
||||
|
@ -86,15 +82,11 @@ export function KbnAggTable(config, RecursionHelper) {
|
|||
formatted && col.formatter ? escape(col.formatter.convert(value)) : escape(value);
|
||||
rowArray.push(formattedValue);
|
||||
}
|
||||
csvRows = [...csvRows, rowArray];
|
||||
csvRows.push(rowArray);
|
||||
}
|
||||
|
||||
// add the columns to the rows
|
||||
csvRows.unshift(
|
||||
columns.map(function (col) {
|
||||
return escape(formatted ? col.title : col.name);
|
||||
})
|
||||
);
|
||||
csvRows.unshift(columns.map(({ title }) => escape(title)));
|
||||
|
||||
return csvRows
|
||||
.map(function (row) {
|
||||
|
@ -112,7 +104,6 @@ export function KbnAggTable(config, RecursionHelper) {
|
|||
if (!table) {
|
||||
$scope.rows = null;
|
||||
$scope.formattedColumns = null;
|
||||
$scope.splitRow = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -122,19 +113,12 @@ export function KbnAggTable(config, RecursionHelper) {
|
|||
|
||||
if (typeof $scope.dimensions === 'undefined') return;
|
||||
|
||||
const { buckets, metrics, splitColumn, splitRow } = $scope.dimensions;
|
||||
const { buckets, metrics } = $scope.dimensions;
|
||||
|
||||
$scope.formattedColumns = table.columns
|
||||
.map(function (col, i) {
|
||||
const isBucket = buckets.find((bucket) => bucket.accessor === i);
|
||||
const isSplitColumn = splitColumn
|
||||
? splitColumn.find((splitColumn) => splitColumn.accessor === i)
|
||||
: undefined;
|
||||
const isSplitRow = splitRow
|
||||
? splitRow.find((splitRow) => splitRow.accessor === i)
|
||||
: undefined;
|
||||
const dimension =
|
||||
isBucket || isSplitColumn || metrics.find((metric) => metric.accessor === i);
|
||||
const dimension = isBucket || metrics.find((metric) => metric.accessor === i);
|
||||
|
||||
const formatter = dimension
|
||||
? getFormatService().deserialize(dimension.format)
|
||||
|
@ -147,10 +131,6 @@ export function KbnAggTable(config, RecursionHelper) {
|
|||
filterable: !!isBucket,
|
||||
};
|
||||
|
||||
if (isSplitRow) {
|
||||
$scope.splitRow = formattedColumn;
|
||||
}
|
||||
|
||||
if (!dimension) return;
|
||||
|
||||
const last = i === table.columns.length - 1;
|
||||
|
|
|
@ -262,14 +262,12 @@ describe('Table Vis - AggTable Directive', function () {
|
|||
|
||||
const $tableScope = $el.isolateScope();
|
||||
const aggTable = $tableScope.aggTable;
|
||||
$tableScope.table = {
|
||||
columns: [
|
||||
{ id: 'a', name: 'one' },
|
||||
{ id: 'b', name: 'two' },
|
||||
{ id: 'c', name: 'with double-quotes(")' },
|
||||
],
|
||||
rows: [{ a: 1, b: 2, c: '"foobar"' }],
|
||||
};
|
||||
$tableScope.rows = [{ a: 1, b: 2, c: '"foobar"' }];
|
||||
$tableScope.formattedColumns = [
|
||||
{ id: 'a', title: 'one' },
|
||||
{ id: 'b', title: 'two' },
|
||||
{ id: 'c', title: 'with double-quotes(")' },
|
||||
];
|
||||
|
||||
expect(aggTable.toCsv()).toBe(
|
||||
'one,two,"with double-quotes("")"' + '\r\n' + '1,2,"""foobar"""' + '\r\n'
|
||||
|
@ -455,14 +453,12 @@ describe('Table Vis - AggTable Directive', function () {
|
|||
const aggTable = $tableScope.aggTable;
|
||||
|
||||
const saveAs = sinon.stub(aggTable, '_saveAs');
|
||||
$tableScope.table = {
|
||||
columns: [
|
||||
{ id: 'a', name: 'one' },
|
||||
{ id: 'b', name: 'two' },
|
||||
{ id: 'c', name: 'with double-quotes(")' },
|
||||
],
|
||||
rows: [{ a: 1, b: 2, c: '"foobar"' }],
|
||||
};
|
||||
$tableScope.rows = [{ a: 1, b: 2, c: '"foobar"' }];
|
||||
$tableScope.formattedColumns = [
|
||||
{ id: 'a', title: 'one' },
|
||||
{ id: 'b', title: 'two' },
|
||||
{ id: 'c', title: 'with double-quotes(")' },
|
||||
];
|
||||
|
||||
aggTable.csv.filename = 'somefilename.csv';
|
||||
aggTable.exportAsCsv();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue