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] Add validation on operation with no fields #98295

Closed
wants to merge 5 commits into from

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Apr 26, 2021

Summary

Fixes #89032

This PR adds one more level of validation to the datasource, checking for inconsistencies between the data and the visualization states.

Screenshot 2021-04-26 at 16 14 46

Screenshot 2021-04-26 at 15 18 07

Screenshot 2021-04-26 at 15 18 39

Screenshot 2021-04-26 at 15 19 02

Screenshot 2021-04-26 at 15 19 19

Note: datatable has an additional issue #98288 when cleaning up field information, hence it was not possible to show Rows and Columns filled with empty dimensions.

Checklist

@dej611 dej611 added release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 Feature:Lens v7.14.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Apr 26, 2021
@dej611 dej611 marked this pull request as ready for review April 27, 2021 08:23
@dej611 dej611 requested a review from a team April 27, 2021 08:23
@elasticmachine
Copy link
Contributor

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

@dej611
Copy link
Contributor Author

dej611 commented Apr 27, 2021

@elasticmachine merge upstream

@flash1293
Copy link
Contributor

It's still rendered as an empty dimension - should we make sure to also show an error in the dimension trigger similar to how calculations handle this? The original issue mentions this.

@dej611
Copy link
Contributor Author

dej611 commented Apr 27, 2021

Yes, I thought about that. I guess we have to decide what to show: in the calculation case it's easier as the referenced column is gone, but the referencing one still holds the label.
In this case there's no information about the type of operation there, it's just visualization state.

We could have a placeholder for this case. What do you think?

@flash1293
Copy link
Contributor

@dej611 Not sure what you have in mind as placeholder, but in this situation the visualization still thinks there's a column while the datasource removed it, right? We could detect this situation and render (warning triangle) Incomplete configuration in the dimension trigger.

@dej611
Copy link
Contributor Author

dej611 commented Apr 27, 2021

Yes, I meant "what to write in the space" as placeholder. I'll add the proposed copy.

@dej611
Copy link
Contributor Author

dej611 commented Apr 27, 2021

Updated the PR with some tiny refactoring + now showing the incomplete configuration message:

Screenshot 2021-04-27 at 18 19 36

Screenshot 2021-04-27 at 18 19 41

Screenshot 2021-04-27 at 18 19 59

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

I tested this and found a new error that this introduces:

  1. Create 2 metrics
  2. Delete the field of one metric
  3. Drag the metric to change its order, and you get an error in
export function hasField(column: BaseIndexPatternColumn): column is FieldBasedIndexPatternColumn {
  return 'sourceField' in column;
}

@flash1293
Copy link
Contributor

flash1293 commented Apr 28, 2021

Good point @wylieconlon . This makes me think whether this is the right way of handling backspace for the field in the first place:

Should we just set the field property to empty string or something like this and treat that as a validation error on the datasource side? I think it would keep the rest of the system working and would be easily detectable in the validation logic? What do you think @dej611

@mbondyra
Copy link
Contributor

@flash1293 would we use your proposal (setting a field to the empty string) when we switch between operations and the field is not compatible? We have two similar cases:

  1. Setup the operation A. Remove the field. Close popover -> you get the empty dimension
  2. Setup the operation A. Change to the operation B that doesn't accept the same field. Close popover. You get the last correct state. (operation A)

good
Maybe it's not for this task, it just we have a lot of inconsistency here and just wanted to mention that.

@flash1293
Copy link
Contributor

@mbondyra IMHO it's nice the last valid state is kept in this case. That got me thinking - maybe we should just not do anything if the user tries to delete the field?

We can totally do this - it's as simple as removing the onDeleteColumn callback. I just tried it and the backspace keystroke is simply ignored. It has the additional advantage of being very simple to implement :)

@mbondyra
Copy link
Contributor

Agreed, I also like this option better, let's just test it for fullReference operations too (if it's not worse than the bug we have here #97431)

@dej611
Copy link
Contributor Author

dej611 commented Apr 28, 2021

@flash1293 backspace does not do anything, but whitespace still clears the field input.
The latter has no effect on the state, but if you close the dropdown it's still empty and "invalid". Closing the flyout will restore the previous valid state:

delete_field

I think it's still acceptable as behaviour, just documenting it. If we all agree on that I can do on that direction.

@flash1293
Copy link
Contributor

@dej611 Good point, I think that's fine

@dej611
Copy link
Contributor Author

dej611 commented Apr 28, 2021

Ok, I'll create a separate PR as this one will need to be completely reverted 😅

@dej611 dej611 closed this Apr 28, 2021
@kibanamachine
Copy link
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
lens 965.1KB 966.4KB +1.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
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Lens release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Fix buggy handling of user pressing delete on the field selector
6 participants