Skip to content
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

[Lens] Handle missing fields gracefully #78173

Merged
merged 11 commits into from
Oct 1, 2020

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Sep 22, 2020

Fixes #73843

This PR addresses the case of fields in an index pattern disappearing or changing their properties, rendering existing visualization invalid.

It's caught in two places:

  • No datasource suggestions will get generated if there are broken references
  • Broken operations are highlighted in the UI:

Screenshot 2020-09-22 at 18 05 43

Screenshot 2020-09-22 at 18 05 48

This gives the user to recover visualizations from this pretty common type of error instead of having to recreate the complete visualization from scratch.

Testing

  • Create a mapping for an index
PUT myindex
{
  "mappings": {
    "properties": {
      "myfield": {
        "type": "keyword"
      },
      "myotherfield": {
        "type": "keyword"
      }
    }
  }
}

  • Create an indexpattern for this index
  • Create a Lens visualization based on myfield (even if there is no data)
  • Change the mapping
DELETE myindex
PUT myindex
{
  "mappings": {
    "properties": {
      "myfield": {
        "type": "text"
      },
      "myotherfield": {
        "type": "keyword"
      }
    }
  } 
}
  • Refresh the index pattern
  • Access the visualization

@flash1293 flash1293 marked this pull request as ready for review September 23, 2020 14:09
@flash1293 flash1293 requested a review from a team September 23, 2020 14:09
@flash1293 flash1293 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Sep 23, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@cchaos
Copy link
Contributor

cchaos commented Sep 24, 2020

This is a much more graceful way to handle this edge case, thank you. I have a couple suggestions for the UI implementation.

In the config panel, don't replace the name of the configuration, keep showing the original (especially if they've modified the default) and just add the alert icon with a tooltip.

Invalid

In the dimension editor, don't change the text of the selected item. Use EuiFormRow's error text to explain the problem and add isInvalid to it and the input.

Screen Shot 2020-09-24 at 11 44 10 AM

@mbondyra
Copy link
Contributor

@elasticmachine merge upstream

@mbondyra
Copy link
Contributor

mbondyra commented Sep 28, 2020

Hi @flash1293, I found two additional things that should be fixed:

  1. When you open new dimension editor (eg while having misconfigured field in x dimension and trying to add break down by), it doesn't display the dimension editor correctly, and throws an error in the console from BucketNestingEditor:
    image
    That's because used displayName comes from field of IndexPattern that's not available anymore. We could fix it by passing currentIndexPattern as a prop and with adding a check in lines 42 and 50
      fieldName:
        hasField(c) && !fieldIsInvalid(c.sourceField, c.operationType, indexPattern)
          ? fieldMap[c.sourceField].displayName
          : c.sourceField,
const fieldName =
    hasField(column) && !fieldIsInvalid(column.sourceField, column.operationType, indexPattern)
      ? fieldMap[column.sourceField].displayName
      : column.sourceField;


const { columnId, uniqueLabel } = props;
if (!selectedColumn) {
return null;
}

if (currentFieldIsInvalid) {
Copy link
Contributor

@mbondyra mbondyra Sep 28, 2020

Choose a reason for hiding this comment

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

  1. To change the styles to hover the whole element, you could add a class anchorClassName="lnsLayerPanel__anchor" to tooltip. I also adjusted the code to Caroline's suggestions about anchor, so if you could replace this if with:
 if (currentFieldIsInvalid) {
    return (
      <EuiToolTip
        content={
          <p>
            {i18n.translate('xpack.lens.configure.invalidConfigTooltip', {
              defaultMessage: 'Invalid configuration.',
            })}
            <br />
            {i18n.translate('xpack.lens.configure.invalidConfigTooltipClick', {
              defaultMessage: 'Click for more details.',
            })}
          </p>
        }
        anchorClassName="lnsLayerPanel__anchor"
      >
        <EuiLink
          color="danger"
          id={columnId}
          className="lnsLayerPanel__triggerLink"
          onClick={props.onClick}
          data-test-subj="lns-dimensionTrigger"
          aria-label={i18n.translate('xpack.lens.configure.editConfig', {
            defaultMessage: 'Edit configuration',
          })}
          title={i18n.translate('xpack.lens.configure.editConfig', {
            defaultMessage: 'Edit configuration',
          })}
        >
          <EuiFlexGroup gutterSize="s" alignItems="center" responsive={false}>
            <EuiFlexItem grow={false}>
              <EuiIcon size="s" type="alert" />
            </EuiFlexItem>
            <EuiFlexItem grow={true}>{selectedColumn.sourceField}</EuiFlexItem>
          </EuiFlexGroup>
        </EuiLink>
      </EuiToolTip>
    );
  }

That replaces this:
image

with:

image

@flash1293
Copy link
Contributor Author

Thanks @cchaos and @mbondyra , adjusted the PR. This is how it looks now:
Screenshot 2020-09-30 at 14 34 41
Screenshot 2020-09-30 at 14 34 29

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Screenshots look great to me 👍

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

1 similar comment
@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Tested on Chrome/FF and reviewed. The design looks good but the BucketNestingEditor error is still here. Could you take a second look at my comment @flash1293 please?

@mbondyra mbondyra self-requested a review September 30, 2020 15:29
@flash1293
Copy link
Contributor Author

@mbondyra Misunderstood your comment the first time, sorry. It should be fixed now.

@mbondyra
Copy link
Contributor

mbondyra commented Oct 1, 2020

Re-tested on FF, all works as expected, thanks! :)

@@ -21,6 +22,10 @@ function nestColumn(columnOrder: string[], outer: string, inner: string) {
return result;
}

function getFieldName(fieldMap: Record<string, IndexPatternField>, column: IndexPatternColumn) {
return hasField(column) ? fieldMap[column.sourceField]?.displayName || column.sourceField : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

much better than what I suggested! 👏

@flash1293 flash1293 merged commit 8d7f2d0 into elastic:master Oct 1, 2020
flash1293 added a commit to flash1293/kibana that referenced this pull request Oct 1, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
lens 995.6KB 999.9KB +4.3KB

History

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Unable to edit broken lens visualization
5 participants