Skip to content

Commit eb1ba5d

Browse files
committed
fix: Updated with review comments.
1 parent 478a2bd commit eb1ba5d

File tree

6 files changed

+50
-87
lines changed

6 files changed

+50
-87
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const MyComponentExample: React.FunctionComponent = () => (
112112
<MyComponent customLabel="My label">
113113
);
114114
115-
export default BatteryLowExample;
115+
export default MyComponentExample;
116116
```
117117

118118
### Sub-components:

cypress/component/Severity.cy.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import Severity, { SeverityType } from '../../packages/module/dist/dynamic/Severity';
3+
4+
const severities = [
5+
{ type: SeverityType.critical, label: 'Critical severity', ouiaId: 'Severity-critical' },
6+
{ type: SeverityType.important, label: 'Important severity', ouiaId: 'Severity-important' },
7+
{ type: SeverityType.moderate, label: 'Moderate severity', ouiaId: 'Severity-moderate' },
8+
{ type: SeverityType.minor, label: 'Minor severity', ouiaId: 'Severity-minor' },
9+
{ type: SeverityType.none, label: 'No severity', ouiaId: 'Severity-none' },
10+
{ type: SeverityType.undefined, label: 'Undefined severity', ouiaId: 'Severity-undefined' }
11+
];
12+
13+
describe('Severity', () => {
14+
severities.map(({ type, label, ouiaId }) => {
15+
it(`renders Severity with ${type} severity`, () => {
16+
cy.mount(<Severity severity={type} label={label} ouiaId={ouiaId} />);
17+
cy.get(`[data-ouia-component-id="${ouiaId}"]`).should('exist');
18+
cy.get(`[data-ouia-component-id="${ouiaId}"]`).should('have.attr', 'title', label);
19+
cy.get('span').contains(label);
20+
});
21+
});
22+
23+
it('hides label when labelHidden is true', () => {
24+
cy.mount(<Severity severity={SeverityType.important} label="Important severity" labelHidden />);
25+
cy.contains('Important severity').should('not.exist');
26+
});
27+
});

migration.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ The guide should be applicable when migrating from frontend-components **version
1010
1111
**SOLUTION:** use the `className` property if you need a custom color
1212
13-
14-
## Battery
15-
16-
- No action required
17-
18-
1913
## ErrorState
2014
2115
- The default error description *“If the problem persists, contact [Red Hat Support](https://access.redhat.com/support) or check our [status page](https://status.redhat.com) for known outages.”* has been removed.
@@ -55,7 +49,10 @@ The guide should be applicable when migrating from frontend-components **version
5549
5650
**SOLUTION:** handle `/beta` in your URL on your own and pass a final URL using the new `toLandingPageUrl` property
5751
58-
52+
​## Severity
53+
54+
- No action required
55+
5956
## SkeletonTable
6057
6158
- No action required

packages/module/patternfly-docs/content/extensions/component-groups/examples/Severity/Severity.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packa
1616

1717
import Severity, { SeverityType } from '@patternfly/react-component-groups/dist/dynamic/Severity';
1818

19-
The **battery** component generates a battery, which corresponds to a level `low`, `medium`, `high` or `critical`. Each level corresponds with a severity level and respective color:
19+
The **severity** component generates an icon with an optional label, which corresponds to a level `minor`, `moderate`, `important` or `critical`. Each level corresponds with a severity level and respective color:
2020

2121
| Severity level | Meaning | Style |
2222
| --- | --- | --- |
23-
| Level 1 | Low severity (best case scenario) | 1 green bar | "1", "low" |
24-
| Level 2 | Medium severity | 2 yellow bars |
25-
| Level 3 | High severity | 3 orange bars |
26-
| Level 4 | Critical severity (worst case scenario) | 4 red bars |
23+
| Level 1 | Minor severity (best case scenario) | Dark grey icon |
24+
| Level 2 | Moderate severity | Yellow icon |
25+
| Level 3 | Important severity | Orange icon |
26+
| Level 4 | Critical severity (worst case scenario) | Red icon |
2727

28-
To specify the severity of the battery's risk level, you can pass a predefined enum or text value into the `severity` property that corresponds to the appropriate severity level.
28+
To specify the severity risk level, you can pass a predefined enum or text value into the `severity` property that corresponds to the appropriate severity level.
2929

30-
To add an optional label to a battery, add the `label` property to the `<Severity>` component.
30+
To add an optional label, add the `label` property to the `<Severity>` component.
3131

3232
## Examples
3333

packages/module/src/Severity/Severity.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ describe('Severity component', () => {
4242
expect(container).toMatchSnapshot();
4343
});
4444
});
45-
});
45+
});

packages/module/src/Severity/Severity.tsx

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useMemo } from 'react';
2-
import clsx from 'clsx';
32
import {
43
SeverityCriticalIcon,
54
SeverityImportantIcon,
@@ -8,79 +7,21 @@ import {
87
SeverityNoneIcon,
98
SeverityUndefinedIcon
109
} from '@patternfly/react-icons';
11-
import { createUseStyles } from 'react-jss';
1210

13-
const severityCritical = {
14-
'& svg': {
15-
'& path': { fill: 'var(--pf-t--global--color--status--danger--default)' }
16-
}
17-
};
18-
19-
const severityImportant = {
20-
'& svg': {
21-
'& path': { fill: 'var(--pf-t--global--icon--color--severity--important--default)' }
22-
}
23-
};
24-
25-
const severityModerate = {
26-
'& svg': {
27-
'& path': { fill: 'var(-pf-t--global--icon--color--severity--moderate--default)' }
28-
}
29-
};
30-
31-
const severityMinor = {
32-
'& svg': {
33-
'& path': { fill: 'var(--pf-t--global--icon--color--severity--minor--default)' }
34-
}
35-
};
36-
37-
const severityNone = {
38-
'& svg': {
39-
'& path': { fill: 'var(--pf-t--global--icon--color--severity--none--default)' }
40-
}
41-
};
42-
43-
const severityUndefined = {
44-
'& svg': {
45-
'& path': { stroke: 'var(--pf-t--global--icon--color--severity--undefined--default)' }
46-
}
47-
};
48-
49-
const useStyles = createUseStyles({
50-
severity: {
51-
display: 'inline-block',
52-
'line-height': 0,
53-
'& svg': {
54-
position: 'relative',
55-
top: 'var(--pf-t--global--spacer--sm)',
56-
height: 'calc(var(--pf-t--global--spacer--md) * 1.75)',
57-
},
58-
},
59-
severityLabel: {
60-
'margin-left': 'var(--pf-t--global--spacer--xs)'
61-
},
62-
severityNone,
63-
severityMinor,
64-
severityModerate,
65-
severityImportant,
66-
severityCritical,
67-
severityUndefined
68-
});
69-
70-
const severityLevels = (severity: SeverityType, classMode?: boolean) => {
11+
const severityLevels = (severity: SeverityType) => {
7112
switch (severity) {
7213
case 'critical':
73-
return classMode ? 'severityCritical' : <SeverityCriticalIcon />;
14+
return <SeverityCriticalIcon color='var(--pf-t--global--icon--color--severity--critical--default)'/>;
7415
case 'important':
75-
return classMode ? 'severityImportant' : <SeverityImportantIcon />;
16+
return <SeverityImportantIcon color='var(--pf-t--global--icon--color--severity--important--default)' />;
7617
case 'minor':
77-
return classMode ? 'severityMinor' : <SeverityMinorIcon />;
18+
return <SeverityMinorIcon color='var(--pf-t--global--icon--color--severity--minor--default)' />;
7819
case 'moderate':
79-
return classMode ? 'severityModerate' : <SeverityModerateIcon />;
20+
return <SeverityModerateIcon color='var(--pf-t--global--icon--color--severity--moderate--default)' />;
8021
case 'none':
81-
return classMode ? 'severityMinor' : <SeverityNoneIcon />;
22+
return <SeverityNoneIcon color='var(--pf-t--global--icon--color--severity--none--default)' />;
8223
default:
83-
return classMode ? 'severityNone' : <SeverityUndefinedIcon />;
24+
return <SeverityUndefinedIcon color='var(--pf-t--global--icon--color--severity--undefined--default)' />;
8425
}
8526
};
8627

@@ -112,12 +53,10 @@ export const Severity: React.FunctionComponent<SeverityProps> = ({
11253
severity,
11354
label,
11455
labelHidden,
115-
className,
11656
ouiaId = 'Severity-icon',
11757
...props
11858
}: SeverityProps) => {
119-
const classes = useStyles();
120-
const severityClasses = clsx(classes.severity, classes[String(severityLevels(severity, true))], className);
59+
12160

12261
const title = { title: `${severity} ${label}` };
12362

@@ -126,10 +65,10 @@ export const Severity: React.FunctionComponent<SeverityProps> = ({
12665
return (
12766
<React.Fragment>
12867
{/* eslint-disable-next-line react/no-unknown-property */}
129-
<i className={severityClasses} {...title} {...props} widget-type="Severity" widget-id={label} data-ouia-component-id={ouiaId}>
68+
<i {...title} {...props} widget-type="Severity" widget-id={label} data-ouia-component-id={ouiaId}>
13069
{severityVariant}
13170
</i>
132-
{!labelHidden && <span className={clsx(classes.severityLabel)}> {label} </span>}
71+
{!labelHidden && label}
13372
</React.Fragment>
13473
);
13574
};

0 commit comments

Comments
 (0)