Skip to content

Index pattern field editor - Load and save fields#89390

Merged
sebelga merged 74 commits intoelastic:feature/index-pattern-field-editorfrom
mattkime:ipfe-load-and-save-index-pattern
Feb 9, 2021
Merged

Index pattern field editor - Load and save fields#89390
sebelga merged 74 commits intoelastic:feature/index-pattern-field-editorfrom
mattkime:ipfe-load-and-save-index-pattern

Conversation

@mattkime
Copy link
Copy Markdown
Contributor

@mattkime mattkime commented Jan 27, 2021

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.

Screen Shot 2021-02-02 at 11 45 12 PM

emit('hello world') is always a good painless script to start with.

To Do

  • Save index pattern when flyout is closed.
  • Update field list when flyout is closed.
  • Define type for index pattern field editor object. Should just contain the editable values of a field.
  • Extract field editor values from index pattern field.
  • Retrieve field editor values from field editor and apply to index pattern field.
  • Field formatter options should change based on field type.
  • Require painless script for runtime fields

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@mattkime mattkime changed the title partial progress, saving index pattern, loading field Index pattern field editor - Load and save fields Jan 27, 2021
@mattkime mattkime added the WIP Work in progress label Jan 27, 2021
mattkime and others added 25 commits January 27, 2021 07:11
…ic/kibana into ipfe-load-and-save-index-pattern
…itor' into index-pattern-field-editor/editor
…ic/kibana into ipfe-load-and-save-index-pattern
…ic/kibana into ipfe-load-and-save-index-pattern
Copy link
Copy Markdown
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

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

Screenshot 2021-02-05 at 12 32 36

  • 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:

Screenshot 2021-02-05 at 12 34 48

I saved the field, went to Discover. The new format did not get applied

Screenshot 2021-02-05 at 12 34 22

It might be good to look into those.

Copy link
Copy Markdown
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

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.

Screenshot 2021-02-08 at 12 26 36

Screenshot 2021-02-08 at 12 26 46

Screenshot 2021-02-08 at 12 27 01

[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

Screenshot 2021-02-08 at 12 28 02

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

Choose a reason for hiding this comment

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

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 doesnt 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}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

@mattkime mattkime Feb 8, 2021

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Here too we have the "Learn about script syntax." in index template. I think it sounds less like an order ("Learn script syntax!" 😊 )

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"about" is ok

'indexPatternFieldEditor.editor.form.validations.nameIsRequiredErrorMessage',
{
defaultMessage: 'Give a name to the field.',
defaultMessage: 'A name is required.',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If this change is to align with consistency in other areas of Kibana, then I'm 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++

<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 doesnt 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}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
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}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@gchaps gchaps Feb 8, 2021

Choose a reason for hiding this comment

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

++ 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.

@sebelga sebelga self-requested a review February 8, 2021 18:41
Copy link
Copy Markdown
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

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! 👍

@cjcenizal
Copy link
Copy Markdown
Contributor

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.

.filter((fld) => fld.isMapped)
.map((fld) => ({
name: fld.name,
type: fld.esTypes![0]!,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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.

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
indexPatternFieldEditor 19.3KB 21.0KB +1.8KB
indexPatternManagement 564.1KB 565.4KB +1.4KB
total +3.1KB

Page load bundle

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

id before after diff
data 798.0KB 798.6KB +586.0B
esUiShared 217.0KB 217.1KB +75.0B
indexPatternFieldEditor 78.4KB 82.9KB +4.5KB
total +5.2KB

History

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

@sebelga
Copy link
Copy Markdown
Contributor

sebelga commented Feb 9, 2021

Great point @cjcenizal. Those seem like good candidates for functional tests. 👍

@sebelga sebelga merged commit bb04664 into elastic:feature/index-pattern-field-editor Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants