Skip to content

Commit fef0f60

Browse files
authored
fix(ocm): replace usage of pf-icons to mui icons (#2275)
1 parent 2bebc8c commit fef0f60

File tree

11 files changed

+96
-47
lines changed

11 files changed

+96
-47
lines changed

.changeset/green-trees-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@janus-idp/shared-react": minor
3+
---
4+
5+
Modified the package to enable the StatusIcon component to accept className as a prop

.changeset/hip-walls-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@janus-idp/backstage-plugin-ocm": minor
3+
---
4+
5+
replaced pf-icons with mui icons

plugins/ocm/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ catalog:
187187
yarn workspace app add @janus-idp/backstage-plugin-ocm
188188
```
189189

190-
1. Select the components that you want to use, such as:
190+
2. Select the components that you want to use, such as:
191191

192192
- `OcmPage`: This is a standalone page or dashboard displaying all clusters as tiles. You can add `OcmPage` to `packages/app/src/App.tsx` file as follows:
193193

@@ -208,15 +208,15 @@ catalog:
208208

209209
```tsx title="packages/app/src/components/Root/Root.tsx"
210210
/* highlight-add-next-line */
211-
import StorageIcon from '@material-ui/icons/Storage';
211+
import { OcmIcon } from '@janus-idp/backstage-plugin-ocm';
212212
213213
export const Root = ({ children }: PropsWithChildren<{}>) => (
214214
<SidebarPage>
215215
<Sidebar>
216216
<SidebarGroup label="Menu" icon={<MenuIcon />}>
217217
{/* ... */}
218218
{/* highlight-add-next-line */}
219-
<SidebarItem icon={StorageIcon} to="ocm" text="Clusters" />
219+
<SidebarItem icon={OcmIcon} to="ocm" text="Clusters" />
220220
</SidebarGroup>
221221
{/* ... */}
222222
</Sidebar>

plugins/ocm/dev/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
ClusterContextProvider,
2020
ClusterInfoCard,
2121
} from '../src';
22-
import { OcmPage, ocmPlugin } from '../src/plugin';
22+
import { OcmIcon, OcmPage, ocmPlugin } from '../src/plugin';
2323

2424
const clusterEntity = (name: string): Entity => ({
2525
apiVersion: 'backstage.io/v1beta1',
@@ -87,8 +87,9 @@ createDevApp()
8787
.addThemes(getAllThemes())
8888
.addPage({
8989
element: <OcmPage />,
90-
title: 'Root Page',
90+
title: 'Clusters',
9191
path: '/ocm',
92+
icon: OcmIcon,
9293
})
9394
.addPage({
9495
path: '/catalog/:kind/:namespace/:name',

plugins/ocm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"@material-ui/core": "^4.9.13",
5151
"@material-ui/icons": "^4.11.3",
5252
"@material-ui/lab": "^4.0.0-alpha.45",
53+
"@mui/icons-material": "^5.16.4",
5354
"@patternfly/patternfly": "^5.1.0",
54-
"@patternfly/react-icons": "^5.1.1",
5555
"react-use": "^17.4.0",
5656
"semver": "^7.5.4"
5757
},

plugins/ocm/src/components/common.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@backstage/core-components';
88

99
import { Button, Grid, makeStyles, Tooltip } from '@material-ui/core';
10-
import { ArrowCircleUpIcon } from '@patternfly/react-icons';
10+
import ArrowCircleUpIcon from '@mui/icons-material/ArrowCircleUp';
1111

1212
import { ClusterStatus } from '@janus-idp/backstage-plugin-ocm-common';
1313

plugins/ocm/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
export { ocmPlugin, OcmPage } from './plugin';
1+
export { ocmPlugin, OcmPage, OcmIcon } from './plugin';
22
export { ClusterAvailableResourceCard } from './components/ClusterAvailableResourcesCard';
33
export {
44
ClusterContextProvider,
55
useCluster,
66
} from './components/ClusterContext';
77
export { ClusterInfoCard } from './components/ClusterInfoCard';
8-
export { default as OcmIcon } from '@material-ui/icons/Storage';

plugins/ocm/src/plugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import {
33
createApiFactory,
44
createPlugin,
55
createRoutableExtension,
6+
IconComponent,
67
identityApiRef,
78
} from '@backstage/core-plugin-api';
89

10+
import HubOutlinedIcon from '@mui/icons-material/HubOutlined';
11+
912
import { OcmApiClient, OcmApiRef } from './api';
1013
import { rootRouteRef } from './routes';
1114

@@ -35,3 +38,5 @@ export const OcmPage = ocmPlugin.provide(
3538
mountPoint: rootRouteRef,
3639
}),
3740
);
41+
42+
export const OcmIcon = HubOutlinedIcon as IconComponent;

plugins/shared-react/src/components/common/Status.tsx

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ import {
99
StatusWarning,
1010
} from '@backstage/core-components';
1111

12-
import { makeStyles } from '@material-ui/core';
12+
import { createStyles, makeStyles, Theme } from '@material-ui/core';
1313
import OffIcon from '@mui/icons-material/DoNotDisturbOnOutlined';
1414
import UnknownIcon from '@mui/icons-material/HelpOutline';
1515
import AngleDoubleRightIcon from '@mui/icons-material/KeyboardDoubleArrowRight';
1616
import BanIcon from '@mui/icons-material/NotInterestedOutlined';
1717
import PauseIcon from '@mui/icons-material/PauseCircleOutlineOutlined';
18+
import cx from 'classnames';
1819

1920
import { StatusIconAndText } from './StatusIconAndText';
2021

21-
const useStyles = makeStyles({
22-
iconStyles: {
23-
height: '0.8em',
24-
width: '0.8em',
25-
top: '0.125em',
26-
position: 'relative',
27-
flexShrink: 0,
28-
marginRight: '8px',
29-
},
30-
});
22+
const useStyles = makeStyles<Theme>(theme =>
23+
createStyles({
24+
iconStyles: {
25+
height: '0.8em',
26+
width: '0.8em',
27+
top: '0.125em',
28+
position: 'relative',
29+
flexShrink: 0,
30+
marginRight: theme.spacing(0.6),
31+
},
32+
}),
33+
);
3134

3235
const DASH = '-';
3336

@@ -59,37 +62,43 @@ const useStatusStyles = makeStyles(theme => ({
5962
},
6063
}));
6164

62-
const StatusIcon = ({ statusKey }: { statusKey: StatusClassKey }) => {
65+
const StatusIcon = ({
66+
statusKey,
67+
className,
68+
}: {
69+
statusKey: StatusClassKey;
70+
className?: string;
71+
}) => {
6372
const statusStyles = useStatusStyles();
6473

6574
switch (statusKey) {
6675
case 'ok':
6776
return (
68-
<g className={statusStyles.success}>
77+
<g className={cx(statusStyles.success, className)}>
6978
<StatusOK />{' '}
7079
</g>
7180
);
7281
case 'pending':
7382
return (
74-
<g className={statusStyles.pending}>
83+
<g className={cx(statusStyles.pending, className)}>
7584
<StatusPending />{' '}
7685
</g>
7786
);
7887
case 'running':
7988
return (
80-
<g className={statusStyles.running}>
89+
<g className={cx(statusStyles.running, className)}>
8190
<StatusRunning />{' '}
8291
</g>
8392
);
8493
case 'warning':
8594
return (
86-
<g className={statusStyles.warning}>
95+
<g className={cx(statusStyles.warning, className)}>
8796
<StatusWarning />{' '}
8897
</g>
8998
);
9099
case 'error':
91100
return (
92-
<g className={statusStyles.error}>
101+
<g className={cx(statusStyles.error, className)}>
93102
<StatusError />{' '}
94103
</g>
95104
);
@@ -103,6 +112,7 @@ const StatusIcon = ({ statusKey }: { statusKey: StatusClassKey }) => {
103112
* @param {string} status - type of status to be displayed
104113
* @param {boolean} [iconOnly] - (optional) if true, only displays icon
105114
* @param {string} [className] - (optional) additional class name for the component
115+
* @param {string} [displayStatusText] - (optional) use a different text to display the status
106116
107117
* @example
108118
* ```tsx
@@ -114,17 +124,24 @@ export const Status = ({
114124
iconOnly,
115125
className,
116126
displayStatusText,
127+
dataTestId,
128+
iconStyles,
129+
iconClassName,
117130
}: {
118131
status: string | null;
119132
displayStatusText?: string;
120133
iconOnly?: boolean;
121134
className?: string;
135+
dataTestId?: string;
136+
iconStyles?: React.CSSProperties;
137+
iconClassName?: string;
122138
}): React.ReactElement => {
123139
const classes = useStyles();
124140
const statusProps = {
125141
title: displayStatusText || status || '',
126142
iconOnly,
127143
className,
144+
dataTestId,
128145
};
129146

130147
switch (status) {
@@ -135,12 +152,13 @@ export const Status = ({
135152
return (
136153
<StatusIconAndText
137154
{...statusProps}
138-
icon={<StatusIcon statusKey="pending" />}
155+
icon={<StatusIcon statusKey="pending" className={iconClassName} />}
139156
/>
140157
);
141158

142159
case 'In Progress':
143160
case 'Progress':
161+
case 'Progressing':
144162
case 'Installing':
145163
case 'InstallReady':
146164
case 'Replacing':
@@ -151,7 +169,7 @@ export const Status = ({
151169
return (
152170
<StatusIconAndText
153171
{...statusProps}
154-
icon={<StatusIcon statusKey="running" />}
172+
icon={<StatusIcon statusKey="running" className={iconClassName} />}
155173
/>
156174
);
157175

@@ -166,7 +184,7 @@ export const Status = ({
166184
return (
167185
<StatusIconAndText
168186
{...statusProps}
169-
icon={<BanIcon className={classes.iconStyles} />}
187+
icon={<BanIcon className={classes.iconStyles} style={iconStyles} />}
170188
/>
171189
);
172190

@@ -175,58 +193,67 @@ export const Status = ({
175193
return (
176194
<StatusIconAndText
177195
{...statusProps}
178-
icon={<StatusIcon statusKey="warning" />}
196+
icon={<StatusIcon statusKey="warning" className={iconClassName} />}
179197
/>
180198
);
181199

182200
case 'ImagePullBackOff':
183201
case 'Error':
184202
case 'Failed':
203+
case 'Failure':
185204
case 'CrashLoopBackOff':
186205
case 'ErrImagePull':
187206
return (
188207
<StatusIconAndText
189208
{...statusProps}
190-
icon={<StatusIcon statusKey="error" />}
209+
icon={<StatusIcon statusKey="error" className={iconClassName} />}
191210
/>
192211
);
193212

194213
case 'Completed':
195214
case 'Succeeded':
215+
case 'Synced':
196216
return (
197217
<StatusIconAndText
198218
{...statusProps}
199-
icon={<StatusIcon statusKey="ok" />}
219+
icon={<StatusIcon statusKey="ok" className={iconClassName} />}
200220
/>
201221
);
202222

203223
case 'Skipped':
204224
return (
205225
<StatusIconAndText
206226
{...statusProps}
207-
icon={<AngleDoubleRightIcon className={classes.iconStyles} />}
227+
icon={
228+
<AngleDoubleRightIcon
229+
className={classes.iconStyles}
230+
style={iconStyles}
231+
/>
232+
}
208233
/>
209234
);
210235
case 'Paused':
211236
return (
212237
<StatusIconAndText
213238
{...statusProps}
214-
icon={<PauseIcon className={classes.iconStyles} />}
239+
icon={<PauseIcon className={classes.iconStyles} style={iconStyles} />}
215240
/>
216241
);
217242
case 'Stopped':
218243
return (
219244
<StatusIconAndText
220245
{...statusProps}
221-
icon={<OffIcon className={classes.iconStyles} />}
246+
icon={<OffIcon className={classes.iconStyles} style={iconStyles} />}
222247
/>
223248
);
224249

225250
case 'Unknown':
226251
return (
227252
<StatusIconAndText
228253
{...statusProps}
229-
icon={<UnknownIcon className={classes.iconStyles} />}
254+
icon={
255+
<UnknownIcon className={classes.iconStyles} style={iconStyles} />
256+
}
230257
/>
231258
);
232259

plugins/shared-react/src/components/common/StatusIconAndText.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ import CamelCaseWrap from './CamelCaseWrap';
66

77
import './StatusIconAndText.css';
88

9-
type StatusIconAndTextProps = {
10-
title: string;
11-
iconOnly?: boolean;
12-
className?: string;
13-
icon: React.ReactElement;
14-
spin?: boolean;
15-
};
16-
179
const DASH = '-';
1810

1911
export const StatusIconAndText = ({
@@ -22,7 +14,15 @@ export const StatusIconAndText = ({
2214
spin,
2315
iconOnly,
2416
className,
25-
}: StatusIconAndTextProps): React.ReactElement => {
17+
dataTestId,
18+
}: {
19+
title: string;
20+
iconOnly?: boolean;
21+
className?: string;
22+
icon: React.ReactElement;
23+
spin?: boolean;
24+
dataTestId?: string;
25+
}): React.ReactElement => {
2626
if (!title) {
2727
return <>{DASH}</>;
2828
}
@@ -31,7 +31,7 @@ export const StatusIconAndText = ({
3131
return (
3232
<>
3333
{React.cloneElement(icon, {
34-
'data-testid': `icon-only-${title}`,
34+
'data-testid': dataTestId ?? `icon-only-${title}`,
3535
className: icon.props.className,
3636
})}
3737
</>
@@ -41,7 +41,7 @@ export const StatusIconAndText = ({
4141
return (
4242
<span
4343
className={classNames('bs-shared-icon-and-text', className)}
44-
data-testid={`icon-with-title-${title}`}
44+
data-testid={dataTestId ?? `icon-with-title-${title}`}
4545
title={title}
4646
>
4747
{React.cloneElement(icon, {

0 commit comments

Comments
 (0)