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

Add LocalizedMoneyInput Component #339

Merged
merged 25 commits into from
Jan 7, 2019
Merged

Conversation

islam3zzat
Copy link
Contributor

Summary

image

image

Description

Copy link
Contributor

@montezume montezume left a comment

Choose a reason for hiding this comment

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

Oh, I forgot to submit 🙈. Hopefully not all outdated

src/components/inputs/localized-money-input/README.md Outdated Show resolved Hide resolved
selectedCurrency: 'CAD',
hideExpansionControls: true,
});
const USDInput = container.querySelector('input[name="foo.USD.amount"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to do the changes in moneyinput first so we could do getByLabelText here

Copy link
Contributor

@dferber90 dferber90 left a comment

Choose a reason for hiding this comment

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

Looking good so far!

I've got a few suggestions for the API of the static methods to be more inline with how we're doing things in LocalizedTextInput.

src/components/inputs/localized-money-input/README.md Outdated Show resolved Hide resolved
src/utils/localized.js Outdated Show resolved Hide resolved
Copy link
Contributor

@dferber90 dferber90 left a comment

Choose a reason for hiding this comment

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

Looks very good to me 👍 Thanks for working on it. We're almost over the finish line 🏁

The MoneyInput now supports labels, so we can probably improve the tests by using other get-methods (e.g. getByLabelText).

We're also missing some translations.

selectedCurrency: 'CAD',
});
const event = { target: { value: '17.34' } };
const input = container.querySelector('input[name="foo.CAD.amount"]');
Copy link
Contributor

@dferber90 dferber90 Jan 4, 2019

Choose a reason for hiding this comment

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

Is there a way to find this input using a label or another approach than querySelector? We should strive not to use other getters first. I believe we should be able to, now that MoneyInput works with labels. You probably need to rebase first.

image

See "Which get method should I use?"

});
getByLabelText(/show all currencies/i).click();
const event = { target: { value: '12.98' } };
const USDInput = container.querySelector('input[name="foo.USD.amount"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rename this to usdInput. It's a regular variable so it should start lowercase. Otherwise the USDInput.value access later on looks like we're reading a static property from a class. It's pretty nitpicky, but I wouldn't want this naming pattern to start spreading.

@@ -0,0 +1,115 @@
import React from 'react';
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you refactor this to match our current VRT tests?

we need one .visualroute.js and one .visualspec.js 👍


const value = {
EUR: '12.77',
USD: '13.55',
CAD: '19.82',
};

screenshot('LocalizedMoneyInput', () => (
export const routePath = '/localized-money-input';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

expect(
container.querySelector('input[name="foo.CAD.amount"]')
).toBeInTheDocument();
expect(getByLabelText('CAD')).toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't really test that it has an HTML name though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not directly, or indirectly :D
updated the test name

name: 'foo',
selectedCurrency: 'CAD',
onBlur,
});
const input = container.querySelector('input[name="foo.CAD.amount"]');
const input = getByLabelText('CAD');
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@dferber90 dferber90 left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@dferber90
Copy link
Contributor

I pinged @filippobocik for a review of the Visual Regression Tests baseline.

@montezume This looks ready to be reviewed again.

const initialValues = docToFormValues(doc);
const renderErrors = (errors) => {
Object.keys(errors.prices).reduce(currency => {
const error = errors.prices[currency]?.missing && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just the diff or is the formatting off?

errors,
touched,
setFieldValue,
setFieldTouched,
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use half of these below, should we remove them given that this is a copy and paste basis?

onBlur: PropTypes.func,
onFocus: PropTypes.func,
hideExpansionControls: PropTypes.bool,
isDefaultExpanded: (props, propName, componentName, ...rest) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@dferber90 is this consistent with #389?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice catch! Yeah, this needs to be changed indeed! I totally missed it :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so isDefaultExpanded will be defaultExpandCurrencies?
this doesn't sound like a boolean prop, or did I misunderstand the change here

Copy link
Contributor

Choose a reason for hiding this comment

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

@dferber90 please clarify the intended prop here :)

Copy link
Contributor

@montezume montezume Jan 7, 2019

Choose a reason for hiding this comment

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

I believe it should be

    hideCurrencyExpansionControls,
    isDefaultExpanded

right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification

Copy link
Contributor

Choose a reason for hiding this comment

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

What we want is:

defaultExpandCurrencies // replaces isDefaultExpanded
hideCurrencyExpansionControls // replaces hideExpansionControls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

There are still references to isDefaultExpanded in the README and in a spec file 🔍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry forgot to push :D

src/components/inputs/localized-money-input/README.md Outdated Show resolved Hide resolved
src/components/inputs/localized-money-input/README.md Outdated Show resolved Hide resolved
import Constraints from '../../constraints';
import {
createLocalizedDataAttributes,
getHasErrorOnRemainingLanguages,
Copy link
Contributor

Choose a reason for hiding this comment

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

did we decide where or not it makes sense to make these into their own functions, instead of reusing the language ones?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe renaming the function would be good enough?

@montezume
Copy link
Contributor

@islam3zzat can you rebase to master and see if there's any issues now that #387 has been merged?

Copy link
Contributor

@montezume montezume left a comment

Choose a reason for hiding this comment

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

Thanks for all your hard work @islam3zzat 🎉

@dferber90 dferber90 merged commit 8dbaf07 into master Jan 7, 2019
@dferber90 dferber90 deleted the add-localized-money-input branch January 7, 2019 11:36
@dferber90
Copy link
Contributor

I merged as @islam3zzat didn't have the permissions to do so himself. Nice to have this in 🌈

@islam3zzat
Copy link
Contributor Author

Thanks @dferber90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👨‍🎨 Status: UI/UX Review Requires review from design team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants