@perses-dev/plugin-system 0.41.0 → 0.42.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 (166) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +26 -55
  2. package/dist/cjs/components/DatasourceSelect.js +22 -10
  3. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +1 -0
  4. package/dist/cjs/components/PluginEditor/PluginEditor.js +2 -1
  5. package/dist/cjs/components/ProjectSelect.js +96 -0
  6. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +14 -12
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +50 -2
  8. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +11 -8
  9. package/dist/cjs/components/index.js +1 -0
  10. package/dist/cjs/context/ProjectStoreProvider.js +78 -0
  11. package/dist/cjs/context/index.js +30 -0
  12. package/dist/cjs/context/query-params.js +49 -0
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/model/index.js +1 -0
  15. package/dist/cjs/model/trace-queries.js +16 -0
  16. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +17 -5
  17. package/dist/cjs/runtime/DataQueriesProvider/model.js +27 -7
  18. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +27 -18
  19. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +43 -0
  20. package/dist/cjs/runtime/TimeRangeProvider/index.js +1 -0
  21. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +7 -39
  22. package/dist/cjs/runtime/TimeRangeProvider/refresh-interval.js +30 -0
  23. package/dist/cjs/runtime/datasources.js +3 -2
  24. package/dist/cjs/runtime/index.js +1 -0
  25. package/dist/cjs/runtime/trace-queries.js +59 -0
  26. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +2 -1
  27. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +12 -0
  28. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +2 -2
  29. package/dist/cjs/test/mock-data.js +26 -3
  30. package/dist/cjs/validation/role.js +85 -0
  31. package/dist/cjs/validation/rolebinding.js +55 -0
  32. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +7 -7
  33. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  34. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +26 -16
  35. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  36. package/dist/components/DatasourceSelect.d.ts +1 -0
  37. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  38. package/dist/components/DatasourceSelect.js +22 -10
  39. package/dist/components/DatasourceSelect.js.map +1 -1
  40. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +1 -1
  41. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  42. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +1 -0
  43. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  44. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  45. package/dist/components/PluginEditor/PluginEditor.js +2 -1
  46. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  47. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  48. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  49. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  50. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +1 -0
  51. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  52. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  53. package/dist/components/ProjectSelect.d.ts +15 -0
  54. package/dist/components/ProjectSelect.d.ts.map +1 -0
  55. package/dist/components/ProjectSelect.js +91 -0
  56. package/dist/components/ProjectSelect.js.map +1 -0
  57. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +1 -1
  58. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +15 -13
  59. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -1
  60. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -2
  61. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  62. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +50 -2
  63. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  64. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +2 -1
  65. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  66. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +11 -8
  67. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  68. package/dist/components/index.d.ts +1 -0
  69. package/dist/components/index.d.ts.map +1 -1
  70. package/dist/components/index.js +1 -0
  71. package/dist/components/index.js.map +1 -1
  72. package/dist/context/ProjectStoreProvider.d.ts +16 -0
  73. package/dist/context/ProjectStoreProvider.d.ts.map +1 -0
  74. package/dist/context/ProjectStoreProvider.js +56 -0
  75. package/dist/context/ProjectStoreProvider.js.map +1 -0
  76. package/dist/context/index.d.ts +2 -0
  77. package/dist/context/index.d.ts.map +1 -0
  78. package/dist/context/index.js +15 -0
  79. package/dist/context/index.js.map +1 -0
  80. package/dist/context/query-params.d.ts +5 -0
  81. package/dist/context/query-params.d.ts.map +1 -0
  82. package/dist/context/query-params.js +41 -0
  83. package/dist/context/query-params.js.map +1 -0
  84. package/dist/index.d.ts +1 -0
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +1 -0
  87. package/dist/index.js.map +1 -1
  88. package/dist/model/index.d.ts +1 -0
  89. package/dist/model/index.d.ts.map +1 -1
  90. package/dist/model/index.js +1 -0
  91. package/dist/model/index.js.map +1 -1
  92. package/dist/model/plugin-base.d.ts +1 -0
  93. package/dist/model/plugin-base.d.ts.map +1 -1
  94. package/dist/model/plugin-base.js.map +1 -1
  95. package/dist/model/plugins.d.ts +2 -0
  96. package/dist/model/plugins.d.ts.map +1 -1
  97. package/dist/model/plugins.js.map +1 -1
  98. package/dist/model/trace-queries.d.ts +18 -0
  99. package/dist/model/trace-queries.d.ts.map +1 -0
  100. package/dist/model/trace-queries.js +15 -0
  101. package/dist/model/trace-queries.js.map +1 -0
  102. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  103. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +17 -5
  104. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  105. package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
  106. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  107. package/dist/runtime/DataQueriesProvider/model.js +27 -7
  108. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  109. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +4 -3
  110. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  111. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +28 -19
  112. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  113. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +9 -0
  114. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +1 -0
  115. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +30 -0
  116. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +1 -0
  117. package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
  118. package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
  119. package/dist/runtime/TimeRangeProvider/index.js +1 -0
  120. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  121. package/dist/runtime/TimeRangeProvider/query-params.d.ts +4 -4
  122. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  123. package/dist/runtime/TimeRangeProvider/query-params.js +8 -40
  124. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  125. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts +7 -0
  126. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -0
  127. package/dist/runtime/TimeRangeProvider/refresh-interval.js +25 -0
  128. package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -0
  129. package/dist/runtime/datasources.d.ts +29 -2
  130. package/dist/runtime/datasources.d.ts.map +1 -1
  131. package/dist/runtime/datasources.js +3 -2
  132. package/dist/runtime/datasources.js.map +1 -1
  133. package/dist/runtime/index.d.ts +1 -0
  134. package/dist/runtime/index.d.ts.map +1 -1
  135. package/dist/runtime/index.js +1 -0
  136. package/dist/runtime/index.js.map +1 -1
  137. package/dist/runtime/trace-queries.d.ts +10 -0
  138. package/dist/runtime/trace-queries.d.ts.map +1 -0
  139. package/dist/runtime/trace-queries.js +47 -0
  140. package/dist/runtime/trace-queries.js.map +1 -0
  141. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  142. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -1
  143. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  144. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
  145. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +12 -0
  146. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  147. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +2 -2
  148. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -1
  149. package/dist/stories/shared-utils/decorators/WithTimeRange.js +2 -2
  150. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  151. package/dist/test/mock-data.d.ts +2 -1
  152. package/dist/test/mock-data.d.ts.map +1 -1
  153. package/dist/test/mock-data.js +15 -0
  154. package/dist/test/mock-data.js.map +1 -1
  155. package/dist/utils/action.d.ts +1 -1
  156. package/dist/utils/action.d.ts.map +1 -1
  157. package/dist/utils/action.js.map +1 -1
  158. package/dist/validation/role.d.ts +228 -0
  159. package/dist/validation/role.d.ts.map +1 -0
  160. package/dist/validation/role.js +66 -0
  161. package/dist/validation/role.js.map +1 -0
  162. package/dist/validation/rolebinding.d.ts +137 -0
  163. package/dist/validation/rolebinding.d.ts.map +1 -0
  164. package/dist/validation/rolebinding.js +47 -0
  165. package/dist/validation/rolebinding.js.map +1 -0
  166. package/package.json +5 -4
@@ -0,0 +1,49 @@
1
+ // Copyright 2023 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
+ Object.defineProperty(exports, "useSetProjectParams", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return useSetProjectParams;
21
+ }
22
+ });
23
+ const _react = require("react");
24
+ const _usequeryparams = require("use-query-params");
25
+ function useSetProjectParams(enabledURLParams = true) {
26
+ const [query, setQuery] = (0, _usequeryparams.useQueryParams)({
27
+ project: ''
28
+ }, {
29
+ updateType: 'replaceIn'
30
+ });
31
+ const [projectState, setProjectState] = (0, _react.useState)('none');
32
+ const setProject = (0, _react.useCallback)((project)=>{
33
+ return setQuery({
34
+ project
35
+ });
36
+ }, [
37
+ setQuery
38
+ ]);
39
+ if (enabledURLParams) {
40
+ return {
41
+ project: query.project || 'none',
42
+ setProject
43
+ };
44
+ }
45
+ return {
46
+ project: projectState,
47
+ setProject: setProjectState
48
+ };
49
+ }
package/dist/cjs/index.js CHANGED
@@ -21,6 +21,7 @@ _export_star(require("./runtime"), exports);
21
21
  _export_star(require("./test-utils"), exports);
22
22
  _export_star(require("./utils"), exports);
23
23
  _export_star(require("./validation"), exports);
24
+ _export_star(require("./context"), exports);
24
25
  function _export_star(from, to) {
25
26
  Object.keys(from).forEach(function(k) {
26
27
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -21,6 +21,7 @@ _export_star(require("./plugins"), exports);
21
21
  _export_star(require("./plugin-base"), exports);
22
22
  _export_star(require("./plugin-loading"), exports);
23
23
  _export_star(require("./time-series-queries"), exports);
24
+ _export_star(require("./trace-queries"), exports);
24
25
  _export_star(require("./variables"), exports);
25
26
  function _export_star(from, to) {
26
27
  Object.keys(from).forEach(function(k) {
@@ -0,0 +1,16 @@
1
+ // Copyright 2023 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
+ });
@@ -37,6 +37,7 @@ _export(exports, {
37
37
  const _jsxruntime = require("react/jsx-runtime");
38
38
  const _react = require("react");
39
39
  const _timeseriesqueries = require("../time-series-queries");
40
+ const _tracequeries = require("../trace-queries");
40
41
  const _model = require("./model");
41
42
  const DataQueriesContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
42
43
  function useDataQueriesContext() {
@@ -49,11 +50,14 @@ function useDataQueriesContext() {
49
50
  function useDataQueries(queryType) {
50
51
  const ctx = useDataQueriesContext();
51
52
  // Filter the query results based on the specified query type
52
- const filteredQueryResults = ctx.queryResults.filter((queryResult)=>queryResult.definition.kind === queryType);
53
+ const filteredQueryResults = ctx.queryResults.filter((queryResult)=>{
54
+ var _queryResult_definition;
55
+ return (queryResult === null || queryResult === void 0 ? void 0 : (_queryResult_definition = queryResult.definition) === null || _queryResult_definition === void 0 ? void 0 : _queryResult_definition.kind) === queryType;
56
+ });
53
57
  // Filter the errors based on the specified query type
54
58
  const filteredErrors = ctx.errors.filter((errors, index)=>{
55
- var _ctx_queryResults_index;
56
- return ((_ctx_queryResults_index = ctx.queryResults[index]) === null || _ctx_queryResults_index === void 0 ? void 0 : _ctx_queryResults_index.definition.kind) === queryType;
59
+ var _ctx_queryResults_index, _ctx_queryResults_index_definition;
60
+ return ((_ctx_queryResults_index = ctx.queryResults[index]) === null || _ctx_queryResults_index === void 0 ? void 0 : (_ctx_queryResults_index_definition = _ctx_queryResults_index.definition) === null || _ctx_queryResults_index_definition === void 0 ? void 0 : _ctx_queryResults_index_definition.kind) === queryType;
57
61
  });
58
62
  // Create a new context object with the filtered results and errors
59
63
  const filteredCtx = {
@@ -67,6 +71,7 @@ function useDataQueries(queryType) {
67
71
  }
68
72
  function DataQueriesProvider(props) {
69
73
  const { definitions , options , children , queryOptions } = props;
74
+ // Returns a query kind, for example "TimeSeriesQuery" = getQueryType("PrometheusTimeSeriesQuery")
70
75
  const getQueryType = (0, _model.useQueryType)();
71
76
  const queryDefinitions = definitions.map((definition)=>{
72
77
  const type = getQueryType(definition.kind);
@@ -80,14 +85,19 @@ function DataQueriesProvider(props) {
80
85
  // Filter definitions for time series query and other future query plugins
81
86
  const timeSeriesQueries = queryDefinitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
82
87
  const timeSeriesResults = (0, _timeseriesqueries.useTimeSeriesQueries)(timeSeriesQueries, options, queryOptions);
88
+ const traceQueries = queryDefinitions.filter((definition)=>definition.kind === 'TraceQuery');
89
+ const traceResults = (0, _tracequeries.useTraceQueries)(traceQueries);
83
90
  const refetchAll = (0, _react.useCallback)(()=>{
84
91
  timeSeriesResults.forEach((result)=>result.refetch());
92
+ traceResults.forEach((result)=>result.refetch());
85
93
  }, [
86
- timeSeriesResults
94
+ timeSeriesResults,
95
+ traceResults
87
96
  ]);
88
97
  const ctx = (0, _react.useMemo)(()=>{
89
98
  const mergedQueryResults = [
90
- ...(0, _model.transformQueryResults)(timeSeriesResults, timeSeriesQueries)
99
+ ...(0, _model.transformQueryResults)(timeSeriesResults, timeSeriesQueries),
100
+ ...(0, _model.transformQueryResults)(traceResults, traceQueries)
91
101
  ];
92
102
  return {
93
103
  queryResults: mergedQueryResults,
@@ -99,6 +109,8 @@ function DataQueriesProvider(props) {
99
109
  }, [
100
110
  timeSeriesQueries,
101
111
  timeSeriesResults,
112
+ traceQueries,
113
+ traceResults,
102
114
  refetchAll
103
115
  ]);
104
116
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(DataQueriesContext.Provider, {
@@ -43,23 +43,42 @@ function transformQueryResults(results, definitions) {
43
43
  });
44
44
  }
45
45
  function useQueryType() {
46
- const { data: timeSeriesQueryPlugins , isLoading } = (0, _pluginregistry.useListPluginMetadata)('TimeSeriesQuery');
46
+ const { data: timeSeriesQueryPlugins , isLoading: isTimeSeriesQueryLoading } = (0, _pluginregistry.useListPluginMetadata)('TimeSeriesQuery');
47
+ const { data: traceQueryPlugins , isLoading: isTraceQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)('TraceQuery');
48
+ // For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
47
49
  const queryTypeMap = (0, _react.useMemo)(()=>{
48
50
  const map = {
49
- TimeSeriesQuery: []
51
+ TimeSeriesQuery: [],
52
+ TraceQuery: []
50
53
  };
51
54
  if (timeSeriesQueryPlugins) {
52
55
  timeSeriesQueryPlugins.forEach((plugin)=>{
53
- var _map_TimeSeriesQuery;
54
- (_map_TimeSeriesQuery = map['TimeSeriesQuery']) === null || _map_TimeSeriesQuery === void 0 ? void 0 : _map_TimeSeriesQuery.push(plugin.kind);
56
+ var _map_plugin_pluginType;
57
+ (_map_plugin_pluginType = map[plugin.pluginType]) === null || _map_plugin_pluginType === void 0 ? void 0 : _map_plugin_pluginType.push(plugin.kind);
58
+ });
59
+ }
60
+ if (traceQueryPlugins) {
61
+ traceQueryPlugins.forEach((plugin)=>{
62
+ var _map_plugin_pluginType;
63
+ (_map_plugin_pluginType = map[plugin.pluginType]) === null || _map_plugin_pluginType === void 0 ? void 0 : _map_plugin_pluginType.push(plugin.kind);
55
64
  });
56
65
  }
57
66
  return map;
58
67
  }, [
59
- timeSeriesQueryPlugins
68
+ timeSeriesQueryPlugins,
69
+ traceQueryPlugins
60
70
  ]);
61
71
  const getQueryType = (0, _react.useCallback)((pluginKind)=>{
62
- if (isLoading) {
72
+ const isLoading = (pluginKind)=>{
73
+ switch(pluginKind){
74
+ case 'PrometheusTimeSeriesQuery':
75
+ return isTimeSeriesQueryLoading;
76
+ case 'TempoTraceQuery':
77
+ return isTraceQueryPluginLoading;
78
+ }
79
+ throw new Error(`Unable to determine the query type: ${pluginKind}`);
80
+ };
81
+ if (isLoading(pluginKind)) {
63
82
  return undefined;
64
83
  }
65
84
  for(const queryType in queryTypeMap){
@@ -71,7 +90,8 @@ function useQueryType() {
71
90
  throw new Error(`Unable to determine the query type: ${pluginKind}`);
72
91
  }, [
73
92
  queryTypeMap,
74
- isLoading
93
+ isTimeSeriesQueryLoading,
94
+ isTraceQueryPluginLoading
75
95
  ]);
76
96
  return getQueryType;
77
97
  }
@@ -37,7 +37,7 @@ _export(exports, {
37
37
  const _jsxruntime = require("react/jsx-runtime");
38
38
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
39
39
  const _core = require("@perses-dev/core");
40
- const _queryparams = require("./query-params");
40
+ const _refreshinterval = require("./refresh-interval");
41
41
  function _getRequireWildcardCache(nodeInterop) {
42
42
  if (typeof WeakMap !== "function") return null;
43
43
  var cacheBabelInterop = new WeakMap();
@@ -89,34 +89,43 @@ function useTimeRange() {
89
89
  return useTimeRangeContext();
90
90
  }
91
91
  function TimeRangeProvider(props) {
92
- const { initialTimeRange , initialRefreshInterval , enabledURLParams , children } = props;
93
- const { timeRange , setTimeRange } = (0, _queryparams.useSetTimeRangeParams)(initialTimeRange, enabledURLParams);
94
- const { refreshInterval , setRefreshInterval , refreshIntervalInMs } = (0, _queryparams.useSetRefreshIntervalParams)(initialRefreshInterval, enabledURLParams);
95
- const [refreshKey, setRefreshKey] = (0, _react.useState)(0);
92
+ const { timeRange , refreshInterval , children , setTimeRange , setRefreshInterval } = props;
93
+ const [localTimeRange, setLocalTimeRange] = (0, _react.useState)(timeRange);
94
+ const [localRefreshInterval, setLocalefreshInterval] = (0, _react.useState)(refreshInterval);
95
+ const [refreshCounter, setRefreshCounter] = (0, _react.useState)(0);
96
+ (0, _react.useEffect)(()=>{
97
+ setLocalTimeRange(timeRange);
98
+ }, [
99
+ timeRange
100
+ ]);
101
+ (0, _react.useEffect)(()=>{
102
+ setLocalefreshInterval(refreshInterval);
103
+ }, [
104
+ refreshInterval
105
+ ]);
96
106
  const refresh = (0, _react.useCallback)(()=>{
97
- setRefreshKey(refreshKey + 1);
107
+ setRefreshCounter((counter)=>counter + 1);
98
108
  }, [
99
- refreshKey
109
+ setRefreshCounter
100
110
  ]);
101
111
  const ctx = (0, _react.useMemo)(()=>{
102
- const absoluteTimeRange = (0, _core.isRelativeTimeRange)(timeRange) ? (0, _core.toAbsoluteTimeRange)(timeRange) : timeRange;
112
+ const absoluteTimeRange = (0, _core.isRelativeTimeRange)(localTimeRange) ? (0, _core.toAbsoluteTimeRange)(localTimeRange) : localTimeRange;
103
113
  return {
104
- timeRange,
105
- setTimeRange,
114
+ timeRange: localTimeRange,
115
+ setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : setLocalTimeRange,
106
116
  absoluteTimeRange,
107
117
  refresh,
108
- refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,
109
- refreshInterval,
110
- refreshIntervalInMs,
111
- setRefreshInterval
118
+ refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${localRefreshInterval}:${refreshCounter}`,
119
+ refreshInterval: localRefreshInterval,
120
+ refreshIntervalInMs: (0, _refreshinterval.getRefreshIntervalInMs)(localRefreshInterval),
121
+ setRefreshInterval: setRefreshInterval !== null && setRefreshInterval !== void 0 ? setRefreshInterval : setLocalefreshInterval
112
122
  };
113
123
  }, [
114
- timeRange,
124
+ localTimeRange,
115
125
  setTimeRange,
116
126
  refresh,
117
- refreshKey,
118
- refreshInterval,
119
- refreshIntervalInMs,
127
+ refreshCounter,
128
+ localRefreshInterval,
120
129
  setRefreshInterval
121
130
  ]);
122
131
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(TimeRangeContext.Provider, {
@@ -0,0 +1,43 @@
1
+ // Copyright 2023 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
+ Object.defineProperty(exports, "TimeRangeProviderWithQueryParams", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return TimeRangeProviderWithQueryParams;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _react = /*#__PURE__*/ _interop_require_default(require("react"));
25
+ const _TimeRangeProvider = require("./TimeRangeProvider");
26
+ const _queryparams = require("./query-params");
27
+ function _interop_require_default(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+ function TimeRangeProviderWithQueryParams(props) {
33
+ const { initialTimeRange , initialRefreshInterval , children } = props;
34
+ const { timeRange , setTimeRange } = (0, _queryparams.useTimeRangeParams)(initialTimeRange);
35
+ const { refreshInterval , setRefreshInterval } = (0, _queryparams.useSetRefreshIntervalParams)(initialRefreshInterval);
36
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeRangeProvider.TimeRangeProvider, {
37
+ timeRange: timeRange,
38
+ refreshInterval: refreshInterval,
39
+ setTimeRange: setTimeRange,
40
+ setRefreshInterval: setRefreshInterval,
41
+ children: children
42
+ });
43
+ }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _export_star(require("./TimeRangeProvider"), exports);
18
+ _export_star(require("./TimeRangeProviderWithQueryParams"), exports);
18
19
  _export_star(require("./query-params"), exports);
19
20
  function _export_star(from, to) {
20
21
  Object.keys(from).forEach(function(k) {
@@ -39,8 +39,8 @@ _export(exports, {
39
39
  useInitialTimeRange: function() {
40
40
  return useInitialTimeRange;
41
41
  },
42
- useSetTimeRangeParams: function() {
43
- return useSetTimeRangeParams;
42
+ useTimeRangeParams: function() {
43
+ return useTimeRangeParams;
44
44
  },
45
45
  useInitialRefreshInterval: function() {
46
46
  return useInitialRefreshInterval;
@@ -132,19 +132,16 @@ function useInitialTimeRange(dashboardDuration) {
132
132
  dashboardDuration
133
133
  ]);
134
134
  }
135
- function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
135
+ function useTimeRangeParams(initialTimeRange) {
136
136
  const [query, setQuery] = (0, _usequeryparams.useQueryParams)(timeRangeQueryConfig, {
137
137
  updateType: 'replaceIn'
138
138
  });
139
139
  // determine whether initial param had previously been populated to fix back btn
140
140
  const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
141
- // optional fallback when app does not want query string as source of truth
142
- // this occurs when enabledURLParams is set to false on TimeRangeProvider
143
- const [timeRangeState, setTimeRangeState] = (0, _react.useState)(initialTimeRange);
144
141
  const { start } = query;
145
142
  (0, _react.useEffect)(()=>{
146
143
  // when dashboard loaded with no params, default to dashboard duration
147
- if (enabledURLParams && !paramsLoaded && !start) {
144
+ if (!paramsLoaded && !start) {
148
145
  if ((0, _core.isRelativeTimeRange)(initialTimeRange)) {
149
146
  setQuery({
150
147
  start: initialTimeRange.pastDuration,
@@ -155,7 +152,6 @@ function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
155
152
  }
156
153
  }, [
157
154
  initialTimeRange,
158
- enabledURLParams,
159
155
  paramsLoaded,
160
156
  start,
161
157
  setQuery
@@ -172,12 +168,6 @@ function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
172
168
  }, [
173
169
  setQuery
174
170
  ]);
175
- if (!enabledURLParams) {
176
- return {
177
- timeRange: timeRangeState,
178
- setTimeRange: setTimeRangeState
179
- };
180
- }
181
171
  return {
182
172
  timeRange: initialTimeRange,
183
173
  setTimeRange: setTimeRange
@@ -203,29 +193,16 @@ function useInitialRefreshInterval(dashboardDuration) {
203
193
  refresh
204
194
  ]);
205
195
  }
206
- function getRefreshIntervalInMs(refreshInterval) {
207
- let refreshIntervalInMs = 0;
208
- if (refreshInterval) {
209
- const refreshIntervalDuration = (0, _core.parseDurationString)(refreshInterval);
210
- if (refreshIntervalDuration && refreshIntervalDuration.seconds) {
211
- refreshIntervalInMs = (refreshIntervalDuration === null || refreshIntervalDuration === void 0 ? void 0 : refreshIntervalDuration.seconds) * 1000;
212
- }
213
- }
214
- return refreshIntervalInMs;
215
- }
216
- function useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams = true) {
196
+ function useSetRefreshIntervalParams(initialRefreshInterval) {
217
197
  const [query, setQuery] = (0, _usequeryparams.useQueryParams)(refreshIntervalQueryConfig, {
218
198
  updateType: 'replaceIn'
219
199
  });
220
200
  // determine whether initial param had previously been populated to fix back btn
221
201
  const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
222
- // optional fallback when app does not want query string as source of truth
223
- // this occurs when enabledURLParams is set to false on TimeRangeProvider
224
- const [refreshIntervalState, setRefreshIntervalState] = (0, _react.useState)(initialRefreshInterval);
225
202
  const { refresh } = query;
226
203
  (0, _react.useEffect)(()=>{
227
204
  // when dashboard loaded with no params, default to dashboard refresh interval
228
- if (enabledURLParams && !paramsLoaded && !refresh) {
205
+ if (!paramsLoaded && !refresh) {
229
206
  setQuery({
230
207
  refresh: initialRefreshInterval
231
208
  });
@@ -233,7 +210,6 @@ function useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams =
233
210
  }
234
211
  }, [
235
212
  initialRefreshInterval,
236
- enabledURLParams,
237
213
  paramsLoaded,
238
214
  refresh,
239
215
  setQuery
@@ -243,16 +219,8 @@ function useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams =
243
219
  }), [
244
220
  setQuery
245
221
  ]);
246
- if (!enabledURLParams) {
247
- return {
248
- refreshInterval: refreshIntervalState,
249
- setRefreshInterval: setRefreshIntervalState,
250
- refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState)
251
- };
252
- }
253
222
  return {
254
223
  refreshInterval: initialRefreshInterval,
255
- setRefreshInterval: setRefreshInterval,
256
- refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval)
224
+ setRefreshInterval: setRefreshInterval
257
225
  };
258
226
  }
@@ -0,0 +1,30 @@
1
+ // Copyright 2023 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
+ Object.defineProperty(exports, "getRefreshIntervalInMs", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return getRefreshIntervalInMs;
21
+ }
22
+ });
23
+ const _core = require("@perses-dev/core");
24
+ const _datefns = require("date-fns");
25
+ function getRefreshIntervalInMs(refreshInterval) {
26
+ if (refreshInterval !== undefined && refreshInterval !== null) {
27
+ return (0, _datefns.milliseconds)((0, _core.parseDurationString)(refreshInterval));
28
+ }
29
+ return 0;
30
+ }
@@ -47,11 +47,12 @@ function useDatasourceStore() {
47
47
  }
48
48
  return ctx;
49
49
  }
50
- function useListDatasourceSelectItems(datasourcePluginKind) {
50
+ function useListDatasourceSelectItems(datasourcePluginKind, project) {
51
51
  const { listDatasourceSelectItems } = useDatasourceStore();
52
52
  return (0, _reactquery.useQuery)([
53
53
  'listDatasourceSelectItems',
54
- datasourcePluginKind
54
+ datasourcePluginKind,
55
+ project
55
56
  ], ()=>listDatasourceSelectItems(datasourcePluginKind));
56
57
  }
57
58
  function useDatasourceClient(selector) {
@@ -20,6 +20,7 @@ _export_star(require("./plugin-registry"), exports);
20
20
  _export_star(require("./template-variables"), exports);
21
21
  _export_star(require("./TimeRangeProvider"), exports);
22
22
  _export_star(require("./time-series-queries"), exports);
23
+ _export_star(require("./trace-queries"), exports);
23
24
  _export_star(require("./DataQueriesProvider"), exports);
24
25
  function _export_star(from, to) {
25
26
  Object.keys(from).forEach(function(k) {
@@ -0,0 +1,59 @@
1
+ // Copyright 2023 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
+ TRACE_QUERY_KEY: function() {
25
+ return TRACE_QUERY_KEY;
26
+ },
27
+ useTraceQueries: function() {
28
+ return useTraceQueries;
29
+ }
30
+ });
31
+ const _reactquery = require("@tanstack/react-query");
32
+ const _datasources = require("./datasources");
33
+ const _pluginregistry = require("./plugin-registry");
34
+ const TRACE_QUERY_KEY = 'TraceQuery';
35
+ function useTraceQueries(definitions) {
36
+ const { getPlugin } = (0, _pluginregistry.usePluginRegistry)();
37
+ const datasourceStore = (0, _datasources.useDatasourceStore)();
38
+ const ctx = {
39
+ datasourceStore
40
+ };
41
+ return (0, _reactquery.useQueries)({
42
+ queries: definitions.map((definition)=>{
43
+ var _definition_spec, _definition_spec_plugin;
44
+ const queryKey = [
45
+ definition,
46
+ datasourceStore
47
+ ];
48
+ const traceQueryKind = definition === null || definition === void 0 ? void 0 : (_definition_spec = definition.spec) === null || _definition_spec === void 0 ? void 0 : (_definition_spec_plugin = _definition_spec.plugin) === null || _definition_spec_plugin === void 0 ? void 0 : _definition_spec_plugin.kind;
49
+ return {
50
+ queryKey: queryKey,
51
+ queryFn: async ()=>{
52
+ const plugin = await getPlugin(TRACE_QUERY_KEY, traceQueryKind);
53
+ const data = await plugin.getTraceData(definition.spec.plugin.spec, ctx);
54
+ return data;
55
+ }
56
+ };
57
+ })
58
+ });
59
+ }
@@ -90,7 +90,8 @@ const WithPluginRegistry = (Story)=>{
90
90
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.PluginRegistry, {
91
91
  pluginLoader: bundledPluginLoader,
92
92
  defaultPluginKinds: {
93
- TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
93
+ TimeSeriesQuery: 'PrometheusTimeSeriesQuery',
94
+ TraceQuery: 'TempoTraceQuery'
94
95
  },
95
96
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Story, {})
96
97
  });
@@ -76,6 +76,18 @@ const WithPluginSystemDatasourceStore = (Story, context)=>{
76
76
  ]);
77
77
  }
78
78
  throw new Error(`WithDatasourceStore is not configured to support kind: ${datasourcePluginKind}`);
79
+ },
80
+ getSavedDatasources: ()=>{
81
+ return {};
82
+ },
83
+ setSavedDatasources: (datasources)=>{
84
+ return datasources;
85
+ },
86
+ getLocalDatasources: ()=>{
87
+ return {};
88
+ },
89
+ setLocalDatasources: (datasources)=>{
90
+ return datasources;
79
91
  }
80
92
  };
81
93
  const parameter = isWithDatastoreStoreParameter(initParameter) ? initParameter : {
@@ -31,8 +31,8 @@ const WithTimeRange = (Story, context)=>{
31
31
  const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;
32
32
  const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
33
33
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.TimeRangeProvider, {
34
- initialRefreshInterval: "0s",
35
- initialTimeRange: {
34
+ refreshInterval: "0s",
35
+ timeRange: {
36
36
  pastDuration: '1h'
37
37
  },
38
38
  ...props,
@@ -14,10 +14,18 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "MOCK_TIME_SERIES_DATA", {
18
- enumerable: true,
19
- get: function() {
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
+ MOCK_TIME_SERIES_DATA: function() {
20
25
  return MOCK_TIME_SERIES_DATA;
26
+ },
27
+ MOCK_TRACE_DATA: function() {
28
+ return MOCK_TRACE_DATA;
21
29
  }
22
30
  });
23
31
  const MOCK_TIME_SERIES_DATA = {
@@ -55,3 +63,18 @@ const MOCK_TIME_SERIES_DATA = {
55
63
  }
56
64
  ]
57
65
  };
66
+ const MOCK_TRACE_DATA = {
67
+ traces: [
68
+ {
69
+ durationMs: 1120,
70
+ errorCount: 0,
71
+ spanCount: 10,
72
+ startTimeUnixMs: 1699916103945861,
73
+ traceId: '95ba9202315c29c801b5aa41452aa775',
74
+ name: 'rootServiceName="shop-backend", rootTraceName="shop-backend"'
75
+ }
76
+ ],
77
+ metadata: {
78
+ executedQueryString: '{ duration > 1000ms }'
79
+ }
80
+ };