@patternfly/react-data-view 5.5.0 → 5.5.1
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.
|
@@ -40,19 +40,31 @@ const react_table_1 = require("@patternfly/react-table");
|
|
|
40
40
|
const InternalContext_1 = require("../InternalContext");
|
|
41
41
|
const DataViewTableHead_1 = require("../DataViewTableHead");
|
|
42
42
|
const DataViewTable_1 = require("../DataViewTable");
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
const getNodesAffectedBySelection = (allRows, node, isChecking, isSelected) => {
|
|
44
|
+
const getDescendants = (node) => node.children ? node.children.flatMap(getDescendants).concat(node) : [node];
|
|
45
|
+
const findParent = (child, rows) => {
|
|
46
|
+
var _a;
|
|
47
|
+
return (_a = rows.find(row => { var _a; return (_a = row.children) === null || _a === void 0 ? void 0 : _a.some(c => c === child); })) !== null && _a !== void 0 ? _a : rows.flatMap(row => { var _a; return (_a = row.children) !== null && _a !== void 0 ? _a : []; }).map(c => findParent(child, [c])).find(p => p);
|
|
48
|
+
};
|
|
49
|
+
const getAncestors = (node) => {
|
|
50
|
+
const ancestors = [];
|
|
51
|
+
let parent = findParent(node, allRows);
|
|
52
|
+
while (parent) {
|
|
53
|
+
ancestors.push(parent);
|
|
54
|
+
parent = findParent(parent, allRows);
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
return ancestors;
|
|
57
|
+
};
|
|
58
|
+
const affectedNodes = new Set([node, ...getDescendants(node)]);
|
|
59
|
+
getAncestors(node).forEach(ancestor => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const allChildrenSelected = (_a = ancestor.children) === null || _a === void 0 ? void 0 : _a.every(child => (isSelected === null || isSelected === void 0 ? void 0 : isSelected(child)) || affectedNodes.has(child));
|
|
62
|
+
const anyChildAffected = (_b = ancestor.children) === null || _b === void 0 ? void 0 : _b.some(child => affectedNodes.has(child) || child.id === node.id);
|
|
63
|
+
if (isChecking ? !(isSelected === null || isSelected === void 0 ? void 0 : isSelected(ancestor)) && allChildrenSelected : (isSelected === null || isSelected === void 0 ? void 0 : isSelected(ancestor)) && anyChildAffected) {
|
|
64
|
+
affectedNodes.add(ancestor);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return Array.from(affectedNodes);
|
|
56
68
|
};
|
|
57
69
|
const DataViewTableTree = (_a) => {
|
|
58
70
|
var { columns, rows, headStates, bodyStates, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "headStates", "bodyStates", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
@@ -70,7 +82,7 @@ const DataViewTableTree = (_a) => {
|
|
|
70
82
|
}
|
|
71
83
|
const isExpanded = expandedNodeIds.includes(node.id);
|
|
72
84
|
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
73
|
-
const isChecked = isSelected
|
|
85
|
+
const isChecked = isSelected === null || isSelected === void 0 ? void 0 : isSelected(node);
|
|
74
86
|
let icon = leafIcon;
|
|
75
87
|
if (node.children) {
|
|
76
88
|
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
@@ -84,7 +96,7 @@ const DataViewTableTree = (_a) => {
|
|
|
84
96
|
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
85
97
|
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [...otherDetailsExpandedNodeIds, node.id];
|
|
86
98
|
}),
|
|
87
|
-
onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking,
|
|
99
|
+
onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking, getNodesAffectedBySelection(rows, node, isChecking, isSelected)),
|
|
88
100
|
rowIndex,
|
|
89
101
|
props: {
|
|
90
102
|
isExpanded,
|
|
@@ -14,19 +14,31 @@ import { Table, Tbody, Td, TreeRowWrapper, } from '@patternfly/react-table';
|
|
|
14
14
|
import { useInternalContext } from '../InternalContext';
|
|
15
15
|
import { DataViewTableHead } from '../DataViewTableHead';
|
|
16
16
|
import { isDataViewTdObject } from '../DataViewTable';
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const getNodesAffectedBySelection = (allRows, node, isChecking, isSelected) => {
|
|
18
|
+
const getDescendants = (node) => node.children ? node.children.flatMap(getDescendants).concat(node) : [node];
|
|
19
|
+
const findParent = (child, rows) => {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = rows.find(row => { var _a; return (_a = row.children) === null || _a === void 0 ? void 0 : _a.some(c => c === child); })) !== null && _a !== void 0 ? _a : rows.flatMap(row => { var _a; return (_a = row.children) !== null && _a !== void 0 ? _a : []; }).map(c => findParent(child, [c])).find(p => p);
|
|
22
|
+
};
|
|
23
|
+
const getAncestors = (node) => {
|
|
24
|
+
const ancestors = [];
|
|
25
|
+
let parent = findParent(node, allRows);
|
|
26
|
+
while (parent) {
|
|
27
|
+
ancestors.push(parent);
|
|
28
|
+
parent = findParent(parent, allRows);
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
return ancestors;
|
|
31
|
+
};
|
|
32
|
+
const affectedNodes = new Set([node, ...getDescendants(node)]);
|
|
33
|
+
getAncestors(node).forEach(ancestor => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const allChildrenSelected = (_a = ancestor.children) === null || _a === void 0 ? void 0 : _a.every(child => (isSelected === null || isSelected === void 0 ? void 0 : isSelected(child)) || affectedNodes.has(child));
|
|
36
|
+
const anyChildAffected = (_b = ancestor.children) === null || _b === void 0 ? void 0 : _b.some(child => affectedNodes.has(child) || child.id === node.id);
|
|
37
|
+
if (isChecking ? !(isSelected === null || isSelected === void 0 ? void 0 : isSelected(ancestor)) && allChildrenSelected : (isSelected === null || isSelected === void 0 ? void 0 : isSelected(ancestor)) && anyChildAffected) {
|
|
38
|
+
affectedNodes.add(ancestor);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return Array.from(affectedNodes);
|
|
30
42
|
};
|
|
31
43
|
export const DataViewTableTree = (_a) => {
|
|
32
44
|
var { columns, rows, headStates, bodyStates, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "headStates", "bodyStates", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
@@ -44,7 +56,7 @@ export const DataViewTableTree = (_a) => {
|
|
|
44
56
|
}
|
|
45
57
|
const isExpanded = expandedNodeIds.includes(node.id);
|
|
46
58
|
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
47
|
-
const isChecked = isSelected
|
|
59
|
+
const isChecked = isSelected === null || isSelected === void 0 ? void 0 : isSelected(node);
|
|
48
60
|
let icon = leafIcon;
|
|
49
61
|
if (node.children) {
|
|
50
62
|
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
@@ -58,7 +70,7 @@ export const DataViewTableTree = (_a) => {
|
|
|
58
70
|
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
59
71
|
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [...otherDetailsExpandedNodeIds, node.id];
|
|
60
72
|
}),
|
|
61
|
-
onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking,
|
|
73
|
+
onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking, getNodesAffectedBySelection(rows, node, isChecking, isSelected)),
|
|
62
74
|
rowIndex,
|
|
63
75
|
props: {
|
|
64
76
|
isExpanded,
|
package/package.json
CHANGED
|
@@ -12,24 +12,45 @@ import { DataViewTableHead } from '../DataViewTableHead';
|
|
|
12
12
|
import { DataViewTh, DataViewTrTree, isDataViewTdObject } from '../DataViewTable';
|
|
13
13
|
import { DataViewState } from '../DataView/DataView';
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
const getNodesAffectedBySelection = (
|
|
16
|
+
allRows: DataViewTrTree[],
|
|
17
|
+
node: DataViewTrTree,
|
|
18
|
+
isChecking: boolean,
|
|
19
|
+
isSelected?: (item: DataViewTrTree) => boolean
|
|
20
|
+
): DataViewTrTree[] => {
|
|
21
|
+
|
|
22
|
+
const getDescendants = (node: DataViewTrTree): DataViewTrTree[] =>
|
|
23
|
+
node.children ? node.children.flatMap(getDescendants).concat(node) : [ node ];
|
|
24
|
+
|
|
25
|
+
const findParent = (child: DataViewTrTree, rows: DataViewTrTree[]): DataViewTrTree | undefined =>
|
|
26
|
+
rows.find(row => row.children?.some(c => c === child)) ??
|
|
27
|
+
rows.flatMap(row => row.children ?? []).map(c => findParent(child, [ c ])).find(p => p);
|
|
28
|
+
|
|
29
|
+
const getAncestors = (node: DataViewTrTree): DataViewTrTree[] => {
|
|
30
|
+
const ancestors: DataViewTrTree[] = [];
|
|
31
|
+
let parent = findParent(node, allRows);
|
|
32
|
+
while (parent) {
|
|
33
|
+
ancestors.push(parent);
|
|
34
|
+
parent = findParent(parent, allRows);
|
|
35
|
+
}
|
|
36
|
+
return ancestors;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const affectedNodes = new Set([ node, ...getDescendants(node) ]);
|
|
40
|
+
|
|
41
|
+
getAncestors(node).forEach(ancestor => {
|
|
42
|
+
const allChildrenSelected = ancestor.children?.every(child => isSelected?.(child) || affectedNodes.has(child));
|
|
43
|
+
const anyChildAffected = ancestor.children?.some(child => affectedNodes.has(child) || child.id === node.id);
|
|
44
|
+
|
|
45
|
+
if (isChecking ? !isSelected?.(ancestor) && allChildrenSelected : isSelected?.(ancestor) && anyChildAffected) {
|
|
46
|
+
affectedNodes.add(ancestor);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return Array.from(affectedNodes);
|
|
31
51
|
};
|
|
32
52
|
|
|
53
|
+
|
|
33
54
|
/** extends TableProps */
|
|
34
55
|
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
35
56
|
/** Columns definition */
|
|
@@ -83,7 +104,7 @@ export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
|
|
|
83
104
|
}
|
|
84
105
|
const isExpanded = expandedNodeIds.includes(node.id);
|
|
85
106
|
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
86
|
-
const isChecked = isSelected
|
|
107
|
+
const isChecked = isSelected?.(node);
|
|
87
108
|
let icon = leafIcon;
|
|
88
109
|
if (node.children) {
|
|
89
110
|
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
@@ -100,7 +121,7 @@ export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
|
|
|
100
121
|
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
101
122
|
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [ ...otherDetailsExpandedNodeIds, node.id ];
|
|
102
123
|
}),
|
|
103
|
-
onCheckChange: (isSelectDisabled?.(node) || !onSelect) ? undefined : (_event, isChecking) => onSelect?.(isChecking,
|
|
124
|
+
onCheckChange: (isSelectDisabled?.(node) || !onSelect) ? undefined : (_event, isChecking) => onSelect?.(isChecking, getNodesAffectedBySelection(rows, node, isChecking, isSelected)),
|
|
104
125
|
rowIndex,
|
|
105
126
|
props: {
|
|
106
127
|
isExpanded,
|