@parca/profile 0.16.121 → 0.16.123

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.
@@ -11,7 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
 
14
- import {useCallback, useMemo} from 'react';
14
+ import React, {useCallback, useEffect, useMemo} from 'react';
15
15
 
16
16
  import {createColumnHelper, type ColumnDef} from '@tanstack/react-table';
17
17
 
@@ -32,6 +32,8 @@ interface TopTableProps {
32
32
  data?: Top;
33
33
  sampleUnit: string;
34
34
  navigateTo?: NavigateFunction;
35
+ currentSearchString?: string;
36
+ setActionButtons?: (buttons: JSX.Element) => void;
35
37
  }
36
38
 
37
39
  export const RowLabel = (meta: TopNodeMeta | undefined): string => {
@@ -60,15 +62,16 @@ const addPlusSign = (num: string): string => {
60
62
  return `+${num}`;
61
63
  };
62
64
 
63
- export const TopTable = ({
65
+ export const TopTable = React.memo(function TopTable({
64
66
  data: top,
65
67
  sampleUnit: unit,
66
68
  navigateTo,
67
69
  loading,
68
- }: TopTableProps): JSX.Element => {
70
+ currentSearchString,
71
+ setActionButtons,
72
+ }: TopTableProps): JSX.Element {
69
73
  const router = parseParams(window.location.search);
70
74
  const [rawDashboardItems] = useURLState({param: 'dashboard_items'});
71
- const [currentSearchString] = useURLState({param: 'search_string'});
72
75
  const [rawcompareMode] = useURLState({param: 'compare_a'});
73
76
 
74
77
  const compareMode: boolean = rawcompareMode === undefined ? false : rawcompareMode === 'true';
@@ -185,6 +188,27 @@ export const TopTable = ({
185
188
  }
186
189
  }, [navigateTo, router]);
187
190
 
191
+ useEffect(() => {
192
+ if (setActionButtons === undefined) {
193
+ return;
194
+ }
195
+ setActionButtons(
196
+ dashboardItems.length > 1 ? (
197
+ <Button
198
+ color="neutral"
199
+ onClick={clearSelection}
200
+ className="w-auto"
201
+ variant="neutral"
202
+ disabled={currentSearchString === undefined || currentSearchString.length === 0}
203
+ >
204
+ Clear selection
205
+ </Button>
206
+ ) : (
207
+ <></>
208
+ )
209
+ );
210
+ }, [dashboardItems, clearSelection, currentSearchString, setActionButtons]);
211
+
188
212
  const initialSorting = useMemo(() => {
189
213
  return [{id: compareMode ? 'diff' : 'cumulative', desc: true}];
190
214
  }, [compareMode]);
@@ -195,21 +219,6 @@ export const TopTable = ({
195
219
 
196
220
  return (
197
221
  <div className="relative">
198
- {/* Clearing the selection is only useful when two visualizations types are selected. So we'll only show it in that case */}
199
- {dashboardItems.length > 1 && (
200
- <div className="left-[25px] top-[-45px] absolute">
201
- <Button
202
- color="neutral"
203
- onClick={clearSelection}
204
- className="w-auto"
205
- variant="neutral"
206
- disabled={currentSearchString === undefined || currentSearchString.length === 0}
207
- >
208
- Clear selection
209
- </Button>
210
- </div>
211
- )}
212
-
213
222
  <div className="w-full font-robotoMono h-[80vh] overflow-scroll">
214
223
  <Table
215
224
  data={top?.list ?? []}
@@ -223,6 +232,6 @@ export const TopTable = ({
223
232
  </div>
224
233
  </div>
225
234
  );
226
- };
235
+ });
227
236
 
228
237
  export default TopTable;