TabifyDocs: Allow Formatter Parameters#90696
TabifyDocs: Allow Formatter Parameters#90696tsullivan wants to merge 4 commits intoelastic:masterfrom
Conversation
| if (!columns.find((c) => c.id === fieldName)) { | ||
| const fieldType = (field?.type as DatatableColumnType) || typeof value; | ||
| const formatter = field && index?.getFormatterForField(field); | ||
| const formatter = field && index?.getFormatterForField(field, formatParams); |
There was a problem hiding this comment.
This is needed for https://github.com/elastic/kibana/pull/88303/files#diff-a86296d9011252ff17c1007bb3de66763c43af633f7daff1207151da34838e7fR225
But I am interested to know if there is a better way to set the timezone for field formatters in my other PR.
|
Pinging @elastic/kibana-app-services (Team:AppServices) |
💚 Build SucceededMetrics [docs]Page load bundle
History
To update your PR or re-run it, just comment with: |
| if (formatSpec?.id) { | ||
| return this.fieldFormats.getInstance(formatSpec.id, formatSpec.params); | ||
| const instanceParams = { | ||
| ...formatSpec.params, |
There was a problem hiding this comment.
another possibility would be updating index pattern, so fieldFormatMap would contain 'correct' formatSpec (and of course not persisting that change):
// update the timezone for all date fields:
indexPatterns.fields.getByType('date').forEach(field => {
indexPattern.setFieldFormat(field.name, { ...indexPattern.fieldFormatMap[field.name], timezone: myTimezone });
}
const table = tabify(await searchSource.fetch());
| */ | ||
| getFormatterForField( | ||
| field: IndexPatternField | IndexPatternField['spec'] | IFieldType | ||
| field: IndexPatternField | IndexPatternField['spec'] | IFieldType, |
There was a problem hiding this comment.
I don't think we should allow overriding field format params on the index pattern level, that opens up a lot of new possibilities.
There was a problem hiding this comment.
could we investigate how to override uiSetting on the server ? if you could do something like:
uiSettings.override('timezone', myStoredTimezone);
const table = tabify(await searchSource.fetch());
would that solve the problems ?
|
Closing this because the suggested technique works: // apply timezone from the job to all date field formatters
index.fields.getByType('date').forEach(({ name }) => {
this.logger.debug(`setting timezone on ${name}`);
const format: FieldFormatConfig = {
...index.fieldFormatMap[name],
id: index.fieldFormatMap[name]?.id || 'date', // allow id: date_nanos
params: {
...index.fieldFormatMap[name]?.params,
timezone: settings.timezone,
},
};
index.setFieldFormat(name, format);
}); |
Summary
This PR allows
src/plugins/data/common/search/tabify/tabify_docsto pass given parameters for Formatters. This unblocks CSV Export from using tabify on the server-side and have the date strings formatted to the desired timezone.Checklist
Delete any items that are not applicable to this PR.
For maintainers