@perses-dev/plugin-system 0.53.0-beta.1 → 0.53.0-beta.2
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.
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +4 -3
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +72 -27
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +2 -0
- package/dist/cjs/components/PluginEditor/PluginEditor.js +6 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +15 -4
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
- package/dist/cjs/components/Variables/variable-model.js +3 -3
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +70 -33
- package/dist/cjs/runtime/TimeRangeProvider/{TimeRangeProviderWithQueryParams.js → TimeRangeProviders.js} +23 -5
- package/dist/cjs/runtime/TimeRangeProvider/index.js +1 -1
- package/dist/cjs/runtime/log-queries.js +2 -1
- package/dist/cjs/runtime/time-series-queries.js +10 -16
- package/dist/cjs/runtime/trace-queries.js +3 -2
- package/dist/cjs/test/utils.js +4 -4
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +2 -0
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +4 -3
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +2 -0
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +73 -28
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +3 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +6 -6
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +16 -5
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/variable-model.js +3 -3
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +0 -1
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +2 -3
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +70 -33
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +10 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts.map +1 -0
- package/dist/runtime/TimeRangeProvider/{TimeRangeProviderWithQueryParams.js → TimeRangeProviders.js} +13 -3
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -0
- package/dist/runtime/TimeRangeProvider/index.d.ts +1 -1
- package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/index.js +1 -1
- package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
- package/dist/runtime/log-queries.js +2 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +10 -16
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.js +3 -2
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/test/utils.js +5 -5
- package/dist/test/utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +0 -9
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +0 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +0 -1
|
@@ -66,7 +66,7 @@ function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
69
|
-
const { queryTypes, queries = [], filteredQueryPlugins, onChange } = props;
|
|
69
|
+
const { queryTypes, queries = [], queryResults, filteredQueryPlugins, onChange } = props;
|
|
70
70
|
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);
|
|
71
71
|
// State for which queries are collapsed
|
|
72
72
|
const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
|
|
@@ -132,11 +132,12 @@ const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
132
132
|
queryTypes: queryTypes,
|
|
133
133
|
index: i,
|
|
134
134
|
query: query,
|
|
135
|
+
queryResult: queryResults?.[i],
|
|
136
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
135
137
|
isCollapsed: !!queriesCollapsed[i],
|
|
136
138
|
onChange: handleQueryChange,
|
|
137
139
|
onDelete: queries.length > 1 ? handleQueryDelete : undefined,
|
|
138
|
-
onCollapseExpand: handleQueryCollapseExpand
|
|
139
|
-
filteredQueryPlugins: filteredQueryPlugins
|
|
140
|
+
onCollapseExpand: handleQueryCollapseExpand
|
|
140
141
|
}, i))
|
|
141
142
|
}),
|
|
142
143
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
|
|
@@ -27,54 +27,100 @@ const _DeleteOutline = /*#__PURE__*/ _interop_require_default(require("mdi-mater
|
|
|
27
27
|
const _ChevronDown = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ChevronDown"));
|
|
28
28
|
const _ChevronRight = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ChevronRight"));
|
|
29
29
|
const _react = require("react");
|
|
30
|
+
const _Alert = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Alert"));
|
|
31
|
+
const _components = require("@perses-dev/components");
|
|
30
32
|
const _PluginEditor = require("../PluginEditor");
|
|
31
|
-
const _runtime = require("../../runtime");
|
|
32
33
|
function _interop_require_default(obj) {
|
|
33
34
|
return obj && obj.__esModule ? obj : {
|
|
34
35
|
default: obj
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
38
|
-
const { queryTypes,
|
|
39
|
+
const { queryTypes, index, query, queryResult, filteredQueryPlugins, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
39
40
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
40
41
|
spacing: 1,
|
|
41
42
|
children: [
|
|
42
43
|
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
43
44
|
direction: "row",
|
|
44
45
|
alignItems: "center",
|
|
46
|
+
justifyContent: "space-between",
|
|
45
47
|
borderBottom: 1,
|
|
46
48
|
borderColor: (theme)=>theme.palette.divider,
|
|
47
49
|
children: [
|
|
48
|
-
/*#__PURE__*/ (0, _jsxruntime.
|
|
49
|
-
|
|
50
|
-
onClick: ()=>onCollapseExpand(index),
|
|
51
|
-
children: isCollapsed ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronRight.default, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronDown.default, {})
|
|
52
|
-
}),
|
|
53
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Typography, {
|
|
54
|
-
variant: "overline",
|
|
55
|
-
component: "h4",
|
|
50
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
51
|
+
direction: "row",
|
|
56
52
|
children: [
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
54
|
+
size: "small",
|
|
55
|
+
onClick: ()=>onCollapseExpand(index),
|
|
56
|
+
children: isCollapsed ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronRight.default, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronDown.default, {})
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Typography, {
|
|
59
|
+
variant: "overline",
|
|
60
|
+
component: "h4",
|
|
61
|
+
children: [
|
|
62
|
+
"Query #",
|
|
63
|
+
index + 1
|
|
64
|
+
]
|
|
65
|
+
})
|
|
59
66
|
]
|
|
60
67
|
}),
|
|
61
|
-
/*#__PURE__*/ (0, _jsxruntime.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
69
|
+
direction: "row",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
children: [
|
|
72
|
+
queryResult?.isFetching && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {
|
|
73
|
+
"aria-label": "loading",
|
|
74
|
+
size: "1.125rem"
|
|
75
|
+
}),
|
|
76
|
+
queryResult?.error && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.InfoTooltip, {
|
|
77
|
+
description: queryResult.error.message,
|
|
78
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
79
|
+
direction: "row",
|
|
80
|
+
alignItems: "center",
|
|
81
|
+
sx: {
|
|
82
|
+
color: (theme)=>theme.palette.error.main
|
|
83
|
+
},
|
|
84
|
+
children: [
|
|
85
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
86
|
+
"aria-label": "query error",
|
|
87
|
+
size: "small",
|
|
88
|
+
sx: {
|
|
89
|
+
color: (theme)=>theme.palette.error.main
|
|
90
|
+
},
|
|
91
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Alert.default, {})
|
|
92
|
+
}),
|
|
93
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
94
|
+
sx: {
|
|
95
|
+
maxWidth: 300,
|
|
96
|
+
whiteSpace: 'nowrap',
|
|
97
|
+
overflow: 'hidden',
|
|
98
|
+
textOverflow: 'ellipsis',
|
|
99
|
+
'&:hover ::after': {
|
|
100
|
+
content: '"Click to copy"'
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
children: queryResult.error.message
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
})
|
|
107
|
+
}),
|
|
108
|
+
onDelete && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
109
|
+
"aria-label": "delete query",
|
|
110
|
+
size: "small",
|
|
111
|
+
onClick: ()=>onDelete && onDelete(index),
|
|
112
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_DeleteOutline.default, {})
|
|
113
|
+
})
|
|
114
|
+
]
|
|
70
115
|
})
|
|
71
116
|
]
|
|
72
117
|
}),
|
|
73
118
|
!isCollapsed && /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryEditor, {
|
|
74
|
-
filteredQueryPlugins: filteredQueryPlugins,
|
|
75
119
|
ref: ref,
|
|
76
120
|
queryTypes: queryTypes,
|
|
77
121
|
value: query,
|
|
122
|
+
queryResult: queryResult,
|
|
123
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
78
124
|
onChange: (next)=>onChange(index, next)
|
|
79
125
|
})
|
|
80
126
|
]
|
|
@@ -88,8 +134,7 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
88
134
|
* @param props
|
|
89
135
|
* @constructor
|
|
90
136
|
*/ const QueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
91
|
-
const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;
|
|
92
|
-
const { refresh } = (0, _runtime.useTimeRange)();
|
|
137
|
+
const { value, onChange, queryTypes, queryResult, filteredQueryPlugins, ...others } = props;
|
|
93
138
|
const handlePluginChange = (next)=>{
|
|
94
139
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
95
140
|
draft.kind = next.selection.type;
|
|
@@ -100,7 +145,6 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
100
145
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
101
146
|
...others,
|
|
102
147
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
|
|
103
|
-
postExecuteRunQuery: refresh,
|
|
104
148
|
ref: ref,
|
|
105
149
|
withRunQueryButton: true,
|
|
106
150
|
pluginTypes: queryTypes,
|
|
@@ -112,8 +156,9 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
112
156
|
},
|
|
113
157
|
spec: value.spec.plugin.spec
|
|
114
158
|
},
|
|
115
|
-
|
|
116
|
-
|
|
159
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
160
|
+
onQueryRefresh: queryResult?.refetch,
|
|
161
|
+
onChange: handlePluginChange
|
|
117
162
|
})
|
|
118
163
|
});
|
|
119
164
|
});
|
|
@@ -31,6 +31,7 @@ const PanelSpecEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
31
31
|
const { control, panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;
|
|
32
32
|
const { kind } = panelDefinition.spec.plugin;
|
|
33
33
|
const { data: plugin, isLoading, error } = (0, _runtime.usePlugin)('Panel', kind);
|
|
34
|
+
const { queryResults } = (0, _runtime.useDataQueriesContext)();
|
|
34
35
|
if (error) {
|
|
35
36
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorAlert, {
|
|
36
37
|
error: error
|
|
@@ -54,6 +55,7 @@ const PanelSpecEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
54
55
|
ref: ref,
|
|
55
56
|
queryTypes: plugin.supportedQueryTypes ?? [],
|
|
56
57
|
queries: panelDefinition.spec.queries ?? [],
|
|
58
|
+
queryResults: queryResults,
|
|
57
59
|
onChange: (queries)=>{
|
|
58
60
|
field.onChange(queries);
|
|
59
61
|
onQueriesChange(queries);
|
|
@@ -34,9 +34,9 @@ function _interop_require_default(obj) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
37
|
-
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly,
|
|
37
|
+
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, onQueryRefresh, filteredQueryPlugins, ...others } = props;
|
|
38
38
|
const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
|
|
39
|
-
/*
|
|
39
|
+
/*
|
|
40
40
|
We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
|
|
41
41
|
because at the end of the day, they are all specs.
|
|
42
42
|
However, let's have them separated to keep the code simple and readable.
|
|
@@ -50,13 +50,13 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
50
50
|
...watchedOtherSpecs,
|
|
51
51
|
query: watchedQuery
|
|
52
52
|
});
|
|
53
|
-
|
|
53
|
+
onQueryRefresh?.();
|
|
54
54
|
}, [
|
|
55
|
-
|
|
55
|
+
onQueryRefresh,
|
|
56
56
|
onSpecChange,
|
|
57
|
-
|
|
57
|
+
value.spec,
|
|
58
58
|
watchedOtherSpecs,
|
|
59
|
-
|
|
59
|
+
watchedQuery
|
|
60
60
|
]);
|
|
61
61
|
const queryHandlerSettings = (0, _react.useMemo)(()=>{
|
|
62
62
|
return withRunQueryButton ? {
|
|
@@ -26,11 +26,11 @@ const _material = require("@mui/material");
|
|
|
26
26
|
const _components = require("@perses-dev/components");
|
|
27
27
|
const _reacthookform = require("react-hook-form");
|
|
28
28
|
const _zod = require("@hookform/resolvers/zod");
|
|
29
|
+
const _reactquery = require("@tanstack/react-query");
|
|
29
30
|
const _utils = require("../../../utils");
|
|
30
31
|
const _PluginEditor = require("../../PluginEditor");
|
|
31
32
|
const _context = require("../../../context");
|
|
32
33
|
const _variablemodel = require("../variable-model");
|
|
33
|
-
const _runtime = require("../../../runtime");
|
|
34
34
|
const _VariablePreview = require("./VariablePreview");
|
|
35
35
|
const _variableeditorformmodel = require("./variable-editor-form-model");
|
|
36
36
|
function FallbackPreview() {
|
|
@@ -104,6 +104,7 @@ function TextVariableEditorForm({ action, control }) {
|
|
|
104
104
|
}
|
|
105
105
|
function ListVariableEditorForm({ action, control }) {
|
|
106
106
|
const form = (0, _reacthookform.useFormContext)();
|
|
107
|
+
const queryClient = (0, _reactquery.useQueryClient)();
|
|
107
108
|
/** We use `previewSpec` to know when to explicitly update the
|
|
108
109
|
* spec that will be used for preview. The reason why we do this is to avoid
|
|
109
110
|
* having to re-fetch the values when the user is still editing the spec.
|
|
@@ -122,6 +123,17 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
122
123
|
control: control,
|
|
123
124
|
name: 'spec.sort'
|
|
124
125
|
});
|
|
126
|
+
const handleRefresh = (0, _react.useCallback)(async ()=>{
|
|
127
|
+
await queryClient.invalidateQueries({
|
|
128
|
+
queryKey: [
|
|
129
|
+
'variable',
|
|
130
|
+
previewSpec
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
}, [
|
|
134
|
+
previewSpec,
|
|
135
|
+
queryClient
|
|
136
|
+
]);
|
|
125
137
|
// When variable kind is selected we need to provide default values
|
|
126
138
|
// TODO: check if react-hook-form has a better way to do this
|
|
127
139
|
const values = form.getValues();
|
|
@@ -140,7 +152,6 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
140
152
|
if (!values.spec.sort) {
|
|
141
153
|
form.setValue('spec.sort', 'none');
|
|
142
154
|
}
|
|
143
|
-
const { refresh } = (0, _runtime.useTimeRange)();
|
|
144
155
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
145
156
|
children: [
|
|
146
157
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
@@ -172,7 +183,6 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
172
183
|
name: "spec.plugin",
|
|
173
184
|
render: ({ field })=>{
|
|
174
185
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
|
|
175
|
-
postExecuteRunQuery: refresh,
|
|
176
186
|
withRunQueryButton: true,
|
|
177
187
|
width: "100%",
|
|
178
188
|
pluginTypes: [
|
|
@@ -192,7 +202,8 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
192
202
|
kind: v.selection.kind,
|
|
193
203
|
spec: v.spec
|
|
194
204
|
});
|
|
195
|
-
}
|
|
205
|
+
},
|
|
206
|
+
onQueryRefresh: handleRefresh
|
|
196
207
|
});
|
|
197
208
|
}
|
|
198
209
|
})
|
|
@@ -159,7 +159,7 @@ function VariablePreview(props) {
|
|
|
159
159
|
},
|
|
160
160
|
children: [
|
|
161
161
|
variablePreviewState,
|
|
162
|
-
values?.slice(0, maxValues).map((val, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
|
|
162
|
+
values?.slice(0, maxValues).filter((val)=>val).map((val, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
|
|
163
163
|
size: "small",
|
|
164
164
|
label: val
|
|
165
165
|
}, index)),
|
|
@@ -65,7 +65,7 @@ function useListVariablePluginValues(definition) {
|
|
|
65
65
|
const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
|
|
66
66
|
const datasourceStore = (0, _runtime.useDatasourceStore)();
|
|
67
67
|
const allVariables = (0, _runtime.useAllVariableValues)();
|
|
68
|
-
const { absoluteTimeRange: timeRange
|
|
68
|
+
const { absoluteTimeRange: timeRange } = (0, _runtime.useTimeRange)();
|
|
69
69
|
const variablePluginCtx = {
|
|
70
70
|
timeRange,
|
|
71
71
|
datasourceStore,
|
|
@@ -88,10 +88,10 @@ function useListVariablePluginValues(definition) {
|
|
|
88
88
|
const variablesValueKey = getVariableValuesKey(variables);
|
|
89
89
|
return (0, _reactquery.useQuery)({
|
|
90
90
|
queryKey: [
|
|
91
|
+
'variable',
|
|
91
92
|
definition,
|
|
92
|
-
variablesValueKey,
|
|
93
93
|
timeRange,
|
|
94
|
-
|
|
94
|
+
variablesValueKey
|
|
95
95
|
],
|
|
96
96
|
queryFn: async ({ signal })=>{
|
|
97
97
|
const resp = await variablePlugin?.getVariableOptions(spec, {
|
|
@@ -40,6 +40,7 @@ _export(exports, {
|
|
|
40
40
|
const _jsxruntime = require("react/jsx-runtime");
|
|
41
41
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
42
42
|
const _core = require("@perses-dev/core");
|
|
43
|
+
const _reactquery = require("@tanstack/react-query");
|
|
43
44
|
const _refreshinterval = require("./refresh-interval");
|
|
44
45
|
function _getRequireWildcardCache(nodeInterop) {
|
|
45
46
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -100,62 +101,98 @@ function useSuggestedStepMs(width) {
|
|
|
100
101
|
}
|
|
101
102
|
function TimeRangeProvider(props) {
|
|
102
103
|
const { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/ const [localTimeRange, setLocalTimeRange] = (0, _react.useState)(timeRange);
|
|
109
|
-
const [localRefreshInterval, setLocalRefreshInterval] = (0, _react.useState)(refreshInterval);
|
|
110
|
-
const [refreshCounter, setRefreshCounter] = (0, _react.useState)(0);
|
|
111
|
-
(0, _react.useEffect)(()=>{
|
|
112
|
-
setLocalTimeRange(timeRange);
|
|
104
|
+
const queryClient = (0, _reactquery.useQueryClient)();
|
|
105
|
+
const [absoluteTimeRange, setAbsoluteTimeRange] = (0, _react.useState)((0, _core.isRelativeTimeRange)(timeRange) ? (0, _core.toAbsoluteTimeRange)(timeRange) : timeRange);
|
|
106
|
+
const handleSetTimeRange = (0, _react.useCallback)((value)=>{
|
|
107
|
+
setTimeRange(value);
|
|
108
|
+
setAbsoluteTimeRange((0, _core.isRelativeTimeRange)(value) ? (0, _core.toAbsoluteTimeRange)(value) : value);
|
|
113
109
|
}, [
|
|
114
|
-
|
|
115
|
-
refreshCounter
|
|
110
|
+
setTimeRange
|
|
116
111
|
]);
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
// Refresh is called when clicking on the refresh button, it refreshes all queries including variables
|
|
113
|
+
const refresh = (0, _react.useCallback)(()=>{
|
|
114
|
+
setAbsoluteTimeRange((0, _core.isRelativeTimeRange)(timeRange) ? (0, _core.toAbsoluteTimeRange)(timeRange) : timeRange);
|
|
115
|
+
queryClient.invalidateQueries({
|
|
116
|
+
queryKey: [
|
|
117
|
+
'query'
|
|
118
|
+
]
|
|
119
|
+
}).finally(()=>queryClient.removeQueries({
|
|
120
|
+
queryKey: [
|
|
121
|
+
'query'
|
|
122
|
+
],
|
|
123
|
+
type: 'inactive'
|
|
124
|
+
}));
|
|
125
|
+
queryClient.invalidateQueries({
|
|
126
|
+
queryKey: [
|
|
127
|
+
'variable'
|
|
128
|
+
]
|
|
129
|
+
}).finally(()=>queryClient.removeQueries({
|
|
130
|
+
queryKey: [
|
|
131
|
+
'variable'
|
|
132
|
+
],
|
|
133
|
+
type: 'inactive'
|
|
134
|
+
}));
|
|
119
135
|
}, [
|
|
120
|
-
|
|
136
|
+
queryClient,
|
|
137
|
+
timeRange
|
|
121
138
|
]);
|
|
122
|
-
|
|
123
|
-
|
|
139
|
+
// Auto refresh is only refreshing queries of panels
|
|
140
|
+
const autoRefresh = (0, _react.useCallback)(()=>{
|
|
141
|
+
setAbsoluteTimeRange((0, _core.isRelativeTimeRange)(timeRange) ? (0, _core.toAbsoluteTimeRange)(timeRange) : timeRange);
|
|
142
|
+
queryClient.invalidateQueries({
|
|
143
|
+
queryKey: [
|
|
144
|
+
'query'
|
|
145
|
+
]
|
|
146
|
+
}).finally(()=>{
|
|
147
|
+
queryClient.removeQueries({
|
|
148
|
+
queryKey: [
|
|
149
|
+
'query'
|
|
150
|
+
],
|
|
151
|
+
type: 'inactive'
|
|
152
|
+
});
|
|
153
|
+
queryClient.removeQueries({
|
|
154
|
+
queryKey: [
|
|
155
|
+
'variable'
|
|
156
|
+
],
|
|
157
|
+
type: 'inactive'
|
|
158
|
+
}); // Timerange is in queryKey, can lead to memory leak when using relative timerange
|
|
159
|
+
});
|
|
124
160
|
}, [
|
|
125
|
-
|
|
161
|
+
queryClient,
|
|
162
|
+
timeRange
|
|
163
|
+
]);
|
|
164
|
+
const refreshIntervalInMs = (0, _react.useMemo)(()=>(0, _refreshinterval.getRefreshIntervalInMs)(refreshInterval), [
|
|
165
|
+
refreshInterval
|
|
126
166
|
]);
|
|
127
|
-
const refreshIntervalInMs = (0, _refreshinterval.getRefreshIntervalInMs)(localRefreshInterval);
|
|
128
167
|
(0, _react.useEffect)(()=>{
|
|
129
168
|
if (refreshIntervalInMs > 0) {
|
|
130
169
|
const interval = setInterval(()=>{
|
|
131
|
-
|
|
170
|
+
autoRefresh();
|
|
132
171
|
}, refreshIntervalInMs);
|
|
133
172
|
return ()=>clearInterval(interval);
|
|
134
173
|
}
|
|
135
174
|
}, [
|
|
136
|
-
|
|
175
|
+
autoRefresh,
|
|
137
176
|
refreshIntervalInMs
|
|
138
177
|
]);
|
|
139
178
|
const ctx = (0, _react.useMemo)(()=>{
|
|
140
|
-
const absoluteTimeRange = (0, _core.isRelativeTimeRange)(localTimeRange) ? (0, _core.toAbsoluteTimeRange)(localTimeRange) : localTimeRange;
|
|
141
179
|
return {
|
|
142
|
-
timeRange:
|
|
143
|
-
setTimeRange:
|
|
144
|
-
absoluteTimeRange,
|
|
180
|
+
timeRange: timeRange,
|
|
181
|
+
setTimeRange: handleSetTimeRange,
|
|
182
|
+
absoluteTimeRange: absoluteTimeRange,
|
|
145
183
|
refresh,
|
|
146
|
-
|
|
147
|
-
refreshInterval: localRefreshInterval,
|
|
184
|
+
refreshInterval: refreshInterval,
|
|
148
185
|
refreshIntervalInMs: refreshIntervalInMs,
|
|
149
|
-
setRefreshInterval: setRefreshInterval
|
|
186
|
+
setRefreshInterval: setRefreshInterval
|
|
150
187
|
};
|
|
151
188
|
}, [
|
|
152
|
-
|
|
153
|
-
|
|
189
|
+
absoluteTimeRange,
|
|
190
|
+
handleSetTimeRange,
|
|
154
191
|
refresh,
|
|
155
|
-
|
|
156
|
-
refreshCounter,
|
|
192
|
+
refreshInterval,
|
|
157
193
|
refreshIntervalInMs,
|
|
158
|
-
setRefreshInterval
|
|
194
|
+
setRefreshInterval,
|
|
195
|
+
timeRange
|
|
159
196
|
]);
|
|
160
197
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(TimeRangeContext.Provider, {
|
|
161
198
|
value: ctx,
|
|
@@ -14,9 +14,17 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
TimeRangeProviderBasic: function() {
|
|
25
|
+
return TimeRangeProviderBasic;
|
|
26
|
+
},
|
|
27
|
+
TimeRangeProviderWithQueryParams: function() {
|
|
20
28
|
return TimeRangeProviderWithQueryParams;
|
|
21
29
|
}
|
|
22
30
|
});
|
|
@@ -29,8 +37,7 @@ function _interop_require_default(obj) {
|
|
|
29
37
|
default: obj
|
|
30
38
|
};
|
|
31
39
|
}
|
|
32
|
-
function TimeRangeProviderWithQueryParams(
|
|
33
|
-
const { initialTimeRange, initialRefreshInterval, children } = props;
|
|
40
|
+
function TimeRangeProviderWithQueryParams({ initialTimeRange, initialRefreshInterval, children }) {
|
|
34
41
|
const { timeRange, setTimeRange } = (0, _queryparams.useTimeRangeParams)(initialTimeRange);
|
|
35
42
|
const { refreshInterval, setRefreshInterval } = (0, _queryparams.useSetRefreshIntervalParams)(initialRefreshInterval);
|
|
36
43
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeRangeProvider.TimeRangeProvider, {
|
|
@@ -41,3 +48,14 @@ function TimeRangeProviderWithQueryParams(props) {
|
|
|
41
48
|
children: children
|
|
42
49
|
});
|
|
43
50
|
}
|
|
51
|
+
function TimeRangeProviderBasic({ initialTimeRange, initialRefreshInterval, children }) {
|
|
52
|
+
const [timeRange, setTimeRange] = _react.default.useState(initialTimeRange);
|
|
53
|
+
const [refreshInterval, setRefreshInterval] = _react.default.useState(initialRefreshInterval);
|
|
54
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeRangeProvider.TimeRangeProvider, {
|
|
55
|
+
timeRange: timeRange,
|
|
56
|
+
refreshInterval: refreshInterval,
|
|
57
|
+
setTimeRange: setTimeRange,
|
|
58
|
+
setRefreshInterval: setRefreshInterval,
|
|
59
|
+
children: children
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./TimeRangeProvider"), exports);
|
|
18
|
-
_export_star(require("./
|
|
18
|
+
_export_star(require("./TimeRangeProviders"), exports);
|
|
19
19
|
_export_star(require("./TimeRangeSettingsProvider"), exports);
|
|
20
20
|
_export_star(require("./query-params"), exports);
|
|
21
21
|
function _export_star(from, to) {
|
|
@@ -45,20 +45,20 @@ const _utils = require("./utils");
|
|
|
45
45
|
const _variables = require("./variables");
|
|
46
46
|
const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';
|
|
47
47
|
function getQueryOptions({ plugin, definition, context }) {
|
|
48
|
-
const { timeRange,
|
|
48
|
+
const { timeRange, suggestedStepMs, mode, variableState } = context;
|
|
49
49
|
const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
|
|
50
50
|
const variableDependencies = dependencies?.variables;
|
|
51
51
|
// Determine queryKey
|
|
52
52
|
const filteredVariabledState = (0, _utils.filterVariableStateMap)(variableState, variableDependencies);
|
|
53
53
|
const variablesValueKey = (0, _utils.getVariableValuesKey)(filteredVariabledState);
|
|
54
54
|
const queryKey = [
|
|
55
|
+
'query',
|
|
56
|
+
TIME_SERIES_QUERY_KEY,
|
|
55
57
|
definition,
|
|
56
58
|
timeRange,
|
|
57
|
-
datasourceStore,
|
|
58
|
-
suggestedStepMs,
|
|
59
|
-
mode,
|
|
60
59
|
variablesValueKey,
|
|
61
|
-
|
|
60
|
+
suggestedStepMs,
|
|
61
|
+
mode
|
|
62
62
|
];
|
|
63
63
|
// Determine queryEnabled
|
|
64
64
|
let waitToLoad = false;
|
|
@@ -100,8 +100,8 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
|
|
|
100
100
|
const { getPlugin } = (0, _pluginregistry.usePluginRegistry)();
|
|
101
101
|
const context = {
|
|
102
102
|
...useTimeSeriesQueryContext(),
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
mode: options?.mode,
|
|
104
|
+
suggestedStepMs: options?.suggestedStepMs
|
|
105
105
|
};
|
|
106
106
|
const pluginLoaderResponse = (0, _pluginregistry.usePlugins)(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
|
|
107
107
|
kind: d.spec.plugin.kind
|
|
@@ -119,13 +119,8 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
|
|
|
119
119
|
enabled: (queryOptions?.enabled ?? true) && queryEnabled,
|
|
120
120
|
queryKey: queryKey,
|
|
121
121
|
queryFn: async ({ signal })=>{
|
|
122
|
-
const ctx = {
|
|
123
|
-
...context,
|
|
124
|
-
// Keep suggested step changes out of the query key, so we don´t have to run again query when it changes
|
|
125
|
-
suggestedStepMs: options?.suggestedStepMs
|
|
126
|
-
};
|
|
127
122
|
const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
|
|
128
|
-
const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec,
|
|
123
|
+
const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, context, signal);
|
|
129
124
|
return data;
|
|
130
125
|
}
|
|
131
126
|
};
|
|
@@ -135,14 +130,13 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
|
|
|
135
130
|
/**
|
|
136
131
|
* Build the time series query context object from data available at runtime
|
|
137
132
|
*/ function useTimeSeriesQueryContext() {
|
|
138
|
-
const { absoluteTimeRange
|
|
133
|
+
const { absoluteTimeRange } = (0, _TimeRangeProvider.useTimeRange)();
|
|
139
134
|
const variableState = (0, _variables.useAllVariableValues)();
|
|
140
135
|
const datasourceStore = (0, _datasources.useDatasourceStore)();
|
|
141
136
|
return {
|
|
142
137
|
timeRange: absoluteTimeRange,
|
|
143
138
|
variableState,
|
|
144
|
-
datasourceStore
|
|
145
|
-
refreshKey
|
|
139
|
+
datasourceStore
|
|
146
140
|
};
|
|
147
141
|
}
|
|
148
142
|
function useActiveTimeSeriesQueries() {
|
|
@@ -65,14 +65,15 @@ function useTraceQueries(definitions) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
function getQueryOptions({ plugin, definition, context }) {
|
|
68
|
-
const {
|
|
68
|
+
const { variableState, absoluteTimeRange } = context;
|
|
69
69
|
const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
|
|
70
70
|
const variableDependencies = dependencies?.variables;
|
|
71
71
|
const filteredVariabledState = (0, _utils.filterVariableStateMap)(variableState, variableDependencies);
|
|
72
72
|
const variablesValueKey = (0, _utils.getVariableValuesKey)(filteredVariabledState);
|
|
73
73
|
const queryKey = [
|
|
74
|
+
'query',
|
|
75
|
+
TRACE_QUERY_KEY,
|
|
74
76
|
definition,
|
|
75
|
-
datasourceStore,
|
|
76
77
|
absoluteTimeRange,
|
|
77
78
|
variablesValueKey
|
|
78
79
|
];
|
package/dist/cjs/test/utils.js
CHANGED
|
@@ -41,10 +41,10 @@ function getTestContextWrapper(contextOptions) {
|
|
|
41
41
|
end: new Date()
|
|
42
42
|
};
|
|
43
43
|
return function Wrapper({ children }) {
|
|
44
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
45
|
-
|
|
46
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
47
|
-
|
|
44
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
|
|
45
|
+
client: queryClient,
|
|
46
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.TimeRangeProviderBasic, {
|
|
47
|
+
initialTimeRange: timeRange,
|
|
48
48
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PluginRegistry, {
|
|
49
49
|
pluginLoader: _testplugins.testPluginLoader,
|
|
50
50
|
defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
|
|
3
|
+
import { QueryData } from '../../runtime';
|
|
3
4
|
import { PluginEditorRef } from '../PluginEditor';
|
|
4
5
|
export interface MultiQueryEditorProps {
|
|
5
6
|
queryTypes: QueryPluginType[];
|
|
6
7
|
filteredQueryPlugins?: string[];
|
|
7
8
|
queries?: QueryDefinition[];
|
|
9
|
+
queryResults?: QueryData[];
|
|
8
10
|
onChange: (queries: QueryDefinition[]) => void;
|
|
9
11
|
}
|
|
10
12
|
/**
|