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

Allow typing comma separator for projected budget #523

Merged
merged 4 commits into from
Oct 22, 2020

Conversation

melissaSchmidt0302
Copy link
Contributor

@melissaSchmidt0302 melissaSchmidt0302 commented Jul 23, 2020

Closes #517
Closes #559
Closes #563

@openkfwCI
Copy link

openkfwCI commented Jul 23, 2020

NotesTime
Note for Reviewer: E2E tests on remote server succeededThu, 22 Oct 2020 07:53:37 +0000

Generated by E2E-Test

@melissaSchmidt0302 melissaSchmidt0302 force-pushed the allow-comma-separator branch 2 times, most recently from a080067 to 10bc2cf Compare July 27, 2020 06:35
@daniel-arnauer
Copy link
Contributor

e2e-test is missing

@daniel-arnauer daniel-arnauer self-assigned this Aug 13, 2020
@daniel-arnauer daniel-arnauer force-pushed the allow-comma-separator branch 2 times, most recently from d7914b2 to f42a54e Compare September 23, 2020 09:49
@daniel-arnauer daniel-arnauer force-pushed the allow-comma-separator branch 4 times, most recently from 7f3472d to 00d5619 Compare October 12, 2020 12:06
Copy link
Contributor

@Stezido Stezido left a comment

Choose a reason for hiding this comment

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

The current solution formats the budget before adding it to the other projected budgets. If I type in the wrong format and add it to the budgets suddenly the budget is in the right format but also it is another value. This is an unpredictable behavior.
I would have expected that the value stays the same or the program doesn't let me add the budget in that format - giving an input field error message. Do you agree?

@Stezido Stezido assigned daniel-arnauer and unassigned Stezido Oct 13, 2020
@daniel-arnauer
Copy link
Contributor

So i will ad an regex to check the input value. If the value does not match the regex, an input field error is thrown.
The conditions for regex in english language:

  • after ",", there must follow 3 numbers. Can occur infinitely
  • after ".", there can be an optional amount of numbers (will be rounded to two decimals).
  • If "," or "." is set after an ".", the number is invalid

Other languages:
Same as english, but "," and "." are swapped

@daniel-arnauer daniel-arnauer force-pushed the allow-comma-separator branch 2 times, most recently from e8b3572 to bedc752 Compare October 15, 2020 10:34
@@ -94,6 +94,11 @@ export const toAmountString = (amount, currency) => {
return accounting.formatMoney(amount, getCurrencyFormat(currency));
};

export const testMoneyInput = amount => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the comment and rename the function so it's clear what the function does

Copy link
Contributor

@daniel-arnauer daniel-arnauer Oct 19, 2020

Choose a reason for hiding this comment

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

renamed to validateLanguagePattern(amount)

return (
<TableCell align="right" data-test="saved-projected-budget-amount">
{isEditing && editIndex === currIndex ? (
<TextField
label={strings.common.projected_budget}
value={budgetAmountEdit}
onChange={e => setBudgetAmountEdit(e.target.value)}
onChange={e => {
if (/^[0-9,.-]*$/.test(e.target.value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

explain regex or create own variable to describe what's the condition

Copy link
Contributor

Choose a reason for hiding this comment

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

added var numberSignsRegex

@@ -5,7 +5,8 @@ const fr = {
decimal: ",",
thousand: ".",
precision: 2
}
},
numberRegex: /^([0-9]{1,3}.([0-9]{3}.)*[0-9]{3}|[0-9]+)(,[0-9]+)?$/
Copy link
Contributor

Choose a reason for hiding this comment

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

describe regex in a comment

Copy link
Contributor

@daniel-arnauer daniel-arnauer Oct 19, 2020

Choose a reason for hiding this comment

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

comments:
// numberRegex describes values with "." as decimal separator (matches e.g. 1000; 1,000; 1000.00; 1,000.00)
or
// numberRegex describes values with "," as decimal separator (matches e.g. 1000; 1.000; 1000,00; 1.000,00)

@Stezido Stezido assigned daniel-arnauer and unassigned Stezido Oct 19, 2020
@daniel-arnauer daniel-arnauer force-pushed the allow-comma-separator branch 2 times, most recently from c8bc437 to 8100ba8 Compare October 19, 2020 13:42
daniel-arnauer added 4 commits October 22, 2020 09:20
The number formating depends on the current language.
In english language, the "." is used as comma, in other
languages, the "," is used as comma.
NPM audit fix also includes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants