Skip to content

Commit d051d18

Browse files
aferdfhlavac
andauthored
feat: Add Maintenance component (#410)
* RHCLOUD-33366 Add Maintenance component plus tests and examples * text fix * remove snapshots * add custom footer and body text * fix redirectUrl and custom example * adjust cypress test * Update packages/module/src/Maintenance/Maintenance.tsx * feat(Maintenance): Update cypress/component/Maintenance.cy.tsx --------- Co-authored-by: Filip Hlavac <[email protected]>
1 parent d0ccf35 commit d051d18

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import Maintenance from '@patternfly/react-component-groups/dist/dynamic/Maintenance';
3+
4+
describe('Maintenance', () => {
5+
it('renders Maintenance', () => {
6+
cy.mount(<Maintenance />)
7+
cy.get('[data-ouia-component-id="Maintenance"]').should('exist');
8+
cy.get('[data-ouia-component-id="Maintenance"]').contains('Maintenance in progress');
9+
cy.get('[data-ouia-component-id="Maintenance-body"]').contains('We are currently undergoing scheduled maintenance and will be unavailable from 6am to 8am UTC. For more information please visit status.redhat.com.');
10+
});
11+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# Sidenav top-level section
3+
# should be the same for all markdown files
4+
section: Component groups
5+
subsection: Error communication
6+
# Sidenav secondary level section
7+
# should be the same for all markdown files
8+
id: Maintenance
9+
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10+
source: react
11+
# If you use typescript, the name of the interface to display props for
12+
# These are found through the sourceProps function provided in patternfly-docs.source.js
13+
propComponents: ['Maintenance']
14+
sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/Maintenance/Maintenance.md
15+
---
16+
17+
import Maintenance from '@patternfly/react-component-groups/dist/dynamic/Maintenance';
18+
19+
A **maintenance** component displays a screen to users when they are undergoing scheduled maintenance.
20+
21+
## Examples
22+
23+
### Basic maintenance
24+
25+
To provide users with basic information regarding maintenance. A basic maintenance state should contain an appropriate and informative `titleText`. `defaultBodyText` will be used by default.
26+
27+
```js file="./MaintenanceExample.tsx"
28+
29+
```
30+
31+
### Custom maintenance
32+
33+
To override the default bodyText and footer link, specify your own using `bodyText` and `customFooter`. You may add a `startTime`, `endTime` and `timeZone` that will be displayed as shown below. `timeZone` will be set to UTC by default.
34+
35+
```js file="./MaintenanceCustomExample.tsx"
36+
37+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import Maintenance from '@patternfly/react-component-groups/dist/dynamic/Maintenance'
3+
4+
export const BasicExample: React.FunctionComponent = () => (
5+
<Maintenance bodyText='We are currently undergoing scheduled maintenance and will be unavailable from' customFooter='Please visit' redirectLinkUrl='http://patternfly.com' redirectLinkText='here.' startTime='6am' endTime='8am' timeZone='UTC' />
6+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import Maintenance from '@patternfly/react-component-groups/dist/dynamic/Maintenance'
3+
4+
export const BasicExample: React.FunctionComponent = () => (
5+
<Maintenance />
6+
);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from 'react';
2+
import { Button, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateProps, EmptyStateStatus, EmptyStateVariant } from '@patternfly/react-core';
3+
import { HourglassHalfIcon } from '@patternfly/react-icons';
4+
5+
/** extends EmptyStateProps */
6+
export interface MaintenanceProps extends Omit<EmptyStateProps, 'children' | 'title'> {
7+
/** The title for the maintenance message */
8+
titleText?: string;
9+
/** Custom body text */
10+
bodyText?: React.ReactNode;
11+
/** A default bodyText used if no bodyText is provided */
12+
defaultBodyText?: React.ReactNode;
13+
/** Start time in a specific time zone */
14+
startTime?: string;
15+
/** End time in a specific time zone */
16+
endTime?: string;
17+
/** Time zone specification */
18+
timeZone?: string;
19+
/** Information link */
20+
redirectLinkUrl?: string;
21+
/** Information link title */
22+
redirectLinkText?: string;
23+
/** Custom footer content */
24+
customFooter?: React.ReactNode;
25+
/** Custom OUIA ID */
26+
ouiaId?: string | number; }
27+
28+
const Maintenance: React.FunctionComponent<MaintenanceProps> = ({
29+
titleText = 'Maintenance in progress',
30+
defaultBodyText = 'We are currently undergoing scheduled maintenance. Thank you for understanding.',
31+
startTime,
32+
endTime,
33+
timeZone = 'UTC',
34+
bodyText,
35+
redirectLinkUrl = 'https://status.redhat.com',
36+
redirectLinkText = 'status.redhat.com.',
37+
customFooter = 'For more information please visit',
38+
ouiaId = 'Maintenance',
39+
...props
40+
}: MaintenanceProps) => {
41+
let formattedBodyText = bodyText;
42+
if (startTime && endTime && timeZone) {
43+
formattedBodyText += ` ${startTime} to ${endTime} ${timeZone}.`;
44+
}
45+
46+
return (
47+
<EmptyState headingLevel="h5" status={EmptyStateStatus.danger} icon={HourglassHalfIcon} titleText={titleText} variant={EmptyStateVariant.lg} data-ouia-component-id={ouiaId} {...props}>
48+
<EmptyStateBody data-ouia-component-id={`${ouiaId}-body`}>
49+
{bodyText ? formattedBodyText : defaultBodyText}
50+
</EmptyStateBody>
51+
<EmptyStateFooter data-ouia-component-id={`${ouiaId}-footer`}>
52+
{customFooter && (
53+
<span>
54+
{customFooter}{' '}
55+
<Button
56+
variant="link"
57+
component="span"
58+
isInline
59+
href={redirectLinkUrl}
60+
target="_blank"
61+
ouiaId={`${ouiaId}-link`}
62+
>
63+
{redirectLinkText}
64+
</Button>
65+
</span>
66+
)}
67+
</EmptyStateFooter>
68+
</EmptyState>
69+
)};
70+
71+
export default Maintenance;
72+
73+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default } from './Maintenance';
2+
export * from './Maintenance';

0 commit comments

Comments
 (0)