Debian Codegraph @

node/@patternfly/react-core/src/demos/examples/Card/CardStatus.tsx

raw
1 import { useState } from 'react';
2 import {
3 Alert,
4 Card,
5 CardBody,
6 CardHeader,
7 Divider,
8 Flex,
9 FlexItem,
10 Grid,
11 GridItem,
12 Label,
13 LabelStatus,
14 NotificationDrawer,
15 NotificationDrawerBody,
16 NotificationDrawerGroup,
17 NotificationDrawerList,
18 NotificationDrawerListItem,
19 NotificationDrawerListItemBody,
20 NotificationDrawerListItemHeader,
21 Popover,
22 Title,
23 Icon
24 } from '@patternfly/react-core';
25 import { Table, Thead, Tbody, Tr, Th, Td, ExpandableRowContent } from '@patternfly/react-table';
26 import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/js/icons/rh-ui-check-circle-fill-icon';
27 import RhUiErrorFillIcon from '@patternfly/react-icons/dist/js/icons/rh-ui-error-fill-icon';
28 import t_global_text_color_subtle from '@patternfly/react-tokens/dist/esm/t_global_text_color_subtle';
29
30 export const CardStatus: React.FunctionComponent = () => {
31 const [drawerExpanded, setDrawerExpanded] = useState(false);
32 const handleDrawerToggleClick = () => {
33 setDrawerExpanded(!drawerExpanded);
34 };
35
36 const [rowsExpanded, setRowsExpanded] = useState([false, false, false]);
37 const handleToggleExpand = (_: any, rowIndex: number) => {
38 const newRowsExpanded = [...rowsExpanded];
39 newRowsExpanded[rowIndex] = !rowsExpanded[rowIndex];
40 setRowsExpanded(newRowsExpanded);
41 };
42
43 const header = (
44 <CardHeader>
45 <Title headingLevel="h4" size="lg">
46 Status
47 </Title>
48 </CardHeader>
49 );
50
51 const columns = ['Components', 'Response Rate'];
52
53 const rows = [
54 {
55 content: ['API Servers', '20%'],
56 child: (
57 <Alert
58 title="This is a critical alert that can be associated with the control panel."
59 variant="danger"
60 isInline
61 ></Alert>
62 )
63 },
64 {
65 content: ['Controller Managers', '100%'],
66 child: (
67 <Alert
68 title="This is a critical alert that can be associated with the control panel."
69 variant="danger"
70 isInline
71 ></Alert>
72 )
73 },
74 {
75 content: ['etcd', '91%'],
76 child: (
77 <Alert
78 title="This is a critical alert that can be associated with the control panel."
79 variant="danger"
80 isInline
81 ></Alert>
82 )
83 }
84 ];
85
86 const popoverBodyContent = (
87 <>
88 <div>
89 Components of the Control Panel are responsible for maintaining and reconciling the state of the cluster.
90 </div>
91 <Table variant="compact">
92 <Thead>
93 <Tr>
94 <Th screenReaderText="Row expansion" />
95 {columns.map((column, columnIndex) => (
96 <Th key={columnIndex} modifier="fitContent">
97 {column}
98 </Th>
99 ))}
100 </Tr>
101 </Thead>
102 {rows.map((row, rowIndex) => {
103 const parentRow = (
104 <Tr key={rowIndex}>
105 <Td
106 key={`${rowIndex}_0`}
107 expand={row.child && { isExpanded: rowsExpanded[rowIndex], rowIndex, onToggle: handleToggleExpand }}
108 />
109 {row.content.map((cell, cellIndex) => (
110 <Td key={`${rowIndex}_${cellIndex}`} dataLabel={columns[cellIndex]} modifier="fitContent">
111 {cell}
112 </Td>
113 ))}
114 </Tr>
115 );
116 const childRow = row.child ? (
117 <Tr key={`${rowIndex}_child`} isExpanded={rowsExpanded[rowIndex]}>
118 <Td key={`${rowIndex}_1`} colSpan={3} dataLabel={`${rowIndex}_child`}>
119 <ExpandableRowContent>{row.child}</ExpandableRowContent>
120 </Td>
121 </Tr>
122 ) : null;
123 return (
124 <Tbody key={rowIndex} isExpanded={rowsExpanded[rowIndex]}>
125 {parentRow}
126 {childRow}
127 </Tbody>
128 );
129 })}
130 </Table>
131 </>
132 );
133
134 const body = (
135 <CardBody>
136 <Grid hasGutter sm={6} lg={3}>
137 <GridItem>
138 <Flex spaceItems={{ default: 'spaceItemsSm' }}>
139 <FlexItem>
140 <Icon status="success">
141 <RhUiCheckCircleFillIcon />
142 </Icon>
143 </FlexItem>
144 <FlexItem>
145 <span>Cluster</span>
146 </FlexItem>
147 </Flex>
148 </GridItem>
149 <GridItem>
150 <Flex spaceItems={{ default: 'spaceItemsSm' }}>
151 <FlexItem>
152 <Icon status="danger">
153 <RhUiErrorFillIcon />
154 </Icon>
155 </FlexItem>
156 <FlexItem>
157 <Popover headerContent="Control Panel Status" bodyContent={popoverBodyContent} minWidth="400px">
158 <a href="#" onClick={(e) => e.preventDefault()}>
159 Control Panel
160 </a>
161 </Popover>
162 </FlexItem>
163 </Flex>
164 </GridItem>
165 <GridItem>
166 <Flex spaceItems={{ default: 'spaceItemsSm' }}>
167 <FlexItem>
168 <Icon status="danger">
169 <RhUiErrorFillIcon />
170 </Icon>
171 </FlexItem>
172 <Flex direction={{ default: 'column' }} spaceItems={{ default: 'spaceItemsNone' }}>
173 <FlexItem>
174 <a href="#">Operators</a>
175 </FlexItem>
176 <FlexItem>
177 <span style={{ color: t_global_text_color_subtle.var }}>1 degraded</span>
178 </FlexItem>
179 </Flex>
180 </Flex>
181 </GridItem>
182 <GridItem>
183 <Flex spaceItems={{ default: 'spaceItemsSm' }}>
184 <FlexItem>
185 <Icon status="success">
186 <RhUiCheckCircleFillIcon />
187 </Icon>
188 </FlexItem>
189 <Flex direction={{ default: 'column' }} spaceItems={{ default: 'spaceItemsNone' }}>
190 <FlexItem>
191 <a href="#">Image Vulnerabilities</a>
192 </FlexItem>
193 <FlexItem>
194 <span style={{ color: t_global_text_color_subtle.var }}>0 vulnerabilities</span>
195 </FlexItem>
196 </Flex>
197 </Flex>
198 </GridItem>
199 </Grid>
200 </CardBody>
201 );
202
203 const drawerTitle = (
204 <Flex spaceItems={{ default: 'spaceItemsSm' }}>
205 <FlexItem spacer={{ default: 'spacerMd' }}>
206 <span>Notifications</span>
207 </FlexItem>
208 <Label status={LabelStatus.danger}>1</Label>
209 <Label status={LabelStatus.warning}>3</Label>
210 <Label status={LabelStatus.success}>3</Label>
211 <Label status={LabelStatus.danger}>3</Label>
212 <Label status={LabelStatus.info}>3</Label>
213 </Flex>
214 );
215
216 const drawer = (
217 <NotificationDrawer>
218 <NotificationDrawerBody>
219 <NotificationDrawerGroup
220 count={0}
221 onExpand={handleDrawerToggleClick}
222 isExpanded={drawerExpanded}
223 title={drawerTitle}
224 headingLevel="h4"
225 >
226 <NotificationDrawerList isHidden={!drawerExpanded}>
227 <NotificationDrawerListItem variant="danger">
228 <NotificationDrawerListItemHeader
229 variant="danger"
230 headingLevel="h5"
231 title="Critical alert regarding control plane"
232 />
233 <NotificationDrawerListItemBody>
234 This is a long description to show how the title will wrap if it is long and wraps to multiple lines.
235 </NotificationDrawerListItemBody>
236 </NotificationDrawerListItem>
237 <NotificationDrawerListItem variant="warning">
238 <NotificationDrawerListItemHeader variant="warning" headingLevel="h5" title="Warning alert" />
239 <NotificationDrawerListItemBody>
240 This is a warning notification description.
241 </NotificationDrawerListItemBody>
242 </NotificationDrawerListItem>
243 </NotificationDrawerList>
244 </NotificationDrawerGroup>
245 </NotificationDrawerBody>
246 </NotificationDrawer>
247 );
248
249 return (
250 <Card>
251 {header}
252 {body}
253 <Divider />
254 {drawer}
255 </Card>
256 );
257 };