Skip to content

Commit

Permalink
render-counter directive (#9206)
Browse files Browse the repository at this point in the history
* [docTable/row] delay first render until watchers initialize

* [docTable/row] emit a renderComplete event, count in table directive

* [renderCounter] unify render counting login into directive

* [docTable] remove unused var
  • Loading branch information
spalger authored Nov 23, 2016
1 parent 0e7b5c7 commit 9527a8f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
search-source="savedObj.searchSource"
show-spy-panel="chrome.getVisible()"
ui-state="uiState"
render-counter
class="panel-content">
</visualize>

<doc-table ng-switch-when="search"
<doc-table
ng-switch-when="search"
search-source="savedObj.searchSource"
sorting="panel.sort"
columns="panel.columns"
render-counter
class="panel-content"
filter="filter">
</doc-table>
Expand Down
3 changes: 2 additions & 1 deletion src/core_plugins/kibana/public/discover/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ <h2>Searching</h2>
sorting="state.sort"
columns="state.columns"
infinite-scroll="true"
filter="filterQuery">
filter="filterQuery"
render-counter>
</doc-table>

<div ng-if="rows.length == opts.sampleSize" class="discover-table-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<div class="vis-editor-canvas" ng-class="{ embedded: !chrome.getVisible() }">
<visualize
vis="vis"
render-counter
ui-state="uiState"
show-spy-panel="chrome.getVisible()"
editable-vis="editableVis"
Expand Down
31 changes: 31 additions & 0 deletions src/ui/public/directives/render_counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import uiModules from 'ui/modules';

uiModules
.get('kibana')
.directive('renderCounter', () => ({
controller($scope, $element) {
let counter = 0;

const increment = () => {
counter += 1;
$element.attr('render-counter', counter);
};

const teardown = () => {
$element.off('renderComplete', increment);
};

const setup = () => {
$element.attr('render-counter', counter);
$element.on('renderComplete', increment);
$scope.$on('$destroy', teardown);
};

this.disable = () => {
$element.attr('render-counter', 'disabled');
teardown();
};

setup();
}
}));
17 changes: 6 additions & 11 deletions src/ui/public/doc_table/components/table_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ module.directive('kbnTableRow', function ($compile) {
$el.after('<tr>');
$el.empty();

let init = function () {
createSummaryRow($scope.row, $scope.row._id);
};

// when we compile the details, we use this $scope
let $detailsScope;

Expand Down Expand Up @@ -79,11 +75,11 @@ module.directive('kbnTableRow', function ($compile) {
$compile($detailsTr)($detailsScope);
};

$scope.$watchCollection('columns', function () {
createSummaryRow($scope.row, $scope.row._id);
});

$scope.$watchMulti(['indexPattern.timeFieldName', 'row.highlight'], function () {
$scope.$watchMulti([
'indexPattern.timeFieldName',
'row.highlight',
'[]columns'
], function () {
createSummaryRow($scope.row, $scope.row._id);
});

Expand Down Expand Up @@ -144,6 +140,7 @@ module.directive('kbnTableRow', function ($compile) {

// trim off cells that were not used rest of the cells
$cells.filter(':gt(' + (newHtmls.length - 1) + ')').remove();
$el.trigger('renderComplete');
}

/**
Expand All @@ -161,8 +158,6 @@ module.directive('kbnTableRow', function ($compile) {

return text;
}

init();
}
};
});
2 changes: 1 addition & 1 deletion src/ui/public/doc_table/doc_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
<div ng-if="hits != null && !hits.length" class="table-vis-error">
<h2><i class="fa fa-meh-o"></i></h2>
<h4>No results found</h4>
</div>
</div>
13 changes: 4 additions & 9 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uiModules

return {
restrict: 'E',
require: '?renderCounter',
scope : {
showSpyPanel: '=?',
vis: '=',
Expand All @@ -34,7 +35,7 @@ uiModules
esResp: '=?',
},
template: visualizeTemplate,
link: function ($scope, $el, attr) {
link: function ($scope, $el, attr, renderCounter) {
const minVisChartHeight = 180;

if (_.isUndefined($scope.showSpyPanel)) {
Expand Down Expand Up @@ -72,14 +73,8 @@ uiModules
return legendPositionToVisContainerClassMap[$scope.vis.params.legendPosition];
};

if ($scope.vis.implementsRenderComplete()) {
$el.attr('has-render-count', 'true');
let renderCount = 0;
$el.on('renderComplete', () => {
$el.attr('render-count', ++renderCount);
});
} else {
$el.attr('has-render-count', 'false');
if (renderCounter && !$scope.vis.implementsRenderComplete()) {
renderCounter.disable();
}

$scope.spy = {};
Expand Down

0 comments on commit 9527a8f

Please sign in to comment.