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: trim increment number value #490

Merged
merged 1 commit into from
Jan 14, 2023
Merged

fix: trim increment number value #490

merged 1 commit into from
Jan 14, 2023

Conversation

Skaiir
Copy link
Contributor

@Skaiir Skaiir commented Jan 10, 2023

@Skaiir Skaiir self-assigned this Jan 10, 2023
@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Jan 10, 2023
@@ -91,7 +91,7 @@ function NumberArrowStep(props) {
return value;
};

const setValue = (value) => editField(field, [ 'increment' ], value);
const setValue = (value) => editField(field, [ 'increment' ], value && Big(value).toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this is not side-effect free. When typing rather low and starting to type the digits, the . got erased rather quickly.

Kapture 2023-01-10 at 14 02 52

Copy link
Contributor Author

@Skaiir Skaiir Jan 11, 2023

Choose a reason for hiding this comment

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

Very nice catch, there are three ways we can fix this if we want to keep trimming

[1] We don't treat 45. as a valid value, and wait for the user to enter a more complete entry:

4 is entered => 4 is serialized
5 is entered => 45 is serialized
. is entered => nothing happens
5 is entered => 45.5 is serialized

The downside of this is, if someone were to enter 45. quickly, because the field is debounced, we may have no value at all as the two first steps mentioned above may be outright skipped.

[2] We serialize the dot in the schema

This avoids the above mentioned downside, but may be a little weird in terms of schema to store something like 23.

[3] We implement something at the properties panel field level to deal with this exact scenario

Downside here is implementation time, I'm not sure how/if such an implementation would work well.

@christian-konrad @pinussilvestrus maybe you have some input here? Personally I think option 2 is the right call.

Copy link
Contributor

Choose a reason for hiding this comment

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

We serialize the dot in the schema

As far as I can see45. is valid input data for the numbers itself, as it would simply resolve to 45. You can also specify this via input data; no error is thrown.

Therefore we would be fine persisting it this way in the schema for the increment, as it would be consistent. If we can avoid trimming for such cases, even better - no magic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, I've implemented just that and added a new test case for it.

@Skaiir Skaiir changed the base branch from develop to master January 11, 2023 13:12
Copy link
Contributor

@vsgoulart vsgoulart left a comment

Choose a reason for hiding this comment

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

For the decimal inputs config still accepts non-integer numbers, which I guess it doesn't make sense and it's the point of this PR, no?

Another thing that I think it's unrelated to this PR is that the range validation seems to accept non-integer values but then the validation looks like this
image

In the image above I used 5.3 as a maximum value

@Skaiir
Copy link
Contributor Author

Skaiir commented Jan 12, 2023

For the decimal inputs config still accepts non-integer numbers, which I guess it doesn't make sense and it's the point of this PR, no?

Another thing that I think it's unrelated to this PR is that the range validation seems to accept non-integer values but then the validation looks like this

Actually the config doesn't accept non-integer numbers in either cases. The field doesn't throw a validation error when it's wrong, but if you navigate to another component and come back you'll see the decimals aren't serialized. Unfortunately the properties panel number field just doesn't support this, or the decimal step has to be defined explicitly. And since it also uses the browser default decimal which is a bit inconsistent across browsers we can't do much about it, unless we implement our own number field from a non-decimal input field in the properties panel, like we've done in form-js.

I've raised the issue for min/max here and will tackle it soon, we can fix this by setting a step of any so it's a pretty easy thing.

For increment, the behavior is correct but the UX is quite bad as it's unclear that an integer is expected. Maybe I should migrate over to a text field with number validation, but then we would lose the increment arrows. But I guess it's not a huge deal.

If we want to keep the arrows but also get nice validation, we'll need to make some changes to the properties panel library. I've raise an improvement request here to allow validation of number fields the same way we have them for text fields.

@Skaiir
Copy link
Contributor Author

Skaiir commented Jan 12, 2023

Let's keep the trimming very simple, clearing leading zeroes for increment.

As far as camunda/camunda-modeler#3382 second part is concerned, let's not tackle this until we have the ability to define custom validation for the properties panel number fields. For now UX will not be ideal but to be honest this has always been the case with number properties.

@Skaiir Skaiir force-pushed the mdlr-3382-trim-increment branch 2 times, most recently from 6256992 to 1f48164 Compare January 13, 2023 07:36
Copy link
Contributor

@vsgoulart vsgoulart left a comment

Choose a reason for hiding this comment

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

Looks to me, I think we can just simplify the code a bit before merging.

Feel free to make these changes I suggested without asking for a review again

const clearLeadingZeroes = (value) => {
if (!value) return value;
const trimmed = value.replace(/^0+/g, '');
return (trimmed.startsWith('.') ? '0' : '') + trimmed;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return (trimmed.startsWith('.') ? '0' : '') + trimmed;
return `${trimmed.startsWith('.') ? '0' : ''}${trimmed}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is personal preference, but personally, I wouldn't use computed strings for concatenation. So I'll merge as-is. Thanks for the review :)

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.

3 participants