Skip to content

Commit

Permalink
Add call-out react directive and use it to surface rollup errors in t…
Browse files Browse the repository at this point in the history
…he visualization editor sidebar.
  • Loading branch information
cjcenizal committed Jul 6, 2018
1 parent 7c2e762 commit 3d979e6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/ui/public/react_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
EuiIcon,
EuiColorPicker,
EuiIconTip,
EuiCallOut,
} from '@elastic/eui';

import { uiModules } from './modules';
Expand All @@ -43,3 +44,5 @@ app.directive('icon', reactDirective => reactDirective(EuiIcon));
app.directive('colorPicker', reactDirective => reactDirective(EuiColorPicker));

app.directive('iconTip', reactDirective => reactDirective(EuiIconTip, ['content', 'type', 'position', 'title']));

app.directive('callOut', reactDirective => reactDirective(EuiCallOut, ['title', 'color', 'size', 'iconType', 'children']));
9 changes: 9 additions & 0 deletions src/ui/public/vis/editors/default/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
</div>

<nav class="navbar navbar-default subnav">
<div class="visEditorSidebarError" ng-if="sidebar.persistentError">
<call-out
color="'danger'"
iconType="'alert'"
title="sidebar.persistentError"
size="'s'"
/>
</div>

<div class="container-fluid">

<!-- tabs -->
Expand Down
19 changes: 17 additions & 2 deletions src/ui/public/vis/editors/default/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ import './vis_options';
import { uiModules } from '../../../modules';
import sidebarTemplate from './sidebar.html';

import './sidebar.less';

uiModules
.get('app/visualize')
.directive('visEditorSidebar', function () {


return {
restrict: 'E',
template: sidebarTemplate,
scope: true,
controllerAs: 'sidebar',
controller: function ($scope) {
this.persistentError = undefined;

$scope.$watch('vis.type', (visType) => {
if (visType) {
Expand All @@ -49,6 +50,20 @@ uiModules
this.section = this.section || (this.showData ? 'data' : _.get(visType, 'editorConfig.optionTabs[0].name'));
}
});

$scope.$watch('vis.requestError', (requestError) => {
if (requestError) {
const { resp: { message } } = requestError;
const isRollupError = message.includes('rollup');

if (isRollupError) {
this.persistentError = message;
return;
}
}

this.persistentError = undefined;
});
}
};
});
3 changes: 3 additions & 0 deletions src/ui/public/vis/editors/default/sidebar.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.visEditorSidebarError {
padding: 8px;
}
17 changes: 14 additions & 3 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,27 @@ uiModules
//No need to call the response handler when there have been no data nor has been there changes
//in the vis-state (response handler does not depend on uiStat
const canSkipResponseHandler = (
$scope.previousRequestHandlerResponse && $scope.previousRequestHandlerResponse === requestHandlerResponse &&
$scope.previousVisState && _.isEqual($scope.previousVisState, $scope.vis.getState())
$scope.previousRequestHandlerResponse
&& $scope.previousRequestHandlerResponse === requestHandlerResponse
&& $scope.previousVisState
&& _.isEqual($scope.previousVisState, $scope.vis.getState())
);

$scope.previousVisState = $scope.vis.getState();
$scope.previousRequestHandlerResponse = requestHandlerResponse;

$scope.$evalAsync(() => {
$scope.vis.requestError = undefined;
});

return canSkipResponseHandler ? $scope.visData : Promise.resolve(responseHandler($scope.vis, requestHandlerResponse));
}, e => {
$scope.savedObj.searchSource.cancelQueued();
$scope.vis.requestError = e;

$scope.$evalAsync(() => {
$scope.vis.requestError = e;
});

if (isTermSizeZeroError(e)) {
return toastNotifications.addDanger({
title: `Visualization '${$scope.vis.title}' has an error`,
Expand Down

0 comments on commit 3d979e6

Please sign in to comment.