Index pattern field editor - Load and save fields#89390
Conversation
…ic/kibana into ipfe-load-and-save-index-pattern
…itor' into index-pattern-field-editor/editor
…ave-index-pattern
…ic/kibana into ipfe-load-and-save-index-pattern
…ic/kibana into ipfe-load-and-save-index-pattern
src/plugins/index_pattern_field_editor/public/components/field_editor/field_editor.tsx
Outdated
Show resolved
Hide resolved
...ugins/index_pattern_field_editor/public/components/field_editor/form_fields/format_field.tsx
Show resolved
Hide resolved
sebelga
left a comment
There was a problem hiding this comment.
This starts to look great @mattkime ! I have added some comments in the code.
I did find a few issues:
- If I edit a field and change its name, a new field is created instead of editing the current field
- If I update the format, the new format does not get applied.
What I did is first set the format to be "To Upper case". I then saved the field and went to Discover. It worked fine. Then I went back to the field editor, changed the format to "truncate the field" as shown below:
I saved the field, went to Discover. The new format did not get applied
It might be good to look into those.
src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts
Outdated
Show resolved
Hide resolved
src/plugins/index_pattern_field_editor/public/components/field_editor_flyout_content.tsx
Show resolved
Hide resolved
...ugins/index_pattern_field_editor/public/components/field_editor_flyout_content_container.tsx
Outdated
Show resolved
Hide resolved
...ugins/index_pattern_field_editor/public/components/field_editor_flyout_content_container.tsx
Show resolved
Hide resolved
…save-index-pattern
…save-index-pattern
There was a problem hiding this comment.
Just tested locally and there are still a few things we'd need to address.
- Updating the format does not work. I changed from Uppercase to truncate. The index pattern table indicates the new format (truncate) but it does not reflect inside Discover.
[Edit]: There is a very strange behavior. I can only reproduce this issue when creating the "AA field". When I create another field with a different name, the format updates correctly. Can it be some sort of corupted saved object?
- After I delete the field, it still appears in Discover
[Edit]: It seems to be something to fix in Discover (remove the selected fields that are not part anymore of the field list) as the field is correctly removed from the list of fields. cc @elastic/kibana-app
- The format does not reset the first time I change the type. I need to change the type a second type to have the format being reset.
The state of <FormatSelectEditor /> depends on the value prop.
this.state = {
fieldTypeFormats: getFieldTypeFormatsList(
kbnType,
fieldFormats.getDefaultType(kbnType, esTypes) as FieldFormatInstanceType,
fieldFormats
),
format,
fieldFormatId: value?.id, // here
fieldFormatParams: value?.params, // here
kbnType,
};
}But I don't see in the code a static getDerivedStateFromProps that would update the state when the value prop changes. I think that might be the problem.
| indexedFieldTypeFilter={indexedFieldTypeFilter} | ||
| helpers={{ | ||
| editField: openFieldEditor, | ||
| deleteField: (fieldName) => deleteFields(fieldName), |
There was a problem hiding this comment.
nit: no need to redeclare a function. You can name it deleteField on L220 and forward it here.
| <FormattedMessage | ||
| id="indexPatternFieldEditor.editor.form.source.scriptFieldHelpText" | ||
| defaultMessage="Runtime fields without a script retrieve values from a field with the same name in {source}. If a field with the same name doesn’t exist, no values return when a search request includes the runtime field. {learnMoreLink}" | ||
| defaultMessage="Runtime fields without a script retrieve values from _source. If the field doesn't exist in _source, a search request returns no value. {learnMoreLink}" |
There was a problem hiding this comment.
This copy text was reviewed by the doc team for the editor inside index template. If we want to continue with this change we would need to change it as well in the other editor.
For now I would revert it and let them raise any concern during the copy text review.
There was a problem hiding this comment.
These are updates I got from @gchaps, I'll reach out to her.
| 'indexPatternFieldEditor.editor.form.script.learnMoreLinkText', | ||
| { | ||
| defaultMessage: 'Learn about script syntax.', | ||
| defaultMessage: 'Learn script syntax.', |
There was a problem hiding this comment.
Here too we have the "Learn about script syntax." in index template. I think it sounds less like an order ("Learn script syntax!" 😊 )
There was a problem hiding this comment.
My preference is "Learn about script syntax", but if that breaks from consistency in other areas of Kibana, I'm fine with the suggested change.
| 'indexPatternFieldEditor.editor.form.validations.nameIsRequiredErrorMessage', | ||
| { | ||
| defaultMessage: 'Give a name to the field.', | ||
| defaultMessage: 'A name is required.', |
There was a problem hiding this comment.
Here again, for consistency, we should keep the same error message. If you have a strong opinion on those changes we would need to make them in multiple places.
There was a problem hiding this comment.
If this change is to align with consistency in other areas of Kibana, then I'm 👍
| <FormattedMessage | ||
| id="indexPatternFieldEditor.editor.form.source.scriptFieldHelpText" | ||
| defaultMessage="Runtime fields without a script retrieve values from a field with the same name in {source}. If a field with the same name doesn’t exist, no values return when a search request includes the runtime field. {learnMoreLink}" | ||
| defaultMessage="Runtime fields without a script retrieve values from _source. If the field doesn't exist in _source, a search request returns no value. {learnMoreLink}" |
There was a problem hiding this comment.
| defaultMessage="Runtime fields without a script retrieve values from _source. If the field doesn't exist in _source, a search request returns no value. {learnMoreLink}" | |
| defaultMessage="Runtime fields without a script retrieve values from a field with the same name in _source. If the field doesn't exist in _source, a search request returns no value. {learnMoreLink}" |
There was a problem hiding this comment.
It's important to indicate that runtime fields without a script retrieve values from a field with the same name, and that the field resides in _source. I'm 👍 to the change for the second sentence and included it in the suggested change.
There was a problem hiding this comment.
++ to what Adam said. We should also change the text above the Define script box as well:
Set a value for the field instead of retrieving it from the field with the same name in _source.
...plugins/index_pattern_management/public/components/edit_index_pattern/edit_index_pattern.tsx
Outdated
Show resolved
Hide resolved
sebelga
left a comment
There was a problem hiding this comment.
As we discussed over Zoom, happy to merge this PR after adding the fix to not reset the format field on mount
useEffect(() => {
if (isMounted.current) {
getFields().format.reset();
}
isMounted.current = true;
}, [type, getFields]);We can fix the "switch format twice" issue in a separate work.
Awesome work! 👍
|
Forgive my comment from the peanut gallery! I just want to suggest that we either add tests to cover the bugs Seb identified or create issues to track the need for these tests. They seem like core UX flows that we'll want to ensure remain intact as we continue to iterate on this feature in future releases. |
…dex_pattern/edit_index_pattern.tsx Co-authored-by: gchaps <33642766+gchaps@users.noreply.github.com>
…save-index-pattern
…e/kibana into ipfe-load-and-save-index-pattern
| .filter((fld) => fld.isMapped) | ||
| .map((fld) => ({ | ||
| name: fld.name, | ||
| type: fld.esTypes![0]!, |
There was a problem hiding this comment.
@alisonelizabeth I wanted to point this out to you. The painless autocomplete needs a single type value although index pattern fields can have more than one type. We should address how this is handled to avoid running into problems.
💚 Build SucceededMetrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
|
Great point @cjcenizal. Those seem like good candidates for functional tests. 👍 |







Summary
Allow creation and editing of runtime fields and editing of mapped fields. Also change index pattern list to work with es types instead of kibana types. This change is because runtime fields require es types. es types are a bit more informative, I have a hard time seeing how kibana types are actionable.
emit('hello world')is always a good painless script to start with.To Do
Checklist
Delete any items that are not applicable to this PR.
For maintainers