Skip to content

Commit

Permalink
Fix bug when spliting tables
Browse files Browse the repository at this point in the history
  • Loading branch information
dlumbrer committed Jan 14, 2019
1 parent 4d9f24d commit 4e7ac52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions public/kbn_searchtables.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function TableVisTypeProvider(Private) {
group: 'buckets',
name: 'split',
title: 'Split Table',
max: 1,
aggFilter: ['!filter']
}
])
Expand Down
52 changes: 32 additions & 20 deletions public/kbn_searchtables_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,46 @@ module.controller('KbnSearchTablesVisController', function ($timeout, $scope) {
$scope.hasSomeRows = false;
return;
}

if (!tableGroups.tables[0].rows_default) {
tableGroups.tables[0].rows_default = tableGroups.tables[0].rows;
}
//////////////////////////
if (!inputSearch) {
$scope.config.searchKeyword = inputSearch = '';
}

//Logic to search
var newrows = [];
for (var i = 0; i < tableGroups.tables[0].rows_default.length; i++) {
for (var j = 0; j < tableGroups.tables[0].rows_default[i].length; j++) {
const rowKey = tableGroups.tables[0].rows_default[i][j].key;

// Polyfill for [email protected]
// @see https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L11972
const isRowKeyNil = rowKey == null;
if (!isRowKeyNil) {
const rowKeyStr = `${rowKey}`.toLowerCase();
if (rowKeyStr.includes(inputSearch.toLowerCase())) {
newrows.push(tableGroups.tables[0].rows_default[i]);
break;
for (var k = 0; k < tableGroups.tables.length; k++) {
var newrows = [];

//IMPORTANT: This just allows one level of split table
let tableRows;
if (tableGroups.tables[k].rows) {
tableRows = tableGroups.tables[k]
} else {
tableRows = tableGroups.tables[k].tables[0]
}

//Copy property in order to dont lose the first search
if (!tableRows.rows_default) {
tableRows.rows_default = tableRows.rows;
}

for (var i = 0; i < tableRows.rows_default.length; i++) {
for (var j = 0; j < tableRows.rows_default[i].length; j++) {
const rowKey = tableRows.rows_default[i][j].key;

// Polyfill for [email protected]
// @see https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L11972
const isRowKeyNil = rowKey == null;
if (!isRowKeyNil) {
const rowKeyStr = `${rowKey}`.toLowerCase();
if (rowKeyStr.includes(inputSearch.toLowerCase())) {
newrows.push(tableRows.rows_default[i]);
break;
}
}
}
}
tableRows.rows = newrows;
}

tableGroups.tables[0].rows = newrows;
/////

hasSomeRows = tableGroups.tables.some(function haveRows(table) {
Expand All @@ -98,4 +110,4 @@ module.controller('KbnSearchTablesVisController', function ($timeout, $scope) {
$scope.$watch('config', function () {
$scope.uiState.set('vis.params.config', $scope.config);
}, true);
});
});

0 comments on commit 4e7ac52

Please sign in to comment.