@perses-dev/plugin-system 0.54.0-beta.1 → 0.54.0-beta.10

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 (261) hide show
  1. package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +283 -0
  2. package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +197 -0
  3. package/dist/cjs/components/Annotations/AnnotationEditorForm/index.js +30 -0
  4. package/dist/cjs/components/Annotations/constants.js +23 -0
  5. package/dist/cjs/components/Annotations/index.js +31 -0
  6. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +97 -12
  7. package/dist/cjs/components/MultiQueryEditor/index.js +1 -0
  8. package/dist/cjs/components/MultiQueryEditor/utils.js +36 -0
  9. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +3 -6
  10. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -15
  11. package/dist/cjs/components/PluginRegistry/getPluginSearchHelper.js +92 -0
  12. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +16 -13
  13. package/dist/cjs/components/Variables/variable-model.js +115 -29
  14. package/dist/cjs/components/index.js +1 -0
  15. package/dist/cjs/context/ValidationProvider.js +10 -4
  16. package/dist/cjs/model/alerts-queries.js +16 -0
  17. package/dist/cjs/model/annotations.js +16 -0
  18. package/dist/cjs/model/index.js +3 -0
  19. package/dist/cjs/model/log-volume-utils.js +10 -10
  20. package/dist/cjs/model/plugin-loading.js +24 -8
  21. package/dist/cjs/model/plugins.js +10 -0
  22. package/dist/cjs/model/silences-queries.js +16 -0
  23. package/dist/cjs/remote/PluginRuntime.js +46 -10
  24. package/dist/cjs/remote/remotePluginLoader.js +28 -5
  25. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +33 -24
  26. package/dist/cjs/runtime/DataQueriesProvider/model.js +3 -93
  27. package/dist/cjs/runtime/UsageMetricsProvider.js +2 -2
  28. package/dist/cjs/runtime/alerts-queries.js +101 -0
  29. package/dist/cjs/runtime/annotations.js +148 -0
  30. package/dist/cjs/runtime/index.js +3 -1
  31. package/dist/cjs/runtime/item-actions.js +3 -3
  32. package/dist/cjs/runtime/log-queries.js +4 -1
  33. package/dist/cjs/runtime/plugin-registry.js +12 -3
  34. package/dist/cjs/runtime/profile-queries.js +4 -1
  35. package/dist/cjs/runtime/silences-queries.js +101 -0
  36. package/dist/cjs/runtime/time-series-queries.js +4 -1
  37. package/dist/cjs/runtime/trace-queries.js +4 -1
  38. package/dist/cjs/test/mock-data.js +51 -0
  39. package/dist/cjs/test/test-plugins/bert/index.js +9 -12
  40. package/dist/cjs/test/test-plugins/ernie/index.js +9 -12
  41. package/dist/cjs/test/test-plugins/index.js +2 -2
  42. package/dist/cjs/test-utils/mock-plugin-registry.js +8 -2
  43. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts +16 -0
  44. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts.map +1 -0
  45. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +270 -0
  46. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js.map +1 -0
  47. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts +8 -0
  48. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts.map +1 -0
  49. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +184 -0
  50. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js.map +1 -0
  51. package/dist/components/Annotations/AnnotationEditorForm/index.d.ts +2 -0
  52. package/dist/components/Annotations/AnnotationEditorForm/index.d.ts.map +1 -0
  53. package/dist/{runtime/QueryCountProvider.js → components/Annotations/AnnotationEditorForm/index.js} +2 -13
  54. package/dist/components/Annotations/AnnotationEditorForm/index.js.map +1 -0
  55. package/dist/components/Annotations/constants.d.ts +2 -0
  56. package/dist/components/Annotations/constants.d.ts.map +1 -0
  57. package/dist/components/Annotations/constants.js +15 -0
  58. package/dist/components/Annotations/constants.js.map +1 -0
  59. package/dist/components/Annotations/index.d.ts +3 -0
  60. package/dist/components/Annotations/index.d.ts.map +1 -0
  61. package/dist/components/Annotations/index.js +16 -0
  62. package/dist/components/Annotations/index.js.map +1 -0
  63. package/dist/components/CalculationSelector/CalculationSelector.js +1 -1
  64. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  65. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +1 -2
  66. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  67. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -1
  68. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  69. package/dist/components/DatasourceSelect/DatasourceSelect.js +2 -2
  70. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
  71. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
  72. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
  73. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +2 -2
  74. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
  75. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +1 -1
  76. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
  77. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +1 -1
  78. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  79. package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
  80. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
  81. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
  82. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  83. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  84. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +100 -15
  85. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  86. package/dist/components/MultiQueryEditor/index.d.ts +1 -0
  87. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -1
  88. package/dist/components/MultiQueryEditor/index.js +1 -0
  89. package/dist/components/MultiQueryEditor/index.js.map +1 -1
  90. package/dist/components/MultiQueryEditor/utils.d.ts +8 -0
  91. package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -0
  92. package/dist/components/MultiQueryEditor/utils.js +23 -0
  93. package/dist/components/MultiQueryEditor/utils.js.map +1 -0
  94. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +1 -1
  95. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  96. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
  97. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  98. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +1 -1
  99. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  100. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  101. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +5 -8
  102. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  103. package/dist/components/PluginEditor/PluginEditor.js +1 -1
  104. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  105. package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -1
  106. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  107. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  108. package/dist/components/PluginRegistry/PluginRegistry.js +12 -16
  109. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  110. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts +12 -0
  111. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts.map +1 -0
  112. package/dist/components/PluginRegistry/getPluginSearchHelper.js +88 -0
  113. package/dist/components/PluginRegistry/getPluginSearchHelper.js.map +1 -0
  114. package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -6
  115. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  116. package/dist/components/PluginRegistry/plugin-indexes.js +15 -13
  117. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  118. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  119. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  120. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  121. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js +1 -1
  122. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js.map +1 -1
  123. package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -1
  124. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  125. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -1
  126. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  127. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
  128. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  129. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
  130. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  131. package/dist/components/Variables/variable-model.d.ts +9 -1
  132. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  133. package/dist/components/Variables/variable-model.js +117 -31
  134. package/dist/components/Variables/variable-model.js.map +1 -1
  135. package/dist/components/index.d.ts +1 -0
  136. package/dist/components/index.d.ts.map +1 -1
  137. package/dist/components/index.js +1 -0
  138. package/dist/components/index.js.map +1 -1
  139. package/dist/context/ValidationProvider.d.ts +4 -2
  140. package/dist/context/ValidationProvider.d.ts.map +1 -1
  141. package/dist/context/ValidationProvider.js +10 -4
  142. package/dist/context/ValidationProvider.js.map +1 -1
  143. package/dist/model/alerts-queries.d.ts +33 -0
  144. package/dist/model/alerts-queries.d.ts.map +1 -0
  145. package/dist/model/alerts-queries.js +15 -0
  146. package/dist/model/alerts-queries.js.map +1 -0
  147. package/dist/model/annotations.d.ts +28 -0
  148. package/dist/model/annotations.d.ts.map +1 -0
  149. package/dist/model/annotations.js +17 -0
  150. package/dist/model/annotations.js.map +1 -0
  151. package/dist/model/datasource.d.ts +1 -8
  152. package/dist/model/datasource.d.ts.map +1 -1
  153. package/dist/model/datasource.js +1 -1
  154. package/dist/model/datasource.js.map +1 -1
  155. package/dist/model/index.d.ts +3 -0
  156. package/dist/model/index.d.ts.map +1 -1
  157. package/dist/model/index.js +3 -0
  158. package/dist/model/index.js.map +1 -1
  159. package/dist/model/log-queries.d.ts +2 -1
  160. package/dist/model/log-queries.d.ts.map +1 -1
  161. package/dist/model/log-queries.js.map +1 -1
  162. package/dist/model/plugin-loading.d.ts.map +1 -1
  163. package/dist/model/plugin-loading.js +24 -8
  164. package/dist/model/plugin-loading.js.map +1 -1
  165. package/dist/model/plugins.d.ts +23 -0
  166. package/dist/model/plugins.d.ts.map +1 -1
  167. package/dist/model/plugins.js +4 -1
  168. package/dist/model/plugins.js.map +1 -1
  169. package/dist/model/silences-queries.d.ts +33 -0
  170. package/dist/model/silences-queries.d.ts.map +1 -0
  171. package/dist/model/silences-queries.js +15 -0
  172. package/dist/model/silences-queries.js.map +1 -0
  173. package/dist/model/trace-queries.d.ts +2 -3
  174. package/dist/model/trace-queries.d.ts.map +1 -1
  175. package/dist/model/trace-queries.js.map +1 -1
  176. package/dist/remote/PersesPlugin.types.d.ts +2 -0
  177. package/dist/remote/PersesPlugin.types.d.ts.map +1 -1
  178. package/dist/remote/PersesPlugin.types.js.map +1 -1
  179. package/dist/remote/PluginLoaderComponent.js +1 -1
  180. package/dist/remote/PluginLoaderComponent.js.map +1 -1
  181. package/dist/remote/PluginRuntime.d.ts +7 -1
  182. package/dist/remote/PluginRuntime.d.ts.map +1 -1
  183. package/dist/remote/PluginRuntime.js +46 -10
  184. package/dist/remote/PluginRuntime.js.map +1 -1
  185. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  186. package/dist/remote/remotePluginLoader.js +28 -5
  187. package/dist/remote/remotePluginLoader.js.map +1 -1
  188. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  189. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +35 -26
  190. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  191. package/dist/runtime/DataQueriesProvider/model.d.ts +4 -4
  192. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  193. package/dist/runtime/DataQueriesProvider/model.js +0 -82
  194. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  195. package/dist/runtime/RouterProvider.js +1 -1
  196. package/dist/runtime/RouterProvider.js.map +1 -1
  197. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +1 -1
  198. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  199. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +1 -1
  200. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  201. package/dist/runtime/UsageMetricsProvider.js +2 -2
  202. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  203. package/dist/runtime/alerts-queries.d.ts +11 -0
  204. package/dist/runtime/alerts-queries.d.ts.map +1 -0
  205. package/dist/runtime/alerts-queries.js +89 -0
  206. package/dist/runtime/alerts-queries.js.map +1 -0
  207. package/dist/runtime/annotations.d.ts +6 -0
  208. package/dist/runtime/annotations.d.ts.map +1 -0
  209. package/dist/runtime/annotations.js +129 -0
  210. package/dist/runtime/annotations.js.map +1 -0
  211. package/dist/runtime/datasources.d.ts +6 -0
  212. package/dist/runtime/datasources.d.ts.map +1 -1
  213. package/dist/runtime/datasources.js.map +1 -1
  214. package/dist/runtime/index.d.ts +3 -1
  215. package/dist/runtime/index.d.ts.map +1 -1
  216. package/dist/runtime/index.js +3 -1
  217. package/dist/runtime/index.js.map +1 -1
  218. package/dist/runtime/item-actions.js +1 -1
  219. package/dist/runtime/item-actions.js.map +1 -1
  220. package/dist/runtime/log-queries.js +4 -1
  221. package/dist/runtime/log-queries.js.map +1 -1
  222. package/dist/runtime/plugin-registry.d.ts +2 -2
  223. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  224. package/dist/runtime/plugin-registry.js +12 -3
  225. package/dist/runtime/plugin-registry.js.map +1 -1
  226. package/dist/runtime/profile-queries.js +4 -1
  227. package/dist/runtime/profile-queries.js.map +1 -1
  228. package/dist/runtime/silences-queries.d.ts +11 -0
  229. package/dist/runtime/silences-queries.d.ts.map +1 -0
  230. package/dist/runtime/silences-queries.js +89 -0
  231. package/dist/runtime/silences-queries.js.map +1 -0
  232. package/dist/runtime/time-series-queries.js +4 -1
  233. package/dist/runtime/time-series-queries.js.map +1 -1
  234. package/dist/runtime/trace-queries.js +4 -1
  235. package/dist/runtime/trace-queries.js.map +1 -1
  236. package/dist/test/mock-data.d.ts +3 -1
  237. package/dist/test/mock-data.d.ts.map +1 -1
  238. package/dist/test/mock-data.js +45 -0
  239. package/dist/test/mock-data.js.map +1 -1
  240. package/dist/test/render.js +1 -1
  241. package/dist/test/render.js.map +1 -1
  242. package/dist/test/test-plugins/bert/index.d.ts +12 -6
  243. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  244. package/dist/test/test-plugins/bert/index.js +6 -2
  245. package/dist/test/test-plugins/bert/index.js.map +1 -1
  246. package/dist/test/test-plugins/ernie/index.d.ts +8 -6
  247. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
  248. package/dist/test/test-plugins/ernie/index.js +6 -2
  249. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  250. package/dist/test/test-plugins/index.js +2 -2
  251. package/dist/test/test-plugins/index.js.map +1 -1
  252. package/dist/test/utils.js +1 -1
  253. package/dist/test/utils.js.map +1 -1
  254. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  255. package/dist/test-utils/mock-plugin-registry.js +8 -2
  256. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  257. package/package.json +7 -6
  258. package/dist/cjs/runtime/QueryCountProvider.js +0 -83
  259. package/dist/runtime/QueryCountProvider.d.ts +0 -9
  260. package/dist/runtime/QueryCountProvider.d.ts.map +0 -1
  261. package/dist/runtime/QueryCountProvider.js.map +0 -1
@@ -10,8 +10,6 @@
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 { useCallback, useMemo } from 'react';
14
- import { useListPluginMetadata } from '../plugin-registry';
15
13
  export function transformQueryResults(results, definitions) {
16
14
  return results.map(({ data, isFetching, isLoading, refetch, error }, i)=>{
17
15
  return {
@@ -24,85 +22,5 @@ export function transformQueryResults(results, definitions) {
24
22
  };
25
23
  });
26
24
  }
27
- export function useQueryType() {
28
- const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([
29
- 'TimeSeriesQuery'
30
- ]);
31
- const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata([
32
- 'TraceQuery'
33
- ]);
34
- const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = useListPluginMetadata([
35
- 'ProfileQuery'
36
- ]);
37
- const { data: logQueries, isLoading: isLogQueryPluginLoading } = useListPluginMetadata([
38
- 'LogQuery'
39
- ]);
40
- // For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
41
- const queryTypeMap = useMemo(()=>{
42
- const map = {
43
- TimeSeriesQuery: [],
44
- TraceQuery: [],
45
- ProfileQuery: [],
46
- LogQuery: []
47
- };
48
- if (timeSeriesQueryPlugins) {
49
- timeSeriesQueryPlugins.forEach((plugin)=>{
50
- map[plugin.kind]?.push(plugin.spec.name);
51
- });
52
- }
53
- if (traceQueryPlugins) {
54
- traceQueryPlugins.forEach((plugin)=>{
55
- map[plugin.kind]?.push(plugin.spec.name);
56
- });
57
- }
58
- if (profileQueryPlugins) {
59
- profileQueryPlugins.forEach((plugin)=>{
60
- map[plugin.kind]?.push(plugin.spec.name);
61
- });
62
- }
63
- if (logQueries) {
64
- logQueries.forEach((plugin)=>{
65
- map[plugin.kind]?.push(plugin.spec.name);
66
- });
67
- }
68
- return map;
69
- }, [
70
- timeSeriesQueryPlugins,
71
- traceQueryPlugins,
72
- profileQueryPlugins,
73
- logQueries
74
- ]);
75
- const getQueryType = useCallback((pluginKind)=>{
76
- const isLoading = (pluginKind)=>{
77
- switch(pluginKind){
78
- case 'PrometheusTimeSeriesQuery':
79
- return isTimeSeriesQueryLoading;
80
- case 'TempoTraceQuery':
81
- return isTraceQueryPluginLoading;
82
- case 'PyroscopeProfileQuery':
83
- return isProfileQueryPluginLoading;
84
- case 'LokiLogQuery':
85
- return isLogQueryPluginLoading;
86
- }
87
- return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading || isLogQueryPluginLoading;
88
- };
89
- if (isLoading(pluginKind)) {
90
- return undefined;
91
- }
92
- for(const queryType in queryTypeMap){
93
- if (queryTypeMap[queryType]?.includes(pluginKind)) {
94
- return queryType;
95
- }
96
- }
97
- throw new Error(`Unable to determine the query type: ${pluginKind}`);
98
- }, [
99
- queryTypeMap,
100
- isTimeSeriesQueryLoading,
101
- isTraceQueryPluginLoading,
102
- isProfileQueryPluginLoading,
103
- isLogQueryPluginLoading
104
- ]);
105
- return getQueryType;
106
- }
107
25
 
108
26
  //# sourceMappingURL=model.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.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 { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/spec';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode, useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: Error;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([\n 'TimeSeriesQuery',\n ]);\n const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata(['TraceQuery']);\n const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = useListPluginMetadata(['ProfileQuery']);\n const { data: logQueries, isLoading: isLogQueryPluginLoading } = useListPluginMetadata(['LogQuery']);\n\n // For example, `map: {\"TimeSeriesQuery\":[\"PrometheusTimeSeriesQuery\"],\"TraceQuery\":[\"TempoTraceQuery\"]}`\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n TraceQuery: [],\n ProfileQuery: [],\n LogQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (traceQueryPlugins) {\n traceQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (profileQueryPlugins) {\n profileQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (logQueries) {\n logQueries.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n return map;\n }, [timeSeriesQueryPlugins, traceQueryPlugins, profileQueryPlugins, logQueries]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n const isLoading = (pluginKind: string): boolean => {\n switch (pluginKind) {\n case 'PrometheusTimeSeriesQuery':\n return isTimeSeriesQueryLoading;\n case 'TempoTraceQuery':\n return isTraceQueryPluginLoading;\n case 'PyroscopeProfileQuery':\n return isProfileQueryPluginLoading;\n case 'LokiLogQuery':\n return isLogQueryPluginLoading;\n }\n\n return (\n isTraceQueryPluginLoading ||\n isTimeSeriesQueryLoading ||\n isProfileQueryPluginLoading ||\n isLogQueryPluginLoading\n );\n };\n\n if (isLoading(pluginKind)) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [\n queryTypeMap,\n isTimeSeriesQueryLoading,\n isTraceQueryPluginLoading,\n isProfileQueryPluginLoading,\n isLogQueryPluginLoading,\n ]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","isTimeSeriesQueryLoading","traceQueryPlugins","isTraceQueryPluginLoading","profileQueryPlugins","isProfileQueryPluginLoading","logQueries","isLogQueryPluginLoading","queryTypeMap","TimeSeriesQuery","TraceQuery","ProfileQuery","LogQuery","forEach","plugin","kind","push","spec","name","getQueryType","pluginKind","undefined","queryType","includes","Error"],"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,SAAoBA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AACxD,SAASC,qBAAqB,QAAQ,qBAAqB;AA+B3D,OAAO,SAASC,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,KAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF;AAEA,OAAO,SAASG;IACd,MAAM,EAAEP,MAAMQ,sBAAsB,EAAEN,WAAWO,wBAAwB,EAAE,GAAGd,sBAAsB;QAClG;KACD;IACD,MAAM,EAAEK,MAAMU,iBAAiB,EAAER,WAAWS,yBAAyB,EAAE,GAAGhB,sBAAsB;QAAC;KAAa;IAC9G,MAAM,EAAEK,MAAMY,mBAAmB,EAAEV,WAAWW,2BAA2B,EAAE,GAAGlB,sBAAsB;QAAC;KAAe;IACpH,MAAM,EAAEK,MAAMc,UAAU,EAAEZ,WAAWa,uBAAuB,EAAE,GAAGpB,sBAAsB;QAAC;KAAW;IAEnG,yGAAyG;IACzG,MAAMqB,eAAetB,QAAQ;QAC3B,MAAMK,MAAgC;YACpCkB,iBAAiB,EA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3,"sources":["../../../src/runtime/DataQueriesProvider/model.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 { QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/spec';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode } from 'react';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<Kind = unknown, PluginSpec = UnknownSpec> {\n definitions: Array<QueryDefinition<Kind, PluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryDefinitions: QueryDefinition[];\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: Error;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n"],"names":["transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition"],"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;AAoCjC,OAAO,SAASA,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,KAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { createContext, useContext, useMemo } from 'react';
15
15
  import { Link as RouterLink, useNavigate } from 'react-router-dom';
16
16
  export const RouterContext = /*#__PURE__*/ createContext(undefined);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/RouterProvider.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 React, { createContext, useContext, ReactNode, ReactElement, useMemo } from 'react';\nimport { Link as RouterLink, useNavigate } from 'react-router-dom';\n\ninterface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n to: string;\n}\n\nexport interface RouterContextType {\n RouterComponent?: (props: LinkProps & React.RefAttributes<HTMLAnchorElement>) => ReactNode;\n navigate?: (to: string) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | undefined>(undefined);\n\nexport function useRouterContext(): RouterContextType {\n const ctx = useContext(RouterContext);\n if (ctx === undefined) {\n console.warn('No RouterContext found. Did you forget a <RouterProvider>?');\n return {};\n }\n return ctx;\n}\n\ninterface RouterProviderProps {\n RouterComponent: RouterContextType['RouterComponent'];\n navigate: RouterContextType['navigate'];\n children?: React.ReactNode;\n}\n\n/**\n * Some panel plugins (TraceTable, ScatterPlot, TracingGanttChart) support linking to other pages,\n * e.g. clicking on a trace in the TraceTable should navigate to the TracingGanttChart.\n *\n * We can't use react-router in the panel, because panels might be embedded into React applications\n * which use a different routing library, or a different major version of react-router.\n *\n * This provider abstracts the basic routing functionality, to remove the dependency on the exact version of react-router.\n */\nexport function RouterProvider(props: RouterProviderProps): ReactElement {\n const { RouterComponent, navigate, children } = props;\n\n const ctx = useMemo(() => {\n return { RouterComponent, navigate };\n }, [RouterComponent, navigate]);\n\n return <RouterContext.Provider value={ctx}>{children}</RouterContext.Provider>;\n}\n\ninterface ReactRouterProviderProps {\n children?: React.ReactNode;\n}\n\n/** An implementation of RouterProvider for using the react-router library, shipped with Perses */\nexport function ReactRouterProvider(props: ReactRouterProviderProps): ReactElement {\n const { children } = props;\n const navigate = useNavigate();\n\n return (\n <RouterProvider RouterComponent={RouterLink} navigate={navigate}>\n {children}\n </RouterProvider>\n );\n}\n"],"names":["React","createContext","useContext","useMemo","Link","RouterLink","useNavigate","RouterContext","undefined","useRouterContext","ctx","console","warn","RouterProvider","props","RouterComponent","navigate","children","Provider","value","ReactRouterProvider"],"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,OAAOA,SAASC,aAAa,EAAEC,UAAU,EAA2BC,OAAO,QAAQ,QAAQ;AAC3F,SAASC,QAAQC,UAAU,EAAEC,WAAW,QAAQ,mBAAmB;AAWnE,OAAO,MAAMC,8BAAgBN,cAA6CO,WAAW;AAErF,OAAO,SAASC;IACd,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrBG,QAAQC,IAAI,CAAC;QACb,OAAO,CAAC;IACV;IACA,OAAOF;AACT;AAQA;;;;;;;;CAQC,GACD,OAAO,SAASG,eAAeC,KAA0B;IACvD,MAAM,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGH;IAEhD,MAAMJ,MAAMP,QAAQ;QAClB,OAAO;YAAEY;YAAiBC;QAAS;IACrC,GAAG;QAACD;QAAiBC;KAAS;IAE9B,qBAAO,KAACT,cAAcW,QAAQ;QAACC,OAAOT;kBAAMO;;AAC9C;AAMA,gGAAgG,GAChG,OAAO,SAASG,oBAAoBN,KAA+B;IACjE,MAAM,EAAEG,QAAQ,EAAE,GAAGH;IACrB,MAAME,WAAWV;IAEjB,qBACE,KAACO;QAAeE,iBAAiBV;QAAYW,UAAUA;kBACpDC;;AAGP"}
1
+ {"version":3,"sources":["../../src/runtime/RouterProvider.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 React, { createContext, useContext, ReactNode, ReactElement, useMemo } from 'react';\nimport { Link as RouterLink, useNavigate } from 'react-router-dom';\n\ninterface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n to: string;\n}\n\nexport interface RouterContextType {\n RouterComponent?: (props: LinkProps & React.RefAttributes<HTMLAnchorElement>) => ReactNode;\n navigate?: (to: string) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | undefined>(undefined);\n\nexport function useRouterContext(): RouterContextType {\n const ctx = useContext(RouterContext);\n if (ctx === undefined) {\n console.warn('No RouterContext found. Did you forget a <RouterProvider>?');\n return {};\n }\n return ctx;\n}\n\ninterface RouterProviderProps {\n RouterComponent: RouterContextType['RouterComponent'];\n navigate: RouterContextType['navigate'];\n children?: React.ReactNode;\n}\n\n/**\n * Some panel plugins (TraceTable, ScatterPlot, TracingGanttChart) support linking to other pages,\n * e.g. clicking on a trace in the TraceTable should navigate to the TracingGanttChart.\n *\n * We can't use react-router in the panel, because panels might be embedded into React applications\n * which use a different routing library, or a different major version of react-router.\n *\n * This provider abstracts the basic routing functionality, to remove the dependency on the exact version of react-router.\n */\nexport function RouterProvider(props: RouterProviderProps): ReactElement {\n const { RouterComponent, navigate, children } = props;\n\n const ctx = useMemo(() => {\n return { RouterComponent, navigate };\n }, [RouterComponent, navigate]);\n\n return <RouterContext.Provider value={ctx}>{children}</RouterContext.Provider>;\n}\n\ninterface ReactRouterProviderProps {\n children?: React.ReactNode;\n}\n\n/** An implementation of RouterProvider for using the react-router library, shipped with Perses */\nexport function ReactRouterProvider(props: ReactRouterProviderProps): ReactElement {\n const { children } = props;\n const navigate = useNavigate();\n\n return (\n <RouterProvider RouterComponent={RouterLink} navigate={navigate}>\n {children}\n </RouterProvider>\n );\n}\n"],"names":["React","createContext","useContext","useMemo","Link","RouterLink","useNavigate","RouterContext","undefined","useRouterContext","ctx","console","warn","RouterProvider","props","RouterComponent","navigate","children","Provider","value","ReactRouterProvider"],"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,OAAOA,SAASC,aAAa,EAAEC,UAAU,EAA2BC,OAAO,QAAQ,QAAQ;AAC3F,SAASC,QAAQC,UAAU,EAAEC,WAAW,QAAQ,mBAAmB;AAWnE,OAAO,MAAMC,8BAAgBN,cAA6CO,WAAW;AAErF,OAAO,SAASC;IACd,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrBG,QAAQC,IAAI,CAAC;QACb,OAAO,CAAC;IACV;IACA,OAAOF;AACT;AAQA;;;;;;;;CAQC,GACD,OAAO,SAASG,eAAeC,KAA0B;IACvD,MAAM,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGH;IAEhD,MAAMJ,MAAMP,QAAQ;QAClB,OAAO;YAAEY;YAAiBC;QAAS;IACrC,GAAG;QAACD;QAAiBC;KAAS;IAE9B,qBAAO,KAACT,cAAcW,QAAQ;QAACC,OAAOT;kBAAMO;;AAC9C;AAMA,gGAAgG,GAChG,OAAO,SAASG,oBAAoBN,KAA+B;IACjE,MAAM,EAAEG,QAAQ,EAAE,GAAGH;IACrB,MAAME,WAAWV;IAEjB,qBACE,KAACO;QAAeE,iBAAiBV;QAAYW,UAAUA;kBACpDC;;AAGP"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
15
15
  import { isRelativeTimeRange, toAbsoluteTimeRange, getSuggestedStepMs } from '@perses-dev/spec';
16
16
  import { useQueryClient } from '@tanstack/react-query';
@@ -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 React, { createContext, ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react';\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 { getRefreshIntervalInMs } from './refresh-interval';\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\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 // 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 const refreshIntervalInMs = useMemo(() => getRefreshIntervalInMs(refreshInterval), [refreshInterval]);\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: setRefreshInterval,\n };\n }, [\n absoluteTimeRange,\n handleSetTimeRange,\n refresh,\n refreshInterval,\n refreshIntervalInMs,\n setRefreshInterval,\n timeRange,\n ]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","isRelativeTimeRange","toAbsoluteTimeRange","getSuggestedStepMs","useQueryClient","getRefreshIntervalInMs","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","useSuggestedStepMs","width","absoluteTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","queryClient","setAbsoluteTimeRange","handleSetTimeRange","value","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,OAAOA,SAASC,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClH,SAIEC,mBAAmB,EACnBC,mBAAmB,EACnBC,kBAAkB,QACb,mBAAmB;AAC1B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,sBAAsB,QAAQ,qBAAqB;AAoB5D,OAAO,MAAMC,iCAAmBX,cAAqCY,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMZ,WAAWS;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;I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AAC;YAC7DP,YAAYQ,aAAa,CAAC;gBAAEF,UAAU;oBAAC;iBAAQ;gBAAEG,MAAM;YAAW;YAClET,YAAYQ,aAAa,CAAC;gBAAEF,UAAU;oBAAC;iBAAW;gBAAEG,MAAM;YAAW,IAAI,kFAAkF;QAC7J;IACF,GAAG;QAACT;QAAaL;KAAU;IAE3B,MAAMgB,sBAAsBlC,QAAQ,IAAMM,uBAAuBa,kBAAkB;QAACA;KAAgB;IACpGpB,UAAU;QACR,IAAImC,sBAAsB,GAAG;YAC3B,MAAMC,WAAWC,YAAY;gBAC3BH;YACF,GAAGC;YAEH,OAAO,IAAYG,cAAcF;QACnC;IACF,GAAG;QAACF;QAAaC;KAAoB;IAErC,MAAMxB,MAAMV,QAAQ;QAClB,OAAO;YACLkB,WAAWA;YACXG,cAAcI;YACdV,mBAAmBA;YACnBY;YACAR,iBAAiBA;YACjBe,qBAAqBA;YACrBZ,oBAAoBA;QACtB;IACF,GAAG;QACDP;QACAU;QACAE;QACAR;QACAe;QACAZ;QACAJ;KACD;IAED,qBAAO,KAACX,iBAAiB+B,QAAQ;QAACZ,OAAOhB;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 React, { createContext, ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react';\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 { getRefreshIntervalInMs } from './refresh-interval';\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\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 // 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 const refreshIntervalInMs = useMemo(() => getRefreshIntervalInMs(refreshInterval), [refreshInterval]);\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: setRefreshInterval,\n };\n }, [\n absoluteTimeRange,\n handleSetTimeRange,\n refresh,\n refreshInterval,\n refreshIntervalInMs,\n setRefreshInterval,\n timeRange,\n ]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","isRelativeTimeRange","toAbsoluteTimeRange","getSuggestedStepMs","useQueryClient","getRefreshIntervalInMs","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","useSuggestedStepMs","width","absoluteTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","queryClient","setAbsoluteTimeRange","handleSetTimeRange","value","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,OAAOA,SAASC,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClH,SAIEC,mBAAmB,EACnBC,mBAAmB,EACnBC,kBAAkB,QACb,mBAAmB;AAC1B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,sBAAsB,QAAQ,qBAAqB;AAoB5D,OAAO,MAAMC,iCAAmBX,cAAqCY,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMZ,WAAWS;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,OAAOJ,mBAAmBW,mBAAmBD;AAC/C;AAEA;;CAEC,GACD,OAAO,SAASE,kBAAkBC,KAA6B;IAC7D,MAAM,EAAEC,SAAS,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,kBAAkB,EAAE,GAAGL;IAEnF,MAAMM,cAAclB;IACpB,MAAM,CAACU,mBAAmBS,qBAAqB,GAAGvB,SAChDC,oBAAoBgB,aAAaf,oBAAoBe,aAAaA;IAGpE,MAAMO,qBAA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AcI;YACdV,mBAAmBA;YACnBY;YACAR,iBAAiBA;YACjBe,qBAAqBA;YACrBZ,oBAAoBA;QACtB;IACF,GAAG;QACDP;QACAU;QACAE;QACAR;QACAe;QACAZ;QACAJ;KACD;IAED,qBAAO,KAACX,iBAAiB+B,QAAQ;QAACZ,OAAOhB;kBAAMU;;AACjD"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { createContext, useContext, useMemo } from 'react';
15
15
  import { buildRelativeTimeOption } from '@perses-dev/components';
16
16
  const DEFAULT_OPTIONS = [
@@ -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 { createContext, ReactElement, ReactNode, useContext, useMemo } from 'react';\nimport { buildRelativeTimeOption, TimeOption } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/spec';\n\nconst DEFAULT_OPTIONS: DurationString[] = ['5m', '15m', '30m', '1h', '6h', '12h', '24h', '7d', '14d'];\nconst defaultTimeRangeSettings: TimeRangeSettings = {\n showCustom: true,\n showZoomButtons: true,\n options: DEFAULT_OPTIONS.map((duration) => buildRelativeTimeOption(duration)),\n};\n\nexport interface TimeRangeSettingsProviderProps {\n showCustom?: boolean;\n showZoomButtons?: boolean;\n options?: TimeOption[];\n children: ReactNode;\n}\n\nexport interface TimeRangeSettings {\n showCustom: boolean;\n showZoomButtons: 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 * 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 options: props.options === undefined ? defaultTimeRangeSettings.options : props.options,\n };\n }, [props.showCustom, props.showZoomButtons, props.options]);\n\n return <TimeRangeSettingsContext.Provider value={ctx}>{props.children}</TimeRangeSettingsContext.Provider>;\n}\n"],"names":["createContext","useContext","useMemo","buildRelativeTimeOption","DEFAULT_OPTIONS","defaultTimeRangeSettings","showCustom","showZoomButtons","options","map","duration","TimeRangeSettingsContext","useTimeRangeSettingsContext","ctx","undefined","Error","useTimeRangeSettings","useShowCustomTimeRangeSetting","override","showCustomTimeRange","useShowZoomRangeSetting","showZoomTimeRange","useTimeRangeOptionsSetting","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,aAAa,EAA2BC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AACpF,SAASC,uBAAuB,QAAoB,yBAAyB;AAG7E,MAAMC,kBAAoC;IAAC;IAAM;IAAO;IAAO;IAAM;IAAM;IAAO;IAAO;IAAM;CAAM;AACrG,MAAMC,2BAA8C;IAClDC,YAAY;IACZC,iBAAiB;IACjBC,SAASJ,gBAAgBK,GAAG,CAAC,CAACC,WAAaP,wBAAwBO;AACrE;AAeA,OAAO,MAAMC,yCAA2BX,cAAiCK,0BAA0B;AAEnG,OAAO,SAASO;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,uBAAuBV,UAAU;IAC7D,IAAIY,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AAEA;;;CAGC,GACD,OAAO,SAASC,wBAAwBF,QAAkB;IACxD,MAAMG,oBAAoBL,uBAAuBT,eAAe;IAChE,IAAIW,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;;CAEC,GACD,OAAO,SAASI,0BAA0BC,KAAqC;IAC7E,MAAMX,MAAMX,QAAQ;QAClB,OAAO;YACLI,YAAYkB,MAAMlB,UAAU,KAAKQ,YAAYT,yBAAyBC,UAAU,GAAGkB,MAAMlB,UAAU;YACnGC,iBACEiB,MAAMjB,eAAe,KAAKO,YAAYT,yBAAyBE,eAAe,GAAGiB,MAAMjB,eAAe;YACxGC,SAASgB,MAAMhB,OAAO,KAAKM,YAAYT,yBAAyBG,OAAO,GAAGgB,MAAMhB,OAAO;QACzF;IACF,GAAG;QAACgB,MAAMlB,UAAU;QAAEkB,MAAMjB,eAAe;QAAEiB,MAAMhB,OAAO;KAAC;IAE3D,qBAAO,KAACG,yBAAyBc,QAAQ;QAACC,OAAOb;kBAAMW,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 { createContext, ReactElement, ReactNode, useContext, useMemo } from 'react';\nimport { buildRelativeTimeOption, TimeOption } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/spec';\n\nconst DEFAULT_OPTIONS: DurationString[] = ['5m', '15m', '30m', '1h', '6h', '12h', '24h', '7d', '14d'];\nconst defaultTimeRangeSettings: TimeRangeSettings = {\n showCustom: true,\n showZoomButtons: true,\n options: DEFAULT_OPTIONS.map((duration) => buildRelativeTimeOption(duration)),\n};\n\nexport interface TimeRangeSettingsProviderProps {\n showCustom?: boolean;\n showZoomButtons?: boolean;\n options?: TimeOption[];\n children: ReactNode;\n}\n\nexport interface TimeRangeSettings {\n showCustom: boolean;\n showZoomButtons: 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 * 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 options: props.options === undefined ? defaultTimeRangeSettings.options : props.options,\n };\n }, [props.showCustom, props.showZoomButtons, props.options]);\n\n return <TimeRangeSettingsContext.Provider value={ctx}>{props.children}</TimeRangeSettingsContext.Provider>;\n}\n"],"names":["createContext","useContext","useMemo","buildRelativeTimeOption","DEFAULT_OPTIONS","defaultTimeRangeSettings","showCustom","showZoomButtons","options","map","duration","TimeRangeSettingsContext","useTimeRangeSettingsContext","ctx","undefined","Error","useTimeRangeSettings","useShowCustomTimeRangeSetting","override","showCustomTimeRange","useShowZoomRangeSetting","showZoomTimeRange","useTimeRangeOptionsSetting","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,aAAa,EAA2BC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AACpF,SAASC,uBAAuB,QAAoB,yBAAyB;AAG7E,MAAMC,kBAAoC;IAAC;IAAM;IAAO;IAAO;IAAM;IAAM;IAAO;IAAO;IAAM;CAAM;AACrG,MAAMC,2BAA8C;IAClDC,YAAY;IACZC,iBAAiB;IACjBC,SAASJ,gBAAgBK,GAAG,CAAC,CAACC,WAAaP,wBAAwBO;AACrE;AAeA,OAAO,MAAMC,yCAA2BX,cAAiCK,0BAA0B;AAEnG,OAAO,SAASO;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,uBAAuBV,UAAU;IAC7D,IAAIY,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AAEA;;;CAGC,GACD,OAAO,SAASC,wBAAwBF,QAAkB;IACxD,MAAMG,oBAAoBL,uBAAuBT,eAAe;IAChE,IAAIW,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;;CAEC,GACD,OAAO,SAASI,0BAA0BC,KAAqC;IAC7E,MAAMX,MAAMX,QAAQ;QAClB,OAAO;YACLI,YAAYkB,MAAMlB,UAAU,KAAKQ,YAAYT,yBAAyBC,UAAU,GAAGkB,MAAMlB,UAAU;YACnGC,iBACEiB,MAAMjB,eAAe,KAAKO,YAAYT,yBAAyBE,eAAe,GAAGiB,MAAMjB,eAAe;YACxGC,SAASgB,MAAMhB,OAAO,KAAKM,YAAYT,yBAAyBG,OAAO,GAAGgB,MAAMhB,OAAO;QACzF;IACF,GAAG;QAACgB,MAAMlB,UAAU;QAAEkB,MAAMjB,eAAe;QAAEiB,MAAMhB,OAAO;KAAC;IAE3D,qBAAO,KAACG,yBAAyBc,QAAQ;QAACC,OAAOb;kBAAMW,MAAMG,QAAQ;;AACvE"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,8 +11,7 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import { fetch } from '@perses-dev/core'; // TODO
14
+ import { fetch } from '@perses-dev/client';
15
15
  import { createContext, useContext } from 'react';
16
16
  export const UsageMetricsContext = /*#__PURE__*/ createContext(undefined);
17
17
  export const useUsageMetricsContext = ()=>{
@@ -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 { fetch } from '@perses-dev/core'; // TODO\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}\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 fetch(`${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 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 };\n\n return <UsageMetricsContext.Provider value={ctx}>{children}</UsageMetricsContext.Provider>;\n};\n"],"names":["fetch","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","apiPrefix","method","headers","body","project","dashboard","render_time","render_errors","UsageMetricsProvider","children","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,SA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MAAMmB,uBAAuB,CAAC,EAAER,SAAS,EAAEI,OAAO,EAAEC,SAAS,EAAEI,QAAQ,EAAqB;IACjG,MAAM/B,MAAoB;QACxB0B,SAASA;QACTC,WAAWA;QACXhB,kBAAkB;QAClBQ,iBAAiBF,KAAKC,GAAG;QACzBF,kBAAkB;QAClBT,gBAAgB,IAAIyB;QACpBV;IACF;IAEA,qBAAO,KAAC1B,oBAAoBqC,QAAQ;QAACC,OAAOlC;kBAAM+B;;AACpD,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 { fetch } 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}\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 fetch(`${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 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 };\n\n return <UsageMetricsContext.Provider value={ctx}>{children}</UsageMetricsContext.Provider>;\n};\n"],"names":["fetch","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","apiPrefix","method","headers","body","project","dashboard","render_time","render_errors","UsageMetricsProvider","children","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;A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ACvC;IACF;AACF;AAEA,OAAO,MAAMmB,uBAAuB,CAAC,EAAER,SAAS,EAAEI,OAAO,EAAEC,SAAS,EAAEI,QAAQ,EAAqB;IACjG,MAAM/B,MAAoB;QACxB0B,SAASA;QACTC,WAAWA;QACXhB,kBAAkB;QAClBQ,iBAAiBF,KAAKC,GAAG;QACzBF,kBAAkB;QAClBT,gBAAgB,IAAIyB;QACpBV;IACF;IAEA,qBAAO,KAAC1B,oBAAoBqC,QAAQ;QAACC,OAAOlC;kBAAM+B;;AACpD,EAAE"}
@@ -0,0 +1,11 @@
1
+ import { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';
2
+ import { UseQueryResult } from '@tanstack/react-query';
3
+ export type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;
4
+ export declare const ALERTS_QUERY_KEY = "AlertsQuery";
5
+ /**
6
+ * Run an alerts query using an AlertsQuery plugin and return the results.
7
+ * Alerts represent current state and are NOT time-range dependent.
8
+ * @param definitions: dashboard definition for an alerts query
9
+ */
10
+ export declare function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>>;
11
+ //# sourceMappingURL=alerts-queries.d.ts.map
@@ -0,0 +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;AAO7E,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"}
@@ -0,0 +1,89 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { useQueries } from '@tanstack/react-query';
14
+ import { useDatasourceStore } from './datasources';
15
+ import { usePluginRegistry, usePlugins } from './plugin-registry';
16
+ import { useAllVariableValues } from './variables';
17
+ import { filterVariableStateMap, getVariableValuesKey } from './utils';
18
+ export const ALERTS_QUERY_KEY = 'AlertsQuery';
19
+ /**
20
+ * Run an alerts query using an AlertsQuery plugin and return the results.
21
+ * Alerts represent current state and are NOT time-range dependent.
22
+ * @param definitions: dashboard definition for an alerts query
23
+ */ export function useAlertsQueries(definitions) {
24
+ const { getPlugin } = usePluginRegistry();
25
+ const context = useAlertsQueryContext();
26
+ const pluginLoaderResponse = usePlugins('AlertsQuery', definitions.map((d)=>({
27
+ kind: d.spec.plugin.kind
28
+ })));
29
+ return useQueries({
30
+ queries: definitions.map((definition, idx)=>{
31
+ const plugin = pluginLoaderResponse[idx]?.data;
32
+ const { queryEnabled, queryKey } = getQueryOptions({
33
+ context,
34
+ definition,
35
+ plugin
36
+ });
37
+ const alertsQueryKind = definition?.spec?.plugin?.kind;
38
+ return {
39
+ enabled: queryEnabled,
40
+ queryKey: queryKey,
41
+ refetchOnMount: false,
42
+ refetchOnWindowFocus: false,
43
+ refetchOnReconnect: false,
44
+ staleTime: 60_000,
45
+ queryFn: async ({ signal })=>{
46
+ const plugin = await getPlugin({
47
+ kind: ALERTS_QUERY_KEY,
48
+ name: alertsQueryKind
49
+ });
50
+ const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);
51
+ return data;
52
+ }
53
+ };
54
+ })
55
+ });
56
+ }
57
+ function getQueryOptions({ plugin, definition, context }) {
58
+ const { variableState } = context;
59
+ const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
60
+ const variableDependencies = dependencies?.variables;
61
+ const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);
62
+ const variablesValueKey = getVariableValuesKey(filteredVariabledState);
63
+ // Note: no absoluteTimeRange in query key since alerts are current state
64
+ const queryKey = [
65
+ 'query',
66
+ ALERTS_QUERY_KEY,
67
+ definition,
68
+ variablesValueKey
69
+ ];
70
+ let waitToLoad = false;
71
+ if (variableDependencies) {
72
+ waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
73
+ }
74
+ const queryEnabled = plugin !== undefined && !waitToLoad;
75
+ return {
76
+ queryKey,
77
+ queryEnabled
78
+ };
79
+ }
80
+ function useAlertsQueryContext() {
81
+ const variableState = useAllVariableValues();
82
+ const datasourceStore = useDatasourceStore();
83
+ return {
84
+ variableState,
85
+ datasourceStore
86
+ };
87
+ }
88
+
89
+ //# sourceMappingURL=alerts-queries.js.map
@@ -0,0 +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';\nimport { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useAllVariableValues } from './variables';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\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","useAllVariableValues","filterVariableStateMap","getVariableValuesKey","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;AAE7E,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,iBAAiB,EAAEC,UAAU,QAAQ,oBAAoB;AAClE,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,UAAU;AAGvE,OAAO,MAAMC,mBAAmB,cAAc;AAE9C;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAoC;IACnE,MAAM,EAAEC,SAAS,EAAE,GAAGR;IACtB,MAAMS,UAAUC;IAEhB,MAAMC,uBAAuBV,WAC3B,eACA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S,EAAE,EAAEC;IAClE;IAEA,MAAMvB,eAAeL,WAAW6B,aAAa,CAACJ;IAC9C,OAAO;QACLnB;QACAD;IACF;AACF;AAEA,SAASX;IACP,MAAMwB,gBAAgBhC;IACtB,MAAM4C,kBAAkB/C;IAExB,OAAO;QACLmC;QACAY;IACF;AACF"}
@@ -0,0 +1,6 @@
1
+ import { AnnotationData, AnnotationSpec } from '@perses-dev/spec';
2
+ import { UseQueryResult } from '@tanstack/react-query';
3
+ export declare const ANNOTATION_KEY = "Annotation";
4
+ export declare function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>>;
5
+ export declare function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]>;
6
+ //# sourceMappingURL=annotations.d.ts.map
@@ -0,0 +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;AAQvF,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"}
@@ -0,0 +1,129 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { useQueries, useQuery } from '@tanstack/react-query';
14
+ import { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';
15
+ import { useTimeRange } from './TimeRangeProvider';
16
+ import { useAllVariableValues } from './variables';
17
+ import { useDatasourceStore } from './datasources';
18
+ import { filterVariableStateMap, getVariableValuesKey } from './utils';
19
+ export const ANNOTATION_KEY = 'Annotation';
20
+ function useAnnotationContext() {
21
+ const { absoluteTimeRange } = useTimeRange();
22
+ const variableState = useAllVariableValues();
23
+ const datasourceStore = useDatasourceStore();
24
+ return {
25
+ variableState,
26
+ datasourceStore,
27
+ absoluteTimeRange
28
+ };
29
+ }
30
+ function getQueryOptions({ plugin, definition, context }) {
31
+ const { variableState, absoluteTimeRange } = context;
32
+ const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.plugin.spec, context) : {};
33
+ const variableDependencies = dependencies?.variables;
34
+ const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);
35
+ const variablesValueKey = getVariableValuesKey(filteredVariableState);
36
+ const queryKey = [
37
+ ANNOTATION_KEY,
38
+ definition,
39
+ absoluteTimeRange,
40
+ variablesValueKey
41
+ ];
42
+ let waitToLoad = false;
43
+ if (variableDependencies) {
44
+ waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
45
+ }
46
+ const queryEnabled = plugin !== undefined && !waitToLoad;
47
+ return {
48
+ queryKey,
49
+ queryEnabled
50
+ };
51
+ }
52
+ export function useAnnotations(definitions) {
53
+ const { getPlugin } = usePluginRegistry();
54
+ const context = useAnnotationContext();
55
+ const pluginLoaderResponse = usePlugins('Annotation', definitions.map((d)=>({
56
+ kind: d.plugin.kind
57
+ })));
58
+ // useQueries() handles data fetching from query plugins
59
+ return useQueries({
60
+ queries: definitions.map((definition, idx)=>{
61
+ const plugin = pluginLoaderResponse[idx]?.data;
62
+ const { queryEnabled, queryKey } = getQueryOptions({
63
+ context,
64
+ definition,
65
+ plugin
66
+ });
67
+ const annotationKind = definition?.plugin?.kind;
68
+ return {
69
+ enabled: queryEnabled,
70
+ queryKey: queryKey,
71
+ refetchOnMount: false,
72
+ refetchOnWindowFocus: false,
73
+ refetchOnReconnect: false,
74
+ staleTime: Infinity,
75
+ queryFn: async ({ signal })=>{
76
+ const plugin = await getPlugin({
77
+ kind: ANNOTATION_KEY,
78
+ name: annotationKind
79
+ });
80
+ const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);
81
+ return data;
82
+ }
83
+ };
84
+ })
85
+ });
86
+ }
87
+ export function useAnnotationData(spec) {
88
+ const { data: annotationPlugin } = usePlugin('Annotation', spec.plugin.kind);
89
+ const datasourceStore = useDatasourceStore();
90
+ const allVariables = useAllVariableValues();
91
+ const { absoluteTimeRange: timeRange } = useTimeRange();
92
+ const variablePluginCtx = {
93
+ absoluteTimeRange: timeRange,
94
+ datasourceStore,
95
+ variableState: allVariables
96
+ };
97
+ let dependsOnVariables = Object.keys(allVariables); // Default to all variables
98
+ if (annotationPlugin?.dependsOn) {
99
+ const dependencies = annotationPlugin.dependsOn(spec.plugin.spec, variablePluginCtx);
100
+ dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;
101
+ }
102
+ const variables = useAllVariableValues(dependsOnVariables);
103
+ let waitToLoad = false;
104
+ if (dependsOnVariables) {
105
+ waitToLoad = dependsOnVariables.some((v)=>variables[v]?.loading);
106
+ }
107
+ const variablesValueKey = getVariableValuesKey(variables);
108
+ return useQuery({
109
+ queryKey: [
110
+ 'annotation',
111
+ spec,
112
+ timeRange,
113
+ variablesValueKey
114
+ ],
115
+ queryFn: async ({ signal })=>{
116
+ const resp = await annotationPlugin?.getAnnotationData(spec.plugin.spec, {
117
+ ...variablePluginCtx,
118
+ variableState: variables
119
+ }, signal);
120
+ if (!resp?.length) {
121
+ return [];
122
+ }
123
+ return resp;
124
+ },
125
+ enabled: !!annotationPlugin || waitToLoad
126
+ });
127
+ }
128
+
129
+ //# sourceMappingURL=annotations.js.map
@@ -0,0 +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';\nimport { AnnotationContext, AnnotationPlugin } from '../model';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useAllVariableValues } from './variables';\nimport { useDatasourceStore } from './datasources';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\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","usePlugin","usePluginRegistry","usePlugins","useTimeRange","useAllVariableValues","useDatasourceStore","filterVariableStateMap","getVariableValuesKey","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;AAEvF,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,oBAAoB;AAC7E,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,UAAU;AAEvE,OAAO,MAAMC,iBAAiB,aAAa;AAE3C,SAASC;IACP,MAAM,EAAEC,iBAAiB,EAAE,GAAGP;IAC9B,MAAMQ,gBAAgBP;IACtB,MAAMQ,kBAAkBP;IAExB,OAAO;QACLM;QACAC;QACAF;IACF;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YACX;YACA,OAAOD;QACT;QACAlB,SAAS,CAAC,CAACW,oBAAoB5B;IACjC;AACF"}
@@ -3,6 +3,12 @@ import { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';
3
3
  import { UseQueryResult } from '@tanstack/react-query';
4
4
  export interface DatasourceStore {
5
5
  getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;
6
+ /**
7
+ * Gets a cached datasource spec synchronously if available.
8
+ * Used by variable dependency resolution to avoid async calls in dependsOn().
9
+ * Returns undefined if the spec is not cached.
10
+ */
11
+ getDatasourceSpecSync?(selector: DatasourceSelector): DatasourceSpec | undefined;
6
12
  /**
7
13
  * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.
8
14
  */
@@ -1 +1 @@
1
- {"version":3,"file":"datasources.d.ts","sourceRoot":"","sources":["../../src/runtime/datasources.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGjE,MAAM,WAAW,eAAe;IAE9B,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAErE;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E;;OAEG;IACH,yBAAyB,CAAC,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAAC;IAE9F;;OAEG;IACH,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEtD;;OAEG;IACH,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,CAAC;IAEvE;;OAEG;IACH,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEtD;;OAEG;IAC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