Skip to content

Commit

Permalink
Consider condition when the configured defaultIndex is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Oct 11, 2019
1 parent 60e3557 commit aff471d
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,21 @@ uiRoutes
* @type {State}
*/
const state = new State('_a', {});
const findIndexById = (id) => savedObjects.find(o => o.id === id);

/**
* returns the id of the default index, if none is configured
* the value of the first available indexpattern/saved object is used
*/
const getDefaultIndexId = () => {
if(config.get('defaultIndex')) {
return config.get('defaultIndex');
const defaultIndex = config.get('defaultIndex');
if(defaultIndex && findIndexById(defaultIndex)) {
return defaultIndex;
}
return !savedObjects.length ? '' : savedObjects[0].id;
};

const exists = _.findIndex(savedObjects, o => o.id === state.index) > -1;
const exists = state.index && findIndexById(state.index);
const id = exists ? state.index : getDefaultIndexId();
state.destroy();

Expand Down

0 comments on commit aff471d

Please sign in to comment.