@parca/profile 0.16.379 → 0.16.380

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.
@@ -0,0 +1,89 @@
1
+ // Copyright 2022 The Parca Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+
14
+ import {
15
+ getMemoOptions,
16
+ memo,
17
+ type Row,
18
+ type RowData,
19
+ type RowModel,
20
+ type Table,
21
+ } from '@tanstack/table-core';
22
+
23
+ export function getTopAndBottomExpandedRowModel<TData extends RowData>(): (
24
+ table: Table<TData>
25
+ ) => () => RowModel<TData> {
26
+ return table =>
27
+ memo(
28
+ () => [
29
+ table.getState().expanded,
30
+ table.getPreExpandedRowModel(),
31
+ table.options.paginateExpandedRows,
32
+ ],
33
+ (expanded, rowModel, paginateExpandedRows) => {
34
+ if (
35
+ rowModel.rows.length === 0 ||
36
+ (expanded !== true && Object.keys(expanded ?? {}).length === 0)
37
+ ) {
38
+ return rowModel;
39
+ }
40
+
41
+ if (paginateExpandedRows !== true) {
42
+ // Only expand rows at this point if they are being paginated
43
+ return rowModel;
44
+ }
45
+
46
+ return expandRows(rowModel);
47
+ },
48
+ getMemoOptions(table.options, 'debugTable', 'getExpandedRowModel')
49
+ );
50
+ }
51
+
52
+ export function expandRows<TData extends RowData>(rowModel: RowModel<TData>): RowModel<TData> {
53
+ const expandedRows: Array<Row<TData>> = [];
54
+
55
+ const handleRow = (row: Row<TData>): void => {
56
+ if (!row.getIsExpanded()) {
57
+ expandedRows.push(row);
58
+ return;
59
+ }
60
+
61
+ // @ts-expect-error
62
+ const topSubRows = (row.subRows ?? []).filter(subRow => subRow.original?.isTopSubRow);
63
+ if (topSubRows.length > 0) {
64
+ topSubRows.forEach(handleRow);
65
+ }
66
+ expandedRows.push(row);
67
+
68
+ // @ts-expect-error
69
+ const bottomSubRows = (row.subRows ?? []).filter(subRow => subRow.original?.isBottomSubRow);
70
+
71
+ if (bottomSubRows.length > 0) {
72
+ // Needs to be split into dummy and non-dummy rows to ensure that the dummy rows are rendered at the bottom.
73
+ // @ts-expect-error
74
+ const dummyRows = bottomSubRows.filter(subRow => 'size' in subRow.original);
75
+ // @ts-expect-error
76
+ const nonDummyRows = bottomSubRows.filter(subRow => !('size' in subRow.original));
77
+ nonDummyRows.forEach(handleRow);
78
+ dummyRows.forEach(handleRow);
79
+ }
80
+ };
81
+
82
+ rowModel.rows.forEach(handleRow);
83
+
84
+ return {
85
+ rows: expandedRows,
86
+ flatRows: rowModel.flatRows,
87
+ rowsById: rowModel.rowsById,
88
+ };
89
+ }