Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Update visible buttons on visibility change (edit mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blakko committed Mar 21, 2018
1 parent 3cbfc63 commit 0338fdd
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ function controller($scope, $rootScope, Private, kbnIndex, config, kibiState, ge


const _getButtons = function (relations, entities, compatibleSavedSearchesMap, compatibleDashboardsMap, visibility) {
console.log('visibility');
console.log(visibility);
const buttons = [];
_.each(relations, rel => {
if (rel.domain.type === 'INDEX_PATTERN') {
Expand Down Expand Up @@ -567,7 +565,13 @@ function controller($scope, $rootScope, Private, kbnIndex, config, kibiState, ge
return;
}

savedDashboards.get(currentDashboardId).then(currentDashboard => {
let getDashboard;
if (edit) {
getDashboard = Promise.resolve({ savedSearchId: 'edit' });
} else {
getDashboard = savedDashboards.get(currentDashboardId);
}
getDashboard.then(currentDashboard => {
if (!currentDashboard.savedSearchId && !$scope.vis.error) {
$scope.vis.error = 'This component only works on dashboards which have a saved search set.';
return;
Expand Down Expand Up @@ -617,9 +621,11 @@ function controller($scope, $rootScope, Private, kbnIndex, config, kibiState, ge

const sirenDashboardChangedOff = $rootScope.$on('kibi:dashboard:changed', updateButtons.bind(this, 'kibi:dashboard:changed'));
let editFilterButtonsOff;
let editIndexPatternId;
if (edit) {
editFilterButtonsOff = $rootScope.$on('siren:auto-join-params:filter:indexpattern', (event, indexPatternId) => {
updateButtons('siren:auto-join-params:filter:indexpattern', indexPatternId);
editIndexPatternId = indexPatternId;
});
}

Expand Down Expand Up @@ -670,13 +676,25 @@ function controller($scope, $rootScope, Private, kbnIndex, config, kibiState, ge
}
});

let editUpdateForVisibilityOff;
if (edit) {
editFilterButtonsOff = $scope.$watch(() => { return $scope.vis.params.visibility; }, (newVal, oldVal) => {
if (!_.isEqual(newVal, oldVal)) {
updateButtons('visibility', editIndexPatternId);
}
});
}

$scope.$on('$destroy', function () {
delayExecutionHelper.cancel();
sirenDashboardChangedOff();
removeAutorefreshHandler();
if (editFilterButtonsOff) {
editFilterButtonsOff();
}
if (editUpdateForVisibilityOff) {
editUpdateForVisibilityOff();
}
kibiMeta.flushRelationalButtonsFromQueue();
});

Expand Down

0 comments on commit 0338fdd

Please sign in to comment.