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

Refactor Fields.tsx to use a declarative React component API #169

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

subhankar-panda
Copy link
Contributor

@subhankar-panda subhankar-panda commented Jan 22, 2020

I've kept some old artifacts from before the refactor eg: createInput, createRow, createColumn because they are depended on by (New)EventForm that is currently being worked on in #163.

I will refactor that and nuke the old code when it eventually gets merged.

Fixes #165

Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

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

Wow what an improvement! It is so much cleaner and easier to maintain now.

It seems that there are still a few formFields that need converting?

};

export type ApplicationInputProps = {
className?: string;
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 worth creating base types (then inheriting) if they have common properties? Such as className, required, placeholder, etc.? Many fields have these properties so it'd be nice if they aren't repeated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good point! I forgot I was going to let the base inherit from JSX.InstrisicTypes (or whatever it's called) and pass the props down to allow things like aria tags to get on the fields

Copy link
Contributor

Choose a reason for hiding this comment

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

ARIA fields 😮 Are we GDPR compliant as well? 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Future proofing 🤣

type = 'text',
normalize,
placeholder,
}) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

You could pull out the fields that don't match the "Field" prop types and then just use the spread operator for the rest. eg. {errorTextInput, ...rest} then <Field component={errorTextInput} {...rest}/>.

I think that's the syntax for the spread, I'm doing this without a linter so you'll have to let me know.

</ApplicationCol>

<ApplicationCol className="col-md">
{this.createInstitutionCard(InstitutionType.UCSD, 'institution-ucsd',
Copy link
Contributor

Choose a reason for hiding this comment

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

These can probably be migrated too, 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.

I thought about it, but I think the real intent behind this refactor is to remove the nested function calls to make things more composable, didn't see a real use for "display components" to be migrated away as yet

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that's the major selling point of this refactor, but having a createXYZ function that generates a component is basically just a constructor of a stateless component with extra steps and less readability.

)}

</ApplicationCol>
</ApplicationRow>
<Fields names={['institution']} component={this.showInstitutionBox} />
Copy link
Contributor

Choose a reason for hiding this comment

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

{this.showInstitutionBox} seems hacky as well?

'sd-form__input-text')
)}
<ApplicationCol className="col-sm-4">
{FormFields.createMonthPicker()}
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔

)
<ApplicationCol className="col-sm-12">
<ApplicationLabel required={true}>
<>Why Do You Want To Attend {event.name}?</>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this require the empty blocks? I guess because it needs to be a React component to pass the type checking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! We are passing in Why Do you want to attend {event.name}? to ApplicationLabel, and the use of {event.name} requires the surrounding text to be a React node - so I wrapped it in a Fragment, which is the intended use case anyway.

className?: string;
forTag?: string;
// hack?
children?: string | JSX.Element[] | JSX.Element;
Copy link
Contributor

Choose a reason for hiding this comment

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

@subhankar-panda
Copy link
Contributor Author

yikes what happened to this branch

@RedbackThomson
Copy link
Contributor

yikes what happened to this branch

Did you pull fast-forward instead of rebase?

@subhankar-panda
Copy link
Contributor Author

nope, i rebased off master and fixed a bunch of conflicts, but i might have somehow rebased on an old version of master maybe?

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.

Refactor Fields.tsx into React-style components
3 participants