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

[WIP] makeStyles and functional components #3461

Closed
wants to merge 21 commits into from
Closed

[WIP] makeStyles and functional components #3461

wants to merge 21 commits into from

Conversation

MohammedFaragallah
Copy link
Contributor

@MohammedFaragallah MohammedFaragallah commented Jul 25, 2019

Refs #3453

current status

  • examples/demo/src/layout/Login.js
  • ra-input-rich-text/src/index.js
  • ra-tree-ui-materialui/src/DragLayer.js
  • ra-tree-ui-materialui/src/DragPreview.js
  • ra-tree-ui-materialui/src/NodeActions.js
  • ra-tree-ui-materialui/src/NodeForm.js
  • ra-tree-ui-materialui/src/NodeView.js
  • ra-tree-ui-materialui/src/RootDropTarget.js
  • ra-tree-ui-materialui/src/Tree.js
  • ra-tree-ui-materialui/src/TreeNode.js
  • ra-ui-materialui/src/Link.tsx
  • ra-ui-materialui/src/auth/Login.tsx
  • ra-ui-materialui/src/auth/LoginForm.tsx
  • ra-ui-materialui/src/button/CreateButton.js
  • ra-ui-materialui/src/button/SaveButton.js
  • ra-ui-materialui/src/field/BooleanField.tsx
  • ra-ui-materialui/src/field/ChipField.tsx
  • ra-ui-materialui/src/field/FileField.tsx
  • ra-ui-materialui/src/field/ImageField.tsx
  • ra-ui-materialui/src/form/FormInput.js
  • ra-ui-materialui/src/form/SimpleFormIterator.js
  • ra-ui-materialui/src/form/TabbedForm.js
  • ra-ui-materialui/src/form/Toolbar.js
  • ra-ui-materialui/src/input/AutocompleteArrayInput.js
  • ra-ui-materialui/src/input/AutocompleteArrayInputChip.js
  • ra-ui-materialui/src/input/AutocompleteInput.js
  • ra-ui-materialui/src/input/CheckboxGroupInput.js
  • ra-ui-materialui/src/input/FileInput.js
  • ra-ui-materialui/src/input/FileInputPreview.js
  • ra-ui-materialui/src/input/ImageInput.js
  • ra-ui-materialui/src/input/Labeled.js
  • ra-ui-materialui/src/input/NullableBooleanInput.js
  • ra-ui-materialui/src/input/RadioButtonGroupInput.js
  • ra-ui-materialui/src/input/ResettableTextField.js
  • ra-ui-materialui/src/input/SearchInput.js
  • ra-ui-materialui/src/input/SelectArrayInput.js
  • ra-ui-materialui/src/input/SelectInput.js
  • ra-ui-materialui/src/layout/AppBar.js
  • ra-ui-materialui/src/layout/CardContentInner.js
  • ra-ui-materialui/src/layout/Confirm.js
  • ra-ui-materialui/src/layout/Error.js
  • ra-ui-materialui/src/layout/Layout.js
  • ra-ui-materialui/src/layout/LinearProgress.js
  • ra-ui-materialui/src/layout/Loading.js
  • ra-ui-materialui/src/layout/LoadingIndicator.js
  • ra-ui-materialui/src/layout/Menu.js
  • ra-ui-materialui/src/layout/MenuItemLink.js
  • ra-ui-materialui/src/layout/NotFound.js
  • ra-ui-materialui/src/layout/Notification.js
  • ra-ui-materialui/src/layout/Sidebar.js
  • ra-ui-materialui/src/list/BulkActions.js
  • ra-ui-materialui/src/list/BulkActionsToolbar.js
  • ra-ui-materialui/src/list/Datagrid.js
  • ra-ui-materialui/src/list/DatagridHeaderCell.js
  • ra-ui-materialui/src/list/DatagridLoading.js
  • ra-ui-materialui/src/list/Filter.js
  • ra-ui-materialui/src/list/FilterButton.js
  • ra-ui-materialui/src/list/FilterForm.js
  • ra-ui-materialui/src/list/PaginationActions.js
  • ra-ui-materialui/src/list/SimpleList.js
  • ra-ui-materialui/src/list/SingleFieldList.js

And then there is the doc:

  • CreateEdit.md
  • Fields.md
  • List.md
  • Theming.md
  • Tutorial.md

Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Cool :) I think you don't have to use createStyles when you use makeStyles (see https://material-ui.com/styles/basics/#hook-api)

@Kmaschta
Copy link
Contributor

Ah! The tests are failing because with the withStyles HOC, the components were wrapped on the tests like WithStyles(Component).

This is no longer the case now with the hook.
Can you remove all the WithStyles(x) and only keep the x in the tests that are failing?

@djhi
Copy link
Collaborator

djhi commented Jul 25, 2019

Can you remove all the WithStyles(x) and only keep the x in the tests that are failing?

Even better, if you feel up for it, convert them to react-testing-library 😍

@MohammedFaragallah
Copy link
Contributor Author

Even better, if you feel up for it, convert them to react-testing-library 😍

sorry @djhi i don't think i can do this i'm not very good with testing

@MohammedFaragallah MohammedFaragallah changed the title makeStyles for functional components [WIP] makeStyles and functional components Jul 26, 2019
Copy link
Contributor Author

@MohammedFaragallah MohammedFaragallah left a comment

Choose a reason for hiding this comment

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

i need feedback on this if it's good i will continue converting the others to functional components
also how should i handle components with shouldComponentUpdate

@Kmaschta
Copy link
Contributor

This looks very good to me.
But don't bother transforming class-based components into function-based ones.

You can use useStyles in a render() function of a class-based component.
That way, you can let all the lifecycle in place.

@djhi
Copy link
Collaborator

djhi commented Jul 26, 2019

You can use useStyles in a render() function of a class-based component.

No, useStyles is a hook. Hooks can't be used in a class component

See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-from-react-functions

@Kmaschta
Copy link
Contributor

Kmaschta commented Jul 26, 2019

My bad! Seems like we can't.

So, about your question, you can use React.memo instead of shouldComponentUpdate: https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-shouldcomponentupdate

@MohammedFaragallah
Copy link
Contributor Author

@djhi some components are class based while they dot use any lifecycle methods or internal state like ra-tree-ui-materialui/TreeNodeContent should i convert them too ?

and could you give savebutton tests a look

@Kmaschta
Copy link
Contributor

If you feel like you can convert them, else you don't have to.
We'll just mark them as non-converted, it's ok.

@MohammedFaragallah
Copy link
Contributor Author

It's fine by me i would love to help this awesome project whenever i can

@Kmaschta
Copy link
Contributor

Don't feel obligated to migrate all the components at once!
The smaller the PR is, the faster it will be reviewed and merged.
The bigger it is, the more you might get rebase to do and request changes.

This one tend to be huge, and a split might be a good idea IMHO.

@fzaninotto
Copy link
Member

fzaninotto commented Jul 31, 2019

@MohammedFaragallah please fix the tests before converting more components. We can't merge this PRs if it breaks the tests.

@MohammedFaragallah
Copy link
Contributor Author

@Kmaschta yes i won't be converting any more components this status list is for the maintainers to keep track whats almost done, but i'll focus on getting tests fixed as @fzaninotto asked, sorry for the delay but i'm really busy this days and my lack of experience with testing isn't helping very soon all will be resolved i hope

@djhi
Copy link
Collaborator

djhi commented Aug 5, 2019

@MohammedFaragallah I'm going to change all inputs for react-final-form migration. I will update them to use makeStyle at the same time. You should omit them to avoid conflicts later in your smaller prs

@Kunnu01
Copy link
Contributor

Kunnu01 commented Aug 7, 2019

@djhi , What to do in case of componentDidCatch?

@fzaninotto
Copy link
Member

Thanks a lot for your effort, but your work isn't going to be merged soon, because of the rebases and failed tests. I'm going to close this, and I recommend that you cherry-pick the commits to open smaller PRs, migrating a handful of components only (less than a dozen), and making sure the tests pass. I'll do the same for your other PR.

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.

5 participants