-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBasicExample.tsx
More file actions
173 lines (166 loc) · 5.5 KB
/
BasicExample.tsx
File metadata and controls
173 lines (166 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import React from 'react';
import WidgetLayout from '../../../src/WidgetLayout/WidgetLayout';
import { WidgetMapping, ExtendedTemplateConfig } from '../../../src/WidgetLayout/types';
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
import ChartLineIcon from '@patternfly/react-icons/dist/esm/icons/chart-line-icon';
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon';
import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon';
import {
Card,
CardBody,
CardFooter,
Content,
ContentVariants,
DescriptionList,
DescriptionListDescription,
DescriptionListGroup,
DescriptionListTerm,
Icon,
List,
ListItem,
} from '@patternfly/react-core';
// A simple overview widget with key stats
const OverviewWidget = () => (
<Card isPlain isFullHeight>
<CardBody>
<DescriptionList isHorizontal isCompact>
<DescriptionListGroup>
<DescriptionListTerm>Clusters</DescriptionListTerm>
<DescriptionListDescription>12</DescriptionListDescription>
</DescriptionListGroup>
<DescriptionListGroup>
<DescriptionListTerm>Running</DescriptionListTerm>
<DescriptionListDescription>10</DescriptionListDescription>
</DescriptionListGroup>
<DescriptionListGroup>
<DescriptionListTerm>Degraded</DescriptionListTerm>
<DescriptionListDescription>1</DescriptionListDescription>
</DescriptionListGroup>
<DescriptionListGroup>
<DescriptionListTerm>Stopped</DescriptionListTerm>
<DescriptionListDescription>1</DescriptionListDescription>
</DescriptionListGroup>
</DescriptionList>
</CardBody>
<CardFooter>
<a href="#">
View all clusters
<Icon isInline>
<ArrowRightIcon />
</Icon>
</a>
</CardFooter>
</Card>
);
// A widget showing recent activity
const ActivityWidget = () => (
<Card isPlain isFullHeight>
<CardBody>
<Content component={ContentVariants.p}>Recent deployments and changes across your infrastructure.</Content>
<List isPlain>
<ListItem>Production deploy completed — 2 min ago</ListItem>
<ListItem>Config update applied — 15 min ago</ListItem>
<ListItem>New node added to cluster-03 — 1 hr ago</ListItem>
<ListItem>Certificate renewed — 3 hr ago</ListItem>
<ListItem>Scaling policy triggered — 5 hr ago</ListItem>
</List>
</CardBody>
<CardFooter>
<a href="#">
View full report
<Icon isInline>
<ArrowRightIcon />
</Icon>
</a>
</CardFooter>
</Card>
);
// A notifications widget
const NotificationsWidget = () => (
<Card isPlain isFullHeight>
<CardBody>
<List isPlain>
<ListItem>3 alerts require attention</ListItem>
<ListItem>Maintenance window scheduled for Saturday</ListItem>
<ListItem>2 patches available</ListItem>
</List>
</CardBody>
<CardFooter>
<a href="https://www.patternfly.org">
View all notifications
<Icon isInline>
<ExternalLinkAltIcon />
</Icon>
</a>
</CardFooter>
</Card>
);
// Define widget mapping
const widgetMapping: WidgetMapping = {
'overview-widget': {
defaults: { w: 2, h: 3, maxH: 6, minH: 2 },
config: {
title: 'Cluster Overview',
icon: <CubeIcon />,
headerLink: {
title: 'View details',
href: '#'
}
},
renderWidget: () => <OverviewWidget />
},
'activity-widget': {
defaults: { w: 2, h: 4, maxH: 8, minH: 3 },
config: {
title: 'Recent Activity',
icon: <ChartLineIcon />,
headerLink: {
title: 'View full report',
href: '#'
}
},
renderWidget: () => <ActivityWidget />
},
'notifications-widget': {
defaults: { w: 1, h: 3, maxH: 6, minH: 2 },
config: {
title: 'Notifications',
icon: <BellIcon />
},
renderWidget: () => <NotificationsWidget />
}
};
// Define initial template
const initialTemplate: ExtendedTemplateConfig = {
xl: [
{ i: 'overview-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' },
{ i: 'activity-widget#1', x: 2, y: 0, w: 2, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' },
],
lg: [
{ i: 'overview-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' },
{ i: 'activity-widget#1', x: 0, y: 3, w: 2, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' },
],
md: [
{ i: 'overview-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' },
{ i: 'activity-widget#1', x: 0, y: 3, w: 2, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' },
],
sm: [
{ i: 'overview-widget#1', x: 0, y: 0, w: 1, h: 3, widgetType: 'overview-widget', title: 'Cluster Overview' },
{ i: 'activity-widget#1', x: 0, y: 3, w: 1, h: 4, widgetType: 'activity-widget', title: 'Recent Activity' },
]
};
export const BasicExample: React.FunctionComponent = () => {
const [template, setTemplate] = React.useState(initialTemplate);
return (
<div style={{ height: '800px', overflowY: 'scroll' }}>
<WidgetLayout
widgetMapping={widgetMapping}
initialTemplate={template}
onTemplateChange={setTemplate}
documentationLink="https://www.patternfly.org"
initialDrawerOpen={true}
/>
</div>
);
};