@perses-dev/plugin-system 0.46.0 → 0.47.0

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 (188) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +70 -99
  2. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -1
  3. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
  4. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +49 -19
  5. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +1 -0
  6. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +10 -71
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +408 -376
  8. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +2 -2
  9. package/dist/cjs/components/Variables/variable-model.js +24 -22
  10. package/dist/cjs/context/ProjectStoreProvider.js +7 -4
  11. package/dist/cjs/context/ValidationProvider.js +69 -0
  12. package/dist/cjs/context/index.js +1 -0
  13. package/dist/cjs/index.js +0 -1
  14. package/dist/cjs/runtime/QueryCountProvider.js +83 -0
  15. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +100 -0
  16. package/dist/cjs/runtime/TimeRangeProvider/index.js +2 -1
  17. package/dist/cjs/runtime/builtin-variables.js +1 -1
  18. package/dist/cjs/runtime/datasources.js +22 -13
  19. package/dist/cjs/runtime/index.js +3 -2
  20. package/dist/cjs/runtime/plugin-registry.js +33 -22
  21. package/dist/cjs/runtime/time-series-queries.js +3 -3
  22. package/dist/cjs/runtime/trace-queries.js +5 -1
  23. package/dist/cjs/runtime/{template-variables.js → variables.js} +19 -19
  24. package/dist/cjs/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +8 -8
  25. package/dist/cjs/stories/shared-utils/decorators/index.js +2 -2
  26. package/dist/cjs/test/mock-data.js +25 -4
  27. package/dist/cjs/test/render.js +1 -9
  28. package/dist/cjs/test/test-plugins/bert/index.js +20 -19
  29. package/dist/cjs/utils/variables.js +23 -23
  30. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +2 -2
  31. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  32. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +71 -100
  33. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  34. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -3
  35. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  36. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -1
  37. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
  38. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  39. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
  40. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  41. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +3 -1
  42. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  43. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +50 -20
  44. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  45. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  46. package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -0
  47. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  48. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -2
  49. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  50. package/dist/components/TimeRangeControls/TimeRangeControls.js +12 -70
  51. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  52. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  53. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +411 -379
  54. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  55. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +2 -2
  56. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  57. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  58. package/dist/components/Variables/variable-model.js +25 -23
  59. package/dist/components/Variables/variable-model.js.map +1 -1
  60. package/dist/context/ProjectStoreProvider.d.ts.map +1 -1
  61. package/dist/context/ProjectStoreProvider.js +7 -4
  62. package/dist/context/ProjectStoreProvider.js.map +1 -1
  63. package/dist/context/ValidationProvider.d.ts +19 -0
  64. package/dist/context/ValidationProvider.d.ts.map +1 -0
  65. package/dist/context/ValidationProvider.js +52 -0
  66. package/dist/context/ValidationProvider.js.map +1 -0
  67. package/dist/context/index.d.ts +1 -0
  68. package/dist/context/index.d.ts.map +1 -1
  69. package/dist/context/index.js +1 -0
  70. package/dist/context/index.js.map +1 -1
  71. package/dist/index.d.ts +0 -1
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +0 -1
  74. package/dist/index.js.map +1 -1
  75. package/dist/model/panels.d.ts +2 -2
  76. package/dist/model/panels.d.ts.map +1 -1
  77. package/dist/model/panels.js.map +1 -1
  78. package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
  79. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  80. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  81. package/dist/runtime/QueryCountProvider.d.ts +9 -0
  82. package/dist/runtime/QueryCountProvider.d.ts.map +1 -0
  83. package/dist/{validation/duration.js → runtime/QueryCountProvider.js} +13 -4
  84. package/dist/runtime/QueryCountProvider.js.map +1 -0
  85. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +32 -0
  86. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -0
  87. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +82 -0
  88. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -0
  89. package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
  90. package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
  91. package/dist/runtime/TimeRangeProvider/index.js +2 -1
  92. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  93. package/dist/runtime/builtin-variables.d.ts +1 -1
  94. package/dist/runtime/builtin-variables.d.ts.map +1 -1
  95. package/dist/runtime/builtin-variables.js +1 -1
  96. package/dist/runtime/builtin-variables.js.map +1 -1
  97. package/dist/runtime/datasources.d.ts.map +1 -1
  98. package/dist/runtime/datasources.js +22 -13
  99. package/dist/runtime/datasources.js.map +1 -1
  100. package/dist/runtime/index.d.ts +2 -1
  101. package/dist/runtime/index.d.ts.map +1 -1
  102. package/dist/runtime/index.js +3 -2
  103. package/dist/runtime/index.js.map +1 -1
  104. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  105. package/dist/runtime/plugin-registry.js +33 -22
  106. package/dist/runtime/plugin-registry.js.map +1 -1
  107. package/dist/runtime/time-series-queries.d.ts +2 -2
  108. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  109. package/dist/runtime/time-series-queries.js +3 -3
  110. package/dist/runtime/time-series-queries.js.map +1 -1
  111. package/dist/runtime/trace-queries.d.ts.map +1 -1
  112. package/dist/runtime/trace-queries.js +5 -1
  113. package/dist/runtime/trace-queries.js.map +1 -1
  114. package/dist/runtime/{template-variables.d.ts → variables.d.ts} +4 -4
  115. package/dist/runtime/variables.d.ts.map +1 -0
  116. package/dist/runtime/{template-variables.js → variables.js} +18 -17
  117. package/dist/runtime/variables.js.map +1 -0
  118. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +12 -0
  119. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +1 -0
  120. package/dist/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +9 -9
  121. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -0
  122. package/dist/stories/shared-utils/decorators/index.d.ts +1 -1
  123. package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -1
  124. package/dist/stories/shared-utils/decorators/index.js +2 -2
  125. package/dist/stories/shared-utils/decorators/index.js.map +1 -1
  126. package/dist/test/mock-data.d.ts.map +1 -1
  127. package/dist/test/mock-data.js +25 -4
  128. package/dist/test/mock-data.js.map +1 -1
  129. package/dist/test/render.d.ts.map +1 -1
  130. package/dist/test/render.js +1 -9
  131. package/dist/test/render.js.map +1 -1
  132. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  133. package/dist/test/test-plugins/bert/index.js +20 -19
  134. package/dist/test/test-plugins/bert/index.js.map +1 -1
  135. package/dist/utils/variables.d.ts +4 -4
  136. package/dist/utils/variables.d.ts.map +1 -1
  137. package/dist/utils/variables.js +18 -18
  138. package/dist/utils/variables.js.map +1 -1
  139. package/package.json +5 -5
  140. package/dist/cjs/validation/datasource.js +0 -30
  141. package/dist/cjs/validation/duration.js +0 -25
  142. package/dist/cjs/validation/index.js +0 -34
  143. package/dist/cjs/validation/resource.js +0 -24
  144. package/dist/cjs/validation/role.js +0 -86
  145. package/dist/cjs/validation/rolebinding.js +0 -55
  146. package/dist/cjs/validation/secret.js +0 -176
  147. package/dist/cjs/validation/user.js +0 -46
  148. package/dist/cjs/validation/variable.js +0 -48
  149. package/dist/runtime/template-variables.d.ts.map +0 -1
  150. package/dist/runtime/template-variables.js.map +0 -1
  151. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts +0 -12
  152. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts.map +0 -1
  153. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +0 -1
  154. package/dist/validation/datasource.d.ts +0 -19
  155. package/dist/validation/datasource.d.ts.map +0 -1
  156. package/dist/validation/datasource.js +0 -22
  157. package/dist/validation/datasource.js.map +0 -1
  158. package/dist/validation/duration.d.ts +0 -3
  159. package/dist/validation/duration.d.ts.map +0 -1
  160. package/dist/validation/duration.js.map +0 -1
  161. package/dist/validation/index.d.ts +0 -6
  162. package/dist/validation/index.d.ts.map +0 -1
  163. package/dist/validation/index.js +0 -19
  164. package/dist/validation/index.js.map +0 -1
  165. package/dist/validation/resource.d.ts +0 -3
  166. package/dist/validation/resource.d.ts.map +0 -1
  167. package/dist/validation/resource.js +0 -16
  168. package/dist/validation/resource.js.map +0 -1
  169. package/dist/validation/role.d.ts +0 -228
  170. package/dist/validation/role.d.ts.map +0 -1
  171. package/dist/validation/role.js +0 -67
  172. package/dist/validation/role.js.map +0 -1
  173. package/dist/validation/rolebinding.d.ts +0 -137
  174. package/dist/validation/rolebinding.d.ts.map +0 -1
  175. package/dist/validation/rolebinding.js +0 -47
  176. package/dist/validation/rolebinding.js.map +0 -1
  177. package/dist/validation/secret.d.ts +0 -964
  178. package/dist/validation/secret.d.ts.map +0 -1
  179. package/dist/validation/secret.js +0 -157
  180. package/dist/validation/secret.js.map +0 -1
  181. package/dist/validation/user.d.ts +0 -93
  182. package/dist/validation/user.d.ts.map +0 -1
  183. package/dist/validation/user.js +0 -38
  184. package/dist/validation/user.js.map +0 -1
  185. package/dist/validation/variable.d.ts +0 -96
  186. package/dist/validation/variable.d.ts.map +0 -1
  187. package/dist/validation/variable.js +0 -40
  188. package/dist/validation/variable.js.map +0 -1
@@ -155,10 +155,10 @@ function VariablePreview(props) {
155
155
  },
156
156
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {})
157
157
  }),
158
- values === null || values === void 0 ? void 0 : values.slice(0, maxValues).map((val)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
158
+ values === null || values === void 0 ? void 0 : values.slice(0, maxValues).map((val, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
159
159
  size: "small",
160
160
  label: val
161
- }, val)),
161
+ }, index)),
162
162
  notShown > 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
163
163
  onClick: showAll,
164
164
  variant: "outlined",
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -64,7 +64,7 @@ function filterVariableList(data, capturedRegexp) {
64
64
  function useListVariablePluginValues(definition) {
65
65
  const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
66
66
  const datasourceStore = (0, _runtime.useDatasourceStore)();
67
- const allVariables = (0, _runtime.useVariableValues)();
67
+ const allVariables = (0, _runtime.useAllVariableValues)();
68
68
  const { absoluteTimeRange: timeRange, refreshKey } = (0, _runtime.useTimeRange)();
69
69
  const variablePluginCtx = {
70
70
  timeRange,
@@ -78,7 +78,7 @@ function useListVariablePluginValues(definition) {
78
78
  const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
79
79
  dependsOnVariables = dependencies.variables;
80
80
  }
81
- const variables = (0, _runtime.useVariableValues)(dependsOnVariables);
81
+ const variables = (0, _runtime.useAllVariableValues)(dependsOnVariables);
82
82
  let waitToLoad = false;
83
83
  if (dependsOnVariables) {
84
84
  waitToLoad = dependsOnVariables.some((v)=>{
@@ -87,25 +87,27 @@ function useListVariablePluginValues(definition) {
87
87
  });
88
88
  }
89
89
  const variablesValueKey = getVariableValuesKey(variables);
90
- return (0, _reactquery.useQuery)([
91
- definition,
92
- variablesValueKey,
93
- timeRange,
94
- refreshKey
95
- ], async ()=>{
96
- const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
97
- datasourceStore,
98
- variables,
99
- timeRange
100
- }));
101
- if (resp === undefined) {
102
- return [];
103
- }
104
- if (!capturingRegexp) {
105
- return resp.data;
106
- }
107
- return filterVariableList(resp.data, capturingRegexp);
108
- }, {
90
+ return (0, _reactquery.useQuery)({
91
+ queryKey: [
92
+ definition,
93
+ variablesValueKey,
94
+ timeRange,
95
+ refreshKey
96
+ ],
97
+ queryFn: async ()=>{
98
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
99
+ datasourceStore,
100
+ variables,
101
+ timeRange
102
+ }));
103
+ if (resp === undefined) {
104
+ return [];
105
+ }
106
+ if (!capturingRegexp) {
107
+ return resp.data;
108
+ }
109
+ return filterVariableList(resp.data, capturingRegexp);
110
+ },
109
111
  enabled: !!variablePlugin || waitToLoad
110
112
  });
111
113
  }
@@ -41,10 +41,13 @@ const _core = require("@perses-dev/core");
41
41
  const _queryparams = require("./query-params");
42
42
  const ProjectStoreContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
43
43
  function useProjectList() {
44
- return (0, _reactquery.useQuery)([
45
- 'projects'
46
- ], ()=>{
47
- return (0, _core.fetchJson)('/api/v1/projects');
44
+ return (0, _reactquery.useQuery)({
45
+ queryKey: [
46
+ 'projects'
47
+ ],
48
+ queryFn: ()=>{
49
+ return (0, _core.fetchJson)('/api/v1/projects');
50
+ }
48
51
  });
49
52
  }
50
53
  function useProjectStore() {
@@ -0,0 +1,69 @@
1
+ // Copyright 2024 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ ValidationProvider: function() {
25
+ return ValidationProvider;
26
+ },
27
+ ValidationSchemasContext: function() {
28
+ return ValidationSchemasContext;
29
+ },
30
+ useValidationSchemas: function() {
31
+ return useValidationSchemas;
32
+ }
33
+ });
34
+ const _jsxruntime = require("react/jsx-runtime");
35
+ const _react = require("react");
36
+ const _core = require("@perses-dev/core");
37
+ const ValidationSchemasContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
38
+ function useValidationSchemas() {
39
+ const ctx = (0, _react.useContext)(ValidationSchemasContext);
40
+ if (ctx === undefined) {
41
+ throw new Error('No ValidationSchemasContext found. Did you forget a Provider?');
42
+ }
43
+ return ctx;
44
+ }
45
+ function ValidationProvider({ children }) {
46
+ const [datasourceEditorSchema, setDatasourceEditorSchema] = (0, _react.useState)(_core.datasourceDefinitionSchema);
47
+ const [panelEditorSchema, setPanelEditorSchema] = (0, _react.useState)(_core.panelEditorSchema);
48
+ const [variableEditorSchema, setVariableEditorSchema] = (0, _react.useState)(_core.variableDefinitionSchema);
49
+ function setDatasourceEditorSchemaPlugin(pluginSchema) {
50
+ setDatasourceEditorSchema((0, _core.buildDatasourceDefinitionSchema)(pluginSchema));
51
+ }
52
+ function setPanelEditorSchemaPlugin(pluginSchema) {
53
+ setPanelEditorSchema((0, _core.buildPanelEditorSchema)(pluginSchema));
54
+ }
55
+ function setVariableEditorSchemaPlugin(pluginSchema) {
56
+ setVariableEditorSchema((0, _core.buildVariableDefinitionSchema)(pluginSchema));
57
+ }
58
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(ValidationSchemasContext.Provider, {
59
+ value: {
60
+ datasourceEditorSchema,
61
+ panelEditorSchema,
62
+ variableEditorSchema,
63
+ setDatasourceEditorSchemaPlugin,
64
+ setPanelEditorSchemaPlugin,
65
+ setVariableEditorSchemaPlugin
66
+ },
67
+ children: children
68
+ });
69
+ }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _export_star(require("./ProjectStoreProvider"), exports);
18
+ _export_star(require("./ValidationProvider"), exports);
18
19
  function _export_star(from, to) {
19
20
  Object.keys(from).forEach(function(k) {
20
21
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
package/dist/cjs/index.js CHANGED
@@ -20,7 +20,6 @@ _export_star(require("./model"), exports);
20
20
  _export_star(require("./runtime"), exports);
21
21
  _export_star(require("./test-utils"), exports);
22
22
  _export_star(require("./utils"), exports);
23
- _export_star(require("./validation"), exports);
24
23
  _export_star(require("./context"), exports);
25
24
  function _export_star(from, to) {
26
25
  Object.keys(from).forEach(function(k) {
@@ -0,0 +1,83 @@
1
+ // Copyright 2024 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ QueryCountProvider: function() {
25
+ return QueryCountProvider;
26
+ },
27
+ useQueryCountContext: function() {
28
+ return useQueryCountContext;
29
+ }
30
+ });
31
+ const _jsxruntime = require("react/jsx-runtime");
32
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
33
+ function _getRequireWildcardCache(nodeInterop) {
34
+ if (typeof WeakMap !== "function") return null;
35
+ var cacheBabelInterop = new WeakMap();
36
+ var cacheNodeInterop = new WeakMap();
37
+ return (_getRequireWildcardCache = function(nodeInterop) {
38
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
39
+ })(nodeInterop);
40
+ }
41
+ function _interop_require_wildcard(obj, nodeInterop) {
42
+ if (!nodeInterop && obj && obj.__esModule) {
43
+ return obj;
44
+ }
45
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
46
+ return {
47
+ default: obj
48
+ };
49
+ }
50
+ var cache = _getRequireWildcardCache(nodeInterop);
51
+ if (cache && cache.has(obj)) {
52
+ return cache.get(obj);
53
+ }
54
+ var newObj = {
55
+ __proto__: null
56
+ };
57
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
58
+ for(var key in obj){
59
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
60
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
61
+ if (desc && (desc.get || desc.set)) {
62
+ Object.defineProperty(newObj, key, desc);
63
+ } else {
64
+ newObj[key] = obj[key];
65
+ }
66
+ }
67
+ }
68
+ newObj.default = obj;
69
+ if (cache) {
70
+ cache.set(obj, newObj);
71
+ }
72
+ return newObj;
73
+ }
74
+ const QueryCountContext = /*#__PURE__*/ (0, _react.createContext)(0);
75
+ const QueryCountProvider = ({ queryCount, children })=>{
76
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryCountContext.Provider, {
77
+ value: queryCount,
78
+ children: children
79
+ });
80
+ };
81
+ const useQueryCountContext = ()=>{
82
+ return (0, _react.useContext)(QueryCountContext);
83
+ };
@@ -0,0 +1,100 @@
1
+ // Copyright 2024 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ TimeRangeSettingsContext: function() {
25
+ return TimeRangeSettingsContext;
26
+ },
27
+ TimeRangeSettingsProvider: function() {
28
+ return TimeRangeSettingsProvider;
29
+ },
30
+ useShowCustomTimeRangeSetting: function() {
31
+ return useShowCustomTimeRangeSetting;
32
+ },
33
+ useTimeRangeOptionsSetting: function() {
34
+ return useTimeRangeOptionsSetting;
35
+ },
36
+ useTimeRangeSettings: function() {
37
+ return useTimeRangeSettings;
38
+ },
39
+ useTimeRangeSettingsContext: function() {
40
+ return useTimeRangeSettingsContext;
41
+ }
42
+ });
43
+ const _jsxruntime = require("react/jsx-runtime");
44
+ const _react = require("react");
45
+ const _components = require("@perses-dev/components");
46
+ const DEFAULT_OPTIONS = [
47
+ '5m',
48
+ '15m',
49
+ '30m',
50
+ '1h',
51
+ '6h',
52
+ '12h',
53
+ '24h',
54
+ '7d',
55
+ '14d'
56
+ ];
57
+ const defaultTimeRangeSettings = {
58
+ showCustom: true,
59
+ options: DEFAULT_OPTIONS.map((duration)=>(0, _components.buildRelativeTimeOption)(duration))
60
+ };
61
+ const TimeRangeSettingsContext = /*#__PURE__*/ (0, _react.createContext)(defaultTimeRangeSettings);
62
+ function useTimeRangeSettingsContext() {
63
+ const ctx = (0, _react.useContext)(TimeRangeSettingsContext);
64
+ if (ctx === undefined) {
65
+ throw new Error('No TimeRangeContext found. Did you forget a Provider?');
66
+ }
67
+ return ctx;
68
+ }
69
+ function useTimeRangeSettings() {
70
+ return useTimeRangeSettingsContext();
71
+ }
72
+ function useShowCustomTimeRangeSetting(override) {
73
+ const showCustomTimeRange = useTimeRangeSettings().showCustom;
74
+ if (override !== undefined) {
75
+ return override;
76
+ }
77
+ return showCustomTimeRange;
78
+ }
79
+ function useTimeRangeOptionsSetting(override) {
80
+ const showCustomTimeRange = useTimeRangeSettings().options;
81
+ if (override !== undefined) {
82
+ return override;
83
+ }
84
+ return showCustomTimeRange;
85
+ }
86
+ function TimeRangeSettingsProvider(props) {
87
+ const ctx = (0, _react.useMemo)(()=>{
88
+ return {
89
+ showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,
90
+ options: props.options === undefined ? defaultTimeRangeSettings.options : props.options
91
+ };
92
+ }, [
93
+ props.showCustom,
94
+ props.options
95
+ ]);
96
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(TimeRangeSettingsContext.Provider, {
97
+ value: ctx,
98
+ children: props.children
99
+ });
100
+ }
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _export_star(require("./TimeRangeProvider"), exports);
18
18
  _export_star(require("./TimeRangeProviderWithQueryParams"), exports);
19
+ _export_star(require("./TimeRangeSettingsProvider"), exports);
19
20
  _export_star(require("./query-params"), exports);
20
21
  function _export_star(from, to) {
21
22
  Object.keys(from).forEach(function(k) {
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -49,23 +49,32 @@ function useDatasourceStore() {
49
49
  }
50
50
  function useListDatasourceSelectItems(datasourcePluginKind, project) {
51
51
  const { listDatasourceSelectItems } = useDatasourceStore();
52
- return (0, _reactquery.useQuery)([
53
- 'listDatasourceSelectItems',
54
- datasourcePluginKind,
55
- project
56
- ], ()=>listDatasourceSelectItems(datasourcePluginKind));
52
+ return (0, _reactquery.useQuery)({
53
+ queryKey: [
54
+ 'listDatasourceSelectItems',
55
+ datasourcePluginKind,
56
+ project
57
+ ],
58
+ queryFn: ()=>listDatasourceSelectItems(datasourcePluginKind)
59
+ });
57
60
  }
58
61
  function useDatasourceClient(selector) {
59
62
  const store = useDatasourceStore();
60
- return (0, _reactquery.useQuery)([
61
- 'getDatasourceClient',
62
- selector
63
- ], ()=>store.getDatasourceClient(selector));
63
+ return (0, _reactquery.useQuery)({
64
+ queryKey: [
65
+ 'getDatasourceClient',
66
+ selector
67
+ ],
68
+ queryFn: ()=>store.getDatasourceClient(selector)
69
+ });
64
70
  }
65
71
  function useDatasource(selector) {
66
72
  const store = useDatasourceStore();
67
- return (0, _reactquery.useQuery)([
68
- 'getDatasource',
69
- selector
70
- ], ()=>store.getDatasource(selector));
73
+ return (0, _reactquery.useQuery)({
74
+ queryKey: [
75
+ 'getDatasource',
76
+ selector
77
+ ],
78
+ queryFn: ()=>store.getDatasource(selector)
79
+ });
71
80
  }
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -17,11 +17,12 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _export_star(require("./builtin-variables"), exports);
18
18
  _export_star(require("./datasources"), exports);
19
19
  _export_star(require("./plugin-registry"), exports);
20
- _export_star(require("./template-variables"), exports);
20
+ _export_star(require("./variables"), exports);
21
21
  _export_star(require("./TimeRangeProvider"), exports);
22
22
  _export_star(require("./time-series-queries"), exports);
23
23
  _export_star(require("./trace-queries"), exports);
24
24
  _export_star(require("./DataQueriesProvider"), exports);
25
+ _export_star(require("./QueryCountProvider"), exports);
25
26
  function _export_star(from, to) {
26
27
  Object.keys(from).forEach(function(k) {
27
28
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -58,11 +58,15 @@ function usePlugin(pluginType, kind, options) {
58
58
  enabled: ((_options_enabled = options === null || options === void 0 ? void 0 : options.enabled) !== null && _options_enabled !== void 0 ? _options_enabled : true) && pluginType !== undefined && kind !== ''
59
59
  };
60
60
  const { getPlugin } = usePluginRegistry();
61
- return (0, _reactquery.useQuery)([
62
- 'getPlugin',
63
- pluginType,
64
- kind
65
- ], ()=>getPlugin(pluginType, kind), options);
61
+ return (0, _reactquery.useQuery)({
62
+ queryKey: [
63
+ 'getPlugin',
64
+ pluginType,
65
+ kind
66
+ ],
67
+ queryFn: ()=>getPlugin(pluginType, kind),
68
+ ...options
69
+ });
66
70
  }
67
71
  function usePlugins(pluginType, plugins) {
68
72
  const { getPlugin } = usePluginRegistry();
@@ -81,27 +85,34 @@ function usePlugins(pluginType, plugins) {
81
85
  }
82
86
  function useListPluginMetadata(pluginTypes, options) {
83
87
  const { listPluginMetadata } = usePluginRegistry();
84
- return (0, _reactquery.useQuery)([
85
- 'listPluginMetadata',
86
- pluginTypes
87
- ], ()=>listPluginMetadata(pluginTypes), options);
88
+ return (0, _reactquery.useQuery)({
89
+ queryKey: [
90
+ 'listPluginMetadata',
91
+ pluginTypes
92
+ ],
93
+ queryFn: ()=>listPluginMetadata(pluginTypes),
94
+ ...options
95
+ });
88
96
  }
89
97
  function usePluginBuiltinVariableDefinitions() {
90
98
  const { getPlugin, listPluginMetadata } = usePluginRegistry();
91
- return (0, _reactquery.useQuery)([
92
- 'usePluginBuiltinVariableDefinitions'
93
- ], async ()=>{
94
- const datasources = await listPluginMetadata([
95
- 'Datasource'
96
- ]);
97
- const datasourceKinds = new Set(datasources.map((datasource)=>datasource.kind));
98
- const result = [];
99
- for (const kind of datasourceKinds){
100
- const plugin = await getPlugin('Datasource', kind);
101
- if (plugin.getBuiltinVariableDefinitions) {
102
- plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
99
+ return (0, _reactquery.useQuery)({
100
+ queryKey: [
101
+ 'usePluginBuiltinVariableDefinitions'
102
+ ],
103
+ queryFn: async ()=>{
104
+ const datasources = await listPluginMetadata([
105
+ 'Datasource'
106
+ ]);
107
+ const datasourceKinds = new Set(datasources.map((datasource)=>datasource.kind));
108
+ const result = [];
109
+ for (const kind of datasourceKinds){
110
+ const plugin = await getPlugin('Datasource', kind);
111
+ if (plugin.getBuiltinVariableDefinitions) {
112
+ plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
113
+ }
103
114
  }
115
+ return result;
104
116
  }
105
- return result;
106
117
  });
107
118
  }
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -38,7 +38,7 @@ _export(exports, {
38
38
  }
39
39
  });
40
40
  const _reactquery = require("@tanstack/react-query");
41
- const _templatevariables = require("./template-variables");
41
+ const _variables = require("./variables");
42
42
  const _TimeRangeProvider = require("./TimeRangeProvider");
43
43
  const _datasources = require("./datasources");
44
44
  const _pluginregistry = require("./plugin-registry");
@@ -151,7 +151,7 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
151
151
  * Build the time series query context object from data available at runtime
152
152
  */ function useTimeSeriesQueryContext() {
153
153
  const { absoluteTimeRange, refreshKey } = (0, _TimeRangeProvider.useTimeRange)();
154
- const variableState = (0, _templatevariables.useVariableValues)();
154
+ const variableState = (0, _variables.useAllVariableValues)();
155
155
  const datasourceStore = (0, _datasources.useDatasourceStore)();
156
156
  return {
157
157
  timeRange: absoluteTimeRange,
@@ -69,7 +69,11 @@ function useTraceQueries(definitions) {
69
69
  const plugin = await getPlugin(TRACE_QUERY_KEY, traceQueryKind);
70
70
  const data = await plugin.getTraceData(definition.spec.plugin.spec, context);
71
71
  return data;
72
- }
72
+ },
73
+ // The data returned by getTraceData() contains circular dependencies (a span has a reference to the parent span, and the parent span has an array of child spans)
74
+ // Therefore structuralSharing must be turned off, otherwise the query is stuck in the 'fetching' state on re-fetch.
75
+ // Ref: https://github.com/TanStack/query/issues/6954#issuecomment-1962321426
76
+ structuralSharing: false
73
77
  };
74
78
  })
75
79
  });
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -21,18 +21,18 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- TemplateVariableContext: function() {
25
- return TemplateVariableContext;
24
+ VariableContext: function() {
25
+ return VariableContext;
26
26
  },
27
27
  VariableStoreStateMap: function() {
28
28
  return VariableStoreStateMap;
29
29
  },
30
+ useAllVariableValues: function() {
31
+ return useAllVariableValues;
32
+ },
30
33
  useReplaceVariablesInString: function() {
31
34
  return useReplaceVariablesInString;
32
35
  },
33
- useTemplateVariableValues: function() {
34
- return useTemplateVariableValues;
35
- },
36
36
  useVariableValues: function() {
37
37
  return useVariableValues;
38
38
  }
@@ -114,16 +114,16 @@ class VariableStoreStateMap {
114
114
  _define_property(this, "_state", {});
115
115
  }
116
116
  }
117
- const TemplateVariableContext = (0, _react.createContext)(undefined);
118
- function useTemplateVariableContext() {
119
- const ctx = (0, _react.useContext)(TemplateVariableContext);
117
+ const VariableContext = (0, _react.createContext)(undefined);
118
+ function useVariableContext() {
119
+ const ctx = (0, _react.useContext)(VariableContext);
120
120
  if (ctx === undefined) {
121
- throw new Error('No TemplateVariableContext found. Did you forget a Provider?');
121
+ throw new Error('No VariableContext found. Did you forget a Provider?');
122
122
  }
123
123
  return ctx;
124
124
  }
125
- function useTemplateVariableValues(names) {
126
- const { state } = useTemplateVariableContext();
125
+ function useVariableValues(names) {
126
+ const { state } = useVariableContext();
127
127
  const values = (0, _react.useMemo)(()=>{
128
128
  const values = {};
129
129
  names === null || names === void 0 ? void 0 : names.forEach((name)=>{
@@ -142,22 +142,22 @@ function useTemplateVariableValues(names) {
142
142
  }
143
143
  return values;
144
144
  }
145
- function useVariableValues(names) {
146
- const templateVariableValues = useTemplateVariableValues(names);
145
+ function useAllVariableValues(names) {
146
+ const variableValues = useVariableValues(names);
147
147
  const builtinVariableValues = (0, _builtinvariables.useBuiltinVariableValues)(names);
148
148
  return (0, _react.useMemo)(()=>{
149
149
  return {
150
- ...templateVariableValues,
150
+ ...variableValues,
151
151
  ...builtinVariableValues
152
152
  };
153
153
  }, [
154
- templateVariableValues,
154
+ variableValues,
155
155
  builtinVariableValues
156
156
  ]);
157
157
  }
158
158
  function useReplaceVariablesInString(str) {
159
- const variablesInString = str ? (0, _utils.parseTemplateVariables)(str) : [];
160
- const variableValues = useVariableValues(variablesInString);
159
+ const variablesInString = str ? (0, _utils.parseVariables)(str) : [];
160
+ const variableValues = useAllVariableValues(variablesInString);
161
161
  if (!str) return undefined;
162
- return (0, _utils.replaceTemplateVariables)(str, variableValues);
162
+ return (0, _utils.replaceVariables)(str, variableValues);
163
163
  }