-
Notifications
You must be signed in to change notification settings - Fork 113
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
[KED-2982] Re-write Kedro Dropdown and Menu-option #721
[KED-2982] Re-write Kedro Dropdown and Menu-option #721
Conversation
Signed-off-by: Rashida Kanchwala <[email protected]>
Signed-off-by: Rashida Kanchwala <[email protected]>
Signed-off-by: Rashida Kanchwala <[email protected]>
Signed-off-by: Rashida Kanchwala <[email protected]>
Signed-off-by: Rashida Kanchwala <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for setting this up.
On testing the new dropdown the 'expand more' arrow is current missing - please see below
Part of the main goal of this migration work is to refactor the components and bringing the code up to date with the current react setup in our codebase, which includes stripping away the react lifecycle and local state setup to use react hooks. As per my comments below, please refactor the component with the new react hooks setup.
Thank you!
src/components/dropdown/dropdown.js
Outdated
/** | ||
* React lifecycle method | ||
* {@link https://facebook.github.io/react/docs/react-component.html#componentwillupdate} | ||
* @param {Object} New component props | ||
*/ | ||
componentDidUpdate(prevProps) { | ||
if (this._childrenHaveChanged(prevProps)) { | ||
this.setState({ | ||
selectedOption: this._findSelectedOption(prevProps), | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* React lifecycle method | ||
* {@link https://facebook.github.io/react/docs/react-component.html#componentwillunmount} | ||
* @return {object} JSX for this component | ||
*/ | ||
componentWillUnmount() { | ||
EventController.removeBodyListeners(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to above - this needs refactoring
src/components/dropdown/dropdown.js
Outdated
* @param {object} e - event object | ||
*/ | ||
_handleBodyClicked(e) { | ||
if (!this.dropdown.contains(e.target) && this.state.open) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to above, there won't be any this.state
within react hooks setup - all references to this.state
would now refer to a react hook setState function.
src/components/dropdown/dropdown.js
Outdated
EventController.addBodyListener(this._handleBodyClicked); | ||
} | ||
|
||
this.setState({ open: !open }, callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above - this needs to be set up as a react hook.
src/components/dropdown/dropdown.js
Outdated
this.setState({ open: false, selectedOption }, () => { | ||
if (typeof onChanged === 'function') { | ||
onChanged(obj); | ||
} | ||
|
||
if (typeof onClosed === 'function') { | ||
onClosed(); | ||
} | ||
}); | ||
} else { | ||
this.setState({ open: false }, () => { | ||
if (typeof onClosed === 'function') { | ||
onClosed(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These would need to be refactored as a hook for all the setState events here - this applies to all other instances of setState
in this file as well
src/components/dropdown/dropdown.js
Outdated
*/ | ||
render() { | ||
const { children, defaultText, disabled, width } = this.props; | ||
const { open, focusedOption, selectedOption } = this.state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all these state events should be set up as individual hooks
src/components/dropdown/dropdown.js
Outdated
constructor(props) { | ||
super(props); | ||
|
||
this.displayName = 'Dropdown'; | ||
|
||
// bind method scope | ||
this._handleRef = this._handleRef.bind(this); | ||
this._getOptionsList = this._getOptionsList.bind(this); | ||
this._handleLabelClicked = this._handleLabelClicked.bind(this); | ||
this._handleOptionSelected = this._handleOptionSelected.bind(this); | ||
this._handleFocusChange = this._handleFocusChange.bind(this); | ||
this._handleBodyClicked = this._handleBodyClicked.bind(this); | ||
this.open = this.open.bind(this); | ||
this.close = this.close.bind(this); | ||
|
||
this.state = { | ||
focusedOption: null, | ||
selectedOption: this._findSelectedOption(), | ||
open: false, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we are using react hooks within our codebase, we won't be using the react lifecycles. Please rewrite refactor this using the react hook setup.
src/components/dropdown/dropdown.js
Outdated
/** | ||
* React lifecycle method | ||
* {@link https://facebook.github.io/react/docs/react-component.html#componentwillupdate} | ||
* @param {Object} New component props | ||
*/ | ||
componentDidUpdate(prevProps) { | ||
if (this._childrenHaveChanged(prevProps)) { | ||
this.setState({ | ||
selectedOption: this._findSelectedOption(prevProps), | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above - this need to be refactored into a react hook (using useEffect
hook)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have moved this PR to draft stage now, and I will work on changing to hooks before releasing it for review again.
@studioswong after looking at this for well over an hour just now, I'm of the opinion we shouldn't convert this to use hooks at this time. The amount of effort Rashida and I have put in to this is much too great a cost for what we gain, which really isn't anything other than a stylistic alignment of the codebase to use one React pattern. I'm confident we'll be able to live with two components still using the Please let us know what you think. Again, I strongly feel we should leave it as a class given the amount of work involved. We'll then be able to finish the migration epic, and maybe even the sprint. We can revisit this and the |
Thanks for looking into this @tynandebold - may I ask what is the main problem you and Rashida encountered in the refactoring to use hooks? I understand this for now may seem to be a matter of code style, however this has implications down the line as we maintain this piece of work later on - do we still continue down the line of deviating this component from hooks? Do we need to at some point just bite the bullet to refactor this? Don't want to be a blocker, but if we are doing the migration we might as well invest a bit more time to do it now while we are at it. ( broken window analogy, if you will.) Regardless, I will check out this branch and take a look 😃 |
Thanks @studioswong appreciate if you can take over and have a look and see if you can fix it!! |
The main problem is time invested versus payoff. I think there are other things we can do with our time that will benefit the product and thus our users. I also don't remember both the migration of these components to Viz and also updating the pattern of how they are written as part of the epic. I thought it was just the former, though I do agree it should be aligned. And to answer your questions:
No, we combine this rewrite and the one for the
Yes, as stated above. |
If we recall from the beginning, I actually don't think the idea of doing this migration is good given the exact problems we face now ( the need to migrate / refactor and maintain legacy react code in our codebase). But I understand there are benefits down the line ( such as being able to have full control and modify this component without the need to publish new versions of the kedro-ui npm package), and it is exactly for this reason to be able to maintain and make changes to this code that we have to do the rewrite. I would pick clearing tech debt and helping us run faster in the future over any inconvenience now - We are just biting the bullet for bigger rewards later on, exactly the idea of why we are doing this migration in the first place.
Excuse me if I don't exactly understand what you meant here, but last when I checked out the branch and began working on it, the component was in a weird state with half migrated hooks / having errors and needs to fix anyways, so might as well. |
on another note, @rashidakanchwala @tynandebold I am currently refactoring dropdown.js into hooks now, so no need to worry about this - I'll push the changes once it's done |
@rashidakanchwala I had pushed the latest changes in refactoring There is still the problem with the missing 'expand more' arrow on the right of the dropdown, which was a seperate known issue to fix - I'll let you take back over for that one :) |
….com:kedro-org/kedro-viz into KED-2982/rewrite-kedro-dropdown-menu-options
Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
…D-2982/rewrite-kedro-dropdown-menu-options Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good now. Seems to work just as the old one did.
src/components/dropdown/dropdown.js
Outdated
if (typeof onClosed === 'function') { | ||
onClosed(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a callback on setting the state that needs to be handled in a useEffect to ensure this is only executed after the state change (i.e the setOpen
state change here).
Regardless, on checking the code, this is actually already set up in the useEffects above, hence can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good and all works the same now.
Description
This PR is a part of the Kedro-UI migration ticket. In this PR we migrate the dropdown and menu-options functionality from Kedro-ui to Kedro-viz
Development notes
QA notes
Checklist
RELEASE.md
file