Skip to content

Commit d69d6d6

Browse files
authored
chore(ai-integration): migrate MUIv4 to MUIv5 (#3609)
* chore(ai-integration): migrate MUIv4 to MUIv5 Signed-off-by: Yi Cai <yicai@redhat.com> * added eslint rule to avoid MUIv4 import Signed-off-by: Yi Cai <yicai@redhat.com> --------- Signed-off-by: Yi Cai <yicai@redhat.com>
1 parent 06755cb commit d69d6d6

21 files changed

Lines changed: 1610 additions & 1952 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-ai-experience': patch
3+
---
4+
5+
Replace Material UI v4 imports with MUI v5, add StylesProvider with createGenerateClassName seed prefix to prevent CSS collisions, and migrate makeStyles to sx prop.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const materialUiMigrationEslintConfig = {
18+
restrictedImports: [
19+
{
20+
name: '@material-ui/core',
21+
message: 'Use @mui/material instead of Material UI v4.',
22+
},
23+
{
24+
name: '@material-ui/icons',
25+
message:
26+
"Use '@mui/icons-material/<Icon>' instead of Material UI v4 (e.g. import MenuIcon from '@mui/icons-material/Menu').",
27+
},
28+
{
29+
name: '@material-ui/lab',
30+
message: 'Use @mui/material instead of Material UI v4.',
31+
},
32+
{
33+
name: '@material-ui/styles',
34+
message:
35+
'Use @mui/styles, @mui/material (sx/styled), or Backstage UI instead of Material UI v4.',
36+
},
37+
],
38+
restrictedImportPatterns: ['@material-ui/*'],
39+
};
40+
41+
/**
42+
* ESLint config for frontend packages in this workspace (MUI v4 migration guards).
43+
*/
44+
module.exports = function createEslintConfig(packageDir) {
45+
return require('@backstage/cli/config/eslint-factory')(
46+
packageDir,
47+
materialUiMigrationEslintConfig,
48+
);
49+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-user
3+
apiVersion: backstage.io/v1alpha1
4+
kind: User
5+
metadata:
6+
name: guest
7+
spec:
8+
memberOf: [guests]
9+
---
10+
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-group
11+
apiVersion: backstage.io/v1alpha1
12+
kind: Group
13+
metadata:
14+
name: guests
15+
spec:
16+
type: team
17+
children: []

workspaces/ai-integrations/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"resolutions": {
5252
"@types/react": "^18",
5353
"@types/react-dom": "^18",
54-
"isolated-vm": "^6.0.1"
54+
"isolated-vm": "^6.0.1",
55+
"@backstage/plugin-catalog": "2.0.1",
56+
"@backstage/plugin-catalog-react": "^2.1.1"
5557
},
5658
"prettier": "@backstage/cli/config/prettier",
5759
"lint-staged": {

workspaces/ai-integrations/packages/app/.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
16+
17+
// eslint-disable-next-line @backstage/no-relative-monorepo-imports -- workspace ESLint shared config
18+
module.exports = require('../../eslint.frontend-shared.cjs')(__dirname);

workspaces/ai-integrations/packages/app/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
"@backstage/core-plugin-api": "^1.12.7",
2828
"@backstage/integration-react": "^1.2.19",
2929
"@backstage/plugin-api-docs": "^0.14.2",
30-
"@backstage/plugin-catalog": "^2.0.6",
30+
"@backstage/plugin-catalog": "^2.0.1",
3131
"@backstage/plugin-catalog-common": "^1.1.10",
3232
"@backstage/plugin-catalog-graph": "^0.6.5",
3333
"@backstage/plugin-catalog-import": "^0.13.14",
34-
"@backstage/plugin-catalog-react": "^3.1.0",
34+
"@backstage/plugin-catalog-react": "^2.1.1",
3535
"@backstage/plugin-kubernetes": "^0.12.20",
3636
"@backstage/plugin-org": "^0.7.5",
3737
"@backstage/plugin-permission-react": "^0.5.2",
@@ -44,10 +44,10 @@
4444
"@backstage/plugin-user-settings": "^0.9.4",
4545
"@backstage/theme": "^0.7.3",
4646
"@backstage/ui": "^0.16.0",
47-
"@material-ui/core": "^4.12.2",
48-
"@material-ui/icons": "^4.9.1",
47+
"@mui/icons-material": "5.18.0",
48+
"@mui/material": "5.18.0",
4949
"@red-hat-developer-hub/backstage-plugin-ai-experience": "workspace:^",
50-
"@red-hat-developer-hub/backstage-plugin-global-header": "^1.4.0",
50+
"@red-hat-developer-hub/backstage-plugin-global-header": "^1.21.0",
5151
"@red-hat-developer-hub/backstage-plugin-theme": "^0.14.0",
5252
"react": "^18.0.2",
5353
"react-dom": "^18.0.2",

workspaces/ai-integrations/packages/app/src/components/Root/LogoFull.tsx

Lines changed: 9 additions & 18 deletions
Large diffs are not rendered by default.

workspaces/ai-integrations/packages/app/src/components/Root/LogoIcon.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,22 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { makeStyles } from '@material-ui/core';
17-
18-
const useStyles = makeStyles({
19-
svg: {
20-
width: 'auto',
21-
height: 28,
22-
},
23-
path: {
24-
fill: '#7df3e1',
25-
},
26-
});
16+
import Box from '@mui/material/Box';
2717

2818
const LogoIcon = () => {
29-
const classes = useStyles();
30-
3119
return (
32-
<svg
33-
className={classes.svg}
20+
<Box
21+
component="svg"
22+
sx={{ width: 'auto', height: 28 }}
3423
xmlns="http://www.w3.org/2000/svg"
3524
viewBox="0 0 337.46 428.5"
3625
>
37-
<path
38-
className={classes.path}
26+
<Box
27+
component="path"
28+
sx={{ fill: '#7df3e1' }}
3929
d="M303,166.05a80.69,80.69,0,0,0,13.45-10.37c.79-.77,1.55-1.53,2.3-2.3a83.12,83.12,0,0,0,7.93-9.38A63.69,63.69,0,0,0,333,133.23a48.58,48.58,0,0,0,4.35-16.4c1.49-19.39-10-38.67-35.62-54.22L198.56,0,78.3,115.23,0,190.25l108.6,65.91a111.59,111.59,0,0,0,57.76,16.41c24.92,0,48.8-8.8,66.42-25.69,19.16-18.36,25.52-42.12,13.7-61.87a49.22,49.22,0,0,0-6.8-8.87A89.17,89.17,0,0,0,259,178.29h.15a85.08,85.08,0,0,0,31-5.79A80.88,80.88,0,0,0,303,166.05ZM202.45,225.86c-19.32,18.51-50.4,21.23-75.7,5.9L51.61,186.15l67.45-64.64,76.41,46.38C223,184.58,221.49,207.61,202.45,225.86Zm8.93-82.22-70.65-42.89L205.14,39,274.51,81.1c25.94,15.72,29.31,37,10.55,55A60.69,60.69,0,0,1,211.38,143.64Zm29.86,190c-19.57,18.75-46.17,29.09-74.88,29.09a123.73,123.73,0,0,1-64.1-18.2L0,282.52v24.67L108.6,373.1a111.6,111.6,0,0,0,57.76,16.42c24.92,0,48.8-8.81,66.42-25.69,12.88-12.34,20-27.13,19.68-41.49v-1.79A87.27,87.27,0,0,1,241.24,333.68Zm0-39c-19.57,18.75-46.17,29.08-74.88,29.08a123.81,123.81,0,0,1-64.1-18.19L0,243.53v24.68l108.6,65.91a111.6,111.6,0,0,0,57.76,16.42c24.92,0,48.8-8.81,66.42-25.69,12.88-12.34,20-27.13,19.68-41.5v-1.78A87.27,87.27,0,0,1,241.24,294.7Zm0-39c-19.57,18.76-46.17,29.09-74.88,29.09a123.81,123.81,0,0,1-64.1-18.19L0,204.55v24.68l108.6,65.91a111.59,111.59,0,0,0,57.76,16.41c24.92,0,48.8-8.8,66.42-25.68,12.88-12.35,20-27.13,19.68-41.5v-1.82A86.09,86.09,0,0,1,241.24,255.71Zm83.7,25.74a94.15,94.15,0,0,1-60.2,25.86h0V334a81.6,81.6,0,0,0,51.74-22.37c14-13.38,21.14-28.11,21-42.64v-2.19A94.92,94.92,0,0,1,324.94,281.45Zm-83.7,91.21c-19.57,18.76-46.17,29.09-74.88,29.09a123.73,123.73,0,0,1-64.1-18.2L0,321.5v24.68l108.6,65.9a111.6,111.6,0,0,0,57.76,16.42c24.92,0,48.8-8.8,66.42-25.69,12.88-12.34,20-27.13,19.68-41.49v-1.79A86.29,86.29,0,0,1,241.24,372.66ZM327,162.45c-.68.69-1.35,1.38-2.05,2.06a94.37,94.37,0,0,1-10.64,8.65,91.35,91.35,0,0,1-11.6,7,94.53,94.53,0,0,1-26.24,8.71,97.69,97.69,0,0,1-14.16,1.57c.5,1.61.9,3.25,1.25,4.9a53.27,53.27,0,0,1,1.14,12V217h.05a84.41,84.41,0,0,0,25.35-5.55,81,81,0,0,0,26.39-16.82c.8-.77,1.5-1.56,2.26-2.34a82.08,82.08,0,0,0,7.93-9.38A63.76,63.76,0,0,0,333,172.17a48.55,48.55,0,0,0,4.32-16.45c.09-1.23.2-2.47.19-3.7V150q-1.08,1.54-2.25,3.09A96.73,96.73,0,0,1,327,162.45Zm0,77.92c-.69.7-1.31,1.41-2,2.1a94.2,94.2,0,0,1-60.2,25.86h0l0,26.67h0a81.6,81.6,0,0,0,51.74-22.37A73.51,73.51,0,0,0,333,250.13a48.56,48.56,0,0,0,4.32-16.44c.09-1.24.2-2.47.19-3.71v-2.19c-.74,1.07-1.46,2.15-2.27,3.21A95.68,95.68,0,0,1,327,240.37Zm0-39c-.69.7-1.31,1.41-2,2.1a93.18,93.18,0,0,1-10.63,8.65,91.63,91.63,0,0,1-11.63,7,95.47,95.47,0,0,1-37.94,10.18h0V256h0a81.65,81.65,0,0,0,51.74-22.37c.8-.77,1.5-1.56,2.26-2.34a82.08,82.08,0,0,0,7.93-9.38A63.76,63.76,0,0,0,333,211.15a48.56,48.56,0,0,0,4.32-16.44c.09-1.24.2-2.48.19-3.71v-2.2c-.74,1.08-1.46,2.16-2.27,3.22A95.68,95.68,0,0,1,327,201.39Z"
4030
/>
41-
</svg>
31+
</Box>
4232
);
4333
};
4434

workspaces/ai-integrations/packages/app/src/components/Root/Root.tsx

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
* limitations under the License.
1515
*/
1616
import { PropsWithChildren } from 'react';
17-
import { makeStyles } from '@material-ui/core';
18-
import HomeIcon from '@material-ui/icons/Home';
19-
import ExtensionIcon from '@material-ui/icons/Extension';
20-
import LibraryBooks from '@material-ui/icons/LibraryBooks';
21-
import CreateComponentIcon from '@material-ui/icons/AddCircleOutline';
17+
import Box from '@mui/material/Box';
18+
import HomeIcon from '@mui/icons-material/Home';
19+
import ExtensionIcon from '@mui/icons-material/Extension';
20+
import LibraryBooks from '@mui/icons-material/LibraryBooks';
21+
import CreateComponentIcon from '@mui/icons-material/AddCircleOutline';
22+
import MenuIcon from '@mui/icons-material/Menu';
23+
import SearchIcon from '@mui/icons-material/Search';
24+
import GroupIcon from '@mui/icons-material/People';
2225
import LogoFull from './LogoFull';
2326
import LogoIcon from './LogoIcon';
2427
import {
@@ -39,40 +42,38 @@ import {
3942
Link,
4043
CatalogIcon,
4144
} from '@backstage/core-components';
42-
import MenuIcon from '@material-ui/icons/Menu';
43-
import SearchIcon from '@material-ui/icons/Search';
4445
import { MyGroupsSidebarItem } from '@backstage/plugin-org';
45-
import GroupIcon from '@material-ui/icons/People';
4646
import {
4747
GlobalHeaderComponent,
4848
defaultGlobalHeaderComponentsMountPoints,
4949
} from '@red-hat-developer-hub/backstage-plugin-global-header';
5050

51-
const useSidebarLogoStyles = makeStyles({
52-
root: {
53-
width: sidebarConfig.drawerWidthClosed,
54-
height: 3 * sidebarConfig.logoHeight,
55-
display: 'flex',
56-
flexFlow: 'row nowrap',
57-
alignItems: 'center',
58-
marginBottom: -14,
59-
},
60-
link: {
61-
width: sidebarConfig.drawerWidthClosed,
62-
marginLeft: 24,
63-
},
64-
});
65-
6651
const SidebarLogo = () => {
67-
const classes = useSidebarLogoStyles();
6852
const { isOpen } = useSidebarOpenState();
6953

7054
return (
71-
<div className={classes.root}>
72-
<Link to="/" underline="none" className={classes.link} aria-label="Home">
55+
<Box
56+
sx={{
57+
width: sidebarConfig.drawerWidthClosed,
58+
height: 3 * sidebarConfig.logoHeight,
59+
display: 'flex',
60+
flexFlow: 'row nowrap',
61+
alignItems: 'center',
62+
mb: '-14px',
63+
}}
64+
>
65+
<Link
66+
to="/"
67+
underline="none"
68+
aria-label="Home"
69+
style={{
70+
width: sidebarConfig.drawerWidthClosed,
71+
marginLeft: 24,
72+
}}
73+
>
7374
{isOpen ? <LogoFull /> : <LogoIcon />}
7475
</Link>
75-
</div>
76+
</Box>
7677
);
7778
};
7879

workspaces/ai-integrations/packages/app/src/components/catalog/EntityPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { Button, Grid } from '@material-ui/core';
16+
import Button from '@mui/material/Button';
17+
import Grid from '@mui/material/Grid';
1718
import {
1819
EntityApiDefinitionCard,
1920
EntityConsumedApisCard,

0 commit comments

Comments
 (0)