@parca/profile 0.16.425 → 0.16.427
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/CHANGELOG.md +8 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.js +1 -1
- package/dist/ProfileIcicleGraph/index.d.ts +1 -1
- package/dist/ProfileIcicleGraph/index.d.ts.map +1 -1
- package/dist/ProfileIcicleGraph/index.js +4 -59
- package/dist/ProfileSelector/index.d.ts.map +1 -1
- package/dist/ProfileSelector/index.js +11 -6
- package/dist/ProfileView/VisualizationPanel.d.ts.map +1 -1
- package/dist/ProfileView/VisualizationPanel.js +2 -3
- package/dist/ProfileView/index.d.ts.map +1 -1
- package/dist/ProfileView/index.js +21 -14
- package/dist/Table/ColumnsVisibility.js +1 -1
- package/dist/Table/index.d.ts +6 -0
- package/dist/Table/index.d.ts.map +1 -1
- package/dist/Table/index.js +45 -21
- package/dist/ViewMatchers/index.d.ts +14 -0
- package/dist/ViewMatchers/index.d.ts.map +1 -0
- package/dist/ViewMatchers/index.js +103 -0
- package/dist/components/ActionButtons/GroupByDropdown.d.ts.map +1 -0
- package/dist/{ProfileIcicleGraph → components}/ActionButtons/GroupByDropdown.js +1 -1
- package/dist/components/FilterByFunctionButton.d.ts.map +1 -0
- package/dist/components/ShareButton/ResultBox.d.ts.map +1 -0
- package/dist/components/ShareButton/index.d.ts +14 -0
- package/dist/components/ShareButton/index.d.ts.map +1 -0
- package/dist/components/{ProfileShareButton → ShareButton}/index.js +28 -5
- package/dist/components/ViewSelector/Dropdown.d.ts +30 -0
- package/dist/components/ViewSelector/Dropdown.d.ts.map +1 -0
- package/dist/components/ViewSelector/Dropdown.js +41 -0
- package/dist/components/ViewSelector/index.d.ts +3 -0
- package/dist/components/ViewSelector/index.d.ts.map +1 -0
- package/dist/{ProfileView/ViewSelector.js → components/ViewSelector/index.js} +25 -12
- package/dist/components/VisualisationToolbar/MultiLevelDropdown.d.ts +9 -0
- package/dist/components/VisualisationToolbar/MultiLevelDropdown.d.ts.map +1 -0
- package/dist/components/VisualisationToolbar/MultiLevelDropdown.js +123 -0
- package/dist/components/VisualisationToolbar/TableColumnsDropdown.d.ts +9 -0
- package/dist/components/VisualisationToolbar/TableColumnsDropdown.d.ts.map +1 -0
- package/dist/components/VisualisationToolbar/TableColumnsDropdown.js +189 -0
- package/dist/components/VisualisationToolbar/index.d.ts +25 -0
- package/dist/components/VisualisationToolbar/index.d.ts.map +1 -0
- package/dist/components/VisualisationToolbar/index.js +55 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -4
- package/src/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.tsx +1 -1
- package/src/ProfileIcicleGraph/index.tsx +3 -206
- package/src/ProfileSelector/index.tsx +59 -33
- package/src/ProfileView/VisualizationPanel.tsx +1 -6
- package/src/ProfileView/index.tsx +46 -56
- package/src/Table/ColumnsVisibility.tsx +1 -1
- package/src/Table/index.tsx +64 -42
- package/src/ViewMatchers/index.tsx +190 -0
- package/src/{ProfileIcicleGraph → components}/ActionButtons/GroupByDropdown.tsx +1 -1
- package/src/components/{ProfileShareButton → ShareButton}/index.tsx +88 -24
- package/src/components/ViewSelector/Dropdown.tsx +181 -0
- package/src/{ProfileView/ViewSelector.tsx → components/ViewSelector/index.tsx} +32 -39
- package/src/components/VisualisationToolbar/MultiLevelDropdown.tsx +258 -0
- package/src/components/VisualisationToolbar/TableColumnsDropdown.tsx +222 -0
- package/src/components/VisualisationToolbar/index.tsx +171 -0
- package/src/index.tsx +3 -1
- package/dist/ProfileIcicleGraph/ActionButtons/GroupByDropdown.d.ts.map +0 -1
- package/dist/ProfileIcicleGraph/ActionButtons/SortBySelect.d.ts +0 -7
- package/dist/ProfileIcicleGraph/ActionButtons/SortBySelect.d.ts.map +0 -1
- package/dist/ProfileIcicleGraph/ActionButtons/SortBySelect.js +0 -44
- package/dist/ProfileView/FilterByFunctionButton.d.ts.map +0 -1
- package/dist/ProfileView/ViewSelector.d.ts +0 -13
- package/dist/ProfileView/ViewSelector.d.ts.map +0 -1
- package/dist/components/ProfileShareButton/ResultBox.d.ts.map +0 -1
- package/dist/components/ProfileShareButton/index.d.ts +0 -9
- package/dist/components/ProfileShareButton/index.d.ts.map +0 -1
- package/src/ProfileIcicleGraph/ActionButtons/SortBySelect.tsx +0 -81
- /package/dist/{ProfileIcicleGraph → components}/ActionButtons/GroupByDropdown.d.ts +0 -0
- /package/dist/{ProfileView → components}/FilterByFunctionButton.d.ts +0 -0
- /package/dist/{ProfileView → components}/FilterByFunctionButton.js +0 -0
- /package/dist/components/{ProfileShareButton → ShareButton}/ResultBox.d.ts +0 -0
- /package/dist/components/{ProfileShareButton → ShareButton}/ResultBox.js +0 -0
- /package/src/{ProfileView → components}/FilterByFunctionButton.tsx +0 -0
- /package/src/components/{ProfileShareButton → ShareButton}/ResultBox.tsx +0 -0
|
@@ -11,29 +11,11 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {useParcaContext, useURLState} from '@parca/components';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
position: number;
|
|
18
|
-
defaultValue: string;
|
|
19
|
-
placeholderText?: string;
|
|
20
|
-
primary?: boolean;
|
|
21
|
-
addView?: boolean;
|
|
22
|
-
disabled?: boolean;
|
|
23
|
-
icon?: JSX.Element;
|
|
24
|
-
id?: string;
|
|
25
|
-
}
|
|
16
|
+
import Dropdown, {DropdownElement, InnerAction} from './Dropdown';
|
|
26
17
|
|
|
27
|
-
const ViewSelector = ({
|
|
28
|
-
defaultValue,
|
|
29
|
-
position,
|
|
30
|
-
placeholderText,
|
|
31
|
-
primary = false,
|
|
32
|
-
addView = false,
|
|
33
|
-
disabled = false,
|
|
34
|
-
icon,
|
|
35
|
-
id,
|
|
36
|
-
}: Props): JSX.Element => {
|
|
18
|
+
const ViewSelector = (): JSX.Element => {
|
|
37
19
|
const [dashboardItems = ['icicle'], setDashboardItems] = useURLState<string[]>(
|
|
38
20
|
'dashboard_items',
|
|
39
21
|
{
|
|
@@ -56,7 +38,7 @@ const ViewSelector = ({
|
|
|
56
38
|
}: {
|
|
57
39
|
key: string;
|
|
58
40
|
supportingText?: string;
|
|
59
|
-
}):
|
|
41
|
+
}): DropdownElement => {
|
|
60
42
|
const title = <span className="capitalize">{key.replaceAll('-', ' ')}</span>;
|
|
61
43
|
|
|
62
44
|
return {
|
|
@@ -70,44 +52,55 @@ const ViewSelector = ({
|
|
|
70
52
|
};
|
|
71
53
|
};
|
|
72
54
|
|
|
55
|
+
const getInnerActionForItem = (item: {
|
|
56
|
+
key: string;
|
|
57
|
+
canBeSelected: boolean;
|
|
58
|
+
}): InnerAction | undefined => {
|
|
59
|
+
if (dashboardItems.length === 1 && item.key === dashboardItems[0]) return undefined;
|
|
60
|
+
return {
|
|
61
|
+
text:
|
|
62
|
+
!item.canBeSelected && item.key === 'source'
|
|
63
|
+
? 'Add Panel'
|
|
64
|
+
: item.canBeSelected
|
|
65
|
+
? 'Add Panel'
|
|
66
|
+
: 'Close Panel',
|
|
67
|
+
onClick: () => {
|
|
68
|
+
if (item.canBeSelected) {
|
|
69
|
+
setDashboardItems([...dashboardItems, item.key]);
|
|
70
|
+
} else {
|
|
71
|
+
setDashboardItems(dashboardItems.filter(v => v !== item.key));
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
73
77
|
const items = allItems.map(item => ({
|
|
74
78
|
key: item.key,
|
|
75
79
|
disabled: !item.canBeSelected,
|
|
76
80
|
element: getOption(item),
|
|
81
|
+
innerAction: getInnerActionForItem(item),
|
|
77
82
|
}));
|
|
78
83
|
|
|
79
84
|
const onSelection = (value: string): void => {
|
|
80
|
-
if (addView) {
|
|
81
|
-
setDashboardItems([dashboardItems[0], value]);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
85
|
const isOnlyChart = dashboardItems.length === 1;
|
|
86
86
|
if (isOnlyChart) {
|
|
87
87
|
setDashboardItems([value]);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
const isFirstChart = position === 0;
|
|
93
|
-
const newDashboardItems = isFirstChart
|
|
94
|
-
? [value, dashboardItems[1]]
|
|
95
|
-
: [dashboardItems[0], value];
|
|
91
|
+
const newDashboardItems = [dashboardItems[0], value];
|
|
96
92
|
|
|
97
93
|
setDashboardItems(newDashboardItems);
|
|
98
94
|
};
|
|
99
95
|
|
|
100
96
|
return (
|
|
101
|
-
<
|
|
97
|
+
<Dropdown
|
|
102
98
|
className="h-view-selector"
|
|
103
99
|
items={items}
|
|
104
|
-
selectedKey={
|
|
100
|
+
selectedKey={dashboardItems.length >= 2 ? 'Multiple' : dashboardItems[0]}
|
|
105
101
|
onSelection={onSelection}
|
|
106
|
-
placeholder={
|
|
107
|
-
|
|
108
|
-
disabled={disabled}
|
|
109
|
-
icon={icon}
|
|
110
|
-
id={id}
|
|
102
|
+
placeholder={'Select view type...'}
|
|
103
|
+
id="h-view-selector"
|
|
111
104
|
/>
|
|
112
105
|
);
|
|
113
106
|
};
|
|
@@ -0,0 +1,258 @@
|
|
|
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 React, {useCallback} from 'react';
|
|
15
|
+
|
|
16
|
+
import {Menu} from '@headlessui/react';
|
|
17
|
+
import {Icon} from '@iconify/react';
|
|
18
|
+
|
|
19
|
+
import {useURLState} from '@parca/components';
|
|
20
|
+
import {USER_PREFERENCES, useUserPreference} from '@parca/hooks';
|
|
21
|
+
import {ProfileType} from '@parca/parser';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
FIELD_CUMULATIVE,
|
|
25
|
+
FIELD_DIFF,
|
|
26
|
+
FIELD_FUNCTION_NAME,
|
|
27
|
+
} from '../../ProfileIcicleGraph/IcicleGraphArrow';
|
|
28
|
+
import {useProfileViewContext} from '../../ProfileView/ProfileViewContext';
|
|
29
|
+
|
|
30
|
+
interface MenuItemType {
|
|
31
|
+
label: string;
|
|
32
|
+
items?: MenuItemType[];
|
|
33
|
+
onclick?: () => void;
|
|
34
|
+
hide?: boolean;
|
|
35
|
+
id?: string;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
active?: boolean;
|
|
38
|
+
value?: string;
|
|
39
|
+
icon?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type MenuItemProps = MenuItemType & {
|
|
43
|
+
onSelect: (path: string[]) => void;
|
|
44
|
+
path?: string[];
|
|
45
|
+
closeDropdown: () => void;
|
|
46
|
+
isNested?: boolean;
|
|
47
|
+
activeValue?: string;
|
|
48
|
+
icon?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const MenuItem: React.FC<MenuItemProps> = ({
|
|
52
|
+
label,
|
|
53
|
+
items,
|
|
54
|
+
onclick,
|
|
55
|
+
onSelect,
|
|
56
|
+
path = [],
|
|
57
|
+
id,
|
|
58
|
+
closeDropdown,
|
|
59
|
+
isNested = false,
|
|
60
|
+
activeValue,
|
|
61
|
+
value,
|
|
62
|
+
disabled = false,
|
|
63
|
+
icon,
|
|
64
|
+
}) => {
|
|
65
|
+
const isActive = isNested && value === activeValue;
|
|
66
|
+
|
|
67
|
+
const handleSelect = (): void => {
|
|
68
|
+
if (items === undefined) {
|
|
69
|
+
if (onclick !== undefined) {
|
|
70
|
+
onclick();
|
|
71
|
+
closeDropdown();
|
|
72
|
+
} else {
|
|
73
|
+
onSelect([...path, label]);
|
|
74
|
+
closeDropdown();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className="relative">
|
|
81
|
+
<Menu>
|
|
82
|
+
{({close}) => (
|
|
83
|
+
<>
|
|
84
|
+
<Menu.Button
|
|
85
|
+
className={`w-full text-left px-4 py-2 text-sm ${
|
|
86
|
+
disabled
|
|
87
|
+
? 'text-gray-400'
|
|
88
|
+
: isActive
|
|
89
|
+
? 'text-white bg-indigo-400 hover:text-white'
|
|
90
|
+
: 'text-white-600 hover:bg-indigo-600 hover:text-white'
|
|
91
|
+
} flex justify-between items-center`}
|
|
92
|
+
onClick={handleSelect}
|
|
93
|
+
id={id}
|
|
94
|
+
disabled={disabled}
|
|
95
|
+
>
|
|
96
|
+
<span className="flex items-center">
|
|
97
|
+
<div className="flex items-center">
|
|
98
|
+
<span>{label}</span>
|
|
99
|
+
{icon !== undefined && <Icon icon={icon} className="ml-2 h-4 w-4" />}
|
|
100
|
+
</div>
|
|
101
|
+
{isActive && <Icon icon="heroicons-solid:check" className="ml-2 h-4 w-4" />}
|
|
102
|
+
</span>
|
|
103
|
+
{items !== undefined && (
|
|
104
|
+
<Icon icon="flowbite:caret-right-solid" className="h-[14px] w-[14px]" />
|
|
105
|
+
)}
|
|
106
|
+
</Menu.Button>
|
|
107
|
+
{items !== undefined && (
|
|
108
|
+
<Menu.Items className="absolute left-full top-0 w-56 mt-0 origin-top-right bg-white border border-gray-200 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-900 ml-1 dark:border-gray-600">
|
|
109
|
+
{items?.map((item, index) => (
|
|
110
|
+
<MenuItem
|
|
111
|
+
key={index}
|
|
112
|
+
{...item}
|
|
113
|
+
onSelect={selectedPath => {
|
|
114
|
+
onSelect([...path, ...selectedPath]);
|
|
115
|
+
close();
|
|
116
|
+
closeDropdown();
|
|
117
|
+
}}
|
|
118
|
+
path={[...path, label]}
|
|
119
|
+
closeDropdown={closeDropdown}
|
|
120
|
+
isNested={true}
|
|
121
|
+
activeValue={activeValue}
|
|
122
|
+
/>
|
|
123
|
+
))}
|
|
124
|
+
</Menu.Items>
|
|
125
|
+
)}
|
|
126
|
+
</>
|
|
127
|
+
)}
|
|
128
|
+
</Menu>
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
interface MultiLevelDropdownProps {
|
|
134
|
+
onSelect: (path: string[]) => void;
|
|
135
|
+
profileType?: ProfileType;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const MultiLevelDropdown: React.FC<MultiLevelDropdownProps> = ({onSelect, profileType}) => {
|
|
139
|
+
const [storeSortBy, setStoreSortBy] = useURLState('sort_by', {
|
|
140
|
+
defaultValue: FIELD_FUNCTION_NAME,
|
|
141
|
+
});
|
|
142
|
+
const [colorStackLegend, setStoreColorStackLegend] = useURLState('color_stack_legend');
|
|
143
|
+
const [binaryFrameFilter, setBinaryFrameFilter] = useURLState('binary_frame_filter');
|
|
144
|
+
const {compareMode} = useProfileViewContext();
|
|
145
|
+
const [colorProfileName] = useUserPreference<string>(
|
|
146
|
+
USER_PREFERENCES.FLAMEGRAPH_COLOR_PROFILE.key
|
|
147
|
+
);
|
|
148
|
+
const [invertStack = '', setInvertStack] = useURLState('invert_call_stack');
|
|
149
|
+
const isInvert = invertStack === 'true';
|
|
150
|
+
const isColorStackLegendEnabled = colorStackLegend === 'true';
|
|
151
|
+
|
|
152
|
+
// By default, we want delta profiles (CPU) to be relatively compared.
|
|
153
|
+
// For non-delta profiles, like goroutines or memory, we want the profiles to be compared absolutely.
|
|
154
|
+
const compareAbsoluteDefault = profileType?.delta === false ? 'true' : 'false';
|
|
155
|
+
|
|
156
|
+
const [compareAbsolute = compareAbsoluteDefault, setCompareAbsolute] =
|
|
157
|
+
useURLState('compare_absolute');
|
|
158
|
+
const isCompareAbsolute = compareAbsolute === 'true';
|
|
159
|
+
|
|
160
|
+
const setColorStackLegend = useCallback(
|
|
161
|
+
(value: string): void => {
|
|
162
|
+
setStoreColorStackLegend(value);
|
|
163
|
+
},
|
|
164
|
+
[setStoreColorStackLegend]
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const resetLegend = (): void => {
|
|
168
|
+
setBinaryFrameFilter([]);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const menuItems: MenuItemType[] = [
|
|
172
|
+
{
|
|
173
|
+
label: 'Sort by',
|
|
174
|
+
id: 'h-sort-by-filter',
|
|
175
|
+
items: [
|
|
176
|
+
{
|
|
177
|
+
label: 'Function',
|
|
178
|
+
onclick: () => setStoreSortBy(FIELD_FUNCTION_NAME),
|
|
179
|
+
value: FIELD_FUNCTION_NAME,
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
label: 'Cumulative',
|
|
183
|
+
onclick: () => setStoreSortBy(FIELD_CUMULATIVE),
|
|
184
|
+
value: FIELD_CUMULATIVE,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
label: 'Diff',
|
|
188
|
+
onclick: () => setStoreSortBy(FIELD_DIFF),
|
|
189
|
+
value: FIELD_DIFF,
|
|
190
|
+
disabled: !compareMode,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
hide: false,
|
|
194
|
+
icon: 'material-symbols:sort',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
label: isColorStackLegendEnabled ? 'Hide legend' : 'Show legend',
|
|
198
|
+
onclick: () => setColorStackLegend(isColorStackLegendEnabled ? 'false' : 'true'),
|
|
199
|
+
hide: compareMode || colorProfileName === 'default',
|
|
200
|
+
id: 'h-show-legend-button',
|
|
201
|
+
icon: isColorStackLegendEnabled ? 'ph:eye-closed' : 'ph:eye',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
label: isInvert ? 'Original Call Stack' : 'Invert Call Stack',
|
|
205
|
+
onclick: () => setInvertStack(isInvert ? '' : 'true'),
|
|
206
|
+
hide: false,
|
|
207
|
+
icon: isInvert ? 'ph:sort-ascending' : 'ph:sort-descending',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
label: isCompareAbsolute ? 'Compare Relative' : 'Compare Absolute',
|
|
211
|
+
onclick: () => setCompareAbsolute(isCompareAbsolute ? 'false' : 'true'),
|
|
212
|
+
hide: !compareMode,
|
|
213
|
+
icon: isCompareAbsolute ? 'fluent-mdl2:compare' : 'fluent-mdl2:compare-uneven',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
label: 'Reset Legend',
|
|
217
|
+
hide: binaryFrameFilter === undefined || binaryFrameFilter.length === 0,
|
|
218
|
+
onclick: () => resetLegend(),
|
|
219
|
+
id: 'h-reset-legend-button',
|
|
220
|
+
icon: 'system-uicons:reset',
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div className="relative inline-block text-left">
|
|
226
|
+
<Menu>
|
|
227
|
+
{({open, close}) => (
|
|
228
|
+
<>
|
|
229
|
+
<Menu.Button className="inline-flex dark:bg-gray-900 dark:border-gray-600 justify-center w-full px-4 py-2 text-sm font-medium text-white bg-white rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75 border border-gray-200">
|
|
230
|
+
<Icon
|
|
231
|
+
icon="pepicons-pencil:dots-x"
|
|
232
|
+
className="h-5 w-5 text-gray-800 dark:text-gray-200"
|
|
233
|
+
/>
|
|
234
|
+
</Menu.Button>
|
|
235
|
+
{open && (
|
|
236
|
+
<Menu.Items className="absolute z-30 right-0 w-56 mt-2 py-2 origin-top-right bg-white rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none border dark:bg-gray-900 dark:border-gray-600">
|
|
237
|
+
<span className="text-xs text-gray-400 capitalize px-4 py-3">actions</span>
|
|
238
|
+
{menuItems
|
|
239
|
+
.filter(item => item.hide !== undefined && !item.hide)
|
|
240
|
+
.map((item, index) => (
|
|
241
|
+
<MenuItem
|
|
242
|
+
key={index}
|
|
243
|
+
{...item}
|
|
244
|
+
onSelect={onSelect}
|
|
245
|
+
closeDropdown={close}
|
|
246
|
+
activeValue={storeSortBy as string}
|
|
247
|
+
/>
|
|
248
|
+
))}
|
|
249
|
+
</Menu.Items>
|
|
250
|
+
)}
|
|
251
|
+
</>
|
|
252
|
+
)}
|
|
253
|
+
</Menu>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export default MultiLevelDropdown;
|
|
@@ -0,0 +1,222 @@
|
|
|
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 {useEffect, useMemo, useState} from 'react';
|
|
15
|
+
|
|
16
|
+
import {createColumnHelper, type CellContext, type ColumnDef} from '@tanstack/table-core';
|
|
17
|
+
|
|
18
|
+
import {useURLState} from '@parca/components';
|
|
19
|
+
import {ProfileType} from '@parca/parser';
|
|
20
|
+
import {valueFormatter} from '@parca/utilities';
|
|
21
|
+
|
|
22
|
+
import {useProfileViewContext} from '../../ProfileView/ProfileViewContext';
|
|
23
|
+
import {ColumnName, DataRow, Row, addPlusSign, getRatioString, isDummyRow} from '../../Table';
|
|
24
|
+
import ColumnsVisibility from '../../Table/ColumnsVisibility';
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
profileType?: ProfileType;
|
|
28
|
+
total: bigint;
|
|
29
|
+
filtered: bigint;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const TableColumnsDropdown = ({profileType, total, filtered}: Props): JSX.Element => {
|
|
33
|
+
const {compareMode} = useProfileViewContext();
|
|
34
|
+
const [tableColumns, setTableColumns] = useURLState<string[]>('table_columns', {
|
|
35
|
+
alwaysReturnArray: true,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const columnHelper = createColumnHelper<Row>();
|
|
39
|
+
|
|
40
|
+
const unit: string = useMemo(() => profileType?.sampleUnit ?? '', [profileType?.sampleUnit]);
|
|
41
|
+
|
|
42
|
+
const columns = useMemo<Array<ColumnDef<Row>>>(() => {
|
|
43
|
+
return [
|
|
44
|
+
columnHelper.accessor('flat', {
|
|
45
|
+
id: 'flat',
|
|
46
|
+
header: 'Flat',
|
|
47
|
+
cell: info => valueFormatter((info as CellContext<DataRow, bigint>).getValue(), unit, 2),
|
|
48
|
+
size: 80,
|
|
49
|
+
meta: {
|
|
50
|
+
align: 'right',
|
|
51
|
+
},
|
|
52
|
+
invertSorting: true,
|
|
53
|
+
}),
|
|
54
|
+
columnHelper.accessor('flat', {
|
|
55
|
+
id: 'flatPercentage',
|
|
56
|
+
header: 'Flat (%)',
|
|
57
|
+
cell: info => {
|
|
58
|
+
if (isDummyRow(info.row.original)) {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
return getRatioString((info as CellContext<DataRow, bigint>).getValue(), total, filtered);
|
|
62
|
+
},
|
|
63
|
+
size: 120,
|
|
64
|
+
meta: {
|
|
65
|
+
align: 'right',
|
|
66
|
+
},
|
|
67
|
+
invertSorting: true,
|
|
68
|
+
}),
|
|
69
|
+
columnHelper.accessor('flatDiff', {
|
|
70
|
+
id: 'flatDiff',
|
|
71
|
+
header: 'Flat Diff',
|
|
72
|
+
cell: info =>
|
|
73
|
+
addPlusSign(valueFormatter((info as CellContext<DataRow, bigint>).getValue(), unit, 2)),
|
|
74
|
+
size: 120,
|
|
75
|
+
meta: {
|
|
76
|
+
align: 'right',
|
|
77
|
+
},
|
|
78
|
+
invertSorting: true,
|
|
79
|
+
}),
|
|
80
|
+
columnHelper.accessor('flatDiff', {
|
|
81
|
+
id: 'flatDiffPercentage',
|
|
82
|
+
header: 'Flat Diff (%)',
|
|
83
|
+
cell: info => {
|
|
84
|
+
if (isDummyRow(info.row.original)) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
return getRatioString((info as CellContext<DataRow, bigint>).getValue(), total, filtered);
|
|
88
|
+
},
|
|
89
|
+
size: 120,
|
|
90
|
+
meta: {
|
|
91
|
+
align: 'right',
|
|
92
|
+
},
|
|
93
|
+
invertSorting: true,
|
|
94
|
+
}),
|
|
95
|
+
columnHelper.accessor('cumulative', {
|
|
96
|
+
id: 'cumulative',
|
|
97
|
+
header: 'Cumulative',
|
|
98
|
+
cell: info => valueFormatter((info as CellContext<DataRow, bigint>).getValue(), unit, 2),
|
|
99
|
+
size: 150,
|
|
100
|
+
meta: {
|
|
101
|
+
align: 'right',
|
|
102
|
+
},
|
|
103
|
+
invertSorting: true,
|
|
104
|
+
}),
|
|
105
|
+
columnHelper.accessor('cumulative', {
|
|
106
|
+
id: 'cumulativePercentage',
|
|
107
|
+
header: 'Cumulative (%)',
|
|
108
|
+
cell: info => {
|
|
109
|
+
if (isDummyRow(info.row.original)) {
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
return getRatioString((info as CellContext<DataRow, bigint>).getValue(), total, filtered);
|
|
113
|
+
},
|
|
114
|
+
size: 150,
|
|
115
|
+
meta: {
|
|
116
|
+
align: 'right',
|
|
117
|
+
},
|
|
118
|
+
invertSorting: true,
|
|
119
|
+
}),
|
|
120
|
+
columnHelper.accessor('cumulativeDiff', {
|
|
121
|
+
id: 'cumulativeDiff',
|
|
122
|
+
header: 'Cumulative Diff',
|
|
123
|
+
cell: info =>
|
|
124
|
+
addPlusSign(valueFormatter((info as CellContext<DataRow, bigint>).getValue(), unit, 2)),
|
|
125
|
+
size: 170,
|
|
126
|
+
meta: {
|
|
127
|
+
align: 'right',
|
|
128
|
+
},
|
|
129
|
+
invertSorting: true,
|
|
130
|
+
}),
|
|
131
|
+
columnHelper.accessor('cumulativeDiff', {
|
|
132
|
+
id: 'cumulativeDiffPercentage',
|
|
133
|
+
header: 'Cumulative Diff (%)',
|
|
134
|
+
cell: info => {
|
|
135
|
+
if (isDummyRow(info.row.original)) {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
return getRatioString((info as CellContext<DataRow, bigint>).getValue(), total, filtered);
|
|
139
|
+
},
|
|
140
|
+
size: 170,
|
|
141
|
+
meta: {
|
|
142
|
+
align: 'right',
|
|
143
|
+
},
|
|
144
|
+
invertSorting: true,
|
|
145
|
+
}),
|
|
146
|
+
columnHelper.accessor('name', {
|
|
147
|
+
id: 'name',
|
|
148
|
+
header: 'Name',
|
|
149
|
+
cell: info => info.getValue(),
|
|
150
|
+
}),
|
|
151
|
+
columnHelper.accessor('functionSystemName', {
|
|
152
|
+
id: 'functionSystemName',
|
|
153
|
+
header: 'Function System Name',
|
|
154
|
+
cell: info => info.getValue(),
|
|
155
|
+
}),
|
|
156
|
+
columnHelper.accessor('functionFileName', {
|
|
157
|
+
id: 'functionFileName',
|
|
158
|
+
header: 'Function File Name',
|
|
159
|
+
cell: info => info.getValue(),
|
|
160
|
+
}),
|
|
161
|
+
columnHelper.accessor('mappingFile', {
|
|
162
|
+
id: 'mappingFile',
|
|
163
|
+
header: 'Mapping File',
|
|
164
|
+
cell: info => info.getValue(),
|
|
165
|
+
}),
|
|
166
|
+
];
|
|
167
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
168
|
+
}, [profileType, unit]);
|
|
169
|
+
|
|
170
|
+
const [columnVisibility, setColumnVisibility] = useState(() => {
|
|
171
|
+
return {
|
|
172
|
+
flat: true,
|
|
173
|
+
flatPercentage: false,
|
|
174
|
+
flatDiff: compareMode,
|
|
175
|
+
flatDiffPercentage: false,
|
|
176
|
+
cumulative: true,
|
|
177
|
+
cumulativePercentage: false,
|
|
178
|
+
cumulativeDiff: compareMode,
|
|
179
|
+
cumulativeDiffPercentage: false,
|
|
180
|
+
name: true,
|
|
181
|
+
functionSystemName: false,
|
|
182
|
+
functionFileName: false,
|
|
183
|
+
mappingFile: false,
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (Array.isArray(tableColumns)) {
|
|
189
|
+
setColumnVisibility(prevState => {
|
|
190
|
+
const newState = {...prevState};
|
|
191
|
+
(Object.keys(newState) as ColumnName[]).forEach(column => {
|
|
192
|
+
newState[column] = tableColumns.includes(column);
|
|
193
|
+
});
|
|
194
|
+
return newState;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}, [tableColumns]);
|
|
198
|
+
|
|
199
|
+
const updateColumnVisibility = (column: string, isVisible: boolean): void => {
|
|
200
|
+
const updatedColumns = {...columnVisibility, [column]: isVisible};
|
|
201
|
+
|
|
202
|
+
const newTableColumns = (Object.keys(updatedColumns) as ColumnName[]).filter(
|
|
203
|
+
col => updatedColumns[col]
|
|
204
|
+
);
|
|
205
|
+
setTableColumns(newTableColumns);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<div className="flex flex-col gap-1">
|
|
210
|
+
<label className="text-sm">Table Columns</label>
|
|
211
|
+
<ColumnsVisibility
|
|
212
|
+
columns={columns}
|
|
213
|
+
visibility={columnVisibility}
|
|
214
|
+
setVisibility={(id, visible) => {
|
|
215
|
+
updateColumnVisibility(id, visible);
|
|
216
|
+
}}
|
|
217
|
+
/>
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export default TableColumnsDropdown;
|