|
1 | 1 | import React from 'react'; |
2 | 2 | import WidgetLayout from '../../../src/WidgetLayout/WidgetLayout'; |
3 | 3 | import { WidgetMapping, ExtendedTemplateConfig } from '../../../src/WidgetLayout/types'; |
4 | | -import { CubeIcon, ChartLineIcon, BellIcon, ExternalLinkAltIcon, ArrowRightIcon } from '@patternfly/react-icons'; |
5 | | -import { Card, CardBody, CardFooter, Content, Icon } from '@patternfly/react-core'; |
| 4 | +import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon'; |
| 5 | +import ChartLineIcon from '@patternfly/react-icons/dist/esm/icons/chart-line-icon'; |
| 6 | +import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; |
| 7 | +import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon'; |
| 8 | +import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon'; |
| 9 | +import { |
| 10 | + Card, |
| 11 | + CardBody, |
| 12 | + CardFooter, |
| 13 | + Content, |
| 14 | + ContentVariants, |
| 15 | + DescriptionList, |
| 16 | + DescriptionListDescription, |
| 17 | + DescriptionListGroup, |
| 18 | + DescriptionListTerm, |
| 19 | + Icon, |
| 20 | + List, |
| 21 | + ListItem, |
| 22 | +} from '@patternfly/react-core'; |
6 | 23 |
|
7 | | -interface SimpleWidgetProps { |
8 | | - id: number; |
9 | | - body: string; |
10 | | - linkTitle: string; |
11 | | - url: string; |
12 | | - isExternal?: boolean; |
13 | | -} |
14 | | - |
15 | | -const CardExample: React.FunctionComponent<SimpleWidgetProps> = (props) => ( |
16 | | - <Card isPlain> |
17 | | - <CardBody className="pf-v6-u-p-md pf-v6-u-pb-0"> |
18 | | - <Content |
19 | | - key={props.id} |
20 | | - className="pf-v6-u-display-flex pf-v6-u-flex-direction-column" |
21 | | - > |
22 | | - <Content component="p" className="pf-v6-u-flex-grow-1"> |
23 | | - {props.body} |
24 | | - </Content> |
25 | | - </Content> |
| 24 | +// A simple overview widget with key stats |
| 25 | +const OverviewWidget = () => ( |
| 26 | + <Card isPlain isFullHeight> |
| 27 | + <CardBody> |
| 28 | + <DescriptionList isHorizontal isCompact> |
| 29 | + <DescriptionListGroup> |
| 30 | + <DescriptionListTerm>Clusters</DescriptionListTerm> |
| 31 | + <DescriptionListDescription>12</DescriptionListDescription> |
| 32 | + </DescriptionListGroup> |
| 33 | + <DescriptionListGroup> |
| 34 | + <DescriptionListTerm>Running</DescriptionListTerm> |
| 35 | + <DescriptionListDescription>10</DescriptionListDescription> |
| 36 | + </DescriptionListGroup> |
| 37 | + <DescriptionListGroup> |
| 38 | + <DescriptionListTerm>Degraded</DescriptionListTerm> |
| 39 | + <DescriptionListDescription>1</DescriptionListDescription> |
| 40 | + </DescriptionListGroup> |
| 41 | + <DescriptionListGroup> |
| 42 | + <DescriptionListTerm>Stopped</DescriptionListTerm> |
| 43 | + <DescriptionListDescription>1</DescriptionListDescription> |
| 44 | + </DescriptionListGroup> |
| 45 | + </DescriptionList> |
26 | 46 | </CardBody> |
27 | | - <CardFooter className="pf-v6-u-p-md"> |
28 | | - {props.isExternal ? ( |
29 | | - <a href={props.url}> |
30 | | - {props.linkTitle} |
31 | | - <Icon className="pf-v6-u-ml-sm" isInline> |
32 | | - <ExternalLinkAltIcon /> |
33 | | - </Icon> |
34 | | - </a> |
35 | | - ) : ( |
36 | | - <a href={props.url}> |
37 | | - {props.linkTitle} |
38 | | - <Icon className="pf-v6-u-ml-sm" isInline> |
39 | | - <ArrowRightIcon /> |
40 | | - </Icon> |
41 | | - </a> |
42 | | - )} |
| 47 | + <CardFooter> |
| 48 | + <a href="#"> |
| 49 | + View all clusters |
| 50 | + <Icon isInline> |
| 51 | + <ArrowRightIcon /> |
| 52 | + </Icon> |
| 53 | + </a> |
43 | 54 | </CardFooter> |
44 | 55 | </Card> |
45 | 56 | ); |
46 | 57 |
|
47 | | -// Example widget content components |
48 | | -const ExampleWidget1 = () => ( |
49 | | - <CardExample |
50 | | - id={1} |
51 | | - body="This is the content of the first example widget. You can put any React content here!" |
52 | | - linkTitle="View details" |
53 | | - url="https://www.patternfly.org" |
54 | | - isExternal={true} |
55 | | - /> |
56 | | -); |
57 | | - |
58 | | -const ExampleWidget2 = () => ( |
59 | | - <CardExample |
60 | | - id={2} |
61 | | - body="Chart and visualization content would be displayed here." |
62 | | - linkTitle="View full report" |
63 | | - url="#" |
64 | | - isExternal={false} |
65 | | - /> |
| 58 | +// A widget showing recent activity |
| 59 | +const ActivityWidget = () => ( |
| 60 | + <Card isPlain isFullHeight> |
| 61 | + <CardBody> |
| 62 | + <Content component={ContentVariants.p}>Recent deployments and changes across your infrastructure.</Content> |
| 63 | + <List isPlain> |
| 64 | + <ListItem>Production deploy completed — 2 min ago</ListItem> |
| 65 | + <ListItem>Config update applied — 15 min ago</ListItem> |
| 66 | + <ListItem>New node added to cluster-03 — 1 hr ago</ListItem> |
| 67 | + <ListItem>Certificate renewed — 3 hr ago</ListItem> |
| 68 | + <ListItem>Scaling policy triggered — 5 hr ago</ListItem> |
| 69 | + </List> |
| 70 | + </CardBody> |
| 71 | + <CardFooter> |
| 72 | + <a href="#"> |
| 73 | + View full report |
| 74 | + <Icon isInline> |
| 75 | + <ArrowRightIcon /> |
| 76 | + </Icon> |
| 77 | + </a> |
| 78 | + </CardFooter> |
| 79 | + </Card> |
66 | 80 | ); |
67 | 81 |
|
68 | | -const ExampleWidget3 = () => ( |
69 | | - <CardExample |
70 | | - id={3} |
71 | | - body="Recent notifications and updates will appear in this widget." |
72 | | - linkTitle="View all notifications" |
73 | | - url="#" |
74 | | - isExternal={false} |
75 | | - /> |
| 82 | +// A notifications widget |
| 83 | +const NotificationsWidget = () => ( |
| 84 | + <Card isPlain isFullHeight> |
| 85 | + <CardBody> |
| 86 | + <List isPlain> |
| 87 | + <ListItem>3 alerts require attention</ListItem> |
| 88 | + <ListItem>Maintenance window scheduled for Saturday</ListItem> |
| 89 | + <ListItem>2 patches available</ListItem> |
| 90 | + </List> |
| 91 | + </CardBody> |
| 92 | + <CardFooter> |
| 93 | + <a href="https://www.patternfly.org"> |
| 94 | + View all notifications |
| 95 | + <Icon isInline> |
| 96 | + <ExternalLinkAltIcon /> |
| 97 | + </Icon> |
| 98 | + </a> |
| 99 | + </CardFooter> |
| 100 | + </Card> |
76 | 101 | ); |
77 | 102 |
|
78 | 103 | // Define widget mapping |
79 | 104 | const widgetMapping: WidgetMapping = { |
80 | | - 'example-widget-1': { |
| 105 | + 'overview-widget': { |
81 | 106 | defaults: { w: 2, h: 3, maxH: 6, minH: 2 }, |
82 | 107 | config: { |
83 | | - title: 'Example Widget', |
| 108 | + title: 'Cluster Overview', |
84 | 109 | icon: <CubeIcon />, |
85 | 110 | headerLink: { |
86 | 111 | title: 'View details', |
87 | 112 | href: '#' |
88 | 113 | } |
89 | 114 | }, |
90 | | - renderWidget: () => <ExampleWidget1 /> |
| 115 | + renderWidget: () => <OverviewWidget /> |
91 | 116 | }, |
92 | | - 'chart-widget': { |
| 117 | + 'activity-widget': { |
93 | 118 | defaults: { w: 2, h: 4, maxH: 8, minH: 3 }, |
94 | 119 | config: { |
95 | | - title: 'Chart Widget', |
96 | | - icon: <ChartLineIcon /> |
| 120 | + title: 'Recent Activity', |
| 121 | + icon: <ChartLineIcon />, |
| 122 | + headerLink: { |
| 123 | + title: 'View full report', |
| 124 | + href: '#' |
| 125 | + } |
97 | 126 | }, |
98 | | - renderWidget: () => <ExampleWidget2 /> |
| 127 | + renderWidget: () => <ActivityWidget /> |
99 | 128 | }, |
100 | 129 | 'notifications-widget': { |
101 | 130 | defaults: { w: 1, h: 3, maxH: 6, minH: 2 }, |
102 | 131 | config: { |
103 | | - title: 'Notification Widget', |
| 132 | + title: 'Notifications', |
104 | 133 | icon: <BellIcon /> |
105 | 134 | }, |
106 | | - renderWidget: () => <ExampleWidget3 /> |
| 135 | + renderWidget: () => <NotificationsWidget /> |
107 | 136 | } |
108 | 137 | }; |
109 | 138 |
|
110 | 139 | // Define initial template |
111 | 140 | const initialTemplate: ExtendedTemplateConfig = { |
112 | 141 | xl: [ |
113 | | - { i: 'example-widget-1#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'example-widget-1', title: 'Example Widget' }, |
114 | | - { i: 'chart-widget#1', x: 2, y: 0, w: 2, h: 4, widgetType: 'chart-widget', title: 'Chart Widget' } |
| 142 | + { i: 'overview-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' }, |
| 143 | + { i: 'activity-widget#1', x: 2, y: 0, w: 2, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' }, |
115 | 144 | ], |
116 | 145 | lg: [ |
117 | | - { i: 'example-widget-1#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'example-widget-1', title: 'Example Widget' }, |
118 | | - { i: 'chart-widget#1', x: 0, y: 3, w: 2, h: 4, widgetType: 'chart-widget', title: 'Chart Widget' } |
| 146 | + { i: 'overview-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' }, |
| 147 | + { i: 'activity-widget#1', x: 0, y: 3, w: 2, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' }, |
119 | 148 | ], |
120 | 149 | md: [ |
121 | | - { i: 'example-widget-1#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'example-widget-1', title: 'Example Widget' }, |
122 | | - { i: 'chart-widget#1', x: 0, y: 3, w: 2, h: 4, widgetType: 'chart-widget', title: 'Chart Widget' } |
| 150 | + { i: 'overview-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' }, |
| 151 | + { i: 'activity-widget#1', x: 0, y: 3, w: 2, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' }, |
123 | 152 | ], |
124 | 153 | sm: [ |
125 | | - { i: 'example-widget-1#1', x: 0, y: 0, w: 1, h: 3, widgetType: 'example-widget-1', title: 'Example Widget' }, |
126 | | - { i: 'chart-widget#1', x: 0, y: 3, w: 1, h: 4, widgetType: 'chart-widget', title: 'Chart Widget' } |
| 154 | + { i: 'overview-widget#1', x: 0, y: 0, w: 1, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' }, |
| 155 | + { i: 'activity-widget#1', x: 0, y: 3, w: 1, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' }, |
127 | 156 | ] |
128 | 157 | }; |
129 | 158 |
|
130 | 159 | export const BasicExample: React.FunctionComponent = () => { |
131 | 160 | const [template, setTemplate] = React.useState(initialTemplate); |
132 | 161 |
|
133 | 162 | return ( |
134 | | - <div style={{ height: '600px', width: '100%', overflow: 'auto', position: 'relative', isolation: 'isolate' }}> |
| 163 | + <div style={{ height: '800px', overflowY: 'scroll' }}> |
135 | 164 | <WidgetLayout |
136 | 165 | widgetMapping={widgetMapping} |
137 | 166 | initialTemplate={template} |
|
0 commit comments