Skip to content

Commit abc33c3

Browse files
Input controls crashes if index pattern is not available
Closes #72664
1 parent 4db2203 commit abc33c3

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

src/plugins/input_control_vis/public/control/control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export abstract class Control<FilterManager extends BaseFilterManager> {
8383
format = (value: any) => {
8484
const indexPattern = this.filterManager.getIndexPattern();
8585
const field = this.filterManager.getField();
86-
if (field) {
86+
if (field && indexPattern) {
8787
return indexPattern.getFormatterForField(field).convert(value);
8888
}
8989

src/plugins/input_control_vis/public/control/filter_manager/filter_manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export abstract class FilterManager {
2525
constructor(
2626
public controlId: string,
2727
public fieldName: string,
28-
public indexPattern: IndexPattern,
28+
public indexPattern: IndexPattern | null,
2929
public queryFilter: QueryFilterManager
3030
) {}
3131

@@ -41,12 +41,12 @@ export abstract class FilterManager {
4141

4242
abstract getValueFromFilterBar(): any;
4343

44-
getIndexPattern(): IndexPattern {
44+
getIndexPattern(): IndexPattern | null {
4545
return this.indexPattern;
4646
}
4747

4848
getField() {
49-
return this.indexPattern.fields.getByName(this.fieldName);
49+
return this.indexPattern?.fields.getByName(this.fieldName);
5050
}
5151

5252
findFilters(): Filter[] {

src/plugins/input_control_vis/public/control/filter_manager/phrase_filter_manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ export class PhraseFilterManager extends FilterManager {
3131
constructor(
3232
controlId: string,
3333
fieldName: string,
34-
indexPattern: IndexPattern,
34+
indexPattern: IndexPattern | null,
3535
queryFilter: QueryFilterManager
3636
) {
3737
super(controlId, fieldName, indexPattern, queryFilter);
3838
}
3939

4040
createFilter(phrases: any): PhraseFilter {
41+
if (!this.indexPattern) return {} as PhraseFilter;
4142
let newFilter: PhraseFilter;
4243
const value = this.indexPattern.fields.getByName(this.fieldName);
4344

src/plugins/input_control_vis/public/control/filter_manager/range_filter_manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class RangeFilterManager extends FilterManager {
6161
* @return {object} range filter
6262
*/
6363
createFilter(value: SliderValue): RangeFilter {
64+
if (!this.indexPattern) return {} as RangeFilter;
6465
const newFilter = esFilters.buildRangeFilter(
6566
// TODO: Fix type to be required
6667
this.indexPattern.fields.getByName(this.fieldName) as IFieldType,

src/plugins/input_control_vis/public/control/list_control_factory.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,23 @@ export async function listControlFactory(
213213
deps: InputControlVisDependencies
214214
) {
215215
const [, { data: dataPluginStart }] = await deps.core.getStartServices();
216-
const indexPattern = await dataPluginStart.indexPatterns.get(controlParams.indexPattern);
216+
217+
let indexPattern;
218+
try {
219+
indexPattern = await dataPluginStart.indexPatterns.get(controlParams.indexPattern);
220+
} catch (e) {
221+
indexPattern = null;
222+
}
217223

218224
// dynamic options are only allowed on String fields but the setting defaults to true so it could
219225
// be enabled for non-string fields (since UI input is hidden for non-string fields).
220226
// If field is not string, then disable dynamic options.
221-
const field = indexPattern.fields.getAll().find(({ name }) => name === controlParams.fieldName);
227+
const field = indexPattern?.fields.getAll().find(({ name }) => name === controlParams.fieldName);
222228
if (field && field.type !== 'string') {
223229
controlParams.options.dynamicOptions = false;
224230
}
225231

226-
const listControl = new ListControl(
232+
return new ListControl(
227233
controlParams,
228234
new PhraseFilterManager(
229235
controlParams.id,
@@ -235,5 +241,4 @@ export async function listControlFactory(
235241
dataPluginStart.search.searchSource,
236242
deps
237243
);
238-
return listControl;
239244
}

src/plugins/input_control_vis/public/control/range_control_factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ export async function rangeControlFactory(
134134
deps: InputControlVisDependencies
135135
): Promise<RangeControl> {
136136
const [, { data: dataPluginStart }] = await deps.core.getStartServices();
137-
const indexPattern = await dataPluginStart.indexPatterns.get(controlParams.indexPattern);
137+
138+
let indexPattern;
139+
try {
140+
indexPattern = await dataPluginStart.indexPatterns.get(controlParams.indexPattern);
141+
} catch (e) {
142+
indexPattern = null;
143+
}
138144

139145
return new RangeControl(
140146
controlParams,

0 commit comments

Comments
 (0)