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

Informed package refactor for input components #562

Closed
Starotitorov opened this issue Nov 29, 2018 · 10 comments
Closed

Informed package refactor for input components #562

Starotitorov opened this issue Nov 29, 2018 · 10 comments
Labels

Comments

@Starotitorov
Copy link
Contributor

Starotitorov commented Nov 29, 2018

This issue is for the following packages:

[x] venia-concept
[ ] pwa-buildpack
[ ] peregrine
[ ] pwa-devdocs
[ ] upward-js
[ ] upward-spec

This issue is a:

[ ] Bug
[ ] Feature suggestion
[ ] Documentation issue
[x] Tech Debt

Environment

Question Answer
Magento version
Operating System + version
node.js version (node -v)
npm version (npm -v)

Description

In our application we decided to use informed package for managing forms. Informed uses Context API to store field values and other information such as errors, touched etc. In our common Input component we store value in local state, but we should do not do this, because informed is responsible for storing field values and handling changes in form state, our current implementation causes duplication of state. One of our bugs #416 with handling initial values inside Input component is the effect of this architecture mistake.

Expected result:

Field value should be handled by informed package.

Possible solutions:

We can wrap our Input component in asField HOC provided by informed and use BasicText component instead of Text. https://joepuzzo.github.io/informed/?selectedKind=CustomInputs&selectedStory=Creating%20Custom%20Inputs&full=0&addons=0&stories=1&panelRight=0&addonPanel=REACT_STORYBOOK%2Freadme%2Fpanel

@Starotitorov Starotitorov changed the title [Tech Debt] Refactor Input component [Tech Debt]: Input component Nov 29, 2018
@dmtrkad dmtrkad assigned dmtrkad and unassigned dmtrkad Nov 29, 2018
@dmtrkad dmtrkad added refactor and removed Techdebt labels Nov 29, 2018
@ericerway ericerway changed the title [Tech Debt]: Input component Informed package refactor for input components Nov 29, 2018
@ericerway
Copy link

Updated with more descriptive title for issue. Thanks!

@pcvonz
Copy link
Contributor

pcvonz commented Dec 3, 2018

I'd like to take a crack at this. @JStein92 and I worked in a few places right as we made the commitment to use Informed.

@pcvonz pcvonz self-assigned this Dec 3, 2018
@dmtrkad
Copy link

dmtrkad commented Dec 3, 2018

@pcvonz , Hey Paul, Let's wait for approval from @ericerway and @zetlen to continue working on it and sync up with changes we got to exclude double work effort from each side.

@pcvonz pcvonz removed their assignment Dec 3, 2018
@pcvonz
Copy link
Contributor

pcvonz commented Dec 3, 2018

@dmtrkad Ok, sounds good! I'll find something else to work on in the meantime.

@jimbo
Copy link
Contributor

jimbo commented Dec 4, 2018

Hi everyone. I'd like to chime in and provide some context.

The description of this issue is correct.

We're using informed to manage form and field state. Fields should be rendered inside a Form element, which will store form values and other state. This library creates event listeners and updates state automatically, so our field components should be stateless (generally).

This wasn't an architecture mistake, though; it was just a timing conflict.

I tried to have forms and field components in place before anyone was tasked with a user story that involved them, in order to avoid wasting anyone's time and effort. But the PR in which I introduced informed, #226, took a month to get merged, and during that time Paul and Jonathan were working on account creation and ended up creating the Input component.

We only need custom components to render Venia-themed informed components.

In a recent PR, I rewrote our Select component. Instead of being a fully custom implementation of Peregrine's List, it's now a simple wrapper around the Select component from informed. We probably need equivalents for Text, TextArea, Radio, and Checkbox. Application of classnames and restProps is really all these wrappers need to do.

@jimbo
Copy link
Contributor

jimbo commented Dec 4, 2018

I understand that PRs have already been opened to resolve this issue. Hopefully my comments above will provide some insight as to what I'll be looking for.

@Starotitorov Yes, informed provides the asField HOC if you need to make a custom field. In our case, I don't think we need to customize the underlying inputs, so we should avoid the HOC and simply wrap the component (e.g., Text).

@Starotitorov
Copy link
Contributor Author

@jimbo In the official documentation we have an example of input that renders validation error https://joepuzzo.github.io/informed/?selectedKind=CustomInputs&selectedStory=Creating%20Custom%20Inputs&full=0&addons=0&stories=1&panelRight=0&addonPanel=REACT_STORYBOOK%2Freadme%2Fpanel . I guess in our project we need something like this, so we need asField hoc. Text is just a BasicText component wrapped with asField hoc.

@Starotitorov
Copy link
Contributor Author

@jimbo , I agree it is not a good idea to use simple html input, we are going to use BasicText.

@Starotitorov
Copy link
Contributor Author

Starotitorov commented Dec 4, 2018

Also, in our common Input component we are going to add reset button to clear input value when use press it, so we definitely need this hoc.

@awilcoxa
Copy link

awilcoxa commented Feb 6, 2019

closing issue as related PRs were closed, it does not appear that the team is planning any additional work against this issue.

@awilcoxa awilcoxa closed this as completed Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants