-
Notifications
You must be signed in to change notification settings - Fork 8.5k
TabifyDocs: Allow Formatter Parameters #90696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,16 +337,18 @@ export class IndexPattern implements IIndexPattern { | |
| * @param field | ||
| */ | ||
| getFormatterForField( | ||
| field: IndexPatternField | IndexPatternField['spec'] | IFieldType | ||
| field: IndexPatternField | IndexPatternField['spec'] | IFieldType, | ||
| params: Record<string, any> = {} | ||
| ): FieldFormat { | ||
| const fieldFormat = this.getFormatterForFieldNoDefault(field.name); | ||
| const fieldFormat = this.getFormatterForFieldNoDefault(field.name, params); | ||
| if (fieldFormat) { | ||
| return fieldFormat; | ||
| } | ||
|
|
||
| return this.fieldFormats.getDefaultInstance( | ||
| field.type as KBN_FIELD_TYPES, | ||
| field.esTypes as ES_FIELD_TYPES[] | ||
| field.esTypes as ES_FIELD_TYPES[], | ||
| params | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -399,10 +401,14 @@ export class IndexPattern implements IIndexPattern { | |
| * Get formatter for a given field name. Return undefined if none exists | ||
| * @param field | ||
| */ | ||
| getFormatterForFieldNoDefault(fieldname: string) { | ||
| getFormatterForFieldNoDefault(fieldname: string, params: Record<string, any> = {}) { | ||
| const formatSpec = this.fieldFormatMap[fieldname]; | ||
| if (formatSpec?.id) { | ||
| return this.fieldFormats.getInstance(formatSpec.id, formatSpec.params); | ||
| const instanceParams = { | ||
| ...formatSpec.params, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): |
||
| ...params, | ||
| }; | ||
| return this.fieldFormats.getInstance(formatSpec.id, instanceParams); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,8 @@ export interface TabifyDocsOptions { | |
| export const tabifyDocs = ( | ||
| esResponse: SearchResponse<unknown>, | ||
| index?: IndexPattern, | ||
| params: TabifyDocsOptions = {} | ||
| params: TabifyDocsOptions = {}, | ||
| formatParams: Record<string, any> = {} | ||
| ): Datatable => { | ||
| const columns: DatatableColumn[] = []; | ||
|
|
||
|
|
@@ -79,7 +80,7 @@ export const tabifyDocs = ( | |
| const fieldName = field?.name || key; | ||
| 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); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| columns.push({ | ||
| id: fieldName, | ||
| name: fieldName, | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
would that solve the problems ?