@perses-dev/plugin-system 0.55.0-beta.3 → 0.55.0-beta.6

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 (550) hide show
  1. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts +3 -3
  2. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts.map +1 -1
  3. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +11 -11
  4. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js.map +1 -1
  5. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts +3 -3
  6. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts.map +1 -1
  7. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +6 -6
  8. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js.map +1 -1
  9. package/dist/components/Annotations/AnnotationEditorForm/index.js +1 -1
  10. package/dist/components/Annotations/AnnotationEditorForm/index.js.map +1 -1
  11. package/dist/components/Annotations/index.js +2 -2
  12. package/dist/components/Annotations/index.js.map +1 -1
  13. package/dist/components/CalculationSelector/CalculationSelector.d.ts +2 -2
  14. package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
  15. package/dist/components/CalculationSelector/CalculationSelector.js +2 -2
  16. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  17. package/dist/components/CalculationSelector/index.js +1 -1
  18. package/dist/components/CalculationSelector/index.js.map +1 -1
  19. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +2 -2
  20. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  21. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +7 -7
  22. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  23. package/dist/components/DatasourceEditorForm/index.js +1 -1
  24. package/dist/components/DatasourceEditorForm/index.js.map +1 -1
  25. package/dist/components/DatasourceSelect/DatasourceSelect.d.ts +4 -4
  26. package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -1
  27. package/dist/components/DatasourceSelect/DatasourceSelect.js +7 -7
  28. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
  29. package/dist/components/DatasourceSelect/index.js +1 -1
  30. package/dist/components/DatasourceSelect/index.js.map +1 -1
  31. package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.d.ts +2 -2
  32. package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.d.ts.map +1 -1
  33. package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js +4 -4
  34. package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js.map +1 -1
  35. package/dist/components/DatasourceTestConnectionButton/index.js +1 -1
  36. package/dist/components/DatasourceTestConnectionButton/index.js.map +1 -1
  37. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +2 -2
  38. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
  39. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +9 -9
  40. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
  41. package/dist/components/HTTPSettingsEditor/index.js +1 -1
  42. package/dist/components/HTTPSettingsEditor/index.js.map +1 -1
  43. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.d.ts +1 -1
  44. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.d.ts.map +1 -1
  45. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +24 -24
  46. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
  47. package/dist/components/ItemSelectionActionsOptionsEditor/index.js +1 -1
  48. package/dist/components/ItemSelectionActionsOptionsEditor/index.js.map +1 -1
  49. package/dist/components/LayoutEditor/LayoutEditor.d.ts +4 -4
  50. package/dist/components/LayoutEditor/LayoutEditor.d.ts.map +1 -1
  51. package/dist/components/LayoutEditor/LayoutEditor.js +7 -7
  52. package/dist/components/LayoutEditor/LayoutEditor.js.map +1 -1
  53. package/dist/components/LayoutEditor/RepeatLayoutPreview.d.ts +1 -1
  54. package/dist/components/LayoutEditor/RepeatLayoutPreview.d.ts.map +1 -1
  55. package/dist/components/LayoutEditor/RepeatLayoutPreview.js +4 -4
  56. package/dist/components/LayoutEditor/RepeatLayoutPreview.js.map +1 -1
  57. package/dist/components/LayoutEditor/RepeatVariableEditor.d.ts +4 -4
  58. package/dist/components/LayoutEditor/RepeatVariableEditor.d.ts.map +1 -1
  59. package/dist/components/LayoutEditor/RepeatVariableEditor.js +3 -3
  60. package/dist/components/LayoutEditor/RepeatVariableEditor.js.map +1 -1
  61. package/dist/components/LayoutEditor/index.js +3 -3
  62. package/dist/components/LayoutEditor/index.js.map +1 -1
  63. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +2 -2
  64. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  65. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +5 -5
  66. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  67. package/dist/components/LegendOptionsEditor/index.js +1 -1
  68. package/dist/components/LegendOptionsEditor/index.js.map +1 -1
  69. package/dist/components/LinksEditor/LinksEditor.d.ts +3 -3
  70. package/dist/components/LinksEditor/LinksEditor.d.ts.map +1 -1
  71. package/dist/components/LinksEditor/LinksEditor.js +6 -6
  72. package/dist/components/LinksEditor/LinksEditor.js.map +1 -1
  73. package/dist/components/LinksEditor/index.js +1 -1
  74. package/dist/components/LinksEditor/index.js.map +1 -1
  75. package/dist/components/MetricLabelInput/MetricLabelInput.d.ts +1 -1
  76. package/dist/components/MetricLabelInput/MetricLabelInput.d.ts.map +1 -1
  77. package/dist/components/MetricLabelInput/MetricLabelInput.js +2 -2
  78. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
  79. package/dist/components/MetricLabelInput/index.js +1 -1
  80. package/dist/components/MetricLabelInput/index.js.map +1 -1
  81. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +3 -3
  82. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  83. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +6 -6
  84. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  85. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +3 -3
  86. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  87. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +14 -14
  88. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  89. package/dist/components/MultiQueryEditor/index.js +2 -2
  90. package/dist/components/MultiQueryEditor/index.js.map +1 -1
  91. package/dist/components/MultiQueryEditor/utils.d.ts +1 -1
  92. package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -1
  93. package/dist/components/MultiQueryEditor/utils.js.map +1 -1
  94. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +1 -1
  95. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -1
  96. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +4 -4
  97. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  98. package/dist/components/OptionsEditorRadios/index.js +1 -1
  99. package/dist/components/OptionsEditorRadios/index.js.map +1 -1
  100. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +1 -1
  101. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -1
  102. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
  103. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  104. package/dist/components/OptionsEditorTabPanel/index.js +1 -1
  105. package/dist/components/OptionsEditorTabPanel/index.js.map +1 -1
  106. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts +1 -1
  107. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts.map +1 -1
  108. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +4 -4
  109. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  110. package/dist/components/OptionsEditorTabs/index.js +1 -1
  111. package/dist/components/OptionsEditorTabs/index.js.map +1 -1
  112. package/dist/components/PanelSpecEditor/PanelAnnotationsEditor.d.ts +2 -2
  113. package/dist/components/PanelSpecEditor/PanelAnnotationsEditor.d.ts.map +1 -1
  114. package/dist/components/PanelSpecEditor/PanelAnnotationsEditor.js +9 -9
  115. package/dist/components/PanelSpecEditor/PanelAnnotationsEditor.js.map +1 -1
  116. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +5 -5
  117. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  118. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +9 -9
  119. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  120. package/dist/components/PanelSpecEditor/index.js +1 -1
  121. package/dist/components/PanelSpecEditor/index.js.map +1 -1
  122. package/dist/components/PluginEditor/PluginEditor.d.ts +2 -2
  123. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  124. package/dist/components/PluginEditor/PluginEditor.js +7 -7
  125. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  126. package/dist/components/PluginEditor/index.js +2 -2
  127. package/dist/components/PluginEditor/index.js.map +1 -1
  128. package/dist/components/PluginEditor/plugin-editor-api.d.ts +3 -3
  129. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  130. package/dist/components/PluginEditor/plugin-editor-api.js +4 -4
  131. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  132. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +3 -3
  133. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  134. package/dist/components/PluginKindSelect/PluginKindSelect.js +4 -4
  135. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  136. package/dist/components/PluginKindSelect/index.js +1 -1
  137. package/dist/components/PluginKindSelect/index.js.map +1 -1
  138. package/dist/components/PluginRegistry/PluginRegistry.d.ts +2 -2
  139. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  140. package/dist/components/PluginRegistry/PluginRegistry.js +5 -5
  141. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  142. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts +2 -2
  143. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts.map +1 -1
  144. package/dist/components/PluginRegistry/getPluginSearchHelper.js +2 -2
  145. package/dist/components/PluginRegistry/getPluginSearchHelper.js.map +1 -1
  146. package/dist/components/PluginRegistry/index.js +1 -1
  147. package/dist/components/PluginRegistry/index.js.map +1 -1
  148. package/dist/components/PluginRegistry/plugin-indexes.d.ts +2 -1
  149. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  150. package/dist/components/PluginRegistry/plugin-indexes.js +3 -3
  151. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  152. package/dist/components/PluginSpecEditor/DatasourceSpecEditor.d.ts +3 -3
  153. package/dist/components/PluginSpecEditor/DatasourceSpecEditor.d.ts.map +1 -1
  154. package/dist/components/PluginSpecEditor/DatasourceSpecEditor.js +3 -3
  155. package/dist/components/PluginSpecEditor/DatasourceSpecEditor.js.map +1 -1
  156. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +4 -4
  157. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  158. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +4 -4
  159. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  160. package/dist/components/PluginSpecEditor/index.js +1 -1
  161. package/dist/components/PluginSpecEditor/index.js.map +1 -1
  162. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.d.ts +1 -1
  163. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.d.ts.map +1 -1
  164. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js +3 -3
  165. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js.map +1 -1
  166. package/dist/components/SelectionOptionsEditor/index.js +1 -1
  167. package/dist/components/SelectionOptionsEditor/index.js.map +1 -1
  168. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -2
  169. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  170. package/dist/components/TimeRangeControls/TimeRangeControls.js +10 -10
  171. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  172. package/dist/components/TimeRangeControls/index.js +1 -1
  173. package/dist/components/TimeRangeControls/index.js.map +1 -1
  174. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +3 -3
  175. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  176. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +11 -11
  177. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  178. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -2
  179. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  180. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +7 -7
  181. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  182. package/dist/components/Variables/VariableEditorForm/index.js +3 -3
  183. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  184. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +2 -2
  185. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  186. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  187. package/dist/components/Variables/index.js +2 -2
  188. package/dist/components/Variables/index.js.map +1 -1
  189. package/dist/components/Variables/variable-model.d.ts +4 -4
  190. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  191. package/dist/components/Variables/variable-model.js +3 -3
  192. package/dist/components/Variables/variable-model.js.map +1 -1
  193. package/dist/components/index.js +21 -21
  194. package/dist/components/index.js.map +1 -1
  195. package/dist/constants/index.js +2 -2
  196. package/dist/constants/index.js.map +1 -1
  197. package/dist/context/ValidationProvider.d.ts +5 -5
  198. package/dist/context/ValidationProvider.d.ts.map +1 -1
  199. package/dist/context/ValidationProvider.js +5 -5
  200. package/dist/context/ValidationProvider.js.map +1 -1
  201. package/dist/context/index.js +1 -1
  202. package/dist/context/index.js.map +1 -1
  203. package/dist/index.js +9 -9
  204. package/dist/index.js.map +1 -1
  205. package/dist/model/alerts-queries.d.ts +4 -4
  206. package/dist/model/alerts-queries.d.ts.map +1 -1
  207. package/dist/model/alerts-queries.js.map +1 -1
  208. package/dist/model/annotations.d.ts +3 -3
  209. package/dist/model/annotations.d.ts.map +1 -1
  210. package/dist/model/annotations.js.map +1 -1
  211. package/dist/model/calculations.d.ts +1 -1
  212. package/dist/model/calculations.d.ts.map +1 -1
  213. package/dist/model/calculations.js.map +1 -1
  214. package/dist/model/datasource.d.ts +2 -2
  215. package/dist/model/datasource.d.ts.map +1 -1
  216. package/dist/model/datasource.js.map +1 -1
  217. package/dist/model/explore.d.ts +2 -2
  218. package/dist/model/explore.d.ts.map +1 -1
  219. package/dist/model/explore.js.map +1 -1
  220. package/dist/model/index.js +17 -17
  221. package/dist/model/index.js.map +1 -1
  222. package/dist/model/json-queries.d.ts +3 -3
  223. package/dist/model/json-queries.d.ts.map +1 -1
  224. package/dist/model/json-queries.js.map +1 -1
  225. package/dist/model/legend.d.ts +2 -2
  226. package/dist/model/legend.d.ts.map +1 -1
  227. package/dist/model/legend.js +2 -2
  228. package/dist/model/legend.js.map +1 -1
  229. package/dist/model/log-queries.d.ts +3 -3
  230. package/dist/model/log-queries.d.ts.map +1 -1
  231. package/dist/model/log-queries.js.map +1 -1
  232. package/dist/model/panels.d.ts +4 -4
  233. package/dist/model/panels.d.ts.map +1 -1
  234. package/dist/model/panels.js.map +1 -1
  235. package/dist/model/plugin-base.d.ts +1 -1
  236. package/dist/model/plugin-base.d.ts.map +1 -1
  237. package/dist/model/plugin-base.js.map +1 -1
  238. package/dist/model/plugin-loading.d.ts +1 -1
  239. package/dist/model/plugin-loading.d.ts.map +1 -1
  240. package/dist/model/plugin-loading.js +1 -1
  241. package/dist/model/plugin-loading.js.map +1 -1
  242. package/dist/model/plugins.d.ts +14 -14
  243. package/dist/model/plugins.d.ts.map +1 -1
  244. package/dist/model/plugins.js.map +1 -1
  245. package/dist/model/profile-queries.d.ts +4 -4
  246. package/dist/model/profile-queries.d.ts.map +1 -1
  247. package/dist/model/profile-queries.js.map +1 -1
  248. package/dist/model/silences-queries.d.ts +4 -4
  249. package/dist/model/silences-queries.d.ts.map +1 -1
  250. package/dist/model/silences-queries.js.map +1 -1
  251. package/dist/model/time-series-queries.d.ts +4 -4
  252. package/dist/model/time-series-queries.d.ts.map +1 -1
  253. package/dist/model/time-series-queries.js.map +1 -1
  254. package/dist/model/trace-queries.d.ts +4 -4
  255. package/dist/model/trace-queries.d.ts.map +1 -1
  256. package/dist/model/trace-queries.js.map +1 -1
  257. package/dist/model/variables.d.ts +3 -3
  258. package/dist/model/variables.d.ts.map +1 -1
  259. package/dist/model/variables.js.map +1 -1
  260. package/dist/remote/PluginLoaderComponent.d.ts +1 -1
  261. package/dist/remote/PluginLoaderComponent.d.ts.map +1 -1
  262. package/dist/remote/PluginLoaderComponent.js +2 -2
  263. package/dist/remote/PluginLoaderComponent.js.map +1 -1
  264. package/dist/remote/PluginRuntime.d.ts +2 -2
  265. package/dist/remote/PluginRuntime.d.ts.map +1 -1
  266. package/dist/remote/PluginRuntime.js +18 -18
  267. package/dist/remote/PluginRuntime.js.map +1 -1
  268. package/dist/remote/index.js +2 -2
  269. package/dist/remote/index.js.map +1 -1
  270. package/dist/remote/remotePluginLoader.d.ts +2 -2
  271. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  272. package/dist/remote/remotePluginLoader.js +3 -3
  273. package/dist/remote/remotePluginLoader.js.map +1 -1
  274. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +3 -3
  275. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  276. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -10
  277. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  278. package/dist/runtime/DataQueriesProvider/index.js +2 -2
  279. package/dist/runtime/DataQueriesProvider/index.js.map +1 -1
  280. package/dist/runtime/DataQueriesProvider/model.d.ts +3 -3
  281. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  282. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  283. package/dist/runtime/RouterProvider.d.ts +2 -1
  284. package/dist/runtime/RouterProvider.d.ts.map +1 -1
  285. package/dist/runtime/RouterProvider.js +3 -3
  286. package/dist/runtime/RouterProvider.js.map +1 -1
  287. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +3 -2
  288. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  289. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +6 -6
  290. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  291. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +3 -2
  292. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts.map +1 -1
  293. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js +4 -4
  294. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -1
  295. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +2 -2
  296. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -1
  297. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +3 -3
  298. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  299. package/dist/runtime/TimeRangeProvider/index.js +4 -4
  300. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  301. package/dist/runtime/TimeRangeProvider/query-params.d.ts +3 -3
  302. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  303. package/dist/runtime/TimeRangeProvider/query-params.js +4 -4
  304. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  305. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts +1 -1
  306. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -1
  307. package/dist/runtime/TimeRangeProvider/refresh-interval.js +2 -2
  308. package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -1
  309. package/dist/runtime/UsageMetricsProvider.d.ts +3 -3
  310. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
  311. package/dist/runtime/UsageMetricsProvider.js +3 -3
  312. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  313. package/dist/runtime/alerts-queries.d.ts +2 -2
  314. package/dist/runtime/alerts-queries.d.ts.map +1 -1
  315. package/dist/runtime/alerts-queries.js +5 -5
  316. package/dist/runtime/alerts-queries.js.map +1 -1
  317. package/dist/runtime/annotations.d.ts +2 -2
  318. package/dist/runtime/annotations.d.ts.map +1 -1
  319. package/dist/runtime/annotations.js +6 -6
  320. package/dist/runtime/annotations.js.map +1 -1
  321. package/dist/runtime/builtin-variables.d.ts +2 -2
  322. package/dist/runtime/builtin-variables.d.ts.map +1 -1
  323. package/dist/runtime/builtin-variables.js +1 -1
  324. package/dist/runtime/builtin-variables.js.map +1 -1
  325. package/dist/runtime/datasources.d.ts +2 -2
  326. package/dist/runtime/datasources.d.ts.map +1 -1
  327. package/dist/runtime/datasources.js +2 -2
  328. package/dist/runtime/datasources.js.map +1 -1
  329. package/dist/runtime/index.js +16 -16
  330. package/dist/runtime/index.js.map +1 -1
  331. package/dist/runtime/item-actions.d.ts +3 -3
  332. package/dist/runtime/item-actions.d.ts.map +1 -1
  333. package/dist/runtime/item-actions.js +1 -1
  334. package/dist/runtime/item-actions.js.map +1 -1
  335. package/dist/runtime/json-queries.d.ts +2 -2
  336. package/dist/runtime/json-queries.d.ts.map +1 -1
  337. package/dist/runtime/json-queries.js +4 -4
  338. package/dist/runtime/json-queries.js.map +1 -1
  339. package/dist/runtime/log-queries.d.ts +3 -3
  340. package/dist/runtime/log-queries.d.ts.map +1 -1
  341. package/dist/runtime/log-queries.js +5 -5
  342. package/dist/runtime/log-queries.js.map +1 -1
  343. package/dist/runtime/plugin-registry.d.ts +3 -3
  344. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  345. package/dist/runtime/plugin-registry.js +2 -2
  346. package/dist/runtime/plugin-registry.js.map +1 -1
  347. package/dist/runtime/profile-queries.d.ts +2 -2
  348. package/dist/runtime/profile-queries.d.ts.map +1 -1
  349. package/dist/runtime/profile-queries.js +4 -4
  350. package/dist/runtime/profile-queries.js.map +1 -1
  351. package/dist/runtime/silences-queries.d.ts +2 -2
  352. package/dist/runtime/silences-queries.d.ts.map +1 -1
  353. package/dist/runtime/silences-queries.js +5 -5
  354. package/dist/runtime/silences-queries.js.map +1 -1
  355. package/dist/runtime/time-series-queries.d.ts +3 -3
  356. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  357. package/dist/runtime/time-series-queries.js +6 -6
  358. package/dist/runtime/time-series-queries.js.map +1 -1
  359. package/dist/runtime/trace-queries.d.ts +2 -2
  360. package/dist/runtime/trace-queries.d.ts.map +1 -1
  361. package/dist/runtime/trace-queries.js +6 -6
  362. package/dist/runtime/trace-queries.js.map +1 -1
  363. package/dist/runtime/utils.d.ts +1 -1
  364. package/dist/runtime/utils.d.ts.map +1 -1
  365. package/dist/runtime/utils.js.map +1 -1
  366. package/dist/runtime/variables.d.ts +1 -1
  367. package/dist/runtime/variables.d.ts.map +1 -1
  368. package/dist/runtime/variables.js +4 -4
  369. package/dist/runtime/variables.js.map +1 -1
  370. package/dist/schema/index.js +1 -1
  371. package/dist/schema/index.js.map +1 -1
  372. package/dist/schema/panel.d.ts +2 -2
  373. package/dist/schema/panel.d.ts.map +1 -1
  374. package/dist/schema/panel.js +2 -2
  375. package/dist/schema/panel.js.map +1 -1
  376. package/dist/test/index.js +2 -2
  377. package/dist/test/index.js.map +1 -1
  378. package/dist/test/mock-data.d.ts +1 -1
  379. package/dist/test/mock-data.d.ts.map +1 -1
  380. package/dist/test/mock-data.js.map +1 -1
  381. package/dist/test/render-hook.d.ts +2 -2
  382. package/dist/test/render-hook.d.ts.map +1 -1
  383. package/dist/test/render-hook.js +2 -2
  384. package/dist/test/render-hook.js.map +1 -1
  385. package/dist/test/render.d.ts +3 -3
  386. package/dist/test/render.d.ts.map +1 -1
  387. package/dist/test/render.js +3 -3
  388. package/dist/test/render.js.map +1 -1
  389. package/dist/test/setup-tests.js +1 -1
  390. package/dist/test/test-plugins/bert/index.d.ts +3 -3
  391. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  392. package/dist/test/test-plugins/bert/index.js.map +1 -1
  393. package/dist/test/test-plugins/ernie/index.d.ts +1 -1
  394. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
  395. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  396. package/dist/test/test-plugins/index.d.ts +1 -1
  397. package/dist/test/test-plugins/index.d.ts.map +1 -1
  398. package/dist/test/test-plugins/index.js +5 -5
  399. package/dist/test/test-plugins/index.js.map +1 -1
  400. package/dist/test/utils.d.ts +2 -2
  401. package/dist/test/utils.d.ts.map +1 -1
  402. package/dist/test/utils.js +4 -4
  403. package/dist/test/utils.js.map +1 -1
  404. package/dist/test-utils/index.js +1 -1
  405. package/dist/test-utils/index.js.map +1 -1
  406. package/dist/test-utils/mock-plugin-registry.d.ts +2 -2
  407. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  408. package/dist/test-utils/mock-plugin-registry.js +1 -1
  409. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  410. package/dist/utils/event.js +1 -1
  411. package/dist/utils/index.js +3 -3
  412. package/dist/utils/index.js.map +1 -1
  413. package/dist/utils/variables.js +1 -1
  414. package/package.json +7 -7
  415. package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +0 -283
  416. package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +0 -197
  417. package/dist/cjs/components/Annotations/AnnotationEditorForm/index.js +0 -30
  418. package/dist/cjs/components/Annotations/constants.js +0 -23
  419. package/dist/cjs/components/Annotations/index.js +0 -31
  420. package/dist/cjs/components/CalculationSelector/CalculationSelector.js +0 -49
  421. package/dist/cjs/components/CalculationSelector/index.js +0 -30
  422. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +0 -271
  423. package/dist/cjs/components/DatasourceEditorForm/index.js +0 -30
  424. package/dist/cjs/components/DatasourceSelect/DatasourceSelect.js +0 -266
  425. package/dist/cjs/components/DatasourceSelect/index.js +0 -30
  426. package/dist/cjs/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js +0 -53
  427. package/dist/cjs/components/DatasourceTestConnectionButton/index.js +0 -30
  428. package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +0 -593
  429. package/dist/cjs/components/HTTPSettingsEditor/index.js +0 -30
  430. package/dist/cjs/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +0 -1175
  431. package/dist/cjs/components/ItemSelectionActionsOptionsEditor/index.js +0 -30
  432. package/dist/cjs/components/LayoutEditor/LayoutEditor.js +0 -123
  433. package/dist/cjs/components/LayoutEditor/RepeatLayoutPreview.js +0 -105
  434. package/dist/cjs/components/LayoutEditor/RepeatVariableEditor.js +0 -176
  435. package/dist/cjs/components/LayoutEditor/index.js +0 -32
  436. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +0 -211
  437. package/dist/cjs/components/LegendOptionsEditor/index.js +0 -30
  438. package/dist/cjs/components/LinksEditor/LinksEditor.js +0 -162
  439. package/dist/cjs/components/LinksEditor/index.js +0 -30
  440. package/dist/cjs/components/MetricLabelInput/MetricLabelInput.js +0 -41
  441. package/dist/cjs/components/MetricLabelInput/index.js +0 -30
  442. package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +0 -162
  443. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +0 -250
  444. package/dist/cjs/components/MultiQueryEditor/index.js +0 -31
  445. package/dist/cjs/components/MultiQueryEditor/utils.js +0 -36
  446. package/dist/cjs/components/OptionsEditorRadios/OptionsEditorRadios.js +0 -69
  447. package/dist/cjs/components/OptionsEditorRadios/index.js +0 -30
  448. package/dist/cjs/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +0 -39
  449. package/dist/cjs/components/OptionsEditorTabPanel/index.js +0 -30
  450. package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +0 -61
  451. package/dist/cjs/components/OptionsEditorTabs/index.js +0 -30
  452. package/dist/cjs/components/PanelSpecEditor/PanelAnnotationsEditor.js +0 -246
  453. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +0 -144
  454. package/dist/cjs/components/PanelSpecEditor/index.js +0 -30
  455. package/dist/cjs/components/PluginEditor/PluginEditor.js +0 -99
  456. package/dist/cjs/components/PluginEditor/index.js +0 -31
  457. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +0 -136
  458. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +0 -109
  459. package/dist/cjs/components/PluginKindSelect/index.js +0 -30
  460. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +0 -86
  461. package/dist/cjs/components/PluginRegistry/getPluginSearchHelper.js +0 -92
  462. package/dist/cjs/components/PluginRegistry/index.js +0 -30
  463. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +0 -88
  464. package/dist/cjs/components/PluginSpecEditor/DatasourceSpecEditor.js +0 -70
  465. package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +0 -69
  466. package/dist/cjs/components/PluginSpecEditor/index.js +0 -30
  467. package/dist/cjs/components/SelectionOptionsEditor/SelectionOptionsEditor.js +0 -43
  468. package/dist/cjs/components/SelectionOptionsEditor/index.js +0 -30
  469. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +0 -235
  470. package/dist/cjs/components/TimeRangeControls/index.js +0 -30
  471. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -613
  472. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +0 -193
  473. package/dist/cjs/components/Variables/VariableEditorForm/index.js +0 -32
  474. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -143
  475. package/dist/cjs/components/Variables/index.js +0 -31
  476. package/dist/cjs/components/Variables/variable-model.js +0 -211
  477. package/dist/cjs/components/index.js +0 -50
  478. package/dist/cjs/constants/index.js +0 -31
  479. package/dist/cjs/constants/repeat.js +0 -32
  480. package/dist/cjs/constants/user-interface-text.js +0 -32
  481. package/dist/cjs/context/ValidationProvider.js +0 -77
  482. package/dist/cjs/context/index.js +0 -30
  483. package/dist/cjs/index.js +0 -38
  484. package/dist/cjs/model/alerts-queries.js +0 -16
  485. package/dist/cjs/model/annotations.js +0 -16
  486. package/dist/cjs/model/calculations.js +0 -178
  487. package/dist/cjs/model/datasource.js +0 -16
  488. package/dist/cjs/model/explore.js +0 -16
  489. package/dist/cjs/model/index.js +0 -46
  490. package/dist/cjs/model/json-queries.js +0 -16
  491. package/dist/cjs/model/legend.js +0 -111
  492. package/dist/cjs/model/log-queries.js +0 -16
  493. package/dist/cjs/model/log-volume-utils.js +0 -124
  494. package/dist/cjs/model/panels.js +0 -16
  495. package/dist/cjs/model/plugin-base.js +0 -16
  496. package/dist/cjs/model/plugin-loading.js +0 -56
  497. package/dist/cjs/model/plugins.js +0 -26
  498. package/dist/cjs/model/profile-queries.js +0 -16
  499. package/dist/cjs/model/silences-queries.js +0 -16
  500. package/dist/cjs/model/time-series-queries.js +0 -26
  501. package/dist/cjs/model/trace-queries.js +0 -16
  502. package/dist/cjs/model/variables.js +0 -16
  503. package/dist/cjs/remote/PersesPlugin.types.js +0 -16
  504. package/dist/cjs/remote/PluginLoaderComponent.js +0 -87
  505. package/dist/cjs/remote/PluginRuntime.js +0 -323
  506. package/dist/cjs/remote/index.js +0 -31
  507. package/dist/cjs/remote/remotePluginLoader.js +0 -101
  508. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +0 -162
  509. package/dist/cjs/runtime/DataQueriesProvider/index.js +0 -31
  510. package/dist/cjs/runtime/DataQueriesProvider/model.js +0 -34
  511. package/dist/cjs/runtime/RouterProvider.js +0 -114
  512. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +0 -215
  513. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProviders.js +0 -66
  514. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +0 -126
  515. package/dist/cjs/runtime/TimeRangeProvider/index.js +0 -33
  516. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +0 -250
  517. package/dist/cjs/runtime/TimeRangeProvider/refresh-interval.js +0 -30
  518. package/dist/cjs/runtime/UsageMetricsProvider.js +0 -102
  519. package/dist/cjs/runtime/alerts-queries.js +0 -101
  520. package/dist/cjs/runtime/annotations.js +0 -148
  521. package/dist/cjs/runtime/builtin-variables.js +0 -81
  522. package/dist/cjs/runtime/datasources.js +0 -80
  523. package/dist/cjs/runtime/index.js +0 -45
  524. package/dist/cjs/runtime/item-actions.js +0 -302
  525. package/dist/cjs/runtime/json-queries.js +0 -70
  526. package/dist/cjs/runtime/log-queries.js +0 -76
  527. package/dist/cjs/runtime/plugin-registry.js +0 -135
  528. package/dist/cjs/runtime/profile-queries.js +0 -73
  529. package/dist/cjs/runtime/silences-queries.js +0 -101
  530. package/dist/cjs/runtime/time-series-queries.js +0 -165
  531. package/dist/cjs/runtime/trace-queries.js +0 -106
  532. package/dist/cjs/runtime/utils.js +0 -39
  533. package/dist/cjs/runtime/variables.js +0 -160
  534. package/dist/cjs/schema/index.js +0 -30
  535. package/dist/cjs/schema/panel.js +0 -56
  536. package/dist/cjs/test/index.js +0 -31
  537. package/dist/cjs/test/mock-data.js +0 -366
  538. package/dist/cjs/test/render-hook.js +0 -31
  539. package/dist/cjs/test/render.js +0 -31
  540. package/dist/cjs/test/setup-tests.js +0 -26
  541. package/dist/cjs/test/test-plugins/bert/index.js +0 -99
  542. package/dist/cjs/test/test-plugins/ernie/index.js +0 -149
  543. package/dist/cjs/test/test-plugins/index.js +0 -81
  544. package/dist/cjs/test/utils.js +0 -58
  545. package/dist/cjs/test-utils/index.js +0 -30
  546. package/dist/cjs/test-utils/mock-plugin-registry.js +0 -81
  547. package/dist/cjs/utils/csv-export.js +0 -248
  548. package/dist/cjs/utils/event.js +0 -30
  549. package/dist/cjs/utils/index.js +0 -32
  550. package/dist/cjs/utils/variables.js +0 -44
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n AbsoluteTimeRange,\n DurationString,\n TimeRangeValue,\n isRelativeTimeRange,\n toAbsoluteTimeRange,\n getSuggestedStepMs,\n} from '@perses-dev/spec';\nimport { useQueryClient } from '@tanstack/react-query';\nimport React, { createContext, ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react';\n\nimport { getRefreshIntervalInMs } from './refresh-interval';\nimport { useDisableAutoRefreshSetting } from './TimeRangeSettingsProvider';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n refreshInterval?: DurationString;\n setTimeRange: (value: TimeRangeValue) => void;\n setRefreshInterval: (value: DurationString) => void;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext(): TimeRange {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Gets the suggested step for a graph query in ms for the currently selected time range.\n */\nexport function useSuggestedStepMs(width?: number): number {\n const { absoluteTimeRange } = useTimeRange();\n if (width === undefined) return 0;\n return getSuggestedStepMs(absoluteTimeRange, width);\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps): ReactElement {\n const { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;\n const disableAutoRefresh = useDisableAutoRefreshSetting();\n\n const queryClient = useQueryClient();\n const [absoluteTimeRange, setAbsoluteTimeRange] = useState<AbsoluteTimeRange>(\n isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange,\n );\n\n const handleSetTimeRange = useCallback(\n (value: TimeRangeValue) => {\n setTimeRange(value);\n setAbsoluteTimeRange(isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value);\n },\n [setTimeRange],\n );\n\n // When auto-refresh is disabled by admin, leave URL/spec values untouched and no-op changes.\n const handleSetRefreshInterval = useCallback(\n (value: DurationString) => {\n if (disableAutoRefresh) {\n return;\n }\n setRefreshInterval(value);\n },\n [disableAutoRefresh, setRefreshInterval],\n );\n\n // Refresh is called when clicking on the refresh button, it refreshes all queries including variables\n const refresh = useCallback(() => {\n setAbsoluteTimeRange(isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange);\n queryClient\n .invalidateQueries({ queryKey: ['query'] })\n .finally(() => queryClient.removeQueries({ queryKey: ['query'], type: 'inactive' }));\n queryClient\n .invalidateQueries({ queryKey: ['variable'] })\n .finally(() => queryClient.removeQueries({ queryKey: ['variable'], type: 'inactive' }));\n }, [queryClient, timeRange]);\n\n // Auto refresh is only refreshing queries of panels\n const autoRefresh = useCallback(() => {\n setAbsoluteTimeRange(isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange);\n queryClient.invalidateQueries({ queryKey: ['query'] }).finally(() => {\n queryClient.removeQueries({ queryKey: ['query'], type: 'inactive' });\n queryClient.removeQueries({ queryKey: ['variable'], type: 'inactive' }); // Timerange is in queryKey, can lead to memory leak when using relative timerange\n });\n }, [queryClient, timeRange]);\n\n // Gate the timer only — do not rewrite refreshInterval / ?refresh= so re-enabling restores them.\n const refreshIntervalInMs = useMemo(\n () => (disableAutoRefresh ? 0 : getRefreshIntervalInMs(refreshInterval)),\n [disableAutoRefresh, refreshInterval],\n );\n useEffect(() => {\n if (refreshIntervalInMs > 0) {\n const interval = setInterval(() => {\n autoRefresh();\n }, refreshIntervalInMs);\n\n return (): void => clearInterval(interval);\n }\n }, [autoRefresh, refreshIntervalInMs]);\n\n const ctx = useMemo(() => {\n return {\n timeRange: timeRange,\n setTimeRange: handleSetTimeRange,\n absoluteTimeRange: absoluteTimeRange,\n refresh,\n refreshInterval: refreshInterval,\n refreshIntervalInMs: refreshIntervalInMs,\n setRefreshInterval: handleSetRefreshInterval,\n };\n }, [\n absoluteTimeRange,\n handleSetTimeRange,\n refresh,\n refreshInterval,\n refreshIntervalInMs,\n handleSetRefreshInterval,\n timeRange,\n ]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["isRelativeTimeRange","toAbsoluteTimeRange","getSuggestedStepMs","useQueryClient","React","createContext","useCallback","useContext","useEffect","useMemo","useState","getRefreshIntervalInMs","useDisableAutoRefreshSetting","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","useSuggestedStepMs","width","absoluteTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","disableAutoRefresh","queryClient","setAbsoluteTimeRange","handleSetTimeRange","value","handleSetRefreshInterval","refresh","invalidateQueries","queryKey","finally","removeQueries","type","autoRefresh","refreshIntervalInMs","interval","setInterval","clearInterval","Provider"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAIEA,mBAAmB,EACnBC,mBAAmB,EACnBC,kBAAkB,QACb,mBAAmB;AAC1B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,OAAOC,SAASC,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAElH,SAASC,sBAAsB,QAAQ,qBAAqB;AAC5D,SAASC,4BAA4B,QAAQ,8BAA8B;AAoB3E,OAAO,MAAMC,iCAAmBR,cAAqCS,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMT,WAAWM;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;CAEC,GACD,OAAO,SAASE;IACd,OAAOH;AACT;AAEA;;CAEC,GACD,OAAO,SAASI,mBAAmBC,KAAc;IAC/C,MAAM,EAAEC,iBAAiB,EAAE,GAAGH;IAC9B,IAAIE,UAAUN,WAAW,OAAO;IAChC,OAAOZ,mBAAmBmB,mBAAmBD;AAC/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Q;gBAAEG,MAAM;YAAW;YAClEV,YAAYS,aAAa,CAAC;gBAAEF,UAAU;oBAAC;iBAAW;gBAAEG,MAAM;YAAW,IAAI,kFAAkF;QAC7J;IACF,GAAG;QAACV;QAAaN;KAAU;IAE3B,iGAAiG;IACjG,MAAMkB,sBAAsBjC,QAC1B,IAAOoB,qBAAqB,IAAIlB,uBAAuBc,kBACvD;QAACI;QAAoBJ;KAAgB;IAEvCjB,UAAU;QACR,IAAIkC,sBAAsB,GAAG;YAC3B,MAAMC,WAAWC,YAAY;gBAC3BH;YACF,GAAGC;YAEH,OAAO,IAAYG,cAAcF;QACnC;IACF,GAAG;QAACF;QAAaC;KAAoB;IAErC,MAAM1B,MAAMP,QAAQ;QAClB,OAAO;YACLe,WAAWA;YACXG,cAAcK;YACdX,mBAAmBA;YACnBc;YACAV,iBAAiBA;YACjBiB,qBAAqBA;YACrBd,oBAAoBM;QACtB;IACF,GAAG;QACDb;QACAW;QACAG;QACAV;QACAiB;QACAR;QACAV;KACD;IAED,qBAAO,KAACX,iBAAiBiC,QAAQ;QAACb,OAAOjB;kBAAMU;;AACjD"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AbsoluteTimeRange, DurationString, TimeRangeValue } from '@perses-dev/spec';\nimport { isRelativeTimeRange, toAbsoluteTimeRange, getSuggestedStepMs } from '@perses-dev/spec';\nimport { useQueryClient } from '@tanstack/react-query';\nimport type { ReactElement } from 'react';\nimport React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';\n\nimport { getRefreshIntervalInMs } from './refresh-interval';\nimport { useDisableAutoRefreshSetting } from './TimeRangeSettingsProvider';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n refreshInterval?: DurationString;\n setTimeRange: (value: TimeRangeValue) => void;\n setRefreshInterval: (value: DurationString) => void;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext(): TimeRange {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Gets the suggested step for a graph query in ms for the currently selected time range.\n */\nexport function useSuggestedStepMs(width?: number): number {\n const { absoluteTimeRange } = useTimeRange();\n if (width === undefined) return 0;\n return getSuggestedStepMs(absoluteTimeRange, width);\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps): ReactElement {\n const { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;\n const disableAutoRefresh = useDisableAutoRefreshSetting();\n\n const queryClient = useQueryClient();\n const [absoluteTimeRange, setAbsoluteTimeRange] = useState<AbsoluteTimeRange>(\n isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange,\n );\n\n const handleSetTimeRange = useCallback(\n (value: TimeRangeValue) => {\n setTimeRange(value);\n setAbsoluteTimeRange(isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value);\n },\n [setTimeRange],\n );\n\n // When auto-refresh is disabled by admin, leave URL/spec values untouched and no-op changes.\n const handleSetRefreshInterval = useCallback(\n (value: DurationString) => {\n if (disableAutoRefresh) {\n return;\n }\n setRefreshInterval(value);\n },\n [disableAutoRefresh, setRefreshInterval],\n );\n\n // Refresh is called when clicking on the refresh button, it refreshes all queries including variables\n const refresh = useCallback(() => {\n setAbsoluteTimeRange(isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange);\n queryClient\n .invalidateQueries({ queryKey: ['query'] })\n .finally(() => queryClient.removeQueries({ queryKey: ['query'], type: 'inactive' }));\n queryClient\n .invalidateQueries({ queryKey: ['variable'] })\n .finally(() => queryClient.removeQueries({ queryKey: ['variable'], type: 'inactive' }));\n }, [queryClient, timeRange]);\n\n // Auto refresh is only refreshing queries of panels\n const autoRefresh = useCallback(() => {\n setAbsoluteTimeRange(isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange);\n queryClient.invalidateQueries({ queryKey: ['query'] }).finally(() => {\n queryClient.removeQueries({ queryKey: ['query'], type: 'inactive' });\n queryClient.removeQueries({ queryKey: ['variable'], type: 'inactive' }); // Timerange is in queryKey, can lead to memory leak when using relative timerange\n });\n }, [queryClient, timeRange]);\n\n // Gate the timer only — do not rewrite refreshInterval / ?refresh= so re-enabling restores them.\n const refreshIntervalInMs = useMemo(\n () => (disableAutoRefresh ? 0 : getRefreshIntervalInMs(refreshInterval)),\n [disableAutoRefresh, refreshInterval],\n );\n useEffect(() => {\n if (refreshIntervalInMs > 0) {\n const interval = setInterval(() => {\n autoRefresh();\n }, refreshIntervalInMs);\n\n return (): void => clearInterval(interval);\n }\n }, [autoRefresh, refreshIntervalInMs]);\n\n const ctx = useMemo(() => {\n return {\n timeRange: timeRange,\n setTimeRange: handleSetTimeRange,\n absoluteTimeRange: absoluteTimeRange,\n refresh,\n refreshInterval: refreshInterval,\n refreshIntervalInMs: refreshIntervalInMs,\n setRefreshInterval: handleSetRefreshInterval,\n };\n }, [\n absoluteTimeRange,\n handleSetTimeRange,\n refresh,\n refreshInterval,\n refreshIntervalInMs,\n handleSetRefreshInterval,\n timeRange,\n ]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["isRelativeTimeRange","toAbsoluteTimeRange","getSuggestedStepMs","useQueryClient","React","createContext","useCallback","useContext","useEffect","useMemo","useState","getRefreshIntervalInMs","useDisableAutoRefreshSetting","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","useSuggestedStepMs","width","absoluteTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","disableAutoRefresh","queryClient","setAbsoluteTimeRange","handleSetTimeRange","value","handleSetRefreshInterval","refresh","invalidateQueries","queryKey","finally","removeQueries","type","autoRefresh","refreshIntervalInMs","interval","setInterval","clearInterval","Provider"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,mBAAmB,EAAEC,mBAAmB,EAAEC,kBAAkB,QAAQ,mBAAmB;AAChG,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,OAAOC,SAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAEpG,SAASC,sBAAsB,QAAQ,wBAAqB;AAC5D,SAASC,4BAA4B,QAAQ,iCAA8B;AAoB3E,OAAO,MAAMC,iCAAmBR,cAAqCS,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMT,WAAWM;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;CAEC,GACD,OAAO,SAASE;IACd,OAAOH;AACT;AAEA;;CAEC,GACD,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aAAaA;QACvFM,YAAYM,iBAAiB,CAAC;YAAEC,UAAU;gBAAC;aAAQ;QAAC,GAAGC,OAAO,CAAC;YAC7DR,YAAYS,aAAa,CAAC;gBAAEF,UAAU;oBAAC;iBAAQ;gBAAEG,MAAM;YAAW;YAClEV,YAAYS,aAAa,CAAC;gBAAEF,UAAU;oBAAC;iBAAW;gBAAEG,MAAM;YAAW,IAAI,kFAAkF;QAC7J;IACF,GAAG;QAACV;QAAaN;KAAU;IAE3B,iGAAiG;IACjG,MAAMkB,sBAAsBjC,QAC1B,IAAOoB,qBAAqB,IAAIlB,uBAAuBc,kBACvD;QAACI;QAAoBJ;KAAgB;IAEvCjB,UAAU;QACR,IAAIkC,sBAAsB,GAAG;YAC3B,MAAMC,WAAWC,YAAY;gBAC3BH;YACF,GAAGC;YAEH,OAAO,IAAYG,cAAcF;QACnC;IACF,GAAG;QAACF;QAAaC;KAAoB;IAErC,MAAM1B,MAAMP,QAAQ;QAClB,OAAO;YACLe,WAAWA;YACXG,cAAcK;YACdX,mBAAmBA;YACnBc;YACAV,iBAAiBA;YACjBiB,qBAAqBA;YACrBd,oBAAoBM;QACtB;IACF,GAAG;QACDb;QACAW;QACAG;QACAV;QACAiB;QACAR;QACAV;KACD;IAED,qBAAO,KAACX,iBAAiBiC,QAAQ;QAACb,OAAOjB;kBAAMU;;AACjD"}
@@ -1,5 +1,6 @@
1
- import { DurationString, TimeRangeValue } from '@perses-dev/spec';
2
- import React, { ReactElement } from 'react';
1
+ import type { DurationString, TimeRangeValue } from '@perses-dev/spec';
2
+ import type { ReactElement } from 'react';
3
+ import React from 'react';
3
4
  export interface TimeRangeProvidersProps {
4
5
  initialTimeRange: TimeRangeValue;
5
6
  initialRefreshInterval?: DurationString;
@@ -1 +1 @@
1
- {"version":3,"file":"TimeRangeProviders.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK5C,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,cAAc,CAAC;IACjC,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gCAAgC,CAAC,EAC/C,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAexC;AAED,wBAAgB,sBAAsB,CAAC,EACrC,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAcxC"}
1
+ {"version":3,"file":"TimeRangeProviders.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,cAAc,CAAC;IACjC,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gCAAgC,CAAC,EAC/C,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAexC;AAED,wBAAgB,sBAAsB,CAAC,EACrC,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAcxC"}
@@ -11,10 +11,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { TimeZoneProvider } from '@perses-dev/components';
15
- import React from 'react';
16
- import { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from './query-params';
17
- import { TimeRangeProvider } from './TimeRangeProvider';
14
+ import { TimeZoneProvider } from "@perses-dev/components";
15
+ import React from "react";
16
+ import { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from "./query-params.js";
17
+ import { TimeRangeProvider } from "./TimeRangeProvider.js";
18
18
  export function TimeRangeProviderWithQueryParams({ initialTimeRange, initialRefreshInterval, children }) {
19
19
  const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);
20
20
  const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeZoneProvider } from '@perses-dev/components';\nimport { DurationString, TimeRangeValue } from '@perses-dev/spec';\nimport React, { ReactElement } from 'react';\n\nimport { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from './query-params';\nimport { TimeRangeProvider } from './TimeRangeProvider';\n\nexport interface TimeRangeProvidersProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n children?: React.ReactNode;\n}\n\nexport function TimeRangeProviderWithQueryParams({\n initialTimeRange,\n initialRefreshInterval,\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);\n const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);\n const { timeZone } = useTimeZoneParams('local');\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n <TimeZoneProvider timeZone={timeZone}>{children}</TimeZoneProvider>\n </TimeRangeProvider>\n );\n}\n\nexport function TimeRangeProviderBasic({\n initialTimeRange,\n initialRefreshInterval,\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const [timeRange, setTimeRange] = React.useState<TimeRangeValue>(initialTimeRange);\n const [refreshInterval, setRefreshInterval] = React.useState<DurationString | undefined>(initialRefreshInterval);\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n {children}\n </TimeRangeProvider>\n );\n}\n"],"names":["TimeZoneProvider","React","useSetRefreshIntervalParams","useTimeRangeParams","useTimeZoneParams","TimeRangeProvider","TimeRangeProviderWithQueryParams","initialTimeRange","initialRefreshInterval","children","timeRange","setTimeRange","refreshInterval","setRefreshInterval","timeZone","TimeRangeProviderBasic","useState"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,gBAAgB,QAAQ,yBAAyB;AAE1D,OAAOC,WAA6B,QAAQ;AAE5C,SAASC,2BAA2B,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,iBAAiB;AACpG,SAASC,iBAAiB,QAAQ,sBAAsB;AAQxD,OAAO,SAASC,iCAAiC,EAC/CC,gBAAgB,EAChBC,sBAAsB,EACtBC,QAAQ,EACgB;IACxB,MAAM,EAAEC,SAAS,EAAEC,YAAY,EAAE,GAAGR,mBAAmBI;IACvD,MAAM,EAAEK,eAAe,EAAEC,kBAAkB,EAAE,GAAGX,4BAA4BM;IAC5E,MAAM,EAAEM,QAAQ,EAAE,GAAGV,kBAAkB;IAEvC,qBACE,KAACC;QACCK,WAAWA;QACXE,iBAAiBA;QACjBD,cAAcA;QACdE,oBAAoBA;kBAEpB,cAAA,KAACb;YAAiBc,UAAUA;sBAAWL;;;AAG7C;AAEA,OAAO,SAASM,uBAAuB,EACrCR,gBAAgB,EAChBC,sBAAsB,EACtBC,QAAQ,EACgB;IACxB,MAAM,CAACC,WAAWC,aAAa,GAAGV,MAAMe,QAAQ,CAAiBT;IACjE,MAAM,CAACK,iBAAiBC,mBAAmB,GAAGZ,MAAMe,QAAQ,CAA6BR;IAEzF,qBACE,KAACH;QACCK,WAAWA;QACXE,iBAAiBA;QACjBD,cAAcA;QACdE,oBAAoBA;kBAEnBJ;;AAGP"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeZoneProvider } from '@perses-dev/components';\nimport type { DurationString, TimeRangeValue } from '@perses-dev/spec';\nimport type { ReactElement } from 'react';\nimport React from 'react';\n\nimport { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from './query-params';\nimport { TimeRangeProvider } from './TimeRangeProvider';\n\nexport interface TimeRangeProvidersProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n children?: React.ReactNode;\n}\n\nexport function TimeRangeProviderWithQueryParams({\n initialTimeRange,\n initialRefreshInterval,\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);\n const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);\n const { timeZone } = useTimeZoneParams('local');\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n <TimeZoneProvider timeZone={timeZone}>{children}</TimeZoneProvider>\n </TimeRangeProvider>\n );\n}\n\nexport function TimeRangeProviderBasic({\n initialTimeRange,\n initialRefreshInterval,\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const [timeRange, setTimeRange] = React.useState<TimeRangeValue>(initialTimeRange);\n const [refreshInterval, setRefreshInterval] = React.useState<DurationString | undefined>(initialRefreshInterval);\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n {children}\n </TimeRangeProvider>\n );\n}\n"],"names":["TimeZoneProvider","React","useSetRefreshIntervalParams","useTimeRangeParams","useTimeZoneParams","TimeRangeProvider","TimeRangeProviderWithQueryParams","initialTimeRange","initialRefreshInterval","children","timeRange","setTimeRange","refreshInterval","setRefreshInterval","timeZone","TimeRangeProviderBasic","useState"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,gBAAgB,QAAQ,yBAAyB;AAG1D,OAAOC,WAAW,QAAQ;AAE1B,SAASC,2BAA2B,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,oBAAiB;AACpG,SAASC,iBAAiB,QAAQ,yBAAsB;AAQxD,OAAO,SAASC,iCAAiC,EAC/CC,gBAAgB,EAChBC,sBAAsB,EACtBC,QAAQ,EACgB;IACxB,MAAM,EAAEC,SAAS,EAAEC,YAAY,EAAE,GAAGR,mBAAmBI;IACvD,MAAM,EAAEK,eAAe,EAAEC,kBAAkB,EAAE,GAAGX,4BAA4BM;IAC5E,MAAM,EAAEM,QAAQ,EAAE,GAAGV,kBAAkB;IAEvC,qBACE,KAACC;QACCK,WAAWA;QACXE,iBAAiBA;QACjBD,cAAcA;QACdE,oBAAoBA;kBAEpB,cAAA,KAACb;YAAiBc,UAAUA;sBAAWL;;;AAG7C;AAEA,OAAO,SAASM,uBAAuB,EACrCR,gBAAgB,EAChBC,sBAAsB,EACtBC,QAAQ,EACgB;IACxB,MAAM,CAACC,WAAWC,aAAa,GAAGV,MAAMe,QAAQ,CAAiBT;IACjE,MAAM,CAACK,iBAAiBC,mBAAmB,GAAGZ,MAAMe,QAAQ,CAA6BR;IAEzF,qBACE,KAACH;QACCK,WAAWA;QACXE,iBAAiBA;QACjBD,cAAcA;QACdE,oBAAoBA;kBAEnBJ;;AAGP"}
@@ -1,5 +1,5 @@
1
- import { TimeOption } from '@perses-dev/components';
2
- import { ReactElement, ReactNode } from 'react';
1
+ import type { TimeOption } from '@perses-dev/components';
2
+ import type { ReactElement, ReactNode } from 'react';
3
3
  export interface TimeRangeSettingsProviderProps {
4
4
  showCustom?: boolean;
5
5
  showZoomButtons?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"TimeRangeSettingsProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAA2B,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE7E,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAUpF,MAAM,WAAW,8BAA8B;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,UAAU,EAA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AC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,wBAAwB,4CAA6D,CAAC;AAEnG,wBAAgB,2BAA2B,IAAI,iBAAiB,CAM/D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAExD;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAMzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAMnE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAMhF;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAMxE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,8BAA8B,GAAG,YAAY,CAa7F"}
@@ -1,4 +1,3 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  // Copyright The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,8 +10,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- import { buildRelativeTimeOption } from '@perses-dev/components';
15
- import { createContext, useContext, useMemo } from 'react';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { buildRelativeTimeOption } from "@perses-dev/components";
15
+ import { createContext, useContext, useMemo } from "react";
16
16
  const DEFAULT_OPTIONS = [
17
17
  '5m',
18
18
  '15m',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { buildRelativeTimeOption, TimeOption } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/spec';\nimport { createContext, ReactElement, ReactNode, useContext, useMemo } from 'react';\n\nconst DEFAULT_OPTIONS: DurationString[] = ['5m', '15m', '30m', '1h', '6h', '12h', '24h', '7d', '14d'];\nconst defaultTimeRangeSettings: TimeRangeSettings = {\n showCustom: true,\n showZoomButtons: true,\n disableAutoRefresh: false,\n options: DEFAULT_OPTIONS.map((duration) => buildRelativeTimeOption(duration)),\n};\n\nexport interface TimeRangeSettingsProviderProps {\n showCustom?: boolean;\n showZoomButtons?: boolean;\n disableAutoRefresh?: boolean;\n options?: TimeOption[];\n children: ReactNode;\n}\n\nexport interface TimeRangeSettings {\n showCustom: boolean;\n showZoomButtons: boolean;\n disableAutoRefresh: boolean;\n options: TimeOption[];\n}\n\nexport const TimeRangeSettingsContext = createContext<TimeRangeSettings>(defaultTimeRangeSettings);\n\nexport function useTimeRangeSettingsContext(): TimeRangeSettings {\n const ctx = useContext(TimeRangeSettingsContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRangeSettings(): TimeRangeSettings {\n return useTimeRangeSettingsContext();\n}\n\n/**\n * Get the current value of the showCustom setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowCustomTimeRangeSetting(override?: boolean): boolean {\n const showCustomTimeRange = useTimeRangeSettings().showCustom;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Get the current value of the showZoomButtons setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowZoomRangeSetting(override?: boolean): boolean {\n const showZoomTimeRange = useTimeRangeSettings().showZoomButtons;\n if (override !== undefined) {\n return override;\n }\n return showZoomTimeRange;\n}\n\n/**\n * Get the current value of the options setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useTimeRangeOptionsSetting(override?: TimeOption[]): TimeOption[] {\n const showCustomTimeRange = useTimeRangeSettings().options;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Get the current value of the disableAutoRefresh setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useDisableAutoRefreshSetting(override?: boolean): boolean {\n const disableAutoRefresh = useTimeRangeSettings().disableAutoRefresh;\n if (override !== undefined) {\n return override;\n }\n return disableAutoRefresh;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeSettingsProvider(props: TimeRangeSettingsProviderProps): ReactElement {\n const ctx = useMemo(() => {\n return {\n showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,\n showZoomButtons:\n props.showZoomButtons === undefined ? defaultTimeRangeSettings.showZoomButtons : props.showZoomButtons,\n disableAutoRefresh:\n props.disableAutoRefresh === undefined ? defaultTimeRangeSettings.disableAutoRefresh : props.disableAutoRefresh,\n options: props.options === undefined ? defaultTimeRangeSettings.options : props.options,\n };\n }, [props.showCustom, props.showZoomButtons, props.disableAutoRefresh, props.options]);\n\n return <TimeRangeSettingsContext.Provider value={ctx}>{props.children}</TimeRangeSettingsContext.Provider>;\n}\n"],"names":["buildRelativeTimeOption","createContext","useContext","useMemo","DEFAULT_OPTIONS","defaultTimeRangeSettings","showCustom","showZoomButtons","disableAutoRefresh","options","map","duration","TimeRangeSettingsContext","useTimeRangeSettingsContext","ctx","undefined","Error","useTimeRangeSettings","useShowCustomTimeRangeSetting","override","showCustomTimeRange","useShowZoomRangeSetting","showZoomTimeRange","useTimeRangeOptionsSetting","useDisableAutoRefreshSetting","TimeRangeSettingsProvider","props","Provider","value","children"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,uBAAuB,QAAoB,yBAAyB;AAE7E,SAASC,aAAa,EAA2BC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEpF,MAAMC,kBAAoC;IAAC;IAAM;IAAO;IAAO;IAAM;IAAM;IAAO;IAAO;IAAM;CAAM;AACrG,MAAMC,2BAA8C;IAClDC,YAAY;IACZC,iBAAiB;IACjBC,oBAAoB;IACpBC,SAASL,gBAAgBM,GAAG,CAAC,CAACC,WAAaX,wBAAwBW;AACrE;AAiBA,OAAO,MAAMC,yCAA2BX,cAAiCI,0BAA0B;AAEnG,OAAO,SAASQ;IACd,MAAMC,MAAMZ,WAAWU;IACvB,IAAIE,QAAQC,WAAW;QACrB,MAAM,IAAIC,MAAM;IAClB;IACA,OAAOF;AACT;AAEA;;CAEC,GACD,OAAO,SAASG;IACd,OAAOJ;AACT;AAEA;;;CAGC,GACD,OAAO,SAASK,8BAA8BC,QAAkB;IAC9D,MAAMC,sBAAsBH,uBAAuBX,UAAU;IAC7D,IAAIa,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AAEA;;;CAGC,GACD,OAAO,SAASC,wBAAwBF,QAAkB;IACxD,MAAMG,oBAAoBL,uBAAuBV,eAAe;IAChE,IAAIY,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOG;AACT;AAEA;;;CAGC,GACD,OAAO,SAASC,2BAA2BJ,QAAuB;IAChE,MAAMC,sBAAsBH,uBAAuBR,OAAO;IAC1D,IAAIU,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AAEA;;;CAGC,GACD,OAAO,SAASI,6BAA6BL,QAAkB;IAC7D,MAAMX,qBAAqBS,uBAAuBT,kBAAkB;IACpE,IAAIW,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOX;AACT;AAEA;;CAEC,GACD,OAAO,SAASiB,0BAA0BC,KAAqC;IAC7E,MAAMZ,MAAMX,QAAQ;QAClB,OAAO;YACLG,YAAYoB,MAAMpB,UAAU,KAAKS,YAAYV,yBAAyBC,UAAU,GAAGoB,MAAMpB,UAAU;YACnGC,iBACEmB,MAAMnB,eAAe,KAAKQ,YAAYV,yBAAyBE,eAAe,GAAGmB,MAAMnB,eAAe;YACxGC,oBACEkB,MAAMlB,kBAAkB,KAAKO,YAAYV,yBAAyBG,kBAAkB,GAAGkB,MAAMlB,kBAAkB;YACjHC,SAASiB,MAAMjB,OAAO,KAAKM,YAAYV,yBAAyBI,OAAO,GAAGiB,MAAMjB,OAAO;QACzF;IACF,GAAG;QAACiB,MAAMpB,UAAU;QAAEoB,MAAMnB,eAAe;QAAEmB,MAAMlB,kBAAkB;QAAEkB,MAAMjB,OAAO;KAAC;IAErF,qBAAO,KAACG,yBAAyBe,QAAQ;QAACC,OAAOd;kBAAMY,MAAMG,QAAQ;;AACvE"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { TimeOption } from '@perses-dev/components';\nimport { buildRelativeTimeOption } from '@perses-dev/components';\nimport type { DurationString } from '@perses-dev/spec';\nimport type { ReactElement, ReactNode } from 'react';\nimport { createContext, useContext, useMemo } from 'react';\n\nconst DEFAULT_OPTIONS: DurationString[] = ['5m', '15m', '30m', '1h', '6h', '12h', '24h', '7d', '14d'];\nconst defaultTimeRangeSettings: TimeRangeSettings = {\n showCustom: true,\n showZoomButtons: true,\n disableAutoRefresh: false,\n options: DEFAULT_OPTIONS.map((duration) => buildRelativeTimeOption(duration)),\n};\n\nexport interface TimeRangeSettingsProviderProps {\n showCustom?: boolean;\n showZoomButtons?: boolean;\n disableAutoRefresh?: boolean;\n options?: TimeOption[];\n children: ReactNode;\n}\n\nexport interface TimeRangeSettings {\n showCustom: boolean;\n showZoomButtons: boolean;\n disableAutoRefresh: boolean;\n options: TimeOption[];\n}\n\nexport const TimeRangeSettingsContext = createContext<TimeRangeSettings>(defaultTimeRangeSettings);\n\nexport function useTimeRangeSettingsContext(): TimeRangeSettings {\n const ctx = useContext(TimeRangeSettingsContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRangeSettings(): TimeRangeSettings {\n return useTimeRangeSettingsContext();\n}\n\n/**\n * Get the current value of the showCustom setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowCustomTimeRangeSetting(override?: boolean): boolean {\n const showCustomTimeRange = useTimeRangeSettings().showCustom;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Get the current value of the showZoomButtons setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowZoomRangeSetting(override?: boolean): boolean {\n const showZoomTimeRange = useTimeRangeSettings().showZoomButtons;\n if (override !== undefined) {\n return override;\n }\n return showZoomTimeRange;\n}\n\n/**\n * Get the current value of the options setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useTimeRangeOptionsSetting(override?: TimeOption[]): TimeOption[] {\n const showCustomTimeRange = useTimeRangeSettings().options;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Get the current value of the disableAutoRefresh setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useDisableAutoRefreshSetting(override?: boolean): boolean {\n const disableAutoRefresh = useTimeRangeSettings().disableAutoRefresh;\n if (override !== undefined) {\n return override;\n }\n return disableAutoRefresh;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeSettingsProvider(props: TimeRangeSettingsProviderProps): ReactElement {\n const ctx = useMemo(() => {\n return {\n showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,\n showZoomButtons:\n props.showZoomButtons === undefined ? defaultTimeRangeSettings.showZoomButtons : props.showZoomButtons,\n disableAutoRefresh:\n props.disableAutoRefresh === undefined ? defaultTimeRangeSettings.disableAutoRefresh : props.disableAutoRefresh,\n options: props.options === undefined ? defaultTimeRangeSettings.options : props.options,\n };\n }, [props.showCustom, props.showZoomButtons, props.disableAutoRefresh, props.options]);\n\n return <TimeRangeSettingsContext.Provider value={ctx}>{props.children}</TimeRangeSettingsContext.Provider>;\n}\n"],"names":["buildRelativeTimeOption","createContext","useContext","useMemo","DEFAULT_OPTIONS","defaultTimeRangeSettings","showCustom","showZoomButtons","disableAutoRefresh","options","map","duration","TimeRangeSettingsContext","useTimeRangeSettingsContext","ctx","undefined","Error","useTimeRangeSettings","useShowCustomTimeRangeSetting","override","showCustomTimeRange","useShowZoomRangeSetting","showZoomTimeRange","useTimeRangeOptionsSetting","useDisableAutoRefreshSetting","TimeRangeSettingsProvider","props","Provider","value","children"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE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,MAAMZ,MAAMX,QAAQ;QAClB,OAAO;YACLG,YAAYoB,MAAMpB,UAAU,KAAKS,YAAYV,yBAAyBC,UAAU,GAAGoB,MAAMpB,UAAU;YACnGC,iBACEmB,MAAMnB,eAAe,KAAKQ,YAAYV,yBAAyBE,eAAe,GAAGmB,MAAMnB,eAAe;YACxGC,oBACEkB,MAAMlB,kBAAkB,KAAKO,YAAYV,yBAAyBG,kBAAkB,GAAGkB,MAAMlB,kBAAkB;YACjHC,SAASiB,MAAMjB,OAAO,KAAKM,YAAYV,yBAAyBI,OAAO,GAAGiB,MAAMjB,OAAO;QACzF;IACF,GAAG;QAACiB,MAAMpB,UAAU;QAAEoB,MAAMnB,eAAe;QAAEmB,MAAMlB,kBAAkB;QAAEkB,MAAMjB,OAAO;KAAC;IAErF,qBAAO,KAACG,yBAAyBe,QAAQ;QAACC,OAAOd;kBAAMY,MAAMG,QAAQ;;AACvE"}
@@ -10,9 +10,9 @@
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
- export * from './TimeRangeProvider';
14
- export * from './TimeRangeProviders';
15
- export * from './TimeRangeSettingsProvider';
16
- export * from './query-params';
13
+ export * from "./TimeRangeProvider.js";
14
+ export * from "./TimeRangeProviders.js";
15
+ export * from "./TimeRangeSettingsProvider.js";
16
+ export * from "./query-params.js";
17
17
 
18
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TimeRangeProvider';\nexport * from './TimeRangeProviders';\nexport * from './TimeRangeSettingsProvider';\nexport * from './query-params';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB;AACpC,cAAc,uBAAuB;AACrC,cAAc,8BAA8B;AAC5C,cAAc,iBAAiB"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TimeRangeProvider';\nexport * from './TimeRangeProviders';\nexport * from './TimeRangeSettingsProvider';\nexport * from './query-params';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,yBAAsB;AACpC,cAAc,0BAAuB;AACrC,cAAc,iCAA8B;AAC5C,cAAc,oBAAiB"}
@@ -1,6 +1,6 @@
1
- import { TimeRangeValue, DurationString } from '@perses-dev/spec';
2
- import { QueryParamConfig } from 'use-query-params';
3
- import { TimeRange } from './TimeRangeProvider';
1
+ import type { TimeRangeValue, DurationString } from '@perses-dev/spec';
2
+ import type { QueryParamConfig } from 'use-query-params';
3
+ import type { TimeRange } from './TimeRangeProvider';
4
4
  export type TimeOptionValue = Date | DurationString | null | undefined;
5
5
  export declare function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined;
6
6
  export declare function decodeTimeRangeValue(input: string | Array<string | null> | null | undefined): Date | DurationString | null | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/query-params.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAGd,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,gBAAgB,EAA+B,MAAM,kBAAkB,CAAC;AAEjF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AAwBvE,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAWhG;AAGD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAI1C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAQ7E,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;CAEtC,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAE/B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAiBrF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,cAAc,CAAC,CA6BlH;AAED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AACH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAiBrF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,cAAc,CAAC,CA6BlH;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAc3F;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,sBAAsB,CAAC,EAAE,cAAc,GACtC,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,oBAAoB,CAAC,CAyB3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAcnH"}
@@ -10,10 +10,10 @@
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
- import { isRelativeTimeRange, isDurationString } from '@perses-dev/spec';
14
- import { getUnixTime, isDate } from 'date-fns';
15
- import { useMemo, useCallback, useEffect, useState } from 'react';
16
- import { useQueryParams, StringParam } from 'use-query-params';
13
+ import { isRelativeTimeRange, isDurationString } from "@perses-dev/spec";
14
+ import { getUnixTime, isDate } from "date-fns";
15
+ import { useMemo, useCallback, useEffect, useState } from "react";
16
+ import { useQueryParams, StringParam } from "use-query-params";
17
17
  /* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
18
18
  // '' or []
19
19
  if (!input || input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n} from '@perses-dev/spec';\nimport { getUnixTime, isDate } from 'date-fns';\nimport { useMemo, useCallback, useEffect, useState } from 'react';\nimport { QueryParamConfig, useQueryParams, StringParam } from 'use-query-params';\n\nimport { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean,\n): string | null | undefined {\n // '' or []\n if (!input || (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== '')))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str === null || str === undefined) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined,\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (!paramString) return null;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (!valueA || !valueB) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\nexport const timeZoneQueryConfig = {\n tz: StringParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, taking the URL query params.\n */\nexport function useTimeRangeParams(initialTimeRange: TimeRangeValue): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (!paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery],\n );\n\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\n/**\n * Returns refresh interval getter and setter, taking the URL query params.\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (!paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery],\n );\n\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n };\n}\n\n/**\n * Returns timezone getter and setter, taking the URL query params.\n * Defaults to 'local' when not set.\n */\nexport function useTimeZoneParams(initialTimeZone?: string): { timeZone: string; setTimeZone: (tz: string) => void } {\n const [query, setQuery] = useQueryParams(timeZoneQueryConfig, { updateType: 'replaceIn' });\n const { tz } = query;\n\n const timeZone = (tz as string | undefined) ?? initialTimeZone ?? 'local';\n\n const setTimeZone = useCallback(\n (newTz: string) => {\n setQuery({ tz: newTz });\n },\n [setQuery],\n );\n\n return { timeZone, setTimeZone };\n}\n"],"names":["isRelativeTimeRange","isDurationString","getUnixTime","isDate","useMemo","useCallback","useEffect","useState","useQueryParams","StringParam","getEncodedValue","input","allowEmptyString","length","str","Array","undefined","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","timeZoneQueryConfig","tz","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useTimeRangeParams","setQuery","paramsLoaded","setParamsLoaded","setTimeRange","value","timeRange","useInitialRefreshInterval","useSetRefreshIntervalParams","initialRefreshInterval","setRefreshInterval","refreshInterval","useTimeZoneParams","initialTimeZone","timeZone","setTimeZone","newTz"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAEEA,mBAAmB,EACnBC,gBAAgB,QAGX,mBAAmB;AAC1B,SAASC,WAAW,EAAEC,MAAM,QAAQ,WAAW;AAC/C,SAASC,OAAO,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAClE,SAA2BC,cAAc,EAAEC,WAAW,QAAQ,mBAAmB;AAMjF,iGAAiG,GACjG,SAASC,gBACPC,KAAuD,EACvDC,gBAA0B;IAE1B,WAAW;IACX,IAAI,CAACD,SAAUA,MAAME,MAAM,KAAK,KAAM,CAAA,CAACD,oBAAqBA,oBAAoBD,UAAU,EAAE,GAAK;QAC/F,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M,EAAEN,OAAO,EAAE,GAAGK;IACpB,OAAOpC,QAAQ;QACb,IAAIsC,mBAAmCH;QACvC,IAAI,CAACJ,SAAS;YACZ,OAAOO;QACT;QACA,MAAME,WAAWT,QAAQhB,QAAQ;QACjC,IAAIlB,iBAAiB2C,WAAW;YAC9BF,mBAAmBE;QACrB;QACA,OAAOF;IACT,GAAG;QAACH;QAAmBJ;KAAQ;AACjC;AAEA;;CAEC,GACD,OAAO,SAASkB,4BACdC,sBAAuC;IAEvC,MAAM,CAACd,OAAOM,SAAS,GAAGtC,eAAe0B,4BAA4B;QAAEO,YAAY;IAAY;IAE/F,gFAAgF;IAChF,MAAM,CAACM,cAAcC,gBAAgB,GAAGzC,SAAkB;IAE1D,MAAM,EAAE4B,OAAO,EAAE,GAAGK;IAEpBlC,UAAU;QACR,8EAA8E;QAC9E,IAAI,CAACyC,gBAAgB,CAACZ,SAAS;YAC7BW,SAAS;gBAAEX,SAASmB;YAAuB;YAC3CN,gBAAgB;QAClB;IACF,GAAG;QAACM;QAAwBP;QAAcZ;QAASW;KAAS;IAE5D,MAAMS,qBAAsDlD,YAC1D,CAAC8B,UAA4BW,SAAS;YAAEX;QAAQ,IAChD;QAACW;KAAS;IAGZ,OAAO;QACLU,iBAAiBF;QACjBC,oBAAoBA;IACtB;AACF;AAEA;;;CAGC,GACD,OAAO,SAASE,kBAAkBC,eAAwB;IACxD,MAAM,CAAClB,OAAOM,SAAS,GAAGtC,eAAe4B,qBAAqB;QAAEK,YAAY;IAAY;IACxF,MAAM,EAAEJ,EAAE,EAAE,GAAGG;IAEf,MAAMmB,WAAW,AAACtB,MAA6BqB,mBAAmB;IAElE,MAAME,cAAcvD,YAClB,CAACwD;QACCf,SAAS;YAAET,IAAIwB;QAAM;IACvB,GACA;QAACf;KAAS;IAGZ,OAAO;QAAEa;QAAUC;IAAY;AACjC"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { TimeRangeValue, DurationString, AbsoluteTimeRange } from '@perses-dev/spec';\nimport { isRelativeTimeRange, isDurationString } from '@perses-dev/spec';\nimport { getUnixTime, isDate } from 'date-fns';\nimport { useMemo, useCallback, useEffect, useState } from 'react';\nimport type { QueryParamConfig } from 'use-query-params';\nimport { useQueryParams, StringParam } from 'use-query-params';\n\nimport type { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean,\n): string | null | undefined {\n // '' or []\n if (!input || (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== '')))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str === null || str === undefined) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined,\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (!paramString) return null;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (!valueA || !valueB) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\nexport const timeZoneQueryConfig = {\n tz: StringParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, taking the URL query params.\n */\nexport function useTimeRangeParams(initialTimeRange: TimeRangeValue): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (!paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery],\n );\n\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\n/**\n * Returns refresh interval getter and setter, taking the URL query params.\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (!paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery],\n );\n\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n };\n}\n\n/**\n * Returns timezone getter and setter, taking the URL query params.\n * Defaults to 'local' when not set.\n */\nexport function useTimeZoneParams(initialTimeZone?: string): { timeZone: string; setTimeZone: (tz: string) => void } {\n const [query, setQuery] = useQueryParams(timeZoneQueryConfig, { updateType: 'replaceIn' });\n const { tz } = query;\n\n const timeZone = (tz as string | undefined) ?? initialTimeZone ?? 'local';\n\n const setTimeZone = useCallback(\n (newTz: string) => {\n setQuery({ tz: newTz });\n },\n [setQuery],\n );\n\n return { timeZone, setTimeZone };\n}\n"],"names":["isRelativeTimeRange","isDurationString","getUnixTime","isDate","useMemo","useCallback","useEffect","useState","useQueryParams","StringParam","getEncodedValue","input","allowEmptyString","length","str","Array","undefined","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","timeZoneQueryConfig","tz","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useTimeRangeParams","setQuery","paramsLoaded","setParamsLoaded","setTimeRange","value","timeRange","useInitialRefreshInterval","useSetRefreshIntervalParams","initialRefreshInterval","setRefreshInterval","refreshInterval","useTimeZoneParams","initialTimeZone","timeZone","setTimeZone","newTz"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,mBAAmB,EAAEC,gBAAgB,QAAQ,mBAAmB;AACzE,SAASC,WAAW,EAAEC,MAAM,QAAQ,WAAW;AAC/C,SAASC,OAAO,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAElE,SAASC,cAAc,EAAEC,WAAW,QAAQ,mBAAmB;AAM/D,iGAAiG,GACjG,SAASC,gBACPC,KAAuD,EACvDC,gBAA0B;IAE1B,WAAW;IACX,IAAI,CAACD,SAAUA,MAAME,MAAM,KAAK,KAAM,CAAA,C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'@perses-dev/spec';
1
+ import type { DurationString } from '@perses-dev/spec';
2
2
  /**
3
3
  * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.
4
4
  * @param refreshInterval
@@ -1 +1 @@
1
- {"version":3,"file":"refresh-interval.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/refresh-interval.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAGvE;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,CAAC,EAAE,cAAc,GAAG,MAAM,CAK/E"}
1
+ {"version":3,"file":"refresh-interval.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/refresh-interval.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,CAAC,EAAE,cAAc,GAAG,MAAM,CAK/E"}
@@ -10,8 +10,8 @@
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
- import { parseDurationString } from '@perses-dev/spec';
14
- import { milliseconds } from 'date-fns';
13
+ import { parseDurationString } from "@perses-dev/spec";
14
+ import { milliseconds } from "date-fns";
15
15
  /**
16
16
  * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.
17
17
  * @param refreshInterval
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/refresh-interval.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString, parseDurationString } from '@perses-dev/spec';\nimport { milliseconds } from 'date-fns';\n\n/**\n * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.\n * @param refreshInterval\n */\nexport function getRefreshIntervalInMs(refreshInterval?: DurationString): number {\n if (refreshInterval !== undefined && refreshInterval !== null) {\n return milliseconds(parseDurationString(refreshInterval));\n }\n return 0;\n}\n"],"names":["parseDurationString","milliseconds","getRefreshIntervalInMs","refreshInterval","undefined"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAyBA,mBAAmB,QAAQ,mBAAmB;AACvE,SAASC,YAAY,QAAQ,WAAW;AAExC;;;CAGC,GACD,OAAO,SAASC,uBAAuBC,eAAgC;IACrE,IAAIA,oBAAoBC,aAAaD,oBAAoB,MAAM;QAC7D,OAAOF,aAAaD,oBAAoBG;IAC1C;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/refresh-interval.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { DurationString } from '@perses-dev/spec';\nimport { parseDurationString } from '@perses-dev/spec';\nimport { milliseconds } from 'date-fns';\n\n/**\n * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.\n * @param refreshInterval\n */\nexport function getRefreshIntervalInMs(refreshInterval?: DurationString): number {\n if (refreshInterval !== undefined && refreshInterval !== null) {\n return milliseconds(parseDurationString(refreshInterval));\n }\n return 0;\n}\n"],"names":["parseDurationString","milliseconds","getRefreshIntervalInMs","refreshInterval","undefined"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,mBAAmB,QAAQ,mBAAmB;AACvD,SAASC,YAAY,QAAQ,WAAW;AAExC;;;CAGC,GACD,OAAO,SAASC,uBAAuBC,eAAgC;IACrE,IAAIA,oBAAoBC,aAAaD,oBAAoB,MAAM;QAC7D,OAAOF,aAAaD,oBAAoBG;IAC1C;IACA,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
- import { FetchFn } from '@perses-dev/client';
2
- import { QueryDefinition } from '@perses-dev/spec';
3
- import { ReactElement, ReactNode } from 'react';
1
+ import type { FetchFn } from '@perses-dev/client';
2
+ import type { QueryDefinition } from '@perses-dev/spec';
3
+ import type { ReactElement, ReactNode } from 'react';
4
4
  type QueryState = 'pending' | 'success' | 'error';
5
5
  interface UsageMetrics {
6
6
  project: string;
@@ -1 +1 @@
1
- {"version":3,"file":"UsageMetricsProvider.d.ts","sourceRoot":"","sources":["../../src/runtime/UsageMetricsProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAY,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAE3E,KAAK,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAElD,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAA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IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,UAAU,sBAAsB;IAC9B,SAAS,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CACrE;AAED,eAAO,MAAM,mBAAmB,mDAAqD,CAAC;AAEtF,eAAO,MAAM,sBAAsB,QAAO,YAAY,GAAG,SAExD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,sBA6BlC,CAAC;AAiBF,eAAO,MAAM,oBAAoB,GAAI,6CAA6C,iBAAiB,KAAG,YAerG,CAAC"}
@@ -1,4 +1,3 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  // Copyright The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,8 +10,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- import { useFetch } from '@perses-dev/client';
15
- import { createContext, useContext } from 'react';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { useFetch } from "@perses-dev/client";
15
+ import { createContext, useContext } from "react";
16
16
  export const UsageMetricsContext = /*#__PURE__*/ createContext(undefined);
17
17
  export const useUsageMetricsContext = ()=>{
18
18
  return useContext(UsageMetricsContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/UsageMetricsProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FetchFn, useFetch } from '@perses-dev/client';\nimport { QueryDefinition } from '@perses-dev/spec';\nimport { createContext, ReactElement, ReactNode, useContext } from 'react';\n\ntype QueryState = 'pending' | 'success' | 'error';\n\ninterface UsageMetrics {\n project: string;\n dashboard: string;\n startRenderTime: number;\n renderDurationMs: number;\n renderErrorCount: number;\n pendingQueries: Map<string, QueryState>;\n apiPrefix?: string;\n fetchFn: FetchFn;\n}\n\ninterface UsageMetricsProps {\n project: string;\n dashboard: string;\n apiPrefix?: string;\n children: ReactNode;\n}\n\ninterface UseUsageMetricsResults {\n markQuery: (definition: QueryDefinition, state: QueryState) => void;\n}\n\nexport const UsageMetricsContext = createContext<UsageMetrics | undefined>(undefined);\n\nexport const useUsageMetricsContext = (): UsageMetrics | undefined => {\n return useContext(UsageMetricsContext);\n};\n\nexport const useUsageMetrics = (): UseUsageMetricsResults => {\n const ctx = useUsageMetricsContext();\n\n return {\n markQuery: (definition: QueryDefinition, newState: QueryState): void => {\n if (ctx === undefined) {\n return;\n }\n\n const definitionKey = JSON.stringify(definition);\n if (ctx.pendingQueries.has(definitionKey) && newState === 'pending') {\n // Never allow transitions back to pending, to avoid re-sending stats on a re-render.\n return;\n }\n\n if (ctx.pendingQueries.get(definitionKey) !== newState) {\n ctx.pendingQueries.set(definitionKey, newState);\n if (newState === 'error') {\n ctx.renderErrorCount += 1;\n }\n\n const allDone = [...ctx.pendingQueries.values()].every((p) => p !== 'pending');\n if (ctx.renderDurationMs === 0 && allDone) {\n ctx.renderDurationMs = Date.now() - ctx.startRenderTime;\n submitMetrics(ctx);\n }\n }\n },\n };\n};\n\nconst submitMetrics = async (stats: UsageMetrics): Promise<void> => {\n await stats.fetchFn(`${stats.apiPrefix ?? ''}/api/v1/view`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n project: stats.project,\n dashboard: stats.dashboard,\n render_time: stats.renderDurationMs / 1000,\n render_errors: stats.renderErrorCount,\n }),\n });\n};\n\nexport const UsageMetricsProvider = ({ apiPrefix, project, dashboard, children }: UsageMetricsProps): ReactElement => {\n const { fetch } = useFetch();\n\n const ctx: UsageMetrics = {\n project: project,\n dashboard: dashboard,\n renderErrorCount: 0,\n startRenderTime: Date.now(),\n renderDurationMs: 0,\n pendingQueries: new Map(),\n apiPrefix,\n fetchFn: fetch,\n };\n\n return <UsageMetricsContext.Provider value={ctx}>{children}</UsageMetricsContext.Provider>;\n};\n"],"names":["useFetch","createContext","useContext","UsageMetricsContext","undefined","useUsageMetricsContext","useUsageMetrics","ctx","markQuery","definition","newState","definitionKey","JSON","stringify","pendingQueries","has","get","set","renderErrorCount","allDone","values","every","p","renderDurationMs","Date","now","startRenderTime","submitMetrics","stats","fetchFn","apiPrefix","method","headers","body","project","dashboard","render_time","render_errors","UsageMetricsProvider","children","fetch","Map","Provider","value"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAkBA,QAAQ,QAAQ,qBAAqB;AAEvD,SAASC,aAAa,EAA2BC,UAAU,QAAQ,QAAQ;AA0B3E,OAAO,MAAMC,oCAAsBF,cAAwCG,WAAW;AAEtF,OAAO,MAAMC,yBAAyB;IACpC,OAAOH,WAAWC;AACpB,EAAE;AAEF,OAAO,MAAMG,kBAAkB;IAC7B,MAAMC,MAAMF;IAEZ,OAAO;QACLG,WAAW,CAACC,YAA6BC;YACvC,IAAIH,QAAQH,WAAW;gBACrB;YACF;YAEA,MAAMO,gBAAgBC,KAAKC,SAAS,CAAC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D,EAAE"}
1
+ {"version":3,"sources":["../../src/runtime/UsageMetricsProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { FetchFn } from '@perses-dev/client';\nimport { useFetch } from '@perses-dev/client';\nimport type { QueryDefinition } from '@perses-dev/spec';\nimport type { ReactElement, ReactNode } from 'react';\nimport { createContext, useContext } from 'react';\n\ntype QueryState = 'pending' | 'success' | 'error';\n\ninterface UsageMetrics {\n project: string;\n dashboard: string;\n startRenderTime: number;\n renderDurationMs: number;\n renderErrorCount: number;\n pendingQueries: Map<string, QueryState>;\n apiPrefix?: string;\n fetchFn: FetchFn;\n}\n\ninterface UsageMetricsProps {\n project: string;\n dashboard: string;\n apiPrefix?: string;\n children: ReactNode;\n}\n\ninterface UseUsageMetricsResults {\n markQuery: (definition: QueryDefinition, state: QueryState) => void;\n}\n\nexport const UsageMetricsContext = createContext<UsageMetrics | undefined>(undefined);\n\nexport const useUsageMetricsContext = (): UsageMetrics | undefined => {\n return useContext(UsageMetricsContext);\n};\n\nexport const useUsageMetrics = (): UseUsageMetricsResults => {\n const ctx = useUsageMetricsContext();\n\n return {\n markQuery: (definition: QueryDefinition, newState: QueryState): void => {\n if (ctx === undefined) {\n return;\n }\n\n const definitionKey = JSON.stringify(definition);\n if (ctx.pendingQueries.has(definitionKey) && newState === 'pending') {\n // Never allow transitions back to pending, to avoid re-sending stats on a re-render.\n return;\n }\n\n if (ctx.pendingQueries.get(definitionKey) !== newState) {\n ctx.pendingQueries.set(definitionKey, newState);\n if (newState === 'error') {\n ctx.renderErrorCount += 1;\n }\n\n const allDone = [...ctx.pendingQueries.values()].every((p) => p !== 'pending');\n if (ctx.renderDurationMs === 0 && allDone) {\n ctx.renderDurationMs = Date.now() - ctx.startRenderTime;\n submitMetrics(ctx);\n }\n }\n },\n };\n};\n\nconst submitMetrics = async (stats: UsageMetrics): Promise<void> => {\n await stats.fetchFn(`${stats.apiPrefix ?? ''}/api/v1/view`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n project: stats.project,\n dashboard: stats.dashboard,\n render_time: stats.renderDurationMs / 1000,\n render_errors: stats.renderErrorCount,\n }),\n });\n};\n\nexport const UsageMetricsProvider = ({ apiPrefix, project, dashboard, children }: UsageMetricsProps): ReactElement => {\n const { fetch } = useFetch();\n\n const ctx: UsageMetrics = {\n project: project,\n dashboard: dashboard,\n renderErrorCount: 0,\n startRenderTime: Date.now(),\n renderDurationMs: 0,\n pendingQueries: new Map(),\n apiPrefix,\n fetchFn: fetch,\n };\n\n return <UsageMetricsContext.Provider value={ctx}>{children}</UsageMetricsContext.Provider>;\n};\n"],"names":["useFetch","createContext","useContext","UsageMetricsContext","undefined","useUsageMetricsContext","useUsageMetrics","ctx","markQuery","definition","newState","definitionKey","JSON","stringify","pendingQueries","has","get","set","renderErrorCount","allDone","values","every","p","renderDurationMs","Date","now","startRenderTime","submitMetrics","stats","fetchFn","apiPrefix","method","headers","body","project","dashboard","render_time","render_errors","UsageMetricsProvider","children","fetch","Map","Provider","value"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,QAAQ,QAAQ,qBAAqB;AAG9C,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AA0BlD,OAAO,MAAMC,oCAAsBF,cAAwCG,WAAW;AAEtF,OAAO,MAAMC,yBAAyB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2B,SAASA;QACTC,WAAWA;QACXjB,kBAAkB;QAClBQ,iBAAiBF,KAAKC,GAAG;QACzBF,kBAAkB;QAClBT,gBAAgB,IAAI2B;QACpBX;QACAD,SAASW;IACX;IAEA,qBAAO,KAACrC,oBAAoBuC,QAAQ;QAACC,OAAOpC;kBAAMgC;;AACpD,EAAE"}
@@ -1,5 +1,5 @@
1
- import { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';
2
- import { UseQueryResult } from '@tanstack/react-query';
1
+ import type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';
2
+ import type { UseQueryResult } from '@tanstack/react-query';
3
3
  export type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;
4
4
  export declare const ALERTS_QUERY_KEY = "AlertsQuery";
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"alerts-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/alerts-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAwB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQ7E,MAAM,MAAM,qBAAqB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AACzG,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CA6BxG"}
1
+ {"version":3,"file":"alerts-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/alerts-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,qBAAqB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AACzG,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CA6BxG"}
@@ -10,11 +10,11 @@
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
- import { useQueries } from '@tanstack/react-query';
14
- import { useDatasourceStore } from './datasources';
15
- import { usePluginRegistry, usePlugins } from './plugin-registry';
16
- import { filterVariableStateMap, getVariableValuesKey } from './utils';
17
- import { useAllVariableValues } from './variables';
13
+ import { useQueries } from "@tanstack/react-query";
14
+ import { useDatasourceStore } from "./datasources.js";
15
+ import { usePluginRegistry, usePlugins } from "./plugin-registry.js";
16
+ import { filterVariableStateMap, getVariableValuesKey } from "./utils.js";
17
+ import { useAllVariableValues } from "./variables.js";
18
18
  export const ALERTS_QUERY_KEY = 'AlertsQuery';
19
19
  /**
20
20
  * Run an alerts query using an AlertsQuery plugin and return the results.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/alerts-queries.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport { QueryKey, useQueries, UseQueryResult } from '@tanstack/react-query';\n\nimport { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({ kind: d.spec.plugin.kind })),\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const alertsQueryKind = definition?.spec?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: 60_000,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AlertsData> => {\n const plugin = await getPlugin({ kind: ALERTS_QUERY_KEY, name: alertsQueryKind });\n const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AlertsQueryPlugin;\n definition: AlertsQueryDefinition;\n context: AlertsQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n // Note: no absoluteTimeRange in query key since alerts are current state\n const queryKey = ['query', ALERTS_QUERY_KEY, definition, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nfunction useAlertsQueryContext(): AlertsQueryContext {\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ALERTS_QUERY_KEY","useAlertsQueries","definitions","getPlugin","context","useAlertsQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","alertsQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getAlertsData","variableState","dependencies","dependsOn","variableDependencies","variables","filteredVariabledState","variablesValueKey","waitToLoad","some","v","loading","undefined","datasourceStore"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAAmBA,UAAU,QAAwB,wBAAwB;AAG7E,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,iBAAiB,EAAEC,UAAU,QAAQ,oBAAoB;AAClE,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,UAAU;AACvE,SAASC,oBAAoB,QAAQ,cAAc;AAGnD,OAAO,MAAMC,mBAAmB,cAAc;AAE9C;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAoC;IACnE,MAAM,EAAEC,SAAS,EAAE,GAAGR;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I,aAAaJ,qBAAqBK,IAAI,CAAC,CAACC,IAAMT,aAAa,CAACS,EAAE,EAAEC;IAClE;IAEA,MAAMvB,eAAeL,WAAW6B,aAAa,CAACJ;IAC9C,OAAO;QACLnB;QACAD;IACF;AACF;AAEA,SAASX;IACP,MAAMwB,gBAAgB9B;IACtB,MAAM0C,kBAAkB/C;IAExB,OAAO;QACLmC;QACAY;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/runtime/alerts-queries.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({ kind: d.spec.plugin.kind })),\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const alertsQueryKind = definition?.spec?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: 60_000,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AlertsData> => {\n const plugin = await getPlugin({ kind: ALERTS_QUERY_KEY, name: alertsQueryKind });\n const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AlertsQueryPlugin;\n definition: AlertsQueryDefinition;\n context: AlertsQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n // Note: no absoluteTimeRange in query key since alerts are current state\n const queryKey = ['query', ALERTS_QUERY_KEY, definition, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nfunction useAlertsQueryContext(): AlertsQueryContext {\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ALERTS_QUERY_KEY","useAlertsQueries","definitions","getPlugin","context","useAlertsQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","alertsQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getAlertsData","variableState","dependencies","dependsOn","variableDependencies","variables","filteredVariabledState","variablesValueKey","waitToLoad","some","v","loading","undefined","datasourceStore"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,QAAQ,wBAAwB;AAGnD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,iBAAiB,EAAEC,UAAU,QAAQ,uBAAoB;AAClE,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAGnD,OAAO,MAAMC,mBAAmB,cAAc;AAE9C;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAoC;IACnE,MAAM,EAAEC,SAAS,EAAE,GAAGR;IACtB,MAAMS,UAAUC;IAEhB,MAAMC,uBAAuBV,WAC3B,eACAM,YAAYK,GAAG,CAAC,CAACC,IAAO,CAAA;YAAEC,MAAMD,EAAEE,IAAI,CAACC,MAAM,CAACF,IAAI;QAAC,CAAA;IAGrD,OAAOhB,WAAW;QAChBmB,SAASV,YAAYK,GAAG,CAAC,CAACM,YAAYC;YACpC,MAAMH,SAASL,oBAAoB,CAACQ,IAAI,EAAEC;YAC1C,MAAM,EAAEC,YAAY,EAAEC,QAAQ,EAAE,GAAGC,gBAAgB;gBAAEd;gBAASS;gBAAYF;YAAO;YACjF,MAAMQ,kBAAkBN,YAAYH,MAAMC,QAAQF;YAClD,OAAO;gBACLW,SAASJ;gBACTC,UAAUA;gBACVI,gBAAgB;gBAChBC,sBAAsB;gBACtBC,oBAAoB;gBACpBC,WAAW;gBACXC,SAAS,OAAO,EAAEC,MAAM,EAA4B;oBAClD,MAAMf,SAAS,MAAMR,UAAU;wBAAEM,MAAMT;wBAAkB2B,MAAMR;oBAAgB;oBAC/E,MAAMJ,OAAO,MAAMJ,OAAOiB,aAAa,CAACf,WAAWH,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,SAASsB;oBAC9E,OAAOX;gBACT;YACF;QACF;IACF;AACF;AAEA,SAASG,gBAAgB,EACvBP,MAAM,EACNE,UAAU,EACVT,OAAO,EAKR;IAIC,MAAM,EAAEyB,aAAa,EAAE,GAAGzB;IAE1B,MAAM0B,eAAenB,QAAQoB,YAAYpB,OAAOoB,SAAS,CAAClB,WAAWH,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,WAAW,CAAC;IACnG,MAAM4B,uBAAuBF,cAAcG;IAE3C,MAAMC,yBAAyBrC,uBAAuBgC,eAAeG;IACrE,MAAMG,oBAAoBrC,qBAAqBoC;IAC/C,yEAAyE;IACzE,MAAMjB,WAAW;QAAC;QAASjB;QAAkBa;QAAYsB;KAAkB;IAE3E,IAAIC,aAAa;IACjB,IAAIJ,sBAAsB;QACxBI,aAAaJ,qBAAqBK,IAAI,CAAC,CAACC,IAAMT,aAAa,CAACS,EAAE,EAAEC;IAClE;IAEA,MAAMvB,eAAeL,WAAW6B,aAAa,CAACJ;IAC9C,OAAO;QACLnB;QACAD;IACF;AACF;AAEA,SAASX;IACP,MAAMwB,gBAAgB9B;IACtB,MAAM0C,kBAAkB/C;IAExB,OAAO;QACLmC;QACAY;IACF;AACF"}
@@ -1,5 +1,5 @@
1
- import { AnnotationData, AnnotationSpec } from '@perses-dev/spec';
2
- import { UseQueryResult } from '@tanstack/react-query';
1
+ import type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';
2
+ import type { UseQueryResult } from '@tanstack/react-query';
3
3
  export declare const ANNOTATION_KEY = "Annotation";
4
4
  export declare function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>>;
5
5
  export declare function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAkC,cAAc,EAAE,MAAM,uBAAuB,CAAC;AASvF,eAAO,MAAM,cAAc,eAAe,CAAC;AA+C3C,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CA8BrG;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAAC,cAAc,EAAE,CAAC,CAsCxF"}
1
+ {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAUtE,eAAO,MAAM,cAAc,eAAe,CAAC;AA+C3C,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CA8BrG;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAAC,cAAc,EAAE,CAAC,CAsCxF"}
@@ -10,12 +10,12 @@
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
- import { useQueries, useQuery } from '@tanstack/react-query';
14
- import { useDatasourceStore } from './datasources';
15
- import { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';
16
- import { useTimeRange } from './TimeRangeProvider';
17
- import { filterVariableStateMap, getVariableValuesKey } from './utils';
18
- import { useAllVariableValues } from './variables';
13
+ import { useQueries, useQuery } from "@tanstack/react-query";
14
+ import { useDatasourceStore } from "./datasources.js";
15
+ import { usePlugin, usePluginRegistry, usePlugins } from "./plugin-registry.js";
16
+ import { useTimeRange } from "./TimeRangeProvider/index.js";
17
+ import { filterVariableStateMap, getVariableValuesKey } from "./utils.js";
18
+ import { useAllVariableValues } from "./variables.js";
19
19
  export const ANNOTATION_KEY = 'Annotation';
20
20
  function useAnnotationContext() {
21
21
  const { absoluteTimeRange } = useTimeRange();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/annotations.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport { QueryKey, useQueries, useQuery, UseQueryResult } from '@tanstack/react-query';\n\nimport { AnnotationContext, AnnotationPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport const ANNOTATION_KEY = 'Annotation';\n\nfunction useAnnotationContext(): AnnotationContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AnnotationPlugin;\n definition: AnnotationSpec;\n context: AnnotationContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState, absoluteTimeRange } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariableState);\n const queryKey = [ANNOTATION_KEY, definition, absoluteTimeRange, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nexport function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAnnotationContext();\n\n const pluginLoaderResponse = usePlugins(\n 'Annotation',\n definitions.map((d) => ({ kind: d.plugin.kind })),\n );\n\n // useQueries() handles data fetching from query plugins\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const annotationKind = definition?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AnnotationData[]> => {\n const plugin = await getPlugin({ kind: ANNOTATION_KEY, name: annotationKind });\n const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nexport function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]> {\n const { data: annotationPlugin } = usePlugin('Annotation', spec.plugin.kind);\n\n const datasourceStore = useDatasourceStore();\n const allVariables = useAllVariableValues();\n const { absoluteTimeRange: timeRange } = useTimeRange();\n const variablePluginCtx = { absoluteTimeRange: timeRange, datasourceStore, variableState: allVariables };\n\n let dependsOnVariables: string[] = Object.keys(allVariables); // Default to all variables\n if (annotationPlugin?.dependsOn) {\n const dependencies = annotationPlugin.dependsOn(spec.plugin.spec, variablePluginCtx);\n dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;\n }\n\n const variables = useAllVariableValues(dependsOnVariables);\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n return useQuery({\n queryKey: ['annotation', spec, timeRange, variablesValueKey],\n queryFn: async ({ signal }) => {\n const resp = await annotationPlugin?.getAnnotationData(\n spec.plugin.spec,\n { ...variablePluginCtx, variableState: variables },\n signal,\n );\n if (!resp?.length) {\n return [];\n }\n return resp;\n },\n enabled: !!annotationPlugin || waitToLoad,\n });\n}\n"],"names":["useQueries","useQuery","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ANNOTATION_KEY","useAnnotationContext","absoluteTimeRange","variableState","datasourceStore","getQueryOptions","plugin","definition","context","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariableState","variablesValueKey","queryKey","waitToLoad","some","v","loading","queryEnabled","undefined","useAnnotations","definitions","getPlugin","pluginLoaderResponse","map","d","kind","queries","idx","data","annotationKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","getAnnotationData","useAnnotationData","annotationPlugin","allVariables","timeRange","variablePluginCtx","dependsOnVariables","Object","keys","resp","length"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAAmBA,UAAU,EAAEC,QAAQ,QAAwB,wBAAwB;AAGvF,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SA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E,EAAEC;IAC5D;IAEA,MAAML,oBAAoBjB,qBAAqBe;IAE/C,OAAOtB,SAAS;QACdyB,UAAU;YAAC;YAAcL;YAAMoC;YAAWhC;SAAkB;QAC5DyB,SAAS,OAAO,EAAEC,MAAM,EAAE;YACxB,MAAMW,OAAO,MAAMP,kBAAkBF,kBACnChC,KAAKL,MAAM,CAACK,IAAI,EAChB;gBAAE,GAAGqC,iBAAiB;gBAAE7C,eAAeU;YAAU,GACjD4B;YAEF,IAAI,CAACW,MAAMC,QAAQ;gBACjB,OAAO,EAAE;YACX;YACA,OAAOD;QACT;QACAlB,SAAS,CAAC,CAACW,oBAAoB5B;IACjC;AACF"}
1
+ {"version":3,"sources":["../../src/runtime/annotations.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\n\nimport type { AnnotationContext, AnnotationPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport const ANNOTATION_KEY = 'Annotation';\n\nfunction useAnnotationContext(): AnnotationContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AnnotationPlugin;\n definition: AnnotationSpec;\n context: AnnotationContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState, absoluteTimeRange } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariableState);\n const queryKey = [ANNOTATION_KEY, definition, absoluteTimeRange, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nexport function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAnnotationContext();\n\n const pluginLoaderResponse = usePlugins(\n 'Annotation',\n definitions.map((d) => ({ kind: d.plugin.kind })),\n );\n\n // useQueries() handles data fetching from query plugins\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const annotationKind = definition?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AnnotationData[]> => {\n const plugin = await getPlugin({ kind: ANNOTATION_KEY, name: annotationKind });\n const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nexport function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]> {\n const { data: annotationPlugin } = usePlugin('Annotation', spec.plugin.kind);\n\n const datasourceStore = useDatasourceStore();\n const allVariables = useAllVariableValues();\n const { absoluteTimeRange: timeRange } = useTimeRange();\n const variablePluginCtx = { absoluteTimeRange: timeRange, datasourceStore, variableState: allVariables };\n\n let dependsOnVariables: string[] = Object.keys(allVariables); // Default to all variables\n if (annotationPlugin?.dependsOn) {\n const dependencies = annotationPlugin.dependsOn(spec.plugin.spec, variablePluginCtx);\n dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;\n }\n\n const variables = useAllVariableValues(dependsOnVariables);\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n return useQuery({\n queryKey: ['annotation', spec, timeRange, variablesValueKey],\n queryFn: async ({ signal }) => {\n const resp = await annotationPlugin?.getAnnotationData(\n spec.plugin.spec,\n { ...variablePluginCtx, variableState: variables },\n signal,\n );\n if (!resp?.length) {\n return [];\n }\n return resp;\n },\n enabled: !!annotationPlugin || waitToLoad,\n });\n}\n"],"names":["useQueries","useQuery","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ANNOTATION_KEY","useAnnotationContext","absoluteTimeRange","variableState","datasourceStore","getQueryOptions","plugin","definition","context","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariableState","variablesValueKey","queryKey","waitToLoad","some","v","loading","queryEnabled","undefined","useAnnotations","definitions","getPlugin","pluginLoaderResponse","map","d","kind","queries","idx","data","annotationKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","getAnnotationData","useAnnotationData","annotationPlugin","allVariables","timeRange","variablePluginCtx","dependsOnVariables","Object","keys","resp","length"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAA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