@parca/profile 0.19.140 → 0.19.142

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 (253) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/GraphTooltipArrow/Content.js +224 -30
  3. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.js +192 -33
  4. package/dist/GraphTooltipArrow/ExpandOnHoverValue.js +53 -3
  5. package/dist/GraphTooltipArrow/index.d.ts.map +1 -1
  6. package/dist/GraphTooltipArrow/index.js +86 -56
  7. package/dist/GraphTooltipArrow/useGraphTooltip/index.js +37 -37
  8. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.d.ts.map +1 -1
  9. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +104 -72
  10. package/dist/MatchersInput/SuggestionItem.js +91 -12
  11. package/dist/MatchersInput/SuggestionsList.d.ts +2 -1
  12. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  13. package/dist/MatchersInput/SuggestionsList.js +371 -157
  14. package/dist/MatchersInput/SuggestionsList.test.d.ts +2 -0
  15. package/dist/MatchersInput/SuggestionsList.test.d.ts.map +1 -0
  16. package/dist/MatchersInput/index.js +308 -115
  17. package/dist/MetricsCircle/index.js +39 -3
  18. package/dist/MetricsGraph/MetricsContextMenu/index.js +119 -19
  19. package/dist/MetricsGraph/MetricsInfoPanel/index.js +81 -20
  20. package/dist/MetricsGraph/MetricsTooltip/index.d.ts.map +1 -1
  21. package/dist/MetricsGraph/MetricsTooltip/index.js +107 -74
  22. package/dist/MetricsGraph/index.js +552 -203
  23. package/dist/MetricsGraph/useMetricsGraphDimensions.js +46 -25
  24. package/dist/MetricsGraph/utils/colorMapping.js +24 -17
  25. package/dist/MetricsSeries/index.js +70 -7
  26. package/dist/PreSelectedMatchers/index.d.ts.map +1 -1
  27. package/dist/PreSelectedMatchers/index.js +249 -102
  28. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
  29. package/dist/ProfileExplorer/ProfileExplorerCompare.js +241 -45
  30. package/dist/ProfileExplorer/ProfileExplorerSingle.js +98 -11
  31. package/dist/ProfileExplorer/index.js +183 -32
  32. package/dist/ProfileFlameChart/SamplesStrips/SamplesGraph/index.js +333 -148
  33. package/dist/ProfileFlameChart/SamplesStrips/SamplesStrips.stories.js +69 -35
  34. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts +2 -2
  35. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts.map +1 -1
  36. package/dist/ProfileFlameChart/SamplesStrips/index.js +645 -134
  37. package/dist/ProfileFlameChart/SamplesStrips/labelSetUtils.js +114 -55
  38. package/dist/ProfileFlameChart/index.d.ts.map +1 -1
  39. package/dist/ProfileFlameChart/index.js +267 -129
  40. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.d.ts.map +1 -1
  41. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +288 -89
  42. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenuWrapper.js +56 -20
  43. package/dist/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.js +211 -140
  44. package/dist/ProfileFlameGraph/FlameGraphArrow/MemoizedTooltip.js +133 -38
  45. package/dist/ProfileFlameGraph/FlameGraphArrow/MiniMap.js +261 -216
  46. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  47. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +72 -47
  48. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.d.ts.map +1 -1
  49. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.js +58 -28
  50. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.d.ts.map +1 -1
  51. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.js +59 -8
  52. package/dist/ProfileFlameGraph/FlameGraphArrow/index.js +396 -179
  53. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.d.ts.map +1 -1
  54. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.js +68 -50
  55. package/dist/ProfileFlameGraph/FlameGraphArrow/useMappingList.js +62 -38
  56. package/dist/ProfileFlameGraph/FlameGraphArrow/useNodeColor.js +14 -6
  57. package/dist/ProfileFlameGraph/FlameGraphArrow/useScrollViewport.js +124 -82
  58. package/dist/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.js +160 -98
  59. package/dist/ProfileFlameGraph/FlameGraphArrow/useZoom.js +232 -112
  60. package/dist/ProfileFlameGraph/FlameGraphArrow/utils.js +137 -114
  61. package/dist/ProfileFlameGraph/benchmarks/benchdata/populateData.js +85 -0
  62. package/dist/ProfileFlameGraph/index.d.ts.map +1 -1
  63. package/dist/ProfileFlameGraph/index.js +324 -150
  64. package/dist/ProfileMetricsGraph/hooks/useQueryRange.js +140 -32
  65. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  66. package/dist/ProfileMetricsGraph/index.js +519 -258
  67. package/dist/ProfileSelector/CompareButton.js +132 -12
  68. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  69. package/dist/ProfileSelector/MetricsGraphSection.js +236 -64
  70. package/dist/ProfileSelector/index.d.ts.map +1 -1
  71. package/dist/ProfileSelector/index.js +727 -141
  72. package/dist/ProfileSelector/useAutoQuerySelector.js +249 -130
  73. package/dist/ProfileSource.js +230 -163
  74. package/dist/ProfileTypeSelector/index.js +214 -125
  75. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +50 -4
  76. package/dist/ProfileView/components/ActionButtons/SortByDropdown.d.ts.map +1 -1
  77. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +141 -35
  78. package/dist/ProfileView/components/ColorStackLegend.d.ts.map +1 -1
  79. package/dist/ProfileView/components/ColorStackLegend.js +185 -55
  80. package/dist/ProfileView/components/DashboardItems/index.js +87 -28
  81. package/dist/ProfileView/components/DashboardLayout/index.js +108 -16
  82. package/dist/ProfileView/components/DiffLegend.js +172 -29
  83. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +199 -55
  84. package/dist/ProfileView/components/InvertCallStack/index.d.ts.map +1 -1
  85. package/dist/ProfileView/components/InvertCallStack/index.js +100 -12
  86. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +260 -315
  87. package/dist/ProfileView/components/ProfileFilters/index.js +518 -215
  88. package/dist/ProfileView/components/ProfileFilters/useProfileFilters.js +370 -306
  89. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts +2 -1
  90. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts.map +1 -1
  91. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +188 -118
  92. package/dist/ProfileView/components/ProfileHeader/index.js +105 -11
  93. package/dist/ProfileView/components/ShareButton/ResultBox.js +119 -16
  94. package/dist/ProfileView/components/ShareButton/index.js +352 -62
  95. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  96. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +678 -194
  97. package/dist/ProfileView/components/Toolbars/SwitchMenuItem.js +94 -7
  98. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.d.ts.map +1 -1
  99. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +199 -157
  100. package/dist/ProfileView/components/Toolbars/index.d.ts +2 -2
  101. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  102. package/dist/ProfileView/components/Toolbars/index.js +441 -21
  103. package/dist/ProfileView/components/ViewSelector/Dropdown.js +233 -22
  104. package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
  105. package/dist/ProfileView/components/ViewSelector/index.js +212 -86
  106. package/dist/ProfileView/components/VisualizationContainer/index.d.ts.map +1 -1
  107. package/dist/ProfileView/components/VisualizationContainer/index.js +52 -7
  108. package/dist/ProfileView/components/VisualizationPanel.js +185 -8
  109. package/dist/ProfileView/context/DashboardContext.d.ts.map +1 -1
  110. package/dist/ProfileView/context/DashboardContext.js +85 -29
  111. package/dist/ProfileView/context/ProfileViewContext.js +56 -15
  112. package/dist/ProfileView/hooks/useAutoSelectDimension.js +71 -41
  113. package/dist/ProfileView/hooks/useProfileMetadata.js +50 -18
  114. package/dist/ProfileView/hooks/useResetFlameGraphState.d.ts.map +1 -1
  115. package/dist/ProfileView/hooks/useResetFlameGraphState.js +32 -12
  116. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
  117. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +71 -27
  118. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.d.ts.map +1 -1
  119. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +40 -19
  120. package/dist/ProfileView/hooks/useVisualizationState.d.ts +3 -3
  121. package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
  122. package/dist/ProfileView/hooks/useVisualizationState.js +258 -67
  123. package/dist/ProfileView/index.js +383 -45
  124. package/dist/ProfileView/types/visualization.js +1 -13
  125. package/dist/ProfileView/utils/colorUtils.js +8 -7
  126. package/dist/ProfileViewWithData.d.ts.map +1 -1
  127. package/dist/ProfileViewWithData.js +332 -228
  128. package/dist/QueryControls/index.js +418 -47
  129. package/dist/Sandwich/components/CalleesSection.js +54 -4
  130. package/dist/Sandwich/components/CallersSection.js +97 -27
  131. package/dist/Sandwich/components/TableSection.js +77 -4
  132. package/dist/Sandwich/index.d.ts.map +1 -1
  133. package/dist/Sandwich/index.js +126 -14
  134. package/dist/Sandwich/utils/processRowData.js +48 -39
  135. package/dist/SelectWithRefresh/index.js +102 -28
  136. package/dist/SimpleMatchers/Select.js +520 -187
  137. package/dist/SimpleMatchers/index.js +590 -288
  138. package/dist/SourceView/Highlighter.js +230 -70
  139. package/dist/SourceView/LineNo.js +72 -17
  140. package/dist/SourceView/index.d.ts.map +1 -1
  141. package/dist/SourceView/index.js +178 -104
  142. package/dist/SourceView/lang-detector/ext-to-lang.json +798 -798
  143. package/dist/SourceView/lang-detector/index.js +28 -14
  144. package/dist/SourceView/useSelectedLineRange.d.ts.map +1 -1
  145. package/dist/SourceView/useSelectedLineRange.js +99 -23
  146. package/dist/Table/ColorCell.js +42 -1
  147. package/dist/Table/ColumnsVisibility.js +114 -6
  148. package/dist/Table/MoreDropdown.d.ts.map +1 -1
  149. package/dist/Table/MoreDropdown.js +122 -25
  150. package/dist/Table/TableContextMenu.d.ts.map +1 -1
  151. package/dist/Table/TableContextMenu.js +151 -137
  152. package/dist/Table/TableContextMenuWrapper.js +59 -14
  153. package/dist/Table/hooks/useColorManagement.js +58 -16
  154. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  155. package/dist/Table/hooks/useTableConfiguration.js +333 -169
  156. package/dist/Table/index.d.ts.map +1 -1
  157. package/dist/Table/index.js +222 -128
  158. package/dist/Table/utils/functions.js +169 -144
  159. package/dist/Table/utils/topAndBottomExpandedRowModel.js +69 -52
  160. package/dist/TimelineGuide/index.js +209 -16
  161. package/dist/TopTable/benchmarks/benchdata/populateData.js +91 -0
  162. package/dist/TopTable/index.d.ts.map +1 -1
  163. package/dist/TopTable/index.js +342 -123
  164. package/dist/contexts/LabelsQueryProvider.js +94 -32
  165. package/dist/contexts/UnifiedLabelsContext.js +114 -49
  166. package/dist/contexts/utils.js +37 -15
  167. package/dist/hooks/useCompareModeMeta.d.ts.map +1 -1
  168. package/dist/hooks/useCompareModeMeta.js +158 -64
  169. package/dist/hooks/useLabels.js +295 -52
  170. package/dist/hooks/useQueryState.d.ts +3 -3
  171. package/dist/hooks/useQueryState.d.ts.map +1 -1
  172. package/dist/hooks/useQueryState.js +373 -332
  173. package/dist/index.d.ts +2 -3
  174. package/dist/index.d.ts.map +1 -1
  175. package/dist/index.js +22 -8
  176. package/dist/testdata/fg-diff.json +3750 -0
  177. package/dist/testdata/fg-simple.json +1879 -0
  178. package/dist/testdata/link_data.json +56 -0
  179. package/dist/testdata/tabular.json +30 -0
  180. package/dist/testdata/test_flamegraph.json +26846 -0
  181. package/dist/testdata/test_graph.json +53 -0
  182. package/dist/useDelayedLoader.js +32 -18
  183. package/dist/useGrpcQuery/index.js +71 -11
  184. package/dist/useHasProfileData.js +90 -12
  185. package/dist/useQuery.js +205 -64
  186. package/dist/useSumBy.d.ts +1 -1
  187. package/dist/useSumBy.d.ts.map +1 -1
  188. package/dist/useSumBy.js +294 -138
  189. package/dist/utils.js +62 -30
  190. package/package.json +9 -10
  191. package/src/GraphTooltipArrow/index.tsx +3 -0
  192. package/src/GraphTooltipArrow/useGraphTooltipMetaInfo/index.ts +13 -11
  193. package/src/MatchersInput/SuggestionsList.test.tsx +70 -0
  194. package/src/MatchersInput/SuggestionsList.tsx +11 -10
  195. package/src/MatchersInput/index.tsx +1 -1
  196. package/src/MetricsGraph/MetricsTooltip/index.tsx +22 -34
  197. package/src/PreSelectedMatchers/index.tsx +3 -0
  198. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +9 -4
  199. package/src/ProfileFlameChart/SamplesStrips/index.tsx +2 -2
  200. package/src/ProfileFlameChart/index.tsx +28 -21
  201. package/src/ProfileFlameGraph/FlameGraphArrow/ContextMenu.tsx +9 -10
  202. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +6 -5
  203. package/src/ProfileFlameGraph/FlameGraphArrow/TooltipContext.tsx +3 -0
  204. package/src/ProfileFlameGraph/FlameGraphArrow/ZoomControls.tsx +3 -0
  205. package/src/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.ts +3 -0
  206. package/src/ProfileFlameGraph/index.tsx +9 -6
  207. package/src/ProfileMetricsGraph/index.tsx +8 -6
  208. package/src/ProfileSelector/MetricsGraphSection.tsx +10 -5
  209. package/src/ProfileSelector/index.tsx +61 -39
  210. package/src/ProfileView/components/ActionButtons/SortByDropdown.tsx +6 -10
  211. package/src/ProfileView/components/ColorStackLegend.tsx +4 -2
  212. package/src/ProfileView/components/InvertCallStack/index.tsx +4 -5
  213. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.tsx +192 -94
  214. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.ts +21 -21
  215. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +28 -24
  216. package/src/ProfileView/components/Toolbars/TableColumnsDropdown.tsx +5 -4
  217. package/src/ProfileView/components/Toolbars/index.tsx +3 -3
  218. package/src/ProfileView/components/ViewSelector/index.tsx +16 -9
  219. package/src/ProfileView/components/VisualizationContainer/index.tsx +3 -0
  220. package/src/ProfileView/context/DashboardContext.tsx +6 -6
  221. package/src/ProfileView/hooks/useResetFlameGraphState.ts +4 -6
  222. package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +26 -24
  223. package/src/ProfileView/hooks/useResetStateOnSeriesChange.ts +8 -16
  224. package/src/ProfileView/hooks/useVisualizationState.ts +69 -61
  225. package/src/ProfileViewWithData.tsx +35 -29
  226. package/src/Sandwich/index.tsx +3 -4
  227. package/src/SourceView/index.tsx +2 -4
  228. package/src/SourceView/useSelectedLineRange.ts +19 -34
  229. package/src/Table/MoreDropdown.tsx +11 -9
  230. package/src/Table/TableContextMenu.tsx +13 -10
  231. package/src/Table/hooks/useTableConfiguration.tsx +11 -16
  232. package/src/Table/index.tsx +21 -12
  233. package/src/TopTable/index.tsx +4 -3
  234. package/src/hooks/useCompareModeMeta.ts +91 -61
  235. package/src/hooks/useQueryState.test.tsx +345 -275
  236. package/src/hooks/useQueryState.ts +118 -136
  237. package/src/index.tsx +15 -16
  238. package/src/useDelayedLoader.ts +10 -10
  239. package/src/useSumBy.ts +15 -21
  240. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +0 -455
  241. package/dist/hooks/urlParsers.d.ts +0 -18
  242. package/dist/hooks/urlParsers.d.ts.map +0 -1
  243. package/dist/hooks/urlParsers.js +0 -32
  244. package/dist/hooks/useColorBy.d.ts +0 -5
  245. package/dist/hooks/useColorBy.d.ts.map +0 -1
  246. package/dist/hooks/useColorBy.js +0 -26
  247. package/dist/hooks/useDashboardItems.d.ts +0 -5
  248. package/dist/hooks/useDashboardItems.d.ts.map +0 -1
  249. package/dist/hooks/useDashboardItems.js +0 -27
  250. package/dist/hooks/useQueryState.test.js +0 -868
  251. package/src/hooks/urlParsers.ts +0 -38
  252. package/src/hooks/useColorBy.ts +0 -42
  253. package/src/hooks/useDashboardItems.ts +0 -46
@@ -1,4 +1,23 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
6
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
7
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
8
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
9
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
15
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
16
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
18
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
20
+ import { c as _c } from "react-compiler-runtime";
2
21
  // Copyright 2022 The Parca Authors
3
22
  // Licensed under the Apache License, Version 2.0 (the "License");
4
23
  // you may not use this file except in compliance with the License.
@@ -11,167 +30,362 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
11
30
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
31
  // See the License for the specific language governing permissions and
13
32
  // limitations under the License.
14
- import { Fragment, useCallback, useEffect, useState } from 'react';
33
+
34
+ import React, { Fragment, useCallback, useEffect, useState } from 'react';
15
35
  import { Transition } from '@headlessui/react';
16
36
  import { usePopper } from 'react-popper';
17
37
  import { RefreshButton, useParcaContext } from '@parca/components';
18
38
  import { TEST_IDS, testId } from '@parca/test-utils';
19
39
  import SuggestionItem from './SuggestionItem';
20
- export class Suggestion {
21
- constructor(type, typeahead, value) {
22
- this.type = type;
23
- this.typeahead = typeahead;
24
- this.value = value;
25
- }
26
- }
27
- export class Suggestions {
28
- constructor() {
29
- this.literals = [];
30
- this.labelNames = [];
31
- this.labelValues = [];
32
- }
33
- }
34
- const LoadingSpinner = () => {
35
- const { loader: Spinner } = useParcaContext();
36
- return _jsx("div", { className: "pt-2 pb-4", children: Spinner });
40
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
41
+ export var Suggestion = /*#__PURE__*/_createClass(function Suggestion(type, typeahead, value) {
42
+ _classCallCheck(this, Suggestion);
43
+ this.type = type;
44
+ this.typeahead = typeahead;
45
+ this.value = value;
46
+ });
47
+ export var Suggestions = /*#__PURE__*/_createClass(function Suggestions() {
48
+ _classCallCheck(this, Suggestions);
49
+ this.literals = [];
50
+ this.labelNames = [];
51
+ this.labelValues = [];
52
+ });
53
+ var LoadingSpinner = function LoadingSpinner() {
54
+ var $ = _c(2);
55
+ var _useParcaContext = useParcaContext(),
56
+ Spinner = _useParcaContext.loader;
57
+ var t0;
58
+ if ($[0] !== Spinner) {
59
+ t0 = /*#__PURE__*/_jsx("div", {
60
+ className: "pt-2 pb-4",
61
+ children: Spinner
62
+ });
63
+ $[0] = Spinner;
64
+ $[1] = t0;
65
+ } else {
66
+ t0 = $[1];
67
+ }
68
+ return t0;
37
69
  };
38
- const transformLabelsForSuggestions = (labelNames, shouldTrimPrefix = false) => {
39
- const trimmedLabel = shouldTrimPrefix ? labelNames.split('.').pop() ?? labelNames : labelNames;
40
- return trimmedLabel;
70
+ var transformLabelsForSuggestions = function transformLabelsForSuggestions(labelNames) {
71
+ var _labelNames$split$pop;
72
+ var shouldTrimPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
73
+ var trimmedLabel = shouldTrimPrefix ? (_labelNames$split$pop = labelNames.split('.').pop()) !== null && _labelNames$split$pop !== void 0 ? _labelNames$split$pop : labelNames : labelNames;
74
+ return trimmedLabel;
41
75
  };
42
- const SuggestionsList = ({ suggestions, applySuggestion, inputRef, runQuery, focusedInput, isLabelNamesLoading, isLabelValuesLoading, shouldTrimPrefix = false, refetchLabelValues, refetchLabelNames, }) => {
43
- const [popperElement, setPopperElement] = useState(null);
44
- const { styles, attributes } = usePopper(inputRef, popperElement, {
45
- placement: 'bottom-start',
46
- });
47
- const [highlightedSuggestionIndex, setHighlightedSuggestionIndex] = useState(-1);
48
- const [showSuggest, setShowSuggest] = useState(true);
49
- const [isRefetchingValues, setIsRefetchingValues] = useState(false);
50
- const [isRefetchingNames, setIsRefetchingNames] = useState(false);
51
- const handleRefetchValues = useCallback(async () => {
52
- if (isRefetchingValues)
53
- return;
54
- setIsRefetchingValues(true);
55
- try {
56
- await refetchLabelValues();
57
- }
58
- finally {
59
- setIsRefetchingValues(false);
60
- }
61
- }, [refetchLabelValues, isRefetchingValues]);
62
- const handleRefetchNames = useCallback(async () => {
63
- if (isRefetchingNames)
64
- return;
65
- setIsRefetchingNames(true);
66
- try {
67
- await refetchLabelNames();
68
- }
69
- finally {
70
- setIsRefetchingNames(false);
71
- }
72
- }, [refetchLabelNames, isRefetchingNames]);
73
- const suggestionsLength = suggestions.literals.length + suggestions.labelNames.length + suggestions.labelValues.length;
74
- const getSuggestion = useCallback((index) => {
75
- if (index < suggestions.labelNames.length) {
76
- return suggestions.labelNames[index];
77
- }
78
- if (index < suggestions.labelNames.length + suggestions.literals.length) {
79
- return suggestions.literals[index - suggestions.labelNames.length];
80
- }
81
- return suggestions.labelValues[index - suggestions.labelNames.length - suggestions.literals.length];
82
- }, [suggestions]);
83
- const resetHighlight = useCallback(() => setHighlightedSuggestionIndex(-1), [setHighlightedSuggestionIndex]);
84
- const applyHighlightedSuggestion = useCallback(() => {
85
- applySuggestion(getSuggestion(highlightedSuggestionIndex));
86
- resetHighlight();
87
- }, [resetHighlight, applySuggestion, highlightedSuggestionIndex, getSuggestion]);
88
- const applySuggestionWithIndex = useCallback((index) => {
89
- applySuggestion(getSuggestion(index));
90
- resetHighlight();
91
- }, [resetHighlight, applySuggestion, getSuggestion]);
92
- const highlightNext = useCallback(() => {
93
- const nextIndex = highlightedSuggestionIndex + 1;
94
- if (nextIndex === suggestionsLength) {
95
- resetHighlight();
96
- return;
97
- }
98
- setHighlightedSuggestionIndex(nextIndex);
99
- }, [highlightedSuggestionIndex, suggestionsLength, resetHighlight]);
100
- const highlightPrevious = useCallback(() => {
101
- if (highlightedSuggestionIndex === -1) {
102
- // Didn't select anything, so starting at the bottom.
103
- setHighlightedSuggestionIndex(suggestionsLength - 1);
104
- return;
105
- }
106
- setHighlightedSuggestionIndex(highlightedSuggestionIndex - 1);
107
- }, [highlightedSuggestionIndex, suggestionsLength]);
108
- const handleKeyPress = useCallback((event) => {
109
- if (event.key === 'Enter') {
110
- // Disable new line in the text area
111
- event.preventDefault();
112
- }
113
- // If there is a highlighted suggestion and enter is hit, we complete
114
- // with the highlighted suggestion.
115
- if (highlightedSuggestionIndex >= 0 && event.key === 'Enter') {
116
- applyHighlightedSuggestion();
117
- }
118
- // If no suggestions is highlighted and we hit enter, we run the query,
119
- // and hide suggestions until another actions enables them again.
120
- if (highlightedSuggestionIndex === -1 && event.key === 'Enter') {
121
- setShowSuggest(false);
122
- runQuery();
123
- return;
124
- }
125
- setShowSuggest(true);
126
- }, [highlightedSuggestionIndex, applyHighlightedSuggestion, runQuery]);
127
- const handleKeyDown = useCallback((event) => {
128
- // Don't need to handle any key interactions if no suggestions there.
129
- if (suggestionsLength === 0 || !['Tab', 'ArrowUp', 'ArrowDown'].includes(event.key)) {
130
- return;
131
- }
132
- event.preventDefault();
133
- // Handle tabbing through suggestions.
134
- if (event.key === 'Tab' && suggestionsLength > 0) {
135
- event.preventDefault();
136
- if (event.shiftKey) {
137
- // Shift + tab goes up.
138
- highlightPrevious();
139
- return;
140
- }
141
- // Just tab goes down.
142
- highlightNext();
143
- }
144
- // Up arrow highlights previous suggestions.
145
- if (event.key === 'ArrowUp') {
146
- highlightPrevious();
147
- }
148
- // Down arrow highlights next suggestions.
149
- if (event.key === 'ArrowDown') {
150
- highlightNext();
151
- }
152
- }, [suggestionsLength, highlightNext, highlightPrevious]);
153
- useEffect(() => {
154
- if (inputRef == null) {
155
- return;
156
- }
157
- inputRef.addEventListener('keydown', handleKeyDown);
158
- inputRef.addEventListener('keypress', handleKeyPress);
159
- return () => {
160
- inputRef.removeEventListener('keydown', handleKeyDown);
161
- inputRef.removeEventListener('keypress', handleKeyPress);
162
- };
163
- }, [inputRef, highlightedSuggestionIndex, suggestions, handleKeyPress, handleKeyDown]);
164
- useEffect(() => {
165
- if (suggestionsLength > 0 && focusedInput) {
166
- setShowSuggest(true);
167
- }
168
- }, [suggestionsLength, focusedInput]);
169
- return (_jsx(_Fragment, { children: suggestionsLength > 0 && (_jsx("div", { ref: setPopperElement, style: { ...styles.popper, marginLeft: 0 }, ...attributes.popper, className: "z-50", children: _jsx(Transition, { show: focusedInput && showSuggest, as: Fragment, leave: "transition ease-in duration-100", leaveFrom: "opacity-100", leaveTo: "opacity-0", children: _jsxs("div", { style: { width: inputRef?.offsetWidth }, className: "absolute z-10 mt-1 max-h-[400px] rounded-md bg-gray-50 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-900 sm:text-sm flex flex-col", children: [_jsxs("div", { className: "flex-1 overflow-auto min-h-0", children: [isLabelNamesLoading ? (_jsx(LoadingSpinner, {})) : suggestions.literals.length === 0 && suggestions.labelValues.length === 0 ? (_jsx(_Fragment, { children: suggestions.labelNames.length === 0 ? (_jsx("div", { className: "px-4 py-3 text-sm text-gray-500 dark:text-gray-400 text-center", ...testId(TEST_IDS.SUGGESTIONS_NO_RESULTS), children: "No label names found" })) : (suggestions.labelNames.map((l, i) => (_jsx(SuggestionItem, { isHighlighted: highlightedSuggestionIndex === i, onHighlight: () => setHighlightedSuggestionIndex(i), onApplySuggestion: () => applySuggestionWithIndex(i), onResetHighlight: () => resetHighlight(), value: transformLabelsForSuggestions(l.value, shouldTrimPrefix) }, transformLabelsForSuggestions(l.value, shouldTrimPrefix))))) })) : (_jsx(_Fragment, { children: suggestions.labelNames.map((l, i) => (_jsx(SuggestionItem, { isHighlighted: highlightedSuggestionIndex === i, onHighlight: () => setHighlightedSuggestionIndex(i), onApplySuggestion: () => applySuggestionWithIndex(i), onResetHighlight: () => resetHighlight(), value: transformLabelsForSuggestions(l.value, shouldTrimPrefix) }, transformLabelsForSuggestions(l.value, shouldTrimPrefix)))) })), suggestions.literals.map((l, i) => (_jsx(SuggestionItem, { isHighlighted: highlightedSuggestionIndex === i + suggestions.labelNames.length, onHighlight: () => setHighlightedSuggestionIndex(i + suggestions.labelNames.length), onApplySuggestion: () => applySuggestionWithIndex(i + suggestions.labelNames.length), onResetHighlight: () => resetHighlight(), value: l.value }, l.value))), isLabelValuesLoading ? (_jsx(LoadingSpinner, {})) : suggestions.labelNames.length === 0 && suggestions.literals.length === 0 ? (_jsx(_Fragment, { children: suggestions.labelValues.length === 0 ? (_jsx("div", { className: "px-4 py-3 text-sm text-gray-500 dark:text-gray-400 text-center", ...testId(TEST_IDS.SUGGESTIONS_NO_RESULTS), children: "No label values found" })) : (suggestions.labelValues.map((l, i) => (_jsx(SuggestionItem, { isHighlighted: highlightedSuggestionIndex ===
170
- i + suggestions.labelNames.length + suggestions.literals.length, onHighlight: () => setHighlightedSuggestionIndex(i + suggestions.labelNames.length + suggestions.literals.length), onApplySuggestion: () => applySuggestionWithIndex(i + suggestions.labelNames.length + suggestions.literals.length), onResetHighlight: () => resetHighlight(), value: l.value }, l.value)))) })) : (suggestions.labelValues.map((l, i) => (_jsx(SuggestionItem, { isHighlighted: highlightedSuggestionIndex ===
171
- i + suggestions.labelNames.length + suggestions.literals.length, onHighlight: () => setHighlightedSuggestionIndex(i + suggestions.labelNames.length + suggestions.literals.length), onApplySuggestion: () => applySuggestionWithIndex(i + suggestions.labelNames.length + suggestions.literals.length), onResetHighlight: () => resetHighlight(), value: l.value }, l.value))))] }), suggestions.literals.length === 0 &&
172
- suggestions.labelValues.length === 0 &&
173
- !isLabelNamesLoading && (_jsx(RefreshButton, { onClick: () => void handleRefetchNames(), disabled: isRefetchingNames, title: "Refresh label names", testId: "suggestions-refresh-names-button", loading: isRefetchingNames })), suggestions.labelNames.length === 0 &&
174
- suggestions.literals.length === 0 &&
175
- !isLabelValuesLoading && (_jsx(RefreshButton, { onClick: () => void handleRefetchValues(), disabled: isRefetchingValues, title: "Refresh label values", testId: "suggestions-refresh-values-button", loading: isRefetchingValues }))] }) }) })) }));
76
+ var SuggestionsList = function SuggestionsList(_ref) {
77
+ var _inputRef$current;
78
+ var suggestions = _ref.suggestions,
79
+ applySuggestion = _ref.applySuggestion,
80
+ inputRef = _ref.inputRef,
81
+ runQuery = _ref.runQuery,
82
+ focusedInput = _ref.focusedInput,
83
+ isLabelNamesLoading = _ref.isLabelNamesLoading,
84
+ isLabelValuesLoading = _ref.isLabelValuesLoading,
85
+ _ref$shouldTrimPrefix = _ref.shouldTrimPrefix,
86
+ shouldTrimPrefix = _ref$shouldTrimPrefix === void 0 ? false : _ref$shouldTrimPrefix,
87
+ refetchLabelValues = _ref.refetchLabelValues,
88
+ refetchLabelNames = _ref.refetchLabelNames;
89
+ var _useState = useState(null),
90
+ _useState2 = _slicedToArray(_useState, 2),
91
+ popperElement = _useState2[0],
92
+ setPopperElement = _useState2[1];
93
+ var _usePopper = usePopper(inputRef.current, popperElement, {
94
+ placement: 'bottom-start'
95
+ }),
96
+ styles = _usePopper.styles,
97
+ attributes = _usePopper.attributes;
98
+ var _useState3 = useState(-1),
99
+ _useState4 = _slicedToArray(_useState3, 2),
100
+ highlightedSuggestionIndex = _useState4[0],
101
+ setHighlightedSuggestionIndex = _useState4[1];
102
+ var _useState5 = useState(true),
103
+ _useState6 = _slicedToArray(_useState5, 2),
104
+ showSuggest = _useState6[0],
105
+ setShowSuggest = _useState6[1];
106
+ var _useState7 = useState(false),
107
+ _useState8 = _slicedToArray(_useState7, 2),
108
+ isRefetchingValues = _useState8[0],
109
+ setIsRefetchingValues = _useState8[1];
110
+ var _useState9 = useState(false),
111
+ _useState0 = _slicedToArray(_useState9, 2),
112
+ isRefetchingNames = _useState0[0],
113
+ setIsRefetchingNames = _useState0[1];
114
+ var handleRefetchValues = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
115
+ return _regenerator().w(function (_context) {
116
+ while (1) switch (_context.p = _context.n) {
117
+ case 0:
118
+ if (!isRefetchingValues) {
119
+ _context.n = 1;
120
+ break;
121
+ }
122
+ return _context.a(2);
123
+ case 1:
124
+ setIsRefetchingValues(true);
125
+ _context.p = 2;
126
+ _context.n = 3;
127
+ return refetchLabelValues();
128
+ case 3:
129
+ _context.p = 3;
130
+ setIsRefetchingValues(false);
131
+ return _context.f(3);
132
+ case 4:
133
+ return _context.a(2);
134
+ }
135
+ }, _callee, null, [[2,, 3, 4]]);
136
+ })), [refetchLabelValues, isRefetchingValues]);
137
+ var handleRefetchNames = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
138
+ return _regenerator().w(function (_context2) {
139
+ while (1) switch (_context2.p = _context2.n) {
140
+ case 0:
141
+ if (!isRefetchingNames) {
142
+ _context2.n = 1;
143
+ break;
144
+ }
145
+ return _context2.a(2);
146
+ case 1:
147
+ setIsRefetchingNames(true);
148
+ _context2.p = 2;
149
+ _context2.n = 3;
150
+ return refetchLabelNames();
151
+ case 3:
152
+ _context2.p = 3;
153
+ setIsRefetchingNames(false);
154
+ return _context2.f(3);
155
+ case 4:
156
+ return _context2.a(2);
157
+ }
158
+ }, _callee2, null, [[2,, 3, 4]]);
159
+ })), [refetchLabelNames, isRefetchingNames]);
160
+ var suggestionsLength = suggestions.literals.length + suggestions.labelNames.length + suggestions.labelValues.length;
161
+ var getSuggestion = useCallback(function (index) {
162
+ if (index < suggestions.labelNames.length) {
163
+ return suggestions.labelNames[index];
164
+ }
165
+ if (index < suggestions.labelNames.length + suggestions.literals.length) {
166
+ return suggestions.literals[index - suggestions.labelNames.length];
167
+ }
168
+ return suggestions.labelValues[index - suggestions.labelNames.length - suggestions.literals.length];
169
+ }, [suggestions]);
170
+ var resetHighlight = useCallback(function () {
171
+ return setHighlightedSuggestionIndex(-1);
172
+ }, [setHighlightedSuggestionIndex]);
173
+ var applyHighlightedSuggestion = useCallback(function () {
174
+ applySuggestion(getSuggestion(highlightedSuggestionIndex));
175
+ resetHighlight();
176
+ }, [resetHighlight, applySuggestion, highlightedSuggestionIndex, getSuggestion]);
177
+ var applySuggestionWithIndex = useCallback(function (index_0) {
178
+ applySuggestion(getSuggestion(index_0));
179
+ resetHighlight();
180
+ }, [resetHighlight, applySuggestion, getSuggestion]);
181
+ var highlightNext = useCallback(function () {
182
+ var nextIndex = highlightedSuggestionIndex + 1;
183
+ if (nextIndex === suggestionsLength) {
184
+ resetHighlight();
185
+ return;
186
+ }
187
+ setHighlightedSuggestionIndex(nextIndex);
188
+ }, [highlightedSuggestionIndex, suggestionsLength, resetHighlight]);
189
+ var highlightPrevious = useCallback(function () {
190
+ if (highlightedSuggestionIndex === -1) {
191
+ // Didn't select anything, so starting at the bottom.
192
+ setHighlightedSuggestionIndex(suggestionsLength - 1);
193
+ return;
194
+ }
195
+ setHighlightedSuggestionIndex(highlightedSuggestionIndex - 1);
196
+ }, [highlightedSuggestionIndex, suggestionsLength]);
197
+ var handleKeyPress = useCallback(function (event) {
198
+ if (event.key === 'Enter') {
199
+ // Disable new line in the text area
200
+ event.preventDefault();
201
+ }
202
+ // If there is a highlighted suggestion and enter is hit, we complete
203
+ // with the highlighted suggestion.
204
+ if (highlightedSuggestionIndex >= 0 && event.key === 'Enter') {
205
+ applyHighlightedSuggestion();
206
+ }
207
+
208
+ // If no suggestions is highlighted and we hit enter, we run the query,
209
+ // and hide suggestions until another actions enables them again.
210
+ if (highlightedSuggestionIndex === -1 && event.key === 'Enter') {
211
+ setShowSuggest(false);
212
+ runQuery();
213
+ return;
214
+ }
215
+ setShowSuggest(true);
216
+ }, [highlightedSuggestionIndex, applyHighlightedSuggestion, runQuery]);
217
+ var handleKeyDown = useCallback(function (event_0) {
218
+ // Don't need to handle any key interactions if no suggestions there.
219
+ if (suggestionsLength === 0 || !['Tab', 'ArrowUp', 'ArrowDown'].includes(event_0.key)) {
220
+ return;
221
+ }
222
+ event_0.preventDefault();
223
+
224
+ // Handle tabbing through suggestions.
225
+ if (event_0.key === 'Tab' && suggestionsLength > 0) {
226
+ event_0.preventDefault();
227
+ if (event_0.shiftKey) {
228
+ // Shift + tab goes up.
229
+ highlightPrevious();
230
+ return;
231
+ }
232
+ // Just tab goes down.
233
+ highlightNext();
234
+ }
235
+
236
+ // Up arrow highlights previous suggestions.
237
+ if (event_0.key === 'ArrowUp') {
238
+ highlightPrevious();
239
+ }
240
+
241
+ // Down arrow highlights next suggestions.
242
+ if (event_0.key === 'ArrowDown') {
243
+ highlightNext();
244
+ }
245
+ }, [suggestionsLength, highlightNext, highlightPrevious]);
246
+ useEffect(function () {
247
+ var el = inputRef.current;
248
+ if (el == null) {
249
+ return;
250
+ }
251
+ el.addEventListener('keydown', handleKeyDown);
252
+ el.addEventListener('keypress', handleKeyPress);
253
+ return function () {
254
+ el.removeEventListener('keydown', handleKeyDown);
255
+ el.removeEventListener('keypress', handleKeyPress);
256
+ };
257
+ });
258
+ useEffect(function () {
259
+ if (suggestionsLength > 0 && focusedInput) {
260
+ setShowSuggest(true);
261
+ }
262
+ }, [suggestionsLength, focusedInput]);
263
+ return /*#__PURE__*/_jsx(_Fragment, {
264
+ children: suggestionsLength > 0 && /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
265
+ ref: setPopperElement,
266
+ style: _objectSpread(_objectSpread({}, styles.popper), {}, {
267
+ marginLeft: 0
268
+ })
269
+ }, attributes.popper), {}, {
270
+ className: "z-50",
271
+ children: /*#__PURE__*/_jsx(Transition, {
272
+ show: focusedInput && showSuggest,
273
+ as: Fragment,
274
+ leave: "transition ease-in duration-100",
275
+ leaveFrom: "opacity-100",
276
+ leaveTo: "opacity-0",
277
+ children: /*#__PURE__*/_jsxs("div", {
278
+ style: {
279
+ width: (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.offsetWidth
280
+ },
281
+ className: "absolute z-10 mt-1 max-h-[400px] rounded-md bg-gray-50 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-900 sm:text-sm flex flex-col",
282
+ children: [/*#__PURE__*/_jsxs("div", {
283
+ className: "flex-1 overflow-auto min-h-0",
284
+ children: [isLabelNamesLoading ? /*#__PURE__*/_jsx(LoadingSpinner, {}) : suggestions.literals.length === 0 && suggestions.labelValues.length === 0 ? /*#__PURE__*/_jsx(_Fragment, {
285
+ children: suggestions.labelNames.length === 0 ? /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
286
+ className: "px-4 py-3 text-sm text-gray-500 dark:text-gray-400 text-center"
287
+ }, testId(TEST_IDS.SUGGESTIONS_NO_RESULTS)), {}, {
288
+ children: "No label names found"
289
+ })) : suggestions.labelNames.map(function (l, i) {
290
+ return /*#__PURE__*/_jsx(SuggestionItem, {
291
+ isHighlighted: highlightedSuggestionIndex === i,
292
+ onHighlight: function onHighlight() {
293
+ return setHighlightedSuggestionIndex(i);
294
+ },
295
+ onApplySuggestion: function onApplySuggestion() {
296
+ return applySuggestionWithIndex(i);
297
+ },
298
+ onResetHighlight: function onResetHighlight() {
299
+ return resetHighlight();
300
+ },
301
+ value: transformLabelsForSuggestions(l.value, shouldTrimPrefix)
302
+ }, transformLabelsForSuggestions(l.value, shouldTrimPrefix));
303
+ })
304
+ }) : /*#__PURE__*/_jsx(_Fragment, {
305
+ children: suggestions.labelNames.map(function (l_0, i_0) {
306
+ return /*#__PURE__*/_jsx(SuggestionItem, {
307
+ isHighlighted: highlightedSuggestionIndex === i_0,
308
+ onHighlight: function onHighlight() {
309
+ return setHighlightedSuggestionIndex(i_0);
310
+ },
311
+ onApplySuggestion: function onApplySuggestion() {
312
+ return applySuggestionWithIndex(i_0);
313
+ },
314
+ onResetHighlight: function onResetHighlight() {
315
+ return resetHighlight();
316
+ },
317
+ value: transformLabelsForSuggestions(l_0.value, shouldTrimPrefix)
318
+ }, transformLabelsForSuggestions(l_0.value, shouldTrimPrefix));
319
+ })
320
+ }), suggestions.literals.map(function (l_1, i_1) {
321
+ return /*#__PURE__*/_jsx(SuggestionItem, {
322
+ isHighlighted: highlightedSuggestionIndex === i_1 + suggestions.labelNames.length,
323
+ onHighlight: function onHighlight() {
324
+ return setHighlightedSuggestionIndex(i_1 + suggestions.labelNames.length);
325
+ },
326
+ onApplySuggestion: function onApplySuggestion() {
327
+ return applySuggestionWithIndex(i_1 + suggestions.labelNames.length);
328
+ },
329
+ onResetHighlight: function onResetHighlight() {
330
+ return resetHighlight();
331
+ },
332
+ value: l_1.value
333
+ }, l_1.value);
334
+ }), isLabelValuesLoading ? /*#__PURE__*/_jsx(LoadingSpinner, {}) : suggestions.labelNames.length === 0 && suggestions.literals.length === 0 ? /*#__PURE__*/_jsx(_Fragment, {
335
+ children: suggestions.labelValues.length === 0 ? /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
336
+ className: "px-4 py-3 text-sm text-gray-500 dark:text-gray-400 text-center"
337
+ }, testId(TEST_IDS.SUGGESTIONS_NO_RESULTS)), {}, {
338
+ children: "No label values found"
339
+ })) : suggestions.labelValues.map(function (l_2, i_2) {
340
+ return /*#__PURE__*/_jsx(SuggestionItem, {
341
+ isHighlighted: highlightedSuggestionIndex === i_2 + suggestions.labelNames.length + suggestions.literals.length,
342
+ onHighlight: function onHighlight() {
343
+ return setHighlightedSuggestionIndex(i_2 + suggestions.labelNames.length + suggestions.literals.length);
344
+ },
345
+ onApplySuggestion: function onApplySuggestion() {
346
+ return applySuggestionWithIndex(i_2 + suggestions.labelNames.length + suggestions.literals.length);
347
+ },
348
+ onResetHighlight: function onResetHighlight() {
349
+ return resetHighlight();
350
+ },
351
+ value: l_2.value
352
+ }, l_2.value);
353
+ })
354
+ }) : suggestions.labelValues.map(function (l_3, i_3) {
355
+ return /*#__PURE__*/_jsx(SuggestionItem, {
356
+ isHighlighted: highlightedSuggestionIndex === i_3 + suggestions.labelNames.length + suggestions.literals.length,
357
+ onHighlight: function onHighlight() {
358
+ return setHighlightedSuggestionIndex(i_3 + suggestions.labelNames.length + suggestions.literals.length);
359
+ },
360
+ onApplySuggestion: function onApplySuggestion() {
361
+ return applySuggestionWithIndex(i_3 + suggestions.labelNames.length + suggestions.literals.length);
362
+ },
363
+ onResetHighlight: function onResetHighlight() {
364
+ return resetHighlight();
365
+ },
366
+ value: l_3.value
367
+ }, l_3.value);
368
+ })]
369
+ }), suggestions.literals.length === 0 && suggestions.labelValues.length === 0 && !isLabelNamesLoading && /*#__PURE__*/_jsx(RefreshButton, {
370
+ onClick: function onClick() {
371
+ return void handleRefetchNames();
372
+ },
373
+ disabled: isRefetchingNames,
374
+ title: "Refresh label names",
375
+ testId: "suggestions-refresh-names-button",
376
+ loading: isRefetchingNames
377
+ }), suggestions.labelNames.length === 0 && suggestions.literals.length === 0 && !isLabelValuesLoading && /*#__PURE__*/_jsx(RefreshButton, {
378
+ onClick: function onClick() {
379
+ return void handleRefetchValues();
380
+ },
381
+ disabled: isRefetchingValues,
382
+ title: "Refresh label values",
383
+ testId: "suggestions-refresh-values-button",
384
+ loading: isRefetchingValues
385
+ })]
386
+ })
387
+ })
388
+ }))
389
+ });
176
390
  };
177
- export default SuggestionsList;
391
+ export default SuggestionsList;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SuggestionsList.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SuggestionsList.test.d.ts","sourceRoot":"","sources":["../../src/MatchersInput/SuggestionsList.test.tsx"],"names":[],"mappings":""}