@parca/profile 0.19.67 → 0.19.68

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  3. package/dist/MatchersInput/SuggestionsList.js +2 -13
  4. package/dist/MatchersInput/index.d.ts +1 -1
  5. package/dist/MatchersInput/index.d.ts.map +1 -1
  6. package/dist/MatchersInput/index.js +2 -2
  7. package/dist/ProfileSelector/QueryControls.d.ts +2 -1
  8. package/dist/ProfileSelector/QueryControls.d.ts.map +1 -1
  9. package/dist/ProfileSelector/QueryControls.js +14 -5
  10. package/dist/ProfileSelector/index.js +2 -2
  11. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.d.ts +2 -0
  12. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.d.ts.map +1 -1
  13. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +2 -2
  14. package/dist/ProfileView/components/GroupByLabelsDropdown/index.d.ts +3 -1
  15. package/dist/ProfileView/components/GroupByLabelsDropdown/index.d.ts.map +1 -1
  16. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +4 -9
  17. package/dist/ProfileView/components/Toolbars/index.d.ts +5 -1
  18. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  19. package/dist/ProfileView/components/Toolbars/index.js +2 -2
  20. package/dist/ProfileView/index.d.ts.map +1 -1
  21. package/dist/ProfileView/index.js +5 -1
  22. package/dist/ProfileView/types/visualization.d.ts +1 -0
  23. package/dist/ProfileView/types/visualization.d.ts.map +1 -1
  24. package/dist/ProfileViewWithData.d.ts.map +1 -1
  25. package/dist/ProfileViewWithData.js +3 -1
  26. package/dist/SelectWithRefresh/index.d.ts +10 -0
  27. package/dist/SelectWithRefresh/index.d.ts.map +1 -0
  28. package/dist/SelectWithRefresh/index.js +45 -0
  29. package/dist/SimpleMatchers/Select.d.ts +1 -1
  30. package/dist/SimpleMatchers/Select.d.ts.map +1 -1
  31. package/dist/SimpleMatchers/Select.js +2 -8
  32. package/dist/SimpleMatchers/index.js +1 -1
  33. package/dist/contexts/SimpleMatchersLabelContext.d.ts +2 -2
  34. package/dist/contexts/SimpleMatchersLabelContext.d.ts.map +1 -1
  35. package/dist/contexts/SimpleMatchersLabelContext.js +4 -4
  36. package/dist/index.d.ts +2 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +2 -1
  39. package/dist/styles.css +1 -1
  40. package/dist/useQuery.d.ts +2 -0
  41. package/dist/useQuery.d.ts.map +1 -1
  42. package/dist/useQuery.js +10 -3
  43. package/package.json +4 -4
  44. package/src/MatchersInput/SuggestionsList.tsx +1 -40
  45. package/src/MatchersInput/index.tsx +3 -3
  46. package/src/ProfileSelector/QueryControls.tsx +19 -3
  47. package/src/ProfileSelector/index.tsx +6 -6
  48. package/src/ProfileView/components/ActionButtons/GroupByDropdown.tsx +11 -1
  49. package/src/ProfileView/components/GroupByLabelsDropdown/index.tsx +16 -18
  50. package/src/ProfileView/components/Toolbars/index.tsx +8 -2
  51. package/src/ProfileView/index.tsx +5 -1
  52. package/src/ProfileView/types/visualization.ts +1 -0
  53. package/src/ProfileViewWithData.tsx +3 -0
  54. package/src/SelectWithRefresh/index.tsx +98 -0
  55. package/src/SimpleMatchers/Select.tsx +10 -30
  56. package/src/SimpleMatchers/index.tsx +1 -1
  57. package/src/contexts/SimpleMatchersLabelContext.tsx +6 -6
  58. package/src/index.tsx +9 -1
  59. package/src/useQuery.tsx +12 -3
@@ -0,0 +1,98 @@
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 {useCallback, useState} from 'react';
15
+
16
+ import ReactSelect, {type MenuListProps, type Props as ReactSelectProps} from 'react-select';
17
+
18
+ import {RefreshButton} from '@parca/components';
19
+
20
+ export interface SelectWithRefreshProps<Option, IsMulti extends boolean>
21
+ extends ReactSelectProps<Option, IsMulti> {
22
+ onRefresh?: () => Promise<void>;
23
+ refreshTitle?: string;
24
+ refreshTestId?: string;
25
+ menuTestId?: string;
26
+ }
27
+
28
+ export function SelectWithRefresh<Option, IsMulti extends boolean = false>(
29
+ props: SelectWithRefreshProps<Option, IsMulti>
30
+ ): JSX.Element {
31
+ const {
32
+ onRefresh,
33
+ refreshTitle = 'Refresh label names',
34
+ refreshTestId = 'select-refresh-button',
35
+ menuTestId,
36
+ components,
37
+ ...selectProps
38
+ } = props;
39
+
40
+ const [isRefreshing, setIsRefreshing] = useState(false);
41
+
42
+ const handleRefetch = useCallback(async () => {
43
+ if (onRefresh == null || isRefreshing) return;
44
+
45
+ setIsRefreshing(true);
46
+ try {
47
+ await onRefresh();
48
+ } catch (error) {
49
+ console.error('Error during refresh:', error);
50
+ } finally {
51
+ setIsRefreshing(false);
52
+ }
53
+ }, [onRefresh, isRefreshing]);
54
+
55
+ const MenuListWithRefresh = useCallback(
56
+ ({children, innerProps}: MenuListProps<Option, IsMulti>) => {
57
+ const testIdProps = menuTestId != null ? {'data-testid': menuTestId} : {};
58
+
59
+ return (
60
+ <div className="flex flex-col" style={{maxHeight: '332px'}}>
61
+ <div
62
+ className="overflow-y-auto flex-1"
63
+ {...innerProps}
64
+ {...testIdProps}
65
+ style={{...innerProps?.style, fontSize: '14px'}}
66
+ >
67
+ {children}
68
+ </div>
69
+ {onRefresh != null && (
70
+ <RefreshButton
71
+ onClick={() => void handleRefetch()}
72
+ disabled={isRefreshing}
73
+ title={refreshTitle}
74
+ testId={refreshTestId}
75
+ />
76
+ )}
77
+ </div>
78
+ );
79
+ },
80
+ [onRefresh, isRefreshing, handleRefetch, refreshTitle, refreshTestId, menuTestId]
81
+ );
82
+
83
+ const combinedLoadingState = isRefreshing || (selectProps.isLoading ?? false);
84
+
85
+ return (
86
+ <ReactSelect<Option, IsMulti>
87
+ {...selectProps}
88
+ isLoading={combinedLoadingState}
89
+ components={{
90
+ ...components,
91
+ // eslint-disable-next-line react/display-name
92
+ MenuList: MenuListWithRefresh,
93
+ }}
94
+ />
95
+ );
96
+ }
97
+
98
+ export default SelectWithRefresh;
@@ -17,7 +17,7 @@ import {Icon} from '@iconify/react';
17
17
  import cx from 'classnames';
18
18
  import levenshtein from 'fast-levenshtein';
19
19
 
20
- import {Button, DividerWithLabel, useParcaContext} from '@parca/components';
20
+ import {Button, DividerWithLabel, RefreshButton, useParcaContext} from '@parca/components';
21
21
  import {TEST_IDS, testId} from '@parca/test-utils/dist/test-ids';
22
22
 
23
23
  export interface SelectElement {
@@ -56,7 +56,7 @@ interface CustomSelectProps {
56
56
  searchable?: boolean;
57
57
  onButtonClick?: () => void;
58
58
  editable?: boolean;
59
- refetchValues?: () => void;
59
+ refetchValues?: () => Promise<void>;
60
60
  showLoadingInButton?: boolean;
61
61
  }
62
62
 
@@ -374,34 +374,14 @@ const CustomSelect: React.FC<CustomSelectProps & Record<string, any>> = ({
374
374
  )}
375
375
  </div>
376
376
  {refetchValues !== undefined && loading !== true && (
377
- <div className="sticky bottom-0 w-full flex items-center justify-center px-3 py-2 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700 z-20 mt-auto">
378
- <button
379
- onClick={e => {
380
- e.preventDefault();
381
- e.stopPropagation();
382
- void handleRefetch();
383
- }}
384
- disabled={isRefetching}
385
- className={cx(
386
- 'py-1 px-2 flex items-center gap-1 rounded-full transition-all duration-200 w-auto justify-center',
387
- isRefetching
388
- ? 'cursor-wait opacity-50'
389
- : 'hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer'
390
- )}
391
- title="Refresh label values"
392
- type="button"
393
- {...testId(TEST_IDS.LABEL_VALUE_REFRESH_BUTTON)}
394
- >
395
- <Icon
396
- icon="system-uicons:reset"
397
- className={cx(
398
- 'w-3 h-3 text-gray-500 dark:text-gray-400',
399
- isRefetching && 'animate-spin'
400
- )}
401
- />
402
- <span className="text-xs text-gray-500 dark:text-gray-400">Refresh results</span>
403
- </button>
404
- </div>
377
+ <RefreshButton
378
+ onClick={() => void handleRefetch()}
379
+ disabled={isRefetching}
380
+ title="Refresh label values"
381
+ testId={TEST_IDS.LABEL_VALUE_REFRESH_BUTTON}
382
+ sticky={true}
383
+ loading={isRefetching}
384
+ />
405
385
  )}
406
386
  </div>
407
387
  </div>
@@ -485,7 +485,7 @@ const SimpleMatchers = ({
485
485
  onButtonClick={() => handleLabelValueClick(index)}
486
486
  editable={isRowRegex(row)}
487
487
  {...testId(TEST_IDS.LABEL_VALUE_SELECT)}
488
- refetchValues={() => refetchLabelValues(row.labelName)}
488
+ refetchValues={async () => await refetchLabelValues(row.labelName)}
489
489
  showLoadingInButton={true}
490
490
  />
491
491
  <button
@@ -31,8 +31,8 @@ interface LabelContextValue {
31
31
  labelNameOptions: LabelNameSection[];
32
32
  isLoading: boolean;
33
33
  error: Error | null;
34
- refetchLabelValues: (labelName?: string) => void;
35
- refetchLabelNames: () => void;
34
+ refetchLabelValues: (labelName?: string) => Promise<void>;
35
+ refetchLabelNames: () => Promise<void>;
36
36
  }
37
37
 
38
38
  const LabelContext = createContext<LabelContextValue | null>(null);
@@ -141,8 +141,8 @@ export function LabelProvider({
141
141
  }, [profileValues, utilizationValues, labelNameFromMatchers]);
142
142
 
143
143
  const refetchLabelValues = useCallback(
144
- (labelName?: string) => {
145
- void reactQueryClient.refetchQueries({
144
+ async (labelName?: string) => {
145
+ await reactQueryClient.refetchQueries({
146
146
  predicate: query => {
147
147
  const key = query.queryKey;
148
148
  const matchesStructure =
@@ -164,8 +164,8 @@ export function LabelProvider({
164
164
  [reactQueryClient, profileType]
165
165
  );
166
166
 
167
- const refetchLabelNames = useCallback(() => {
168
- refetchLabelNamesQuery();
167
+ const refetchLabelNames = useCallback(async () => {
168
+ await refetchLabelNamesQuery();
169
169
  }, [refetchLabelNamesQuery]);
170
170
 
171
171
  const contextValue = useMemo(
package/src/index.tsx CHANGED
@@ -14,6 +14,7 @@
14
14
  import {useLabelNames} from './MatchersInput';
15
15
  import ProfileExplorer, {getExpressionAsAString} from './ProfileExplorer';
16
16
  import ProfileTypeSelector from './ProfileTypeSelector';
17
+ import SelectWithRefresh from './SelectWithRefresh';
17
18
  import CustomSelect from './SimpleMatchers/Select';
18
19
 
19
20
  export * from './ProfileFlameGraph';
@@ -37,4 +38,11 @@ export const DEFAULT_PROFILE_EXPLORER_PARAM_VALUES = {
37
38
  dashboard_items: 'flamegraph',
38
39
  };
39
40
 
40
- export {ProfileExplorer, ProfileTypeSelector, getExpressionAsAString, CustomSelect, useLabelNames};
41
+ export {
42
+ ProfileExplorer,
43
+ ProfileTypeSelector,
44
+ getExpressionAsAString,
45
+ CustomSelect,
46
+ SelectWithRefresh,
47
+ useLabelNames,
48
+ };
package/src/useQuery.tsx CHANGED
@@ -25,6 +25,7 @@ export interface IQueryResult {
25
25
  response: QueryResponse | null;
26
26
  error: RpcError | null;
27
27
  isLoading: boolean;
28
+ refetch?: () => Promise<void>;
28
29
  }
29
30
 
30
31
  interface UseQueryOptions {
@@ -37,6 +38,7 @@ interface UseQueryOptions {
37
38
  invertCallStack?: boolean;
38
39
  sandwichByFunction?: string;
39
40
  protoFilters?: any[]; // Using any[] to match the Filter type from hook
41
+ staleTime?: number;
40
42
  }
41
43
 
42
44
  export const useQuery = (
@@ -52,7 +54,7 @@ export const useQuery = (
52
54
  return JSON.stringify(options?.protoFilters ?? []);
53
55
  }, [options?.protoFilters]);
54
56
 
55
- const {data, isLoading, error} = useGrpcQuery<QueryResponse | undefined>({
57
+ const {data, isLoading, error, refetch} = useGrpcQuery<QueryResponse | undefined>({
56
58
  key: [
57
59
  'query',
58
60
  profileSource.toKey(),
@@ -104,9 +106,16 @@ export const useQuery = (
104
106
  options: {
105
107
  retry: false,
106
108
  enabled: !skip,
107
- staleTime: 1000 * 60 * 5, // 5 minutes
109
+ staleTime: options?.staleTime ?? 1000 * 60 * 5, // 5 minutes
108
110
  },
109
111
  });
110
112
 
111
- return {isLoading, error: error as RpcError | null, response: data ?? null};
113
+ return {
114
+ isLoading,
115
+ error: error as RpcError | null,
116
+ response: data ?? null,
117
+ refetch: async () => {
118
+ await refetch();
119
+ },
120
+ };
112
121
  };