Skip to content

Commit 1265cac

Browse files
authored
Merge pull request #21 from fhlavac/main
2 parents ed75671 + b24441f commit 1265cac

File tree

5 files changed

+53
-28
lines changed

5 files changed

+53
-28
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
section: extensions
3+
subsection: Component groups
4+
id: NotAuthorized
5+
source: react
6+
propComponents: ['NotAuthorized']
7+
---
8+
9+
import { NotAuthorized } from "@patternfly/react-component-groups";
10+
11+
## Components Usage
12+
13+
### NotAuthorized Component
14+
15+
```js file="./NotAuthorizedExample.tsx"
16+
17+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { NotAuthorized } from '@patternfly/react-component-groups';
3+
import { Button } from '@patternfly/react-core';
4+
5+
export const BasicExample: React.FunctionComponent = () => {
6+
const actions = [
7+
<Button key="1">
8+
First action
9+
</Button>,
10+
<Button key="2" className='pf-u-mx-md'>
11+
Second action
12+
</Button>,
13+
];
14+
return (
15+
<NotAuthorized
16+
actions={actions}
17+
className="something"
18+
description="Description text"
19+
serviceName="Demo bundle"
20+
prevPageButtonText="Go to previous page"
21+
/>
22+
);
23+
}

packages/module/src/NotAuthorized/NotAuthorized.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { createUseStyles } from 'react-jss';
55

66
export interface NotAuthorizedProps extends Omit<EmptyStateProps, 'children' | 'title'> {
77
serviceName?: string;
8-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9-
icon?: React.ComponentType<any>;
8+
icon?: React.ComponentType;
109
description?: React.ReactNode;
1110
showReturnButton?: boolean;
1211
className?: string;
@@ -16,12 +15,6 @@ export interface NotAuthorizedProps extends Omit<EmptyStateProps, 'children' | '
1615
toLandingPageText?: React.ReactNode;
1716
}
1817

19-
const ContactBody = () => (
20-
<React.Fragment>
21-
Contact your organization administrator(s) for more information or visit&nbsp;
22-
<a href={`./settings/my-user-access`}>My User Access</a>&nbsp; to learn more about your permissions.
23-
</React.Fragment>
24-
);
2518

2619
const useStyles = createUseStyles({
2720
title: {
@@ -31,26 +24,25 @@ const useStyles = createUseStyles({
3124
},
3225
})
3326

34-
const NotAuthorized: React.FunctionComponent<NotAuthorizedProps> = ({
27+
export const NotAuthorized: React.FunctionComponent<NotAuthorizedProps> = ({
3528
prevPageButtonText = 'Return to previous page',
3629
toLandingPageText = 'Go to landing page',
37-
title,
3830
actions = null,
3931
serviceName,
32+
title = `You do not have access to ${serviceName}`,
4033
icon: Icon = LockIcon,
41-
description = <ContactBody />,
34+
description = 'Contact your system administrator(s) for more information.',
4235
showReturnButton = true,
4336
className,
4437
...props
45-
}) => {
38+
}: NotAuthorizedProps) => {
4639
const classes = useStyles();
4740

48-
const heading = title || `You do not have access to ${serviceName}`;
4941
return (
5042
<EmptyState variant={EmptyStateVariant.full} className={className} {...props}>
5143
<EmptyStateIcon icon={Icon} />
5244
<Title className={classes.title} headingLevel="h5" size="lg">
53-
{heading}
45+
{title}
5446
</Title>
5547
<EmptyStateBody>{description}</EmptyStateBody>
5648
{actions}

packages/module/src/NotAuthorized/__tests__/__snapshots__/NotAuthorized.test.js.snap

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`NotAuthorized component should apply custom styles 1`] = `
1616
You do not have access to Foo
1717
</Title>
1818
<EmptyStateBody>
19-
<ContactBody />
19+
Contact your system administrator(s) for more information.
2020
</EmptyStateBody>
2121
<Button
2222
component="a"
@@ -43,7 +43,7 @@ exports[`NotAuthorized component should not show buttons 1`] = `
4343
You do not have access to Foo
4444
</Title>
4545
<EmptyStateBody>
46-
<ContactBody />
46+
Contact your system administrator(s) for more information.
4747
</EmptyStateBody>
4848
</EmptyState>
4949
`;
@@ -63,7 +63,7 @@ exports[`NotAuthorized component should render 1`] = `
6363
You do not have access to Foo
6464
</Title>
6565
<EmptyStateBody>
66-
<ContactBody />
66+
Contact your system administrator(s) for more information.
6767
</EmptyStateBody>
6868
<Button
6969
component="a"
@@ -90,7 +90,7 @@ exports[`NotAuthorized component should show custom actions 1`] = `
9090
You do not have access to Foo
9191
</Title>
9292
<EmptyStateBody>
93-
<ContactBody />
93+
Contact your system administrator(s) for more information.
9494
</EmptyStateBody>
9595
<button
9696
id="action-one"
@@ -156,7 +156,7 @@ exports[`NotAuthorized component should show custom title 1`] = `
156156
Custom title
157157
</Title>
158158
<EmptyStateBody>
159-
<ContactBody />
159+
Contact your system administrator(s) for more information.
160160
</EmptyStateBody>
161161
<Button
162162
component="a"
@@ -187,15 +187,7 @@ exports[`NotAuthorized component should use custom icon 1`] = `
187187
<div
188188
className="pf-c-empty-state__body"
189189
>
190-
[
191-
"Contact your organization administrator(s) for more information or visit ",
192-
<a
193-
href="./settings/my-user-access"
194-
>
195-
My User Access
196-
</a>,
197-
"  to learn more about your permissions.",
198-
]
190+
Contact your system administrator(s) for more information.
199191
</div>
200192
<a
201193
aria-disabled={false}

packages/module/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './DetailsPageHeader';
33
export * from './ErrorBoundaryPage';
44
export * from './ErrorState';
55
export * from './HorizontalNav';
6+
export * from './NotAuthorized';

0 commit comments

Comments
 (0)