@perses-dev/plugin-system 0.53.0-beta.0 → 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 +11 -4
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +71 -24
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +2 -0
- package/dist/cjs/components/PluginEditor/PluginEditor.js +8 -7
- package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -4
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +9 -3
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +2 -2
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +2 -2
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +5 -1
- 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 -13
- package/dist/cjs/test/utils.js +4 -4
- package/dist/cjs/utils/event.js +30 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +3 -0
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +11 -4
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +3 -0
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +72 -25
- 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 +8 -7
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +2 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +1 -0
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +9 -3
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +5 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.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/profile-queries.d.ts.map +1 -1
- package/dist/runtime/profile-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.d.ts +1 -5
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +3 -10
- 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/dist/utils/event.d.ts +8 -0
- package/dist/utils/event.d.ts.map +1 -0
- package/dist/utils/event.js +27 -0
- package/dist/utils/event.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.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
|
@@ -32,7 +32,7 @@ function _interop_require_default(obj) {
|
|
|
32
32
|
default: obj
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function useDefaultQueryDefinition(queryTypes) {
|
|
35
|
+
function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
|
|
36
36
|
// Build the default query plugin
|
|
37
37
|
// This will be used only if the queries are empty, to open a starting query
|
|
38
38
|
// Firs the default query type
|
|
@@ -41,7 +41,12 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
41
41
|
// Use as default the plugin kind explicitly set as default or the first in the list
|
|
42
42
|
const { data: queryPlugins, isLoading } = (0, _runtime.useListPluginMetadata)(queryTypes);
|
|
43
43
|
const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
|
|
44
|
-
|
|
44
|
+
let defaultQueryKind = '';
|
|
45
|
+
if (filteredQueryPlugins?.length) {
|
|
46
|
+
defaultQueryKind = queryPlugins?.find((i)=>filteredQueryPlugins.includes(i.spec.name)).spec.name ?? '';
|
|
47
|
+
} else {
|
|
48
|
+
defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
|
|
49
|
+
}
|
|
45
50
|
const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(defaultQueryType, defaultQueryKind, {
|
|
46
51
|
useErrorBoundary: true,
|
|
47
52
|
enabled: true
|
|
@@ -61,8 +66,8 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
64
|
-
const { queryTypes, queries = [], onChange } = props;
|
|
65
|
-
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
|
|
69
|
+
const { queryTypes, queries = [], queryResults, filteredQueryPlugins, onChange } = props;
|
|
70
|
+
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);
|
|
66
71
|
// State for which queries are collapsed
|
|
67
72
|
const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
|
|
68
73
|
// Query handlers
|
|
@@ -127,6 +132,8 @@ const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
127
132
|
queryTypes: queryTypes,
|
|
128
133
|
index: i,
|
|
129
134
|
query: query,
|
|
135
|
+
queryResult: queryResults?.[i],
|
|
136
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
130
137
|
isCollapsed: !!queriesCollapsed[i],
|
|
131
138
|
onChange: handleQueryChange,
|
|
132
139
|
onDelete: queries.length > 1 ? handleQueryDelete : undefined,
|
|
@@ -27,46 +27,91 @@ 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, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
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
|
}),
|
|
@@ -74,6 +119,8 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
|
|
|
74
119
|
ref: ref,
|
|
75
120
|
queryTypes: queryTypes,
|
|
76
121
|
value: query,
|
|
122
|
+
queryResult: queryResult,
|
|
123
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
77
124
|
onChange: (next)=>onChange(index, next)
|
|
78
125
|
})
|
|
79
126
|
]
|
|
@@ -87,8 +134,7 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
87
134
|
* @param props
|
|
88
135
|
* @constructor
|
|
89
136
|
*/ const QueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
90
|
-
const { value, onChange, queryTypes, ...others } = props;
|
|
91
|
-
const { refresh } = (0, _runtime.useTimeRange)();
|
|
137
|
+
const { value, onChange, queryTypes, queryResult, filteredQueryPlugins, ...others } = props;
|
|
92
138
|
const handlePluginChange = (next)=>{
|
|
93
139
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
94
140
|
draft.kind = next.selection.type;
|
|
@@ -99,7 +145,6 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
99
145
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
100
146
|
...others,
|
|
101
147
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
|
|
102
|
-
postExecuteRunQuery: refresh,
|
|
103
148
|
ref: ref,
|
|
104
149
|
withRunQueryButton: true,
|
|
105
150
|
pluginTypes: queryTypes,
|
|
@@ -111,6 +156,8 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
111
156
|
},
|
|
112
157
|
spec: value.spec.plugin.spec
|
|
113
158
|
},
|
|
159
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
160
|
+
onQueryRefresh: queryResult?.refetch,
|
|
114
161
|
onChange: handlePluginChange
|
|
115
162
|
})
|
|
116
163
|
});
|
|
@@ -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 ? {
|
|
@@ -104,7 +104,8 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
104
104
|
},
|
|
105
105
|
error: !!error,
|
|
106
106
|
helperText: error?.message,
|
|
107
|
-
onChange: onSelectionChange
|
|
107
|
+
onChange: onSelectionChange,
|
|
108
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
108
109
|
}),
|
|
109
110
|
withRunQueryButton && !isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
|
|
110
111
|
"data-testid": "run_query_button",
|
|
@@ -20,23 +20,23 @@ Object.defineProperty(exports, "usePluginEditor", {
|
|
|
20
20
|
return usePluginEditor;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
const _core = require("@perses-dev/core");
|
|
24
23
|
const _react = require("react");
|
|
25
24
|
const _immer = require("immer");
|
|
26
25
|
const _runtime = require("../../runtime");
|
|
26
|
+
const _utils = require("../../utils");
|
|
27
27
|
function usePluginEditor(props) {
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
29
|
const { pluginTypes, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
|
|
30
30
|
// Keep a stable reference, so we don't run the effect below when we don't need to
|
|
31
|
-
const onChange = (0,
|
|
32
|
-
const onHideQuery = (0,
|
|
31
|
+
const onChange = (0, _utils.useEvent)(props.onChange);
|
|
32
|
+
const onHideQuery = (0, _utils.useEvent)(onHideQueryEditorChange);
|
|
33
33
|
// The previous spec state for PluginType and kind and a helper function for remembering current values
|
|
34
34
|
const prevSpecState = (0, _react.useRef)({
|
|
35
35
|
[value.selection.type]: {
|
|
36
36
|
[value.selection.kind]: value.spec
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
const rememberCurrentSpecState = (0,
|
|
39
|
+
const rememberCurrentSpecState = (0, _utils.useEvent)(()=>{
|
|
40
40
|
let byPluginType = prevSpecState.current[value.selection.type];
|
|
41
41
|
if (byPluginType === undefined) {
|
|
42
42
|
byPluginType = {};
|
|
@@ -25,10 +25,16 @@ const _material = require("@mui/material");
|
|
|
25
25
|
const _react = require("react");
|
|
26
26
|
const _runtime = require("../../runtime");
|
|
27
27
|
const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
28
|
-
const { pluginTypes, value: propValue, onChange, ...others } = props;
|
|
28
|
+
const { pluginTypes, value: propValue, onChange, filteredQueryPlugins, ...others } = props;
|
|
29
29
|
const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginTypes);
|
|
30
|
-
const sortedData = (0, _react.useMemo)(()=>
|
|
31
|
-
|
|
30
|
+
const sortedData = (0, _react.useMemo)(()=>{
|
|
31
|
+
if (filteredQueryPlugins?.length) {
|
|
32
|
+
return data?.filter((i)=>filteredQueryPlugins.includes(i.spec.name))?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
|
|
33
|
+
}
|
|
34
|
+
return data?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
|
|
35
|
+
}, [
|
|
36
|
+
data,
|
|
37
|
+
filteredQueryPlugins
|
|
32
38
|
]);
|
|
33
39
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
34
40
|
const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
|
|
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "PluginRegistry", {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _core = require("@perses-dev/core");
|
|
25
24
|
const _react = require("react");
|
|
26
25
|
const _runtime = require("../../runtime");
|
|
26
|
+
const _utils = require("../../utils");
|
|
27
27
|
const _pluginindexes = require("./plugin-indexes");
|
|
28
28
|
function PluginRegistry(props) {
|
|
29
29
|
const { pluginLoader: { getInstalledPlugins, importPluginModule }, children, defaultPluginKinds } = props;
|
|
@@ -32,7 +32,7 @@ function PluginRegistry(props) {
|
|
|
32
32
|
const importCache = (0, _react.useRef)(new Map());
|
|
33
33
|
// Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the
|
|
34
34
|
// callback below
|
|
35
|
-
const loadPluginModule = (0,
|
|
35
|
+
const loadPluginModule = (0, _utils.useEvent)((resource)=>{
|
|
36
36
|
let request = importCache.current.get(resource);
|
|
37
37
|
if (request === undefined) {
|
|
38
38
|
request = importPluginModule(resource);
|
|
@@ -28,12 +28,12 @@ _export(exports, {
|
|
|
28
28
|
return usePluginIndexes;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
const _core = require("@perses-dev/core");
|
|
32
31
|
const _react = require("react");
|
|
32
|
+
const _utils = require("../../utils");
|
|
33
33
|
function usePluginIndexes(getInstalledPlugins) {
|
|
34
34
|
// Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
|
|
35
35
|
// and we want a stable reference for the callback below)
|
|
36
|
-
const createPluginIndexes = (0,
|
|
36
|
+
const createPluginIndexes = (0, _utils.useEvent)(async ()=>{
|
|
37
37
|
const installedPlugins = await getInstalledPlugins();
|
|
38
38
|
// Create the two indexes from the installed plugins
|
|
39
39
|
const pluginResourcesByNameAndKind = new Map();
|
|
@@ -211,7 +211,11 @@ function TimeRangeControls({ heightPx, showTimeRangeSelector = true, showRefresh
|
|
|
211
211
|
description: _constants.TOOLTIP_TEXT.refreshInterval,
|
|
212
212
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.RefreshIntervalPicker, {
|
|
213
213
|
timeOptions: DEFAULT_REFRESH_INTERVAL_OPTIONS,
|
|
214
|
-
value:
|
|
214
|
+
value: /* TODO: There is a bug here which should be fixed in a proper way. (This is only a quick remedy)
|
|
215
|
+
display: 1m has the pastDuration of 60s. Initially (if the persisted value is 1m) when the page is loaded, instead of 60s, 1m is passed down.
|
|
216
|
+
This only happens for 1m, because for other items the display and the pastDuration are the same. Example 30s-30s
|
|
217
|
+
HERE The value MUST always be pastDuration, otherwise the component would not work as expected.
|
|
218
|
+
*/ DEFAULT_REFRESH_INTERVAL_OPTIONS.some((i)=>i.value.pastDuration === refreshInterval) ? refreshInterval : DEFAULT_REFRESH_INTERVAL_OPTIONS.find((i)=>i.display === refreshInterval)?.value.pastDuration,
|
|
215
219
|
onChange: handleRefreshIntervalChange,
|
|
216
220
|
height: height
|
|
217
221
|
})
|
|
@@ -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) {
|