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

[BC Break] Upgrade to MUI v5 #6650

Merged
merged 42 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
096e229
Upgrade MUI dependencies
Oct 5, 2021
ece6329
Update imports
Oct 5, 2021
26180df
Apply codemods
Oct 5, 2021
aeea05a
Migrate all makeStyles
Oct 5, 2021
ea5bc23
Fix popper usage
Oct 5, 2021
12927ad
Fix tests targetting user menu
Oct 5, 2021
58bd0ad
Ensure Login uses the theme only when inside a ThemeProvider
Oct 5, 2021
398713f
Temporarily disable loading state on SaveButton
Oct 5, 2021
14c701f
Migrate to new theme format and createTheme
Oct 5, 2021
ec419b1
Migrate auth components to new styling API
Oct 5, 2021
aa09a16
Migrate button components to new styling API
Oct 5, 2021
dc93163
Fix SkipNavigationButton
Oct 5, 2021
2bebe46
Migrate detail components to new styling API
Oct 5, 2021
815f826
Temporary richtextinput fix
Oct 6, 2021
2af0985
Migrate ra-no-code to fix build
Oct 6, 2021
3aea67a
Fix popperjs setup in jest to allow tests to run
Oct 6, 2021
4ed7de0
Restore useListController tests
Oct 6, 2021
4a22ed6
Migrate field components to new styling API
Oct 6, 2021
62f9659
Fix most button tests
Oct 6, 2021
e561c7a
Fix field tests
Oct 6, 2021
b3b91cb
Migrate form components to new styling API
Oct 6, 2021
f77221f
Fix ReferenceArrayField
Oct 7, 2021
fc454ad
Migrate layout components to new styling API
Oct 7, 2021
839916f
Migrate list filters components to new styling API
Oct 7, 2021
33ec296
Migrate list pagination components to new styling API
Oct 7, 2021
34a0f72
Migrate list datagrid components to new styling API
Oct 7, 2021
8a96953
Migrate list components to new styling API
Oct 7, 2021
d2f7d84
Migrate input components to new styling API
Oct 11, 2021
748786b
Cleanup menu
Oct 11, 2021
7c66b81
Fix popperjs related tests
Oct 11, 2021
ed29140
Fix many tests which needed the theme
Oct 11, 2021
553d155
Fix tests and warnings
Oct 11, 2021
cd054c7
Cleanup
Oct 11, 2021
3dfcb60
Migrate richtextinput to new style API
Oct 11, 2021
a72642c
Fix simple example vite config
Oct 11, 2021
b2970af
Fix ra-no-code
Oct 11, 2021
0e57a0a
Migrate simple example
Oct 11, 2021
fad0047
Fix simple example
Oct 11, 2021
bda15bd
Fix edit e2e test
Oct 12, 2021
f0f768e
Fix datagrid styles
Oct 12, 2021
2289437
Fix ecommerce demo
Oct 12, 2021
18c0ee5
Fix crm demo
Oct 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
{
"paths": [
{
"name": "@material-ui/core",
"name": "@mui/material",
"importNames": ["makeStyles", "createMuiTheme"],
"message": "Please import from @material-ui/core/styles instead. See https://material-ui.com/guides/minimizing-bundle-size/#option-2 for more information"
"message": "Please import from @mui/material/styles instead. See https://material-ui.com/guides/minimizing-bundle-size/#option-2 for more information"
}
]
}
Expand Down
15 changes: 15 additions & 0 deletions __mocks__/@popperjs/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mock = () => {
const PopperJS = jest.requireActual('@popperjs/core');
return {
placements: PopperJS.placements,
destroy: () => {},
scheduleUpdate: () => {},
forceUpdate: () => {},
render: function (this: any) {
return this.$options._renderChildren;
},
};
};

export default mock;
export { mock as createPopper };
2 changes: 1 addition & 1 deletion cypress/support/CreatePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default url => ({
descInput: '.ql-editor',
tab: index => `.form-tab:nth-of-type(${index})`,
title: '#react-admin-title',
userMenu: 'button[title="Profile"]',
userMenu: 'button[aria-label="Profile"]',
logout: '.logout',
},

Expand Down
4 changes: 2 additions & 2 deletions cypress/support/EditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default url => ({
return `.ra-input-${name} label`;
}
if (type === 'reference-array-input') {
return `.ra-input div[role=combobox]`;
return `.ra-input div[role=combobox] input`;
}
return `.edit-page [name='${name}']`;
},
Expand All @@ -22,7 +22,7 @@ export default url => ({
cloneButton: '.button-clone',
tab: index => `.form-tab:nth-of-type(${index})`,
title: '#react-admin-title',
userMenu: 'button[title="Profile"]',
userMenu: 'button[aria-label="Profile"]',
logout: '.logout',
},

Expand Down
2 changes: 1 addition & 1 deletion cypress/support/ListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default url => ({
selectAll: '.select-all',
selectedItem: '.select-item input:checked',
selectItem: '.select-item input',
userMenu: 'button[title="Profile"]',
userMenu: 'button[aria-label="Profile"]',
title: '#react-admin-title',
headroomUnfixed: '.headroom--unfixed',
headroomUnpinned: '.headroom--unpinned',
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/ShowPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (url, initialField = 'title') => ({
snackbar: 'div[role="alertdialog"]',
tabs: `.show-tab`,
tab: index => `.show-tab:nth-of-type(${index})`,
userMenu: 'button[title="Profile"]',
userMenu: 'button[aria-label="Profile"]',
logout: '.logout',
},

Expand Down
108 changes: 54 additions & 54 deletions examples/crm/package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
{
"name": "react-admin-crm",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.12.1",
"@material-ui/icons": "^4.11.2",
"@nivo/bar": "^0.67.0",
"@nivo/core": "^0.67.0",
"date-fns": "^2.19.0",
"faker": "~5.4.0",
"lodash": "~4.17.5",
"prop-types": "^15.7.2",
"ra-data-fakerest": "^3.13.4",
"react": "^17.0.0",
"react-admin": "^3.15.0",
"react-beautiful-dnd": "^13.0.0",
"react-dom": "^17.0.0",
"react-scripts": "^4.0.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/classnames": "^2.2.9",
"@types/faker": "^5.1.7",
"@types/jest": "^26.0.19",
"@types/lodash": "~4.14.168",
"@types/react": "^17.0.20",
"@types/react-beautiful-dnd": "^13.0.0",
"@types/react-dom": "^17.0.9",
"rewire": "^5.0.0",
"source-map-explorer": "^2.0.0",
"typescript": "^4.4.0",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "node ./build.js",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"homepage": ".",
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
"name": "react-admin-crm",
"version": "0.1.0",
"private": true,
"dependencies": {
"@mui/material": "^5.0.2",
"@mui/icons-material": "^5.0.1",
"@nivo/bar": "^0.67.0",
"@nivo/core": "^0.67.0",
"date-fns": "^2.19.0",
"faker": "~5.4.0",
"lodash": "~4.17.5",
"prop-types": "^15.7.2",
"ra-data-fakerest": "^3.13.4",
"react": "^17.0.0",
"react-admin": "^3.15.0",
"react-beautiful-dnd": "^13.0.0",
"react-dom": "^17.0.0",
"react-scripts": "^4.0.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/classnames": "^2.2.9",
"@types/faker": "^5.1.7",
"@types/jest": "^26.0.19",
"@types/lodash": "~4.14.168",
"@types/react": "^17.0.20",
"@types/react-beautiful-dnd": "^13.0.0",
"@types/react-dom": "^17.0.9",
"rewire": "^5.0.0",
"source-map-explorer": "^2.0.0",
"typescript": "^4.4.0",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "node ./build.js",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"homepage": ".",
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
10 changes: 2 additions & 8 deletions examples/crm/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as React from 'react';
import { Admin, Resource, ListGuesser, defaultTheme } from 'react-admin';
import {
unstable_createMuiStrictModeTheme,
createMuiTheme,
} from '@material-ui/core/styles';
import { createTheme } from '@mui/material/styles';

import { dataProvider } from './dataProvider';
import { authProvider } from './authProvider';
Expand All @@ -14,10 +11,7 @@ import deals from './deals';
import { Dashboard } from './dashboard/Dashboard';

// FIXME MUI bug https://github.com/mui-org/material-ui/issues/13394
const theme =
process.env.NODE_ENV !== 'production'
? unstable_createMuiStrictModeTheme(defaultTheme)
: createMuiTheme(defaultTheme);
const theme = createTheme(defaultTheme);

const App = () => (
<Admin
Expand Down
22 changes: 14 additions & 8 deletions examples/crm/src/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Tabs, Tab, Toolbar, AppBar, Box, Typography } from '@material-ui/core';
import { styled } from '@mui/material/styles';
import { Tabs, Tab, Toolbar, AppBar, Box, Typography } from '@mui/material';
import { Link, useRouteMatch } from 'react-router-dom';
import { UserMenu, Logout, LoadingIndicator } from 'react-admin';

const useStyles = makeStyles({
root: {
const PREFIX = 'Header';

const classes = {
root: `${PREFIX}-root`,
logo: `${PREFIX}-logo`,
};

const Root = styled('nav')({
[`&.${classes.root}`]: {
flexGrow: 1,
},
logo: {
[`& .${classes.logo}`]: {
width: 50,
height: 43.54,
},
});

const Header = () => {
const classes = useStyles();
const match = useRouteMatch(['/contacts', '/companies', '/deals']);
const currentPath = match?.path ?? '/';

return (
<nav className={classes.root}>
<Root className={classes.root}>
<AppBar position="static" color="primary">
<Toolbar variant="dense">
<Box flex={1} display="flex" justifyContent="space-between">
Expand Down Expand Up @@ -74,7 +80,7 @@ const Header = () => {
</Box>
</Toolbar>
</AppBar>
</nav>
</Root>
);
};

Expand Down
8 changes: 3 additions & 5 deletions examples/crm/src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { Component, ErrorInfo, HtmlHTMLAttributes } from 'react';
import PropTypes from 'prop-types';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { createMuiTheme } from '@material-ui/core/styles';
import { ThemeProvider } from '@material-ui/styles';
import { CssBaseline, Container } from '@material-ui/core';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { CssBaseline, Container } from '@mui/material';
import { CoreLayoutProps } from 'react-admin';

import { Notification, Error } from 'react-admin';
Expand Down Expand Up @@ -42,8 +41,7 @@ class Layout extends Component<LayoutProps, LayoutState> {
const { theme, title, children } = this.props;
const { hasError, errorMessage, errorInfo } = this.state;
return (
// @ts-ignore
<ThemeProvider theme={createMuiTheme(theme)}>
<ThemeProvider theme={createTheme(theme)}>
<CssBaseline />
<Header />
<Container>
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/companies/CompanyAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
EditButton,
ShowButton,
} from 'react-admin';
import { Box, Typography, Divider, Link } from '@material-ui/core';
import { Box, Typography, Divider, Link } from '@mui/material';

import { Company, Sale } from '../types';

Expand Down
28 changes: 18 additions & 10 deletions examples/crm/src/companies/CompanyAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import * as React from 'react';
import { Avatar } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import { styled } from '@mui/material/styles';
import { Avatar } from '@mui/material';
import clsx from 'clsx';

import { Company } from '../types';

const useStyles = makeStyles({
avatar: {
const PREFIX = 'CompanyAvatar';

const classes = {
avatar: `${PREFIX}-avatar`,
img: `${PREFIX}-img`,
small: `${PREFIX}-small`,
large: `${PREFIX}-large`,
};

const StyledAvatar = styled(Avatar)({
[`& .${classes.avatar}`]: {
width: 60,
height: 60,
backgroundColor: 'aliceblue',
},
img: {
[`& .${classes.img}`]: {
objectFit: 'contain',
},
small: {
[`& .${classes.small}`]: {
width: 20,
height: 20,
},
large: {
[`& .${classes.large}`]: {
width: 40,
height: 40,
},
Expand All @@ -31,14 +40,13 @@ export const CompanyAvatar = ({
record?: Company;
size?: 'small' | 'large';
}) => {
const classes = useStyles();
if (!record) return null;
return (
<Avatar
<StyledAvatar
src={process.env.PUBLIC_URL + record.logo}
alt={record.name}
className={classes.avatar}
imgProps={{ className: clsx(classes.img, classes[size]) }}
imgProps={{ className: clsx(classes.img, size) }}
/>
);
};
Loading