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: use hooks #957

Merged
merged 9 commits into from
Jul 26, 2019
Merged

refactor: use hooks #957

merged 9 commits into from
Jul 26, 2019

Conversation

montezume
Copy link
Contributor

Summary

Refactors the select components to use hooks, as well as PasswordField and some smaller components.

@@ -54,7 +54,7 @@ storiesOf('Components|Fields', module)
isRequired={boolean('isRequired', false)}
touched={boolean('touched', false)}
name={text('name', '')}
value={text('value', value)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was annoying, it's better to use the value so that the user can type into the field itself and not into the knob.

@tdeekens
Copy link
Contributor

Nice. So UIKit will have the same React version as a peer dep as app-kit and this will be released as breaking or did we include that in the last release?

@montezume
Copy link
Contributor Author

@tdeekens we included in the last breaking UI-Kit version (10) the requirement for version 16.7 of React and version 3 of react-intl

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

Diffs are hard to trace. Changes feel rather mechanical right?

? intl.formatMessage(messages.hide)
: intl.formatMessage(messages.show)
}
onClick={() => setIsPasswordVisible(!isPasswordVisible)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could be a tiny memoized fn togglePasswordVisibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this what you mean?

4200a7b

I'm not a huge hook expert yet 🤓

}
PasswordField.defaultProps = {
horizontalConstraint: 'scale',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming these just moved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly

// values were removed only. So we have to treat any array we receive as
// a signal of the field having been touched.
static isTouched = touched => Boolean(touched);
const AsyncCreatableSelectInput = props => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to see them all being React.FCs.

},
info
);
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

It is hard to trace changes but I assume it is all about the top.

// { label: 'Flavours', options: flavourOptions },
// ];
// So we "ungroup" the options by merging them all into one list first.
const optionsWithoutGroups = flatMap(props.options, option =>
Copy link
Contributor

Choose a reason for hiding this comment

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

In L40 this has been replaced without using state. Why was this in a gDSFP before?

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'm not really sure why it was there in the first place. We were using a gDSFP without a condition, so it always updated "state" to the new value on every render (including first render), and then we never set the state or did anything with it. Same thing in the other components.

Copy link
Contributor

Choose a reason for hiding this comment

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

Odd. We might just have adopted it cause it was the new thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible that our first implementation of the component had setState happening but then we refactored it out but left the gDSFP 🤷‍♂ ?

@montezume
Copy link
Contributor Author

Yeah most of the diffs came from moving the proptypes + default props + etc outside of the class component

@@ -24,6 +24,10 @@ const PasswordField = props => {
const id = getFieldId(props, {}, sequentialId);
const hasError = props.touched && hasErrors(props.errors);

const togglePasswordVisibility = React.useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly this. Cheers.

@montezume montezume merged commit 33ce5a6 into master Jul 26, 2019
@montezume montezume deleted the ml-hooks branch July 26, 2019 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants