-
Notifications
You must be signed in to change notification settings - Fork 1
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
DT-1110: Migrate away from @mui/styles Part 1 #1730
base: develop
Are you sure you want to change the base?
Conversation
jade-data-repo-ui Run #3920
Run Properties:
|
Project |
jade-data-repo-ui
|
Branch Review |
sh/dt-1110-remove-mui-styles-part1
|
Run status |
Passed #3920
|
Run duration | 02m 52s |
Commit |
10fabcb73b ℹ️: Merge 3a12537f4016d5606888b62d92fcf72522e8801c into 79c0423d9cfcafed88655352e6c8...
|
Committer | Shelby Holden |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
17
|
View all changes introduced in this branch ↗︎ |
e71a9d8
to
c83ff6d
Compare
sx={{ | ||
top: '112px', | ||
bottom: '0px', | ||
flexShrink: 0, | ||
height: 'initial', | ||
zIndex: 10, | ||
minWidth: 300, | ||
width: '40%', | ||
position: 'absolute', | ||
transition: () => | ||
theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
'&.drawerClose': { | ||
transition: () => | ||
theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.leavingScreen, | ||
}), | ||
overflowX: 'hidden', | ||
width: '0px', | ||
minWidth: '0px', | ||
[theme.breakpoints.up('sm')]: { | ||
width: '0px', | ||
}, |
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.
For more complicated styles like this, it may make sense to pull it into a styled component to help with code readability. But, this styling is still only used in one spot so I'm a torn over which is better (leave as sx prop vs. pull into styled component)
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.
Since the refactoring is being done in stages, we can always pull this out into a separate style in the future.
b1577c1
to
5ac0898
Compare
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.
One main question, otherwise lgtm:
fontSize: '14px', | ||
lineHeight: '22px', | ||
fontWeight: '600', | ||
color: 'primary.main', |
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.
Do these need to import theme from 'modules/theme';
and use theme.palette.primary.main
instead like in src/components/DatasetView.tsx
? If so, a number of components in this PR have this issue with color
.
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.
Great question - I believe it is correct as is - Here's the documentation and the basic example has something very similar. We have "ThemeProvider" set up in the index, so the theme should be available to all components in the repo.
I'm possibly not referencing the theme correctly in DatasetView, but I wasn't quite sure how to do the expansion of the custom mixin.
Command used: Can you migrate this component away from using JSS and references to '@mui/styles' and instead use '@mui/system'? Please use the "sx" prop wherever possible instead of "styled". If you need to use the "sx" prop, then we must use the material UI version of the component (e.g. Box instead of div and add an import statement at the beginning of the file). We must also switch any css references of direct numbers to include px (e.g. '10px' instead of 10)
Im not sure where it got that maxwidth from Update references
- title isn't used anywhere add comma
Command: Can you migrate this component away from using JSS and references to '@mui/styles' and instead use '@mui/system'? Please use the "sx" prop wherever possible instead of "styled". If you need to use the "sx" prop, then we must use the material UI version of the component (e.g. Box instead of div and add an import statement at the beginning of the file). We must also switch any css references of direct numbers to include px (e.g. '10px' instead of 10)
- Switch again to use theme mixins - userEmail is not used
}, | ||
); | ||
return ( | ||
<Box sx={{ display: 'flex', justifyContent: 'center', marginTop: '1em' }}> |
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.
If you want to reduce the diff here, and keep the object abstractions, this could be <Box sx={styles(theme).wrapper}>
just as easily, and that way we keep our object abstractions while moving to the sx
property?
To do this you would need to have styles
be a raw object rather than a method (or call it once if we have a theme we could pass), but that should be okay
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.
That's a really interesting idea, and I'm torn about it.
I think I'm less interested in making the diff smaller (copilot is doing the heavy lifting here to move things around), and want to think about how we want this to look long term. We often use existing code as a model for new code, so what do we want our best practices to be going forward?
I think I generally like the sx prop styles to be inline for a small set of changes, but we may want to consider using styled components more frequently to keep a pseudo object abstraction. I could actually build that into the copilot request - like "if there are more than 3 css styles, use a styled component instead of the sx prop".
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.
That's my ultimate preference as well. 3 css styles is fine for inline, more gets bulky. I also think if we have a often reused width or something - with lots of constants reused, that I'd abstract.
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.
Turns out that its tricky to get copilot to handle these two cases 🫠 It's not great at counting, apparently (It would catch some components with >3 styles, but not all).
We may have to do this in two steps (convert to sx prop or styled and then move the rest). I think I'm also having better luck with a newer gpt model in vs code (as opposed to intellij).
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.
👍🏽
I think we need to use @mui/material/styles instead? This is what is referenced in docs: https://mui.com/material-ui/customization/theming/ remove @mui/styles references from theme
80598fd
to
3a12537
Compare
Quality Gate passedIssues Measures |
import DatasetTable from './table/DatasetTable'; | ||
|
||
import { DatasetRoles } from '../constants'; | ||
|
||
const styles = (theme: CustomTheme) => ({ | ||
wrapper: { |
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.
so just a general comment, this is moving us away from having separate style objects and towards inline styling. Is that the principle that we want to follow? I thought that separate objects were preferred because they are reusable and easier to maintain. But maybe that isn't the case. What are the guidelines from the UI working group on this?
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.
My goal in this PR is to use best practices for Material UI. We're moving from an old Material UI concept (@mui/styles), to a new one - sx prop + styled components. I don't think Terra UI uses Material UI, but I'm glad to still run this by them.
RE: separate objects that are reusable/easier to maintain: We should use styled components for this case. The "sx prop" should be used for styles that are used in one spot, styled components are reusable and then we use the global theme to share styling variables. I think this is a helpful guide here: https://mui.com/material-ui/customization/how-to-customize
Background
We must discontinue use of @mui/styles in order to migrate from React 17 to 18. (source)
There is guide for this migration here: https://mui.com/material-ui/migration/migrating-from-jss
Options considered:
sx
prop and use styled components for styles that are used multiple times - From migration guide - "We recommend sx API over styled for creating responsive styles or overriding minor CSS"This PR uses the first option and mostly sticks the
sx
prop. We could also use styled components here where it makes sense. I see this first option as an upgrade that should help us align with best practices. Given that we have to touch every file manually and I think we can utilize copilot for the bulk of the work, I would prefer to do the harder change rather than the lateral change.Steps for Upgrades
Pre-checks:
Common Issues
What step is the copilot upgrade taking?
Box
instead ofdiv
andspan
so that we can use thesx
prop. This prop is only available on components from Material UI. If we want to still use generic component, we can instead use styled components.Example
Before with @mui/styles
With sx prop
Components Impacted in this PR
Recording Video