[Vis Editor] Fix undefined error in Field control (#37179) (#37314)

* Add default value for labels in sortByLabel function

* TS: make label optional
This commit is contained in:
Maryia Lapata 2019-05-29 12:55:38 +03:00 committed by GitHub
parent 3de093d1b6
commit 3f27ffb869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,7 @@ import { AggType } from 'ui/agg_types';
// https://github.com/babel/babel/issues/7641
//
export type ComboBoxGroupedOption = EuiComboBoxOptionProps & {
label: string;
label?: string;
value?: AggType;
options?: ComboBoxGroupedOption[];
};
@ -37,7 +37,7 @@ export type ComboBoxGroupedOption = EuiComboBoxOptionProps & {
* @param groupBy A field name which aggregations is grouped by.
* @param labelName A name of a property which value will be displayed.
*
* @returns An array of grouped and sorted alphabetically `aggs` that are compatible with EuiComboBox options. If `aggs` is not an array, the function returns an ampry array.
* @returns An array of grouped and sorted alphabetically `aggs` that are compatible with EuiComboBox options. If `aggs` is not an array, the function returns an empty array.
*/
function groupAggregationsBy(
aggs: AggType[],
@ -80,7 +80,7 @@ function groupAggregationsBy(
}
function sortByLabel(a: ComboBoxGroupedOption, b: ComboBoxGroupedOption) {
return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
return (a.label || '').toLowerCase().localeCompare((b.label || '').toLowerCase());
}
export { groupAggregationsBy };