Skip to content

Commit

Permalink
use field formattor to format list options (elastic#16804)
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Feb 22, 2018
1 parent 719cae9 commit 2179a77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/core_plugins/input_control_vis/public/control/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand Down

0 comments on commit 2179a77

Please sign in to comment.