Skip to content

Conversation

@tsullivan
Copy link
Member

@tsullivan tsullivan commented Feb 8, 2021

Summary

This PR allows src/plugins/data/common/search/tabify/tabify_docs to 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

@tsullivan tsullivan changed the title Tabifydocs/options to formatter TabifyDocs: Allow Formatter Parameters Feb 8, 2021
@tsullivan tsullivan added release_note:skip Skip the PR/issue when compiling release notes v7.12.0 v7.13.0 v8.0.0 zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead Team:AppServices labels Feb 8, 2021
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tsullivan tsullivan marked this pull request as ready for review February 9, 2021 05:16
@tsullivan tsullivan requested a review from a team as a code owner February 9, 2021 05:16
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 797.7KB 797.8KB +114.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

if (formatSpec?.id) {
return this.fieldFormats.getInstance(formatSpec.id, formatSpec.params);
const instanceParams = {
...formatSpec.params,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should allow overriding field format params on the index pattern level, that opens up a lot of new possibilities.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

@tsullivan
Copy link
Member Author

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);
      });

@tsullivan tsullivan closed this Feb 22, 2021
@tsullivan tsullivan deleted the tabifydocs/options-to-formatter branch February 22, 2021 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.12.0 v7.13.0 v8.0.0 zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants