use field formattor to format list options (#16804) (#16896)

This commit is contained in:
Nathan Reese 2018-02-23 14:24:47 -07:00 committed by GitHub
parent 7eb2bfc2ba
commit 76722b0b8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -26,6 +26,15 @@ export class Control {
throw new Error('fetch method not defined, subclass are required to implement');
}
format(value) {
const field = this.filterManager.getField();
if (field) {
return field.format.convert(value);
}
return value;
}
/**
*
* @param ancestors {array of Controls}

View file

@ -14,6 +14,10 @@ export class FilterManager {
return this.indexPattern;
}
getField() {
return this.indexPattern.fields.byName[this.fieldName];
}
createFilter() {
throw new Error('Must implement createFilter.');
}

View file

@ -78,7 +78,7 @@ class ListControl extends Control {
const resp = await searchSource.fetch();
const selectOptions = _.get(resp, 'aggregations.termsAgg.buckets', []).map((bucket) => {
return { label: bucket.key.toString(), value: bucket.key.toString() };
return { label: this.format(bucket.key), value: bucket.key.toString() };
}).sort((a, b) => {
return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
});