@parca/profile 0.16.183 → 0.16.185

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 (61) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/Callgraph/constants.js +2 -2
  3. package/dist/Callgraph/index.js +35 -45
  4. package/dist/Callgraph/mockData/index.js +28 -11
  5. package/dist/Callgraph/utils.js +51 -58
  6. package/dist/GraphTooltip/ExpandOnHoverValue.js +2 -14
  7. package/dist/GraphTooltip/index.d.ts +5 -5
  8. package/dist/GraphTooltip/index.js +96 -122
  9. package/dist/MatchersInput/SuggestionItem.js +5 -17
  10. package/dist/MatchersInput/SuggestionsList.js +29 -53
  11. package/dist/MatchersInput/index.js +58 -74
  12. package/dist/MetricsCircle/index.js +2 -16
  13. package/dist/MetricsGraph/MetricsTooltip/index.js +27 -53
  14. package/dist/MetricsGraph/index.js +79 -98
  15. package/dist/MetricsSeries/index.js +4 -19
  16. package/dist/ProfileExplorer/ProfileExplorerCompare.js +4 -16
  17. package/dist/ProfileExplorer/ProfileExplorerSingle.js +2 -14
  18. package/dist/ProfileExplorer/index.js +129 -88
  19. package/dist/ProfileIcicleGraph/IcicleGraph/ColorStackLegend.js +15 -31
  20. package/dist/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.d.ts +4 -4
  21. package/dist/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.js +38 -54
  22. package/dist/ProfileIcicleGraph/IcicleGraph/index.d.ts +2 -2
  23. package/dist/ProfileIcicleGraph/IcicleGraph/index.js +15 -31
  24. package/dist/ProfileIcicleGraph/IcicleGraph/useColoredGraph.js +22 -26
  25. package/dist/ProfileIcicleGraph/IcicleGraph/useNodeColor.js +8 -9
  26. package/dist/ProfileIcicleGraph/IcicleGraph/utils.js +18 -20
  27. package/dist/ProfileIcicleGraph/index.d.ts +2 -2
  28. package/dist/ProfileIcicleGraph/index.js +18 -30
  29. package/dist/ProfileMetricsGraph/index.js +36 -88
  30. package/dist/ProfileSelector/CompareButton.js +8 -20
  31. package/dist/ProfileSelector/index.js +69 -69
  32. package/dist/ProfileSource.js +56 -65
  33. package/dist/ProfileTypeSelector/index.js +14 -28
  34. package/dist/ProfileView/FilterByFunctionButton.js +6 -7
  35. package/dist/ProfileView/ViewSelector.js +18 -31
  36. package/dist/ProfileView/VisualizationPanel.js +4 -16
  37. package/dist/ProfileView/index.d.ts +2 -1
  38. package/dist/ProfileView/index.js +73 -151
  39. package/dist/ProfileViewWithData.js +50 -97
  40. package/dist/TopTable/index.js +55 -63
  41. package/dist/components/DiffLegend.js +16 -28
  42. package/dist/components/ProfileShareButton/ResultBox.js +7 -21
  43. package/dist/components/ProfileShareButton/index.js +31 -90
  44. package/dist/useDelayedLoader.js +7 -8
  45. package/dist/useGrpcQuery/index.js +6 -48
  46. package/dist/useQuery.js +14 -58
  47. package/dist/utils.d.ts +1 -1
  48. package/dist/utils.js +16 -68
  49. package/package.json +6 -6
  50. package/src/Callgraph/index.tsx +3 -3
  51. package/src/Callgraph/utils.ts +1 -1
  52. package/src/GraphTooltip/index.tsx +17 -17
  53. package/src/MetricsGraph/index.tsx +3 -3
  54. package/src/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.tsx +9 -10
  55. package/src/ProfileIcicleGraph/IcicleGraph/index.tsx +4 -8
  56. package/src/ProfileIcicleGraph/IcicleGraph/useNodeColor.ts +2 -2
  57. package/src/ProfileIcicleGraph/index.tsx +8 -8
  58. package/src/ProfileView/index.tsx +8 -3
  59. package/src/ProfileViewWithData.tsx +5 -0
  60. package/src/TopTable/index.tsx +3 -3
  61. package/src/utils.ts +2 -2
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
13
2
  // Copyright 2022 The Parca Authors
14
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,57 +16,54 @@ import { createColumnHelper } from '@tanstack/react-table';
27
16
  import { Button, Table, useURLState } from '@parca/components';
28
17
  import { getLastItem, isSearchMatch, parseParams, valueFormatter, } from '@parca/utilities';
29
18
  import { hexifyAddress } from '../utils';
30
- export var RowLabel = function (meta) {
31
- var _a, _b, _c, _d, _e, _f;
19
+ export const RowLabel = (meta) => {
32
20
  if (meta === undefined)
33
21
  return '<unknown>';
34
- var mapping = "".concat(((_a = meta === null || meta === void 0 ? void 0 : meta.mapping) === null || _a === void 0 ? void 0 : _a.file) !== undefined && ((_b = meta === null || meta === void 0 ? void 0 : meta.mapping) === null || _b === void 0 ? void 0 : _b.file) !== ''
35
- ? "[".concat((_c = getLastItem(meta.mapping.file)) !== null && _c !== void 0 ? _c : '', "]")
36
- : '');
37
- if (((_d = meta.function) === null || _d === void 0 ? void 0 : _d.name) !== undefined && ((_e = meta.function) === null || _e === void 0 ? void 0 : _e.name) !== '')
38
- return "".concat(mapping, " ").concat(meta.function.name);
39
- var address = hexifyAddress((_f = meta.location) === null || _f === void 0 ? void 0 : _f.address);
40
- var fallback = "".concat(mapping, " ").concat(address);
22
+ const mapping = `${meta?.mapping?.file !== undefined && meta?.mapping?.file !== ''
23
+ ? `[${getLastItem(meta.mapping.file) ?? ''}]`
24
+ : ''}`;
25
+ if (meta.function?.name !== undefined && meta.function?.name !== '')
26
+ return `${mapping} ${meta.function.name}`;
27
+ const address = hexifyAddress(meta.location?.address);
28
+ const fallback = `${mapping} ${address}`;
41
29
  return fallback === '' ? '<unknown>' : fallback;
42
30
  };
43
- var columnHelper = createColumnHelper();
44
- var addPlusSign = function (num) {
31
+ const columnHelper = createColumnHelper();
32
+ const addPlusSign = (num) => {
45
33
  if (num.charAt(0) === '0' || num.charAt(0) === '-') {
46
34
  return num;
47
35
  }
48
- return "+".concat(num);
36
+ return `+${num}`;
49
37
  };
50
- export var TopTable = React.memo(function TopTable(_a) {
51
- var _b;
52
- var top = _a.data, unit = _a.sampleUnit, navigateTo = _a.navigateTo, loading = _a.loading, currentSearchString = _a.currentSearchString, setActionButtons = _a.setActionButtons;
53
- var router = parseParams(window === null || window === void 0 ? void 0 : window.location.search);
54
- var rawDashboardItems = useURLState({ param: 'dashboard_items' })[0];
55
- var rawcompareMode = useURLState({ param: 'compare_a' })[0];
56
- var compareMode = rawcompareMode === undefined ? false : rawcompareMode === 'true';
57
- var dashboardItems = useMemo(function () {
38
+ export const TopTable = React.memo(function TopTable({ data: top, sampleUnit: unit, navigateTo, loading, currentSearchString, setActionButtons, }) {
39
+ const router = parseParams(window?.location.search);
40
+ const [rawDashboardItems] = useURLState({ param: 'dashboard_items' });
41
+ const [rawcompareMode] = useURLState({ param: 'compare_a' });
42
+ const compareMode = rawcompareMode === undefined ? false : rawcompareMode === 'true';
43
+ const dashboardItems = useMemo(() => {
58
44
  if (rawDashboardItems !== undefined) {
59
45
  return rawDashboardItems;
60
46
  }
61
47
  return ['icicle'];
62
48
  }, [rawDashboardItems]);
63
- var columns = useMemo(function () {
64
- var cols = [
49
+ const columns = useMemo(() => {
50
+ const cols = [
65
51
  columnHelper.accessor('meta', {
66
- header: function () { return _jsx("span", __assign({ className: "text-left" }, { children: "Name" })); },
67
- cell: function (info) {
68
- var meta = info.row.original.meta;
69
- var name = RowLabel(meta);
52
+ header: () => _jsx("span", { className: "text-left", children: "Name" }),
53
+ cell: info => {
54
+ const meta = info.row.original.meta;
55
+ const name = RowLabel(meta);
70
56
  return name;
71
57
  },
72
- sortingFn: function (a, b) {
73
- var aName = RowLabel(a.original.meta);
74
- var bName = RowLabel(b.original.meta);
58
+ sortingFn: (a, b) => {
59
+ const aName = RowLabel(a.original.meta);
60
+ const bName = RowLabel(b.original.meta);
75
61
  return aName.localeCompare(bName);
76
62
  },
77
63
  }),
78
64
  columnHelper.accessor('flat', {
79
- header: function () { return 'Flat'; },
80
- cell: function (info) { return valueFormatter(Number(info.getValue()), unit, 2); },
65
+ header: () => 'Flat',
66
+ cell: info => valueFormatter(info.getValue(), unit, 2),
81
67
  size: 150,
82
68
  meta: {
83
69
  align: 'right',
@@ -85,8 +71,8 @@ export var TopTable = React.memo(function TopTable(_a) {
85
71
  sortDescFirst: true,
86
72
  }),
87
73
  columnHelper.accessor('cumulative', {
88
- header: function () { return 'Cumulative'; },
89
- cell: function (info) { return valueFormatter(Number(info.getValue()), unit, 2); },
74
+ header: () => 'Cumulative',
75
+ cell: info => valueFormatter(info.getValue(), unit, 2),
90
76
  size: 150,
91
77
  meta: {
92
78
  align: 'right',
@@ -96,8 +82,8 @@ export var TopTable = React.memo(function TopTable(_a) {
96
82
  ];
97
83
  if (compareMode) {
98
84
  cols.push(columnHelper.accessor('diff', {
99
- header: function () { return 'Diff'; },
100
- cell: function (info) { return addPlusSign(valueFormatter(Number(info.getValue()), unit, 2)); },
85
+ header: () => 'Diff',
86
+ cell: info => addPlusSign(valueFormatter(info.getValue(), unit, 2)),
101
87
  size: 150,
102
88
  meta: {
103
89
  align: 'right',
@@ -107,50 +93,56 @@ export var TopTable = React.memo(function TopTable(_a) {
107
93
  }
108
94
  return cols;
109
95
  }, [unit, compareMode]);
110
- var selectSpan = useCallback(function (span) {
96
+ const selectSpan = useCallback((span) => {
111
97
  if (navigateTo != null) {
112
- navigateTo('/', __assign(__assign({}, router), { search_string: span.trim() }), { replace: true });
98
+ navigateTo('/', {
99
+ ...router,
100
+ ...{ search_string: span.trim() },
101
+ }, { replace: true });
113
102
  }
114
103
  }, [navigateTo, router]);
115
- var onRowClick = useCallback(function (row) {
104
+ const onRowClick = useCallback((row) => {
116
105
  // If there is only one dashboard item, we don't want to select a span
117
106
  if (dashboardItems.length <= 1) {
118
107
  return;
119
108
  }
120
- var meta = row.meta;
109
+ const meta = row.meta;
121
110
  if (meta === undefined) {
122
111
  return;
123
112
  }
124
- var name = RowLabel(meta);
113
+ const name = RowLabel(meta);
125
114
  selectSpan(name);
126
115
  }, [selectSpan, dashboardItems.length]);
127
- var shouldHighlightRow = useCallback(function (row) {
128
- var meta = row.meta;
116
+ const shouldHighlightRow = useCallback((row) => {
117
+ const meta = row.meta;
129
118
  if (meta === undefined)
130
119
  return false;
131
- var name = RowLabel(meta);
120
+ const name = RowLabel(meta);
132
121
  return isSearchMatch(currentSearchString, name);
133
122
  }, [currentSearchString]);
134
- var enableHighlighting = useMemo(function () {
135
- return currentSearchString != null && (currentSearchString === null || currentSearchString === void 0 ? void 0 : currentSearchString.length) > 0;
123
+ const enableHighlighting = useMemo(() => {
124
+ return currentSearchString != null && currentSearchString?.length > 0;
136
125
  }, [currentSearchString]);
137
- var clearSelection = useCallback(function () {
126
+ const clearSelection = useCallback(() => {
138
127
  if (navigateTo != null) {
139
- navigateTo('/', __assign(__assign({}, router), { search_string: '' }), { replace: true });
128
+ navigateTo('/', {
129
+ ...router,
130
+ ...{ search_string: '' },
131
+ }, { replace: true });
140
132
  }
141
133
  }, [navigateTo, router]);
142
- useEffect(function () {
134
+ useEffect(() => {
143
135
  if (setActionButtons === undefined) {
144
136
  return;
145
137
  }
146
- setActionButtons(dashboardItems.length > 1 ? (_jsx(Button, __assign({ color: "neutral", onClick: clearSelection, className: "w-auto", variant: "neutral", disabled: currentSearchString === undefined || currentSearchString.length === 0 }, { children: "Clear selection" }))) : (_jsx(_Fragment, {})));
138
+ setActionButtons(dashboardItems.length > 1 ? (_jsx(Button, { color: "neutral", onClick: clearSelection, className: "w-auto", variant: "neutral", disabled: currentSearchString === undefined || currentSearchString.length === 0, children: "Clear selection" })) : (_jsx(_Fragment, {})));
147
139
  }, [dashboardItems, clearSelection, currentSearchString, setActionButtons]);
148
- var initialSorting = useMemo(function () {
140
+ const initialSorting = useMemo(() => {
149
141
  return [{ id: compareMode ? 'diff' : 'cumulative', desc: true }];
150
142
  }, [compareMode]);
151
- var total = top != null ? top.list.length : 0;
143
+ const total = top != null ? top.list.length : 0;
152
144
  if (total === 0 && !loading)
153
145
  return _jsx(_Fragment, { children: "Profile has no samples" });
154
- return (_jsx("div", __assign({ className: "relative" }, { children: _jsx("div", __assign({ className: "font-robotoMono h-[80vh] w-full overflow-scroll" }, { children: _jsx(Table, { data: (_b = top === null || top === void 0 ? void 0 : top.list) !== null && _b !== void 0 ? _b : [], columns: columns, initialSorting: initialSorting, onRowClick: onRowClick, enableHighlighting: enableHighlighting, shouldHighlightRow: shouldHighlightRow, usePointerCursor: dashboardItems.length > 1 }) })) })));
146
+ return (_jsx("div", { className: "relative", children: _jsx("div", { className: "font-robotoMono h-[80vh] w-full overflow-scroll", children: _jsx(Table, { data: top?.list ?? [], columns: columns, initialSorting: initialSorting, onRowClick: onRowClick, enableHighlighting: enableHighlighting, shouldHighlightRow: shouldHighlightRow, usePointerCursor: dashboardItems.length > 1 }) }) }));
155
147
  });
156
148
  export default TopTable;
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
2
  // Copyright 2022 The Parca Authors
14
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,13 +16,12 @@ import { Popover, Transition } from '@headlessui/react';
27
16
  import { usePopper } from 'react-popper';
28
17
  import { selectDarkMode, useAppSelector } from '@parca/store';
29
18
  import { getIncreasedSpanColor, getNewSpanColor, getReducedSpanColor } from '@parca/utilities';
30
- var transparencyValues = [-100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100];
31
- var DiffLegendBar = function (_a) {
32
- var onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave;
33
- var isDarkMode = useAppSelector(selectDarkMode);
34
- return (_jsx("div", __assign({ className: "m-2 flex items-center" }, { children: transparencyValues.map(function (value) {
35
- var valueAsPercentage = value / 100;
36
- var absoluteValue = Math.abs(valueAsPercentage);
19
+ const transparencyValues = [-100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100];
20
+ const DiffLegendBar = ({ onMouseEnter, onMouseLeave, }) => {
21
+ const isDarkMode = useAppSelector(selectDarkMode);
22
+ return (_jsx("div", { className: "m-2 flex items-center", children: transparencyValues.map(value => {
23
+ const valueAsPercentage = value / 100;
24
+ const absoluteValue = Math.abs(valueAsPercentage);
37
25
  return (_jsx("div", { onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, className: "h-4 w-8", style: {
38
26
  backgroundColor: absoluteValue === 0
39
27
  ? getNewSpanColor(isDarkMode)
@@ -41,22 +29,22 @@ var DiffLegendBar = function (_a) {
41
29
  ? getIncreasedSpanColor(absoluteValue, isDarkMode)
42
30
  : getReducedSpanColor(absoluteValue, isDarkMode),
43
31
  } }, valueAsPercentage));
44
- }) })));
32
+ }) }));
45
33
  };
46
- var DiffLegend = function () {
47
- var _a = useState(false), showLegendTooltip = _a[0], setShowLegendTooltip = _a[1];
48
- var _b = useState(null), popperElement = _b[0], setPopperElement = _b[1];
49
- var _c = useState(null), referenceElement = _c[0], setReferenceElement = _c[1];
50
- var _d = usePopper(referenceElement, popperElement, {
34
+ const DiffLegend = () => {
35
+ const [showLegendTooltip, setShowLegendTooltip] = useState(false);
36
+ const [popperElement, setPopperElement] = useState(null);
37
+ const [referenceElement, setReferenceElement] = useState(null);
38
+ const { styles, attributes } = usePopper(referenceElement, popperElement, {
51
39
  placement: 'auto-start',
52
40
  strategy: 'absolute',
53
- }), styles = _d.styles, attributes = _d.attributes;
54
- var handleMouseEnter = function () {
41
+ });
42
+ const handleMouseEnter = () => {
55
43
  setShowLegendTooltip(true);
56
44
  };
57
- var handleMouseLeave = function () {
45
+ const handleMouseLeave = () => {
58
46
  setShowLegendTooltip(false);
59
47
  };
60
- return (_jsxs("div", __assign({ className: "mt-1 mb-2" }, { children: [_jsxs("div", __assign({ ref: setReferenceElement, className: "flex items-center justify-center" }, { children: [_jsx("span", { children: "Better" }), _jsx(DiffLegendBar, { onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave }), _jsx("span", { children: "Worse" })] })), _jsx(Popover, __assign({ className: "relative" }, { children: function () { return (_jsx(Transition, __assign({ show: showLegendTooltip, as: Fragment, enter: "transition ease-out duration-200", enterFrom: "opacity-0 translate-y-1", enterTo: "opacity-100 translate-y-0", leave: "transition ease-in duration-150", leaveFrom: "opacity-100 translate-y-0", leaveTo: "opacity-0 translate-y-1" }, { children: _jsx(Popover.Panel, __assign({ ref: setPopperElement, style: styles.popper }, attributes.popper, { children: _jsx("div", __assign({ className: "overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5" }, { children: _jsxs("div", __assign({ className: "bg-gray-50 p-4 dark:bg-gray-800" }, { children: [_jsx("div", { className: "flex items-center justify-center" }), _jsx("span", __assign({ className: "block text-sm text-gray-500 dark:text-gray-50" }, { children: "This is a differential icicle graph, where a purple-colored node means unchanged, and the darker the red, the worse the node got, and the darker the green, the better the node got." }))] })) })) })) }))); } }))] })));
48
+ return (_jsxs("div", { className: "mt-1 mb-2", children: [_jsxs("div", { ref: setReferenceElement, className: "flex items-center justify-center", children: [_jsx("span", { children: "Better" }), _jsx(DiffLegendBar, { onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave }), _jsx("span", { children: "Worse" })] }), _jsx(Popover, { className: "relative", children: () => (_jsx(Transition, { show: showLegendTooltip, as: Fragment, enter: "transition ease-out duration-200", enterFrom: "opacity-0 translate-y-1", enterTo: "opacity-100 translate-y-0", leave: "transition ease-in duration-150", leaveFrom: "opacity-100 translate-y-0", leaveTo: "opacity-0 translate-y-1", children: _jsx(Popover.Panel, { ref: setPopperElement, style: styles.popper, ...attributes.popper, children: _jsx("div", { className: "overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5", children: _jsxs("div", { className: "bg-gray-50 p-4 dark:bg-gray-800", children: [_jsx("div", { className: "flex items-center justify-center" }), _jsx("span", { className: "block text-sm text-gray-500 dark:text-gray-50", children: "This is a differential icicle graph, where a purple-colored node means unchanged, and the darker the red, the worse the node got, and the darker the green, the better the node got." })] }) }) }) })) })] }));
61
49
  };
62
50
  export default DiffLegend;
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
2
  // Copyright 2022 The Parca Authors
14
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,23 +16,20 @@ import { Icon } from '@iconify/react';
27
16
  import cx from 'classnames';
28
17
  import { CopyToClipboard } from 'react-copy-to-clipboard';
29
18
  import { Button } from '@parca/components';
30
- var timeoutHandle = null;
31
- var ResultBox = function (_a) {
32
- var _b;
33
- var value = _a.value, _c = _a.className, className = _c === void 0 ? '' : _c;
34
- var _d = useState(false), isCopied = _d[0], setIsCopied = _d[1];
35
- var onCopy = function () {
36
- var _a, _b;
19
+ let timeoutHandle = null;
20
+ const ResultBox = ({ value, className = '' }) => {
21
+ const [isCopied, setIsCopied] = useState(false);
22
+ const onCopy = () => {
37
23
  if (typeof window === 'undefined') {
38
24
  return;
39
25
  }
40
26
  setIsCopied(true);
41
- (_b = (_a = window.document) === null || _a === void 0 ? void 0 : _a.activeElement) === null || _b === void 0 ? void 0 : _b.blur();
27
+ window.document?.activeElement?.blur();
42
28
  if (timeoutHandle != null) {
43
29
  clearTimeout(timeoutHandle);
44
30
  }
45
- timeoutHandle = setTimeout(function () { return setIsCopied(false); }, 3000);
31
+ timeoutHandle = setTimeout(() => setIsCopied(false), 3000);
46
32
  };
47
- return (_jsxs("div", __assign({ className: cx('flex w-full flex-row', (_b = {}, _b[className] = (className === null || className === void 0 ? void 0 : className.length) > 0, _b)) }, { children: [_jsx("span", __assign({ className: "flex w-16 items-center justify-center rounded-l border border-r-0" }, { children: _jsx(Icon, { icon: "ant-design:link-outlined" }) })), _jsx("input", { type: "text", className: "w-full flex-grow border bg-inherit px-1 py-2 text-sm", value: value, readOnly: true }), _jsx(CopyToClipboard, __assign({ text: value, onCopy: onCopy }, { children: _jsx(Button, __assign({ variant: "link", className: "w-fit items-center whitespace-nowrap rounded-none rounded-r border border-l-0 p-4 !text-indigo-600 dark:!text-indigo-400" }, { children: isCopied ? 'Copied!' : 'Copy Link' })) }))] })));
33
+ return (_jsxs("div", { className: cx('flex w-full flex-row', { [className]: className?.length > 0 }), children: [_jsx("span", { className: "flex w-16 items-center justify-center rounded-l border border-r-0", children: _jsx(Icon, { icon: "ant-design:link-outlined" }) }), _jsx("input", { type: "text", className: "w-full flex-grow border bg-inherit px-1 py-2 text-sm", value: value, readOnly: true }), _jsx(CopyToClipboard, { text: value, onCopy: onCopy, children: _jsx(Button, { variant: "link", className: "w-fit items-center whitespace-nowrap rounded-none rounded-r border border-l-0 p-4 !text-indigo-600 dark:!text-indigo-400", children: isCopied ? 'Copied!' : 'Copy Link' }) })] }));
48
34
  };
49
35
  export default ResultBox;
@@ -1,50 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
49
2
  // Copyright 2022 The Parca Authors
50
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,58 +15,46 @@ import { useState } from 'react';
62
15
  import { Icon } from '@iconify/react';
63
16
  import { Button, Modal, useGrpcMetadata } from '@parca/components';
64
17
  import ResultBox from './ResultBox';
65
- var ProfileShareModal = function (_a) {
66
- var isOpen = _a.isOpen, closeModal = _a.closeModal, queryRequest = _a.queryRequest, queryClient = _a.queryClient;
67
- var _b = useState(false), isShared = _b[0], setIsShared = _b[1];
68
- var _c = useState(false), loading = _c[0], setLoading = _c[1];
69
- var _d = useState(''), error = _d[0], setError = _d[1];
70
- var _e = useState(''), description = _e[0], setDescription = _e[1];
71
- var _f = useState(''), sharedLink = _f[0], setSharedLink = _f[1];
72
- var metadata = useGrpcMetadata();
73
- var isFormDataValid = function () { return true; };
74
- var handleSubmit = function () { return __awaiter(void 0, void 0, void 0, function () {
75
- var response, err_1;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0:
79
- _a.trys.push([0, 2, , 3]);
80
- setLoading(true);
81
- return [4 /*yield*/, queryClient.shareProfile({ queryRequest: queryRequest, description: description }, { meta: metadata })];
82
- case 1:
83
- response = (_a.sent()).response;
84
- setSharedLink(response.link);
85
- setLoading(false);
86
- setIsShared(true);
87
- return [3 /*break*/, 3];
88
- case 2:
89
- err_1 = _a.sent();
90
- if (err_1 instanceof Error) {
91
- console.error(err_1);
92
- setLoading(false);
93
- // https://github.com/microsoft/TypeScript/issues/38347
94
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
95
- setError(err_1.toString());
96
- }
97
- return [3 /*break*/, 3];
98
- case 3: return [2 /*return*/];
18
+ const ProfileShareModal = ({ isOpen, closeModal, queryRequest, queryClient, }) => {
19
+ const [isShared, setIsShared] = useState(false);
20
+ const [loading, setLoading] = useState(false);
21
+ const [error, setError] = useState('');
22
+ const [description, setDescription] = useState('');
23
+ const [sharedLink, setSharedLink] = useState('');
24
+ const metadata = useGrpcMetadata();
25
+ const isFormDataValid = () => true;
26
+ const handleSubmit = async () => {
27
+ try {
28
+ setLoading(true);
29
+ const { response } = await queryClient.shareProfile({ queryRequest, description }, { meta: metadata });
30
+ setSharedLink(response.link);
31
+ setLoading(false);
32
+ setIsShared(true);
33
+ }
34
+ catch (err) {
35
+ if (err instanceof Error) {
36
+ console.error(err);
37
+ setLoading(false);
38
+ // https://github.com/microsoft/TypeScript/issues/38347
39
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
40
+ setError(err.toString());
99
41
  }
100
- });
101
- }); };
102
- var onClose = function () {
42
+ }
43
+ };
44
+ const onClose = () => {
103
45
  setLoading(false);
104
46
  setError('');
105
47
  setDescription('');
106
48
  setIsShared(false);
107
49
  closeModal();
108
50
  };
109
- return (_jsx(Modal, __assign({ isOpen: isOpen, closeModal: onClose, title: "Share Profile", className: "w-[420px]" }, { children: _jsxs("form", __assign({ className: "py-2" }, { children: [_jsx("p", __assign({ className: "text-sm text-gray-500 dark:text-gray-300" }, { children: "Note: Shared profiles can be accessed by anyone with the link, even from people outside your organisation." })), !isShared || (error === null || error === void 0 ? void 0 : error.length) > 0 ? (_jsxs(_Fragment, { children: [_jsx("p", __assign({ className: "mt-3 mb-2 text-sm text-gray-500 dark:text-gray-300" }, { children: "Enter a description (optional)" })), _jsx("textarea", { className: "w-full border bg-inherit px-2 py-2 text-sm text-gray-500 dark:text-gray-300", value: description, onChange: function (e) { return setDescription(e.target.value); } }), _jsx(Button, __assign({ className: "mt-4", onClick: function (e) {
51
+ return (_jsx(Modal, { isOpen: isOpen, closeModal: onClose, title: "Share Profile", className: "w-[420px]", children: _jsxs("form", { className: "py-2", children: [_jsx("p", { className: "text-sm text-gray-500 dark:text-gray-300", children: "Note: Shared profiles can be accessed by anyone with the link, even from people outside your organisation." }), !isShared || error?.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "mt-3 mb-2 text-sm text-gray-500 dark:text-gray-300", children: "Enter a description (optional)" }), _jsx("textarea", { className: "w-full border bg-inherit px-2 py-2 text-sm text-gray-500 dark:text-gray-300", value: description, onChange: e => setDescription(e.target.value) }), _jsx(Button, { className: "mt-4", onClick: e => {
110
52
  e.preventDefault();
111
53
  void handleSubmit();
112
- }, disabled: loading || !isFormDataValid(), type: "submit" }, { children: loading ? 'Sharing' : 'Share' })), error !== '' ? _jsx("p", { children: "Something went wrong please try again" }) : null] })) : (_jsxs(_Fragment, { children: [_jsx(ResultBox, { value: sharedLink, className: "mt-4" }), _jsx("div", __assign({ className: "mt-8 flex justify-center" }, { children: _jsx(Button, __assign({ variant: "neutral", className: "w-fit", onClick: onClose }, { children: "Close" })) }))] }))] })) })));
54
+ }, disabled: loading || !isFormDataValid(), type: "submit", children: loading ? 'Sharing' : 'Share' }), error !== '' ? _jsx("p", { children: "Something went wrong please try again" }) : null] })) : (_jsxs(_Fragment, { children: [_jsx(ResultBox, { value: sharedLink, className: "mt-4" }), _jsx("div", { className: "mt-8 flex justify-center", children: _jsx(Button, { variant: "neutral", className: "w-fit", onClick: onClose, children: "Close" }) })] }))] }) }));
113
55
  };
114
- var ProfileShareButton = function (_a) {
115
- var queryRequest = _a.queryRequest, queryClient = _a.queryClient, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
116
- var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
117
- return (_jsxs(_Fragment, { children: [_jsx(Button, __assign({ color: "neutral", onClick: function () { return setIsOpen(true); }, disabled: disabled }, { children: _jsx(Icon, { icon: "ei:share-apple", width: 20 }) })), _jsx(ProfileShareModal, { isOpen: isOpen, closeModal: function () { return setIsOpen(false); }, queryRequest: queryRequest, queryClient: queryClient })] }));
56
+ const ProfileShareButton = ({ queryRequest, queryClient, disabled = false }) => {
57
+ const [isOpen, setIsOpen] = useState(false);
58
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { color: "neutral", onClick: () => setIsOpen(true), disabled: disabled, children: _jsx(Icon, { icon: "ei:share-apple", width: 20 }) }), _jsx(ProfileShareModal, { isOpen: isOpen, closeModal: () => setIsOpen(false), queryRequest: queryRequest, queryClient: queryClient })] }));
118
59
  };
119
60
  export default ProfileShareButton;
@@ -11,22 +11,21 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { useEffect, useState } from 'react';
14
- var useDelayedLoader = function (isLoading, options) {
15
- if (isLoading === void 0) { isLoading = false; }
16
- var _a = (options !== null && options !== void 0 ? options : {}).delay, delay = _a === void 0 ? 500 : _a;
17
- var _b = useState(false), isLoaderVisible = _b[0], setIsLoaderVisible = _b[1];
18
- useEffect(function () {
19
- var showLoaderTimeout;
14
+ const useDelayedLoader = (isLoading = false, options) => {
15
+ const { delay = 500 } = options ?? {};
16
+ const [isLoaderVisible, setIsLoaderVisible] = useState(false);
17
+ useEffect(() => {
18
+ let showLoaderTimeout;
20
19
  if (isLoading && !isLoaderVisible) {
21
20
  // if the request takes longer than half a second, show the loading icon
22
- showLoaderTimeout = setTimeout(function () {
21
+ showLoaderTimeout = setTimeout(() => {
23
22
  setIsLoaderVisible(true);
24
23
  }, delay);
25
24
  }
26
25
  else if (!isLoading && isLoaderVisible) {
27
26
  setIsLoaderVisible(false);
28
27
  }
29
- return function () { return clearTimeout(showLoaderTimeout); };
28
+ return () => clearTimeout(showLoaderTimeout);
30
29
  }, [isLoading, isLoaderVisible, delay]);
31
30
  return isLoaderVisible;
32
31
  };
@@ -10,55 +10,13 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
13
  import { useQuery } from '@tanstack/react-query';
50
- var useGrpcQuery = function (_a) {
51
- var key = _a.key, queryFn = _a.queryFn, _b = _a.options, _c = _b === void 0 ? {} : _b, _d = _c.enabled, enabled = _d === void 0 ? true : _d, staleTime = _c.staleTime;
52
- return useQuery(key, function () { return __awaiter(void 0, void 0, void 0, function () {
53
- return __generator(this, function (_a) {
54
- switch (_a.label) {
55
- case 0: return [4 /*yield*/, queryFn()];
56
- case 1: return [2 /*return*/, _a.sent()];
57
- }
58
- });
59
- }); }, {
60
- enabled: enabled,
61
- staleTime: staleTime,
14
+ const useGrpcQuery = ({ key, queryFn, options: { enabled = true, staleTime } = {}, }) => {
15
+ return useQuery(key, async () => {
16
+ return await queryFn();
17
+ }, {
18
+ enabled,
19
+ staleTime,
62
20
  });
63
21
  };
64
22
  export default useGrpcQuery;