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

Fix bug that coerced empty scaled float value to 0 #62251

Conversation

cjcenizal
Copy link
Contributor

Fixes #62035

image

@cjcenizal cjcenizal added bug Fixes for quality problems that affect the customer experience Feature:Index Management Index and index templates UI v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v7.8.0 labels Apr 2, 2020
@cjcenizal cjcenizal requested a review from a team as a code owner April 2, 2020 00:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Code LGTM. I left a comment around the actual default value we use.

@@ -502,7 +502,7 @@ export const PARAMETERS_DEFINITION: { [key in ParameterName]: ParameterDefinitio
}
),
fieldConfig: {
defaultValue: '',
defaultValue: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should check with an ES engineer to see what a good default value might be; 1 seems a little weird to me, since it's used as a multiplier. The documentation uses 10 as an example.

Docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#scaled-float-params

Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave it as 1, as multiplying by one does not do anything. The default value should be what ES uses behind the scene in case the parameter is not specified, and I think by default ES does not scale float.

Copy link
Contributor Author

@cjcenizal cjcenizal Apr 2, 2020

Choose a reason for hiding this comment

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

Seb's point is also what I originally had in mind (1 is a good default because it's basically a no-op). But Colin pointed out that it would be a better UX to force the user to consider the option and enter the right value for their use case. I think he's right. It's not helpful to make it easy for users to use a scaled float that doesn't take advantage of the scaling factor (a different type would be better).

Unless anyone objects, I intend to:

  • Close this PR
  • Update the original issue with these notes
  • Update the original issue with a note that we should also validate against a value of 1 and warn the user that this isn't very useful
  • Create a blocker issue that we need to update the form hook lib to allow numeric fields to be empty instead of defaulting to 0

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 sounds good. I agree that leaving it blank would be the better experience. Thanks @cjcenizal!

Copy link
Contributor

@sebelga sebelga Apr 2, 2020

Choose a reason for hiding this comment

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

I haven't checked, but my guess is that it is the EuiNumeric field that defaults to 0.
I would see the reason being: an empty string ("") is not a valid number, thus we render 0.

Copy link
Contributor

@sebelga sebelga Apr 3, 2020

Choose a reason for hiding this comment

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

It seems that the conversion from "" to 0 occurs on the field deSerializer that we have set

deserializer: (value: string | number) => +value,

// Probably needs to be

deserializer: (value: string | number) => value === '' ? '' : +value,

cc @alisonelizabeth @cjcenizal

@cjcenizal
Copy link
Contributor Author

@elasticmachine merge upstream

@cjcenizal
Copy link
Contributor Author

Good catch @sebelga! I've fixed this. Could you take another look @alisonelizabeth? Now the user is required to enter input:

image

@sebelga When you're writing the docs for the form hook lib, you might want to consider that people could find the roles of the deserializer and formatter configuration options to be unclear.

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

This works great now. Thanks @cjcenizal!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@cjcenizal cjcenizal changed the title Set default value for scaled float to 1 in mappings editor Fix bug that coerced empty scaled float value to 0 Apr 4, 2020
@cjcenizal cjcenizal merged commit ce6a291 into elastic:master Apr 4, 2020
@cjcenizal cjcenizal deleted the bug/index-template-mappings-scaled-float-default-value branch April 4, 2020 01:50
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Apr 4, 2020
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Apr 4, 2020
cjcenizal added a commit that referenced this pull request Apr 4, 2020
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Apr 6, 2020
…into event-log/query-support

* 'event-log/query-support' of github.com:gmmorris/kibana: (41 commits)
  [jenkins] refer to sizes in most pipeline code (elastic#62082)
  skip flaky suite (elastic#60470)
  [Discover] Fix flaky FT in field visualize (elastic#62418)
  [ML] Data Frame Analytics: Fix feature importance (elastic#61761)
  [Reporting] Use a shim for server config (elastic#62086)
  [Reporting] Fix reporting for non-default spaces (elastic#62226)
  Fix bug that coerced empty scaled float value to 0 (elastic#62251)
  [SIEM] [Detection Engine] Remove has manage api keys requireme… (elastic#62446)
  [Maps] Safely handle empty string and invalid strings from EuiColorPicker (elastic#62507)
  Reporting/bug more blacklisted headers (elastic#62389)
  [SIEM] Prevent undefined behavior in our ML popover (elastic#62498)
  [SIEM] [Detection Engine] remove all unknowns from all rules t… (elastic#62327)
  base changes for active/current node styling (elastic#62007)
  [kbn/ui-shared-deps] expand and split (elastic#62364)
  [ML] DF Analytics - ensure destination index pattern created (elastic#62450)
  Mark rule run as failure if there was an error (elastic#62383)
  Add docs for metric explorer alerts (elastic#62314)
  skip flaky suite (elastic#62281)
  [SIEM][Detection Engine] Fixes export of single rule and the icons
  fixes flakiness (elastic#62406)
  ...
@sebelga
Copy link
Contributor

sebelga commented Apr 6, 2020

Thanks for the insight @cjcenizal, I will take it into account to clearly explain:

3 lifecycles of field value

  • deSerializer: used only when initializing the field. Applied on the default value provided
  • formatter: used each time the value of the field changes
  • serializer: used only when accessing the form data (form.submit()). BUT, this is not currently true. The serializer is executed each time the value changes. This is a "bug" (not doing any harm) and I plan to fix it once the mappings editor got test coverage as well as the form lib. The reason is, we might have some complex logic in the serializer and we don't want this logic to be executed on each key stroke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Index Management Index and index templates UI release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.7.0 v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mappings editor] Scaled float has wrong default value
5 participants