Skip to content

Commit 3fe9a68

Browse files
authored
fix(orchestrator): various fixes for mixed v4 and v5 material UI (#989)
* fix(orchestrator):various fixes for mixed v4 and v5 material UI Signed-off-by: Marek Libra <marek.libra@gmail.com> * yarn.lock --------- Signed-off-by: Marek Libra <marek.libra@gmail.com>
1 parent 22e947b commit 3fe9a68

9 files changed

Lines changed: 51 additions & 46 deletions

File tree

workspaces/orchestrator/plugins/orchestrator-form-widgets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@red-hat-developer-hub/backstage-plugin-orchestrator-form-api": "workspace:^",
6262
"@rjsf/material-ui": "^5.21.2",
6363
"@rjsf/utils": "^5.21.2",
64+
"clsx": "^2.1.1",
6465
"json-schema": "^0.4.0",
6566
"jsonata": "^2.0.6",
6667
"lodash": "^4.17.21",

workspaces/orchestrator/plugins/orchestrator-form-widgets/src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';
17-
18-
ClassNameGenerator.configure(componentName => {
19-
return componentName.startsWith('v5-')
20-
? componentName
21-
: `v5-${componentName}`;
22-
});
2316

2417
export {
2518
orchestratorFormWidgetsPlugin,

workspaces/orchestrator/plugins/orchestrator-form-widgets/src/widgets/ActiveDropdown.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import React, { useCallback, useEffect, useMemo, useState } from 'react';
17+
import { makeStyles } from 'tss-react/mui';
1718
import { Widget } from '@rjsf/utils';
1819
import { JsonObject } from '@backstage/types';
1920
import { JSONSchema7 } from 'json-schema';
@@ -34,11 +35,23 @@ import {
3435
import { UiProps } from '../uiPropTypes';
3536
import { ErrorText } from './ErrorText';
3637

38+
const useStyles = makeStyles()(_ => ({
39+
menuItem: {
40+
// Workaround, we still have mix of Material 4 and 5 CSS in production, conflict with MuiButtonBase-root
41+
display: 'flex !important',
42+
justifyContent: 'flex-start !important',
43+
paddingTop: '8px !important',
44+
paddingBottom: '8px !important',
45+
paddingLeft: '16px !important',
46+
},
47+
}));
48+
3749
export const ActiveDropdown: Widget<
3850
JsonObject,
3951
JSONSchema7,
4052
OrchestratorFormContextProps
4153
> = props => {
54+
const { classes } = useStyles();
4255
const templateUnitEvaluator = useTemplateUnitEvaluator();
4356

4457
const { id, label, value, onChange, formContext } = props;
@@ -130,6 +143,7 @@ export const ActiveDropdown: Widget<
130143
key={values[idx]}
131144
value={values[idx]}
132145
data-testid={`${id}-menuitem-${values[idx]}`}
146+
className={classes.menuItem}
133147
>
134148
{itemLabel}
135149
</MenuItem>

workspaces/orchestrator/plugins/orchestrator-form-widgets/src/widgets/ActiveMultiSelect.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
* limitations under the License.
1515
*/
1616
import React, { useEffect, useMemo, useState } from 'react';
17+
import clsx from 'clsx';
1718

1819
import { makeStyles } from 'tss-react/mui';
20+
import { Theme } from '@mui/material/styles';
1921
import Box from '@mui/material/Box';
2022
import Autocomplete, { AutocompleteValue } from '@mui/material/Autocomplete';
2123
import FormControl from '@mui/material/FormControl';
@@ -37,14 +39,15 @@ import {
3739
import { UiProps } from '../uiPropTypes';
3840
import { ErrorText } from './ErrorText';
3941

40-
const useStyles = makeStyles()(_ => ({
41-
chipBox: {
42-
'& > div': {
43-
// not referencing the chip's <div> directly to avoid interference with getTagProps()
44-
'margin-bottom': 0,
42+
const useStyles = makeStyles()(
43+
(theme: Theme & { rhdh?: { cardBorderColor: string } }) => ({
44+
chip: {
45+
// Workaround, we still have mix of Material 4 and 5 CSS in production, conflict with MuiButtonBase-root
46+
borderRadius: `16px !important` /* theme.shape.borderRadius is ugly 8px */,
47+
outline: `1px solid ${theme.rhdh?.cardBorderColor ?? '#A3A3A3'} !important`,
4548
},
46-
},
47-
}));
49+
}),
50+
);
4851

4952
export const ActiveMultiSelect: Widget<
5053
JsonObject,
@@ -147,16 +150,20 @@ export const ActiveMultiSelect: Widget<
147150
/>
148151
)}
149152
renderTags={(values, getTagProps) =>
150-
values.map((item, index) => (
151-
<Box key={item} title={item} className={classes.chipBox}>
152-
<Chip
153-
data-testid={`${id}-chip-${item}`}
154-
variant="outlined"
155-
label={item}
156-
{...getTagProps({ index })}
157-
/>
158-
</Box>
159-
))
153+
values.map((item, index) => {
154+
const tagProps = getTagProps({ index });
155+
tagProps.className = clsx(tagProps.className, classes.chip);
156+
return (
157+
<Box key={item} title={item}>
158+
<Chip
159+
data-testid={`${id}-chip-${item}`}
160+
variant="outlined"
161+
label={item}
162+
{...tagProps}
163+
/>
164+
</Box>
165+
);
166+
})
160167
}
161168
/>
162169
</FormControl>

workspaces/orchestrator/plugins/orchestrator/src/components/InfoDialog.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export type ParentComponentRef = HTMLDivElement;
4040

4141
const useStyles = makeStyles()(theme => ({
4242
closeBtn: {
43-
position: 'absolute',
44-
right: theme.spacing(1),
45-
top: theme.spacing(1),
43+
flexShrink: 0,
4644
},
4745
dialogActions: {
4846
justifyContent: 'flex-start',
@@ -51,7 +49,9 @@ const useStyles = makeStyles()(theme => ({
5149
},
5250
titleContainer: {
5351
display: 'flex',
54-
alignItems: 'center',
52+
},
53+
title: {
54+
width: '100%',
5555
},
5656
titleIcon: {
5757
marginRight: theme.spacing(1),
@@ -86,9 +86,11 @@ export const RefForwardingInfoDialog: ForwardRefRenderFunction<
8686
<DialogTitle>
8787
<Box className={classes.titleContainer}>
8888
{titleIcon && <Box className={classes.titleIcon}>{titleIcon}</Box>}
89-
<Typography variant="h4">
89+
90+
<Typography variant="h4" className={classes.title}>
9091
<b>{title}</b>
9192
</Typography>
93+
9294
<IconButton
9395
className={classes.closeBtn}
9496
aria-label="close"

workspaces/orchestrator/plugins/orchestrator/src/components/WorkflowInstancePage/WorkflowInstancePageContent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ const useStyles = makeStyles()(() => ({
7171
topRowCard: {
7272
height: '24rem',
7373
overflow: 'auto',
74+
'& > div:nth-child(2)': {
75+
overflow: 'auto',
76+
},
7477
},
7578
bottomRowCard: {
7679
height: '42rem',

workspaces/orchestrator/plugins/orchestrator/src/components/WorkflowRunDetails.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { AboutField } from '@backstage/plugin-catalog';
2323

2424
import Grid from '@mui/material/Grid';
2525
import Typography from '@mui/material/Typography';
26-
import { makeStyles } from 'tss-react/mui';
2726

2827
import {
2928
capitalize,
@@ -44,17 +43,10 @@ type WorkflowDetailsCardProps = {
4443
details: WorkflowRunDetail;
4544
};
4645

47-
const useStyles = makeStyles()(() => ({
48-
root: {
49-
overflowY: 'auto',
50-
},
51-
}));
52-
5346
export const WorkflowRunDetails: React.FC<WorkflowDetailsCardProps> = ({
5447
assessedBy,
5548
details,
5649
}) => {
57-
const { classes } = useStyles();
5850
const orchestratorApi = useApi(orchestratorApiRef);
5951
const { value, loading, error } =
6052
useAsync(async (): Promise<WorkflowOverviewDTO> => {
@@ -67,7 +59,7 @@ export const WorkflowRunDetails: React.FC<WorkflowDetailsCardProps> = ({
6759
const workflowPageLink = useRouteRef(workflowRouteRef);
6860

6961
return (
70-
<Grid container className={classes.root} alignContent="flex-start">
62+
<Grid container alignContent="flex-start">
7163
<Grid item md={7} key="Workflow">
7264
<AboutField label="Workflow">
7365
<Link to={workflowPageLink({ workflowId: details.workflowId })}>

workspaces/orchestrator/plugins/orchestrator/src/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,5 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';
18-
19-
ClassNameGenerator.configure(componentName => {
20-
return componentName.startsWith('v5-')
21-
? componentName
22-
: `v5-${componentName}`;
23-
});
24-
2517
export { orchestratorPlugin, OrchestratorPage } from './plugin';
2618
export { default as OrchestratorIcon } from './components/OrchestratorIcon';

workspaces/orchestrator/yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11534,6 +11534,7 @@ __metadata:
1153411534
"@testing-library/jest-dom": ^6.0.0
1153511535
"@testing-library/react": ^14.0.0
1153611536
"@testing-library/user-event": ^14.0.0
11537+
clsx: ^2.1.1
1153711538
express: ^5.1.0
1153811539
json-schema: ^0.4.0
1153911540
jsonata: ^2.0.6

0 commit comments

Comments
 (0)