1 | import * as React from 'react';
|
2 |
|
3 | function fillRecords(list, record, indent, childrenColumnName, expandedKeys, getRowKey, index) {
|
4 | list.push({
|
5 | record: record,
|
6 | indent: indent,
|
7 | index: index
|
8 | });
|
9 | var key = getRowKey(record);
|
10 | var expanded = expandedKeys === null || expandedKeys === void 0 ? void 0 : expandedKeys.has(key);
|
11 | if (record && Array.isArray(record[childrenColumnName]) && expanded) {
|
12 |
|
13 | for (var i = 0; i < record[childrenColumnName].length; i += 1) {
|
14 | fillRecords(list, record[childrenColumnName][i], indent + 1, childrenColumnName, expandedKeys, getRowKey, i);
|
15 | }
|
16 | }
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export default function useFlattenRecords(data, childrenColumnName, expandedKeys, getRowKey) {
|
30 | var arr = React.useMemo(function () {
|
31 | if (expandedKeys !== null && expandedKeys !== void 0 && expandedKeys.size) {
|
32 | var list = [];
|
33 |
|
34 |
|
35 | for (var i = 0; i < (data === null || data === void 0 ? void 0 : data.length); i += 1) {
|
36 | var record = data[i];
|
37 |
|
38 |
|
39 | fillRecords(list, record, 0, childrenColumnName, expandedKeys, getRowKey, i);
|
40 | }
|
41 | return list;
|
42 | }
|
43 | return data === null || data === void 0 ? void 0 : data.map(function (item, index) {
|
44 | return {
|
45 | record: item,
|
46 | indent: 0,
|
47 | index: index
|
48 | };
|
49 | });
|
50 | }, [data, childrenColumnName, expandedKeys, getRowKey]);
|
51 | return arr;
|
52 | } |
\ | No newline at end of file |