Skip to content

Commit

Permalink
Refresh known fields if kbn-vis directive detects a broken index pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Ángel committed Feb 18, 2019
1 parent 96c61b7 commit ecd7c8f
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions public/kibana-integrations/kibana-visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { getVisualizeLoader } from './loader';
import { timefilter } from 'ui/timefilter';

const app = uiModules.get('apps/webinar_app', []);

app.directive('kbnVis', function() {
let lockFields = false;
app.directive('kbnVis', function () {
return {
restrict: 'E',
scope: {
Expand All @@ -32,7 +32,8 @@ app.directive('kbnVis', function() {
loadedVisualizations,
tabVisualizations,
discoverPendingUpdates,
visHandlers
visHandlers,
genericReq
) {
let implicitFilter = '';
let rawFilters = [];
Expand Down Expand Up @@ -130,16 +131,21 @@ app.directive('kbnVis', function() {
}
} catch (error) {
if (
error &&
error.message &&
error.message.includes('not locate that index-pattern-field')
((error || {}).message || '').includes('not locate that index-pattern-field')
) {
errorHandler.handle(
`${
error.message
}, please restart Kibana and refresh this page once done`,
'Visualize'
);
if (!lockFields) {
try {
lockFields = true;
errorHandler.info('Detected an incomplete index pattern, refreshing all its known fields...');
await genericReq.request('GET', '/elastic/known-fields/all', {});
lockFields = false;
errorHandler.info('Success');
return myRender(raw);
} catch (error) {
lockFields = false;
throw error;
}
}
} else {
errorHandler.handle(error, 'Visualize');
}
Expand All @@ -161,10 +167,10 @@ app.directive('kbnVis', function() {
updateVisWatcher();
try {
visualization.destroy();
} catch (error) {} // eslint-disable-line
} catch (error) { } // eslint-disable-line
try {
visHandler.destroy();
} catch (error) {} // eslint-disable-line
} catch (error) { } // eslint-disable-line
});

const renderComplete = () => {
Expand All @@ -173,11 +179,11 @@ app.directive('kbnVis', function() {
const currentCompleted = Math.round(
(loadedVisualizations.getList().length /
tabVisualizations.getItem(tabVisualizations.getTab())) *
100
100
);
$rootScope.loadingStatus = `Rendering visualizations... ${
currentCompleted > 100 ? 100 : currentCompleted
} %`;
} %`;

if (currentCompleted >= 100) {
$rootScope.rendered = true;
Expand Down

0 comments on commit ecd7c8f

Please sign in to comment.