[input controls] safely handle case where control index pattern no longer exists (#18931)
* handle case where control index pattern no longer exists * fix errors when vis is edited with missing index pattern
This commit is contained in:
parent
acc3af0c59
commit
41fff1feec
|
@ -48,7 +48,13 @@ export class FieldSelect extends Component {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPattern = await this.props.getIndexPattern(indexPatternId);
|
let indexPattern;
|
||||||
|
try {
|
||||||
|
indexPattern = await this.props.getIndexPattern(indexPatternId);
|
||||||
|
} catch (err) {
|
||||||
|
// index pattern no longer exists
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._hasUnmounted) {
|
if (this._hasUnmounted) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -46,13 +46,15 @@ export class IndexPatternSelect extends Component {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPattern = await this.props.getIndexPattern(indexPatternId);
|
let indexPattern;
|
||||||
|
try {
|
||||||
if (!this._isMounted) {
|
indexPattern = await this.props.getIndexPattern(indexPatternId);
|
||||||
|
} catch (err) {
|
||||||
|
// index pattern no longer exists
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indexPattern) {
|
if (!this._isMounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,13 @@ ListControl.propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
selectedOptions: PropTypes.arrayOf(comboBoxOptionShape).isRequired,
|
selectedOptions: PropTypes.arrayOf(comboBoxOptionShape).isRequired,
|
||||||
options: PropTypes.arrayOf(comboBoxOptionShape).isRequired,
|
options: PropTypes.arrayOf(comboBoxOptionShape),
|
||||||
disableMsg: PropTypes.string,
|
disableMsg: PropTypes.string,
|
||||||
multiselect: PropTypes.bool.isRequired,
|
multiselect: PropTypes.bool.isRequired,
|
||||||
controlIndex: PropTypes.number.isRequired,
|
controlIndex: PropTypes.number.isRequired,
|
||||||
stageFilter: PropTypes.func.isRequired
|
stageFilter: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ListControl.defaultProps = {
|
||||||
|
options: [],
|
||||||
|
};
|
||||||
|
|
|
@ -6,9 +6,14 @@ which doesn't exist on any documents in the "${indexPatternName}" index pattern.
|
||||||
Choose a different field or index documents that contain values for this field.`;
|
Choose a different field or index documents that contain values for this field.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function noIndexPatternMsg(indexPatternId) {
|
||||||
|
return `Could not locate index-pattern id: ${indexPatternId}.`;
|
||||||
|
}
|
||||||
|
|
||||||
export class Control {
|
export class Control {
|
||||||
constructor(controlParams, filterManager, kbnApi, useTimeFilter) {
|
constructor(controlParams, filterManager, kbnApi, useTimeFilter) {
|
||||||
this.id = controlParams.id;
|
this.id = controlParams.id;
|
||||||
|
this.controlParams = controlParams;
|
||||||
this.options = controlParams.options;
|
this.options = controlParams.options;
|
||||||
this.type = controlParams.type;
|
this.type = controlParams.type;
|
||||||
this.label = controlParams.label ? controlParams.label : controlParams.fieldName;
|
this.label = controlParams.label ? controlParams.label : controlParams.fieldName;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import {
|
import {
|
||||||
Control,
|
Control,
|
||||||
noValuesDisableMsg
|
noValuesDisableMsg,
|
||||||
|
noIndexPatternMsg,
|
||||||
} from './control';
|
} from './control';
|
||||||
import { PhraseFilterManager } from './filter_manager/phrase_filter_manager';
|
import { PhraseFilterManager } from './filter_manager/phrase_filter_manager';
|
||||||
import { createSearchSource } from './create_search_source';
|
import { createSearchSource } from './create_search_source';
|
||||||
|
@ -35,6 +36,12 @@ const termsAgg = (field, size, direction) => {
|
||||||
class ListControl extends Control {
|
class ListControl extends Control {
|
||||||
|
|
||||||
async fetch() {
|
async fetch() {
|
||||||
|
const indexPattern = this.filterManager.getIndexPattern();
|
||||||
|
if (!indexPattern) {
|
||||||
|
this.disable(noIndexPatternMsg(this.controlParams.indexPattern));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let ancestorFilters;
|
let ancestorFilters;
|
||||||
if (this.hasAncestors()) {
|
if (this.hasAncestors()) {
|
||||||
if (this.hasUnsetAncestor()) {
|
if (this.hasUnsetAncestor()) {
|
||||||
|
@ -52,7 +59,6 @@ class ListControl extends Control {
|
||||||
ancestorFilters = this.getAncestorFilters();
|
ancestorFilters = this.getAncestorFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPattern = this.filterManager.getIndexPattern();
|
|
||||||
const fieldName = this.filterManager.fieldName;
|
const fieldName = this.filterManager.fieldName;
|
||||||
const initialSearchSourceState = {
|
const initialSearchSourceState = {
|
||||||
timeout: '1s',
|
timeout: '1s',
|
||||||
|
@ -89,7 +95,12 @@ class ListControl extends Control {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listControlFactory(controlParams, kbnApi, useTimeFilter) {
|
export async function listControlFactory(controlParams, kbnApi, useTimeFilter) {
|
||||||
const indexPattern = await kbnApi.indexPatterns.get(controlParams.indexPattern);
|
let indexPattern;
|
||||||
|
try {
|
||||||
|
indexPattern = await kbnApi.indexPatterns.get(controlParams.indexPattern);
|
||||||
|
} catch (err) {
|
||||||
|
// ignore not found error and return control so it can be displayed in disabled state.
|
||||||
|
}
|
||||||
|
|
||||||
return new ListControl(
|
return new ListControl(
|
||||||
controlParams,
|
controlParams,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import {
|
import {
|
||||||
Control,
|
Control,
|
||||||
noValuesDisableMsg
|
noValuesDisableMsg,
|
||||||
|
noIndexPatternMsg,
|
||||||
} from './control';
|
} from './control';
|
||||||
import { RangeFilterManager } from './filter_manager/range_filter_manager';
|
import { RangeFilterManager } from './filter_manager/range_filter_manager';
|
||||||
import { createSearchSource } from './create_search_source';
|
import { createSearchSource } from './create_search_source';
|
||||||
|
@ -30,6 +31,11 @@ class RangeControl extends Control {
|
||||||
|
|
||||||
async fetch() {
|
async fetch() {
|
||||||
const indexPattern = this.filterManager.getIndexPattern();
|
const indexPattern = this.filterManager.getIndexPattern();
|
||||||
|
if (!indexPattern) {
|
||||||
|
this.disable(noIndexPatternMsg(this.controlParams.indexPattern));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const fieldName = this.filterManager.fieldName;
|
const fieldName = this.filterManager.fieldName;
|
||||||
|
|
||||||
const aggs = minMaxAgg(indexPattern.fields.byName[fieldName]);
|
const aggs = minMaxAgg(indexPattern.fields.byName[fieldName]);
|
||||||
|
@ -60,7 +66,12 @@ class RangeControl extends Control {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function rangeControlFactory(controlParams, kbnApi, useTimeFilter) {
|
export async function rangeControlFactory(controlParams, kbnApi, useTimeFilter) {
|
||||||
const indexPattern = await kbnApi.indexPatterns.get(controlParams.indexPattern);
|
let indexPattern;
|
||||||
|
try {
|
||||||
|
indexPattern = await kbnApi.indexPatterns.get(controlParams.indexPattern);
|
||||||
|
} catch (err) {
|
||||||
|
// ignore not found error and return control so it can be displayed in disabled state.
|
||||||
|
}
|
||||||
const unsetValue = { min: 0, max: 1 };
|
const unsetValue = { min: 0, max: 1 };
|
||||||
return new RangeControl(
|
return new RangeControl(
|
||||||
controlParams,
|
controlParams,
|
||||||
|
|
Loading…
Reference in a new issue