From 4e7ac52a573b2c4357c8058d33bcf0a118d265f5 Mon Sep 17 00:00:00 2001 From: David Moreno Date: Mon, 14 Jan 2019 16:27:00 +0100 Subject: [PATCH] Fix bug when spliting tables --- public/kbn_searchtables.js | 1 + public/kbn_searchtables_controller.js | 52 ++++++++++++++++----------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/public/kbn_searchtables.js b/public/kbn_searchtables.js index 6964f5b..aff23f9 100644 --- a/public/kbn_searchtables.js +++ b/public/kbn_searchtables.js @@ -73,6 +73,7 @@ function TableVisTypeProvider(Private) { group: 'buckets', name: 'split', title: 'Split Table', + max: 1, aggFilter: ['!filter'] } ]) diff --git a/public/kbn_searchtables_controller.js b/public/kbn_searchtables_controller.js index 239995a..d44ee3b 100644 --- a/public/kbn_searchtables_controller.js +++ b/public/kbn_searchtables_controller.js @@ -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 lodash@v4.x - // @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 lodash@v4.x + // @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) { @@ -98,4 +110,4 @@ module.controller('KbnSearchTablesVisController', function ($timeout, $scope) { $scope.$watch('config', function () { $scope.uiState.set('vis.params.config', $scope.config); }, true); -}); +}); \ No newline at end of file