@patternfly/react-table 4.91.15 → 4.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "4.91.15",
3
+ "version": "4.92.0",
4
4
  "description": "This library provides a set of React table components for use with the PatternFly 4",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,10 +31,10 @@
31
31
  "clean": "rimraf dist"
32
32
  },
33
33
  "dependencies": {
34
- "@patternfly/react-core": "^4.222.15",
35
- "@patternfly/react-icons": "^4.73.15",
36
- "@patternfly/react-styles": "^4.72.15",
37
- "@patternfly/react-tokens": "^4.74.15",
34
+ "@patternfly/react-core": "^4.223.0",
35
+ "@patternfly/react-icons": "^4.74.0",
36
+ "@patternfly/react-styles": "^4.73.0",
37
+ "@patternfly/react-tokens": "^4.75.0",
38
38
  "lodash": "^4.17.19",
39
39
  "tslib": "^2.0.0"
40
40
  },
@@ -46,5 +46,5 @@
46
46
  "react": "^16.8.0 || ^17.0.0",
47
47
  "react-dom": "^16.8.0 || ^17.0.0"
48
48
  },
49
- "gitHead": "95acf13e41106a55890dd36b6764104a0b8f4b63"
49
+ "gitHead": "d9a07cccab946125e662b145b325eab6525f2211"
50
50
  }
@@ -26,6 +26,8 @@ export interface TrProps extends React.HTMLProps<HTMLTableRowElement>, OUIAProps
26
26
  isRowSelected?: boolean;
27
27
  /** Flag indicating the row is striped */
28
28
  isStriped?: boolean;
29
+ /** Flag indicating the row will act as a border. This is typically used for a table with a nested and sticky header. */
30
+ isBorderRow?: boolean;
29
31
  /** An event handler for the row */
30
32
  onRowClick?: (event?: React.KeyboardEvent | React.MouseEvent) => void;
31
33
  /** Flag indicating that the row is selectable */
@@ -43,6 +45,7 @@ const TrBase: React.FunctionComponent<TrProps> = ({
43
45
  isHoverable = false,
44
46
  isRowSelected = false,
45
47
  isStriped = false,
48
+ isBorderRow = false,
46
49
  innerRef,
47
50
  ouiaId,
48
51
  ouiaSafe = true,
@@ -92,6 +95,7 @@ const TrBase: React.FunctionComponent<TrProps> = ({
92
95
  isHoverable && styles.modifiers.hoverable,
93
96
  isRowSelected && styles.modifiers.selected,
94
97
  isStriped && styles.modifiers.striped,
98
+ isBorderRow && styles.modifiers.borderRow,
95
99
  resetOffset && styles.modifiers.firstCellOffsetReset
96
100
  )}
97
101
  hidden={rowIsHidden}
@@ -372,6 +372,11 @@ The second `Tr` represents the second level of sub columns. The `Th` in this row
372
372
  ```ts file="ComposableTableNestedTableExpandable.tsx"
373
373
  ```
374
374
 
375
+ ### Composable: Nested sticky header
376
+
377
+ ```ts file="ComposableTableNestedStickyHeader.tsx"
378
+ ```
379
+
375
380
  ## Striped
376
381
 
377
382
  ### Composable: Striped
@@ -0,0 +1,201 @@
1
+ import React from 'react';
2
+ import { TableComposable, Thead, Tr, Th, Tbody, Td, InnerScrollContainer, ThProps } from '@patternfly/react-table';
3
+ import { Stack, StackItem } from '@patternfly/react-core';
4
+
5
+ interface PodConnection {
6
+ source: {
7
+ podName: string;
8
+ port: { num: number; protocol: string };
9
+ };
10
+ destination: {
11
+ podName: string;
12
+ port: { num: number; protocol: string };
13
+ };
14
+ timestamp: string;
15
+ protocol: string;
16
+ flowRate: string;
17
+ traffic: string;
18
+ packets: number;
19
+ }
20
+
21
+ export const ComposableTableNestedHeaders: React.FunctionComponent = () => {
22
+ // In real usage, this data would come from some external source like an API via props.
23
+ const connections: PodConnection[] = [
24
+ {
25
+ source: { podName: 'api-pod-source-name', port: { num: 443, protocol: 'HTTPS' } },
26
+ destination: { podName: 'api-pod-destination-name', port: { num: 24, protocol: 'SMTP' } },
27
+ timestamp: '2021-06-22T19:58:24.000Z',
28
+ protocol: 'TCP',
29
+ flowRate: '1.9 Kbps',
30
+ traffic: '2.1 KB',
31
+ packets: 3
32
+ },
33
+ {
34
+ source: { podName: 'api-pod-source2-name', port: { num: 80, protocol: 'HTTP' } },
35
+ destination: { podName: 'api-pod-destination2-name', port: { num: 24, protocol: 'SMTP' } },
36
+ timestamp: '2021-06-22T21:42:01.000Z',
37
+ protocol: 'UDP',
38
+ flowRate: '3.4 Kbps',
39
+ traffic: '6.1 KB',
40
+ packets: 7
41
+ }
42
+ ];
43
+
44
+ const columnNames = {
45
+ pods: 'Pods',
46
+ source: 'Source',
47
+ destination: 'Destination',
48
+ datetime: 'Date & Time',
49
+ ports: 'Ports',
50
+ protocol: 'Protocol',
51
+ flowRate: 'Flow rate',
52
+ traffic: 'Traffic',
53
+ packets: 'Packets'
54
+ };
55
+
56
+ // Index of the currently sorted column
57
+ // Note: if you intend to make columns reorderable, you may instead want to use a non-numeric key
58
+ // as the identifier of the sorted column. See the "Compound expandable" example.
59
+ const [activeSortIndex, setActiveSortIndex] = React.useState<number | null>(null);
60
+
61
+ // Sort direction of the currently sorted column
62
+ const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | null>(null);
63
+
64
+ // Since OnSort specifies sorted columns by index, we need sortable values for our object by column index.
65
+ const getSortableRowValues = (connection: PodConnection): (string | number)[] => {
66
+ const { source, destination, timestamp, protocol, flowRate, traffic, packets } = connection;
67
+ return [
68
+ source.podName,
69
+ destination.podName,
70
+ timestamp,
71
+ source.port.num,
72
+ destination.port.num,
73
+ protocol,
74
+ flowRate,
75
+ traffic,
76
+ packets
77
+ ];
78
+ };
79
+
80
+ // Note that we perform the sort as part of the component's render logic and not in onSort.
81
+ // We shouldn't store the list of data in state because we don't want to have to sync that with props.
82
+ let sortedConnections = connections;
83
+ if (activeSortIndex !== null) {
84
+ sortedConnections = connections.sort((a, b) => {
85
+ const aValue = getSortableRowValues(a)[activeSortIndex];
86
+ const bValue = getSortableRowValues(b)[activeSortIndex];
87
+ if (typeof aValue === 'number') {
88
+ // Numeric sort
89
+ if (activeSortDirection === 'asc') {
90
+ return (aValue as number) - (bValue as number);
91
+ }
92
+ return (bValue as number) - (aValue as number);
93
+ } else {
94
+ // String sort
95
+ if (activeSortDirection === 'asc') {
96
+ return (aValue as string).localeCompare(bValue as string);
97
+ }
98
+ return (bValue as string).localeCompare(aValue as string);
99
+ }
100
+ });
101
+ }
102
+
103
+ const getSortParams = (columnIndex: number): ThProps['sort'] => ({
104
+ sortBy: {
105
+ index: activeSortIndex as number,
106
+ direction: activeSortDirection as 'asc' | 'desc'
107
+ },
108
+ onSort: (_event, index, direction) => {
109
+ setActiveSortIndex(index);
110
+ setActiveSortDirection(direction);
111
+ },
112
+ columnIndex
113
+ });
114
+
115
+ return (
116
+ <InnerScrollContainer>
117
+ <TableComposable aria-label="Nested column headers table" gridBreakPoint="" isStickyHeader>
118
+ <Thead hasNestedHeader>
119
+ <Tr>
120
+ <Th hasRightBorder colSpan={3}>
121
+ {columnNames.pods}
122
+ </Th>
123
+ <Th hasRightBorder colSpan={2}>
124
+ {columnNames.ports}
125
+ </Th>
126
+ <Th modifier="fitContent" hasRightBorder rowSpan={2} sort={getSortParams(5)}>
127
+ {columnNames.protocol}
128
+ </Th>
129
+ <Th modifier="fitContent" hasRightBorder rowSpan={2} sort={getSortParams(6)}>
130
+ {columnNames.flowRate}
131
+ </Th>
132
+ <Th modifier="fitContent" hasRightBorder rowSpan={2} sort={getSortParams(7)}>
133
+ {columnNames.traffic}
134
+ </Th>
135
+ <Th modifier="fitContent" rowSpan={2} sort={getSortParams(8)}>
136
+ {columnNames.packets}
137
+ </Th>
138
+ </Tr>
139
+ <Tr>
140
+ <Th isSubheader sort={getSortParams(0)}>
141
+ {columnNames.source}
142
+ </Th>
143
+ <Th isSubheader sort={getSortParams(1)}>
144
+ {columnNames.destination}
145
+ </Th>
146
+ <Th isSubheader modifier="fitContent" hasRightBorder sort={getSortParams(2)}>
147
+ {columnNames.datetime}
148
+ </Th>
149
+ <Th isSubheader modifier="fitContent" sort={getSortParams(3)}>
150
+ {columnNames.source}
151
+ </Th>
152
+ <Th isSubheader modifier="fitContent" hasRightBorder sort={getSortParams(4)}>
153
+ {columnNames.destination}
154
+ </Th>
155
+ </Tr>
156
+ <Tr isBorderRow aria-hidden="true">
157
+ <Td colSpan={9}></Td>
158
+ </Tr>
159
+ </Thead>
160
+ <Tbody>
161
+ {sortedConnections.map(connection => (
162
+ <Tr key={connection.source.podName}>
163
+ <Td dataLabel={columnNames.source}>{connection.source.podName}</Td>
164
+ <Td dataLabel={columnNames.destination}>{connection.destination.podName}</Td>\
165
+ <Td dataLabel={columnNames.datetime}>
166
+ <div>
167
+ <span>{new Date(connection.timestamp).toDateString()}</span>{' '}
168
+ <span className="pf-u-color-200">{new Date(connection.timestamp).toLocaleTimeString()}</span>
169
+ </div>
170
+ </Td>
171
+ <Td dataLabel={columnNames.source}>
172
+ <Stack>
173
+ <StackItem>
174
+ <span>{connection.source.port.num}</span>
175
+ </StackItem>
176
+ <StackItem>
177
+ <span className="pf-u-color-200">({connection.source.port.protocol})</span>
178
+ </StackItem>
179
+ </Stack>
180
+ </Td>
181
+ <Td dataLabel={columnNames.destination}>
182
+ <Stack>
183
+ <StackItem>
184
+ <span>{connection.destination.port.num}</span>
185
+ </StackItem>
186
+ <StackItem>
187
+ <span className="pf-u-color-200">({connection.destination.port.protocol})</span>
188
+ </StackItem>
189
+ </Stack>
190
+ </Td>
191
+ <Td dataLabel={columnNames.protocol}>{connection.protocol}</Td>
192
+ <Td dataLabel={columnNames.flowRate}>{connection.flowRate}</Td>
193
+ <Td dataLabel={columnNames.traffic}>{connection.traffic}</Td>
194
+ <Td dataLabel={columnNames.packets}>{connection.packets}</Td>
195
+ </Tr>
196
+ ))}
197
+ </Tbody>
198
+ </TableComposable>
199
+ </InnerScrollContainer>
200
+ );
201
+ };