@perses-dev/plugin-system 0.54.0-beta.0 → 0.54.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +283 -0
- package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +197 -0
- package/dist/cjs/components/Annotations/AnnotationEditorForm/index.js +30 -0
- package/dist/cjs/components/Annotations/constants.js +23 -0
- package/dist/cjs/components/Annotations/index.js +31 -0
- package/dist/cjs/components/CalculationSelector/CalculationSelector.js +3 -3
- package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +2 -3
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -5
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +97 -12
- package/dist/cjs/components/MultiQueryEditor/index.js +1 -0
- package/dist/cjs/{utils/action.js → components/MultiQueryEditor/utils.js} +8 -15
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +3 -6
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -15
- package/dist/cjs/components/PluginRegistry/getPluginSearchHelper.js +92 -0
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +16 -13
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -3
- package/dist/cjs/components/Variables/variable-model.js +115 -29
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/ValidationProvider.js +10 -4
- package/dist/cjs/model/alerts-queries.js +16 -0
- package/dist/cjs/model/annotations.js +16 -0
- package/dist/cjs/model/calculations.js +178 -0
- package/dist/cjs/model/index.js +4 -0
- package/dist/cjs/model/legend.js +6 -5
- package/dist/cjs/model/log-volume-utils.js +10 -10
- package/dist/cjs/model/plugin-loading.js +24 -8
- package/dist/cjs/model/plugins.js +10 -0
- package/dist/cjs/model/silences-queries.js +16 -0
- package/dist/cjs/model/time-series-queries.js +10 -0
- package/dist/cjs/remote/PluginRuntime.js +46 -10
- package/dist/cjs/remote/remotePluginLoader.js +28 -5
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +33 -24
- package/dist/cjs/runtime/DataQueriesProvider/model.js +3 -93
- package/dist/cjs/runtime/UsageMetricsProvider.js +2 -2
- package/dist/cjs/runtime/alerts-queries.js +101 -0
- package/dist/cjs/runtime/annotations.js +148 -0
- package/dist/cjs/runtime/index.js +3 -1
- package/dist/cjs/runtime/item-actions.js +3 -3
- package/dist/cjs/runtime/log-queries.js +4 -1
- package/dist/cjs/runtime/plugin-registry.js +12 -3
- package/dist/cjs/runtime/profile-queries.js +4 -1
- package/dist/cjs/runtime/silences-queries.js +101 -0
- package/dist/cjs/runtime/time-series-queries.js +4 -1
- package/dist/cjs/runtime/trace-queries.js +4 -1
- package/dist/cjs/test/mock-data.js +51 -0
- package/dist/cjs/test/test-plugins/bert/index.js +9 -12
- package/dist/cjs/test/test-plugins/ernie/index.js +9 -12
- package/dist/cjs/test/test-plugins/index.js +2 -2
- package/dist/cjs/test/utils.js +2 -2
- package/dist/cjs/test-utils/mock-plugin-registry.js +8 -2
- package/dist/cjs/utils/index.js +0 -1
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts +16 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +270 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts +8 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +184 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/index.d.ts +2 -0
- package/dist/components/Annotations/AnnotationEditorForm/index.d.ts.map +1 -0
- package/dist/{runtime/QueryCountProvider.js → components/Annotations/AnnotationEditorForm/index.js} +2 -13
- package/dist/components/Annotations/AnnotationEditorForm/index.js.map +1 -0
- package/dist/components/Annotations/constants.d.ts +2 -0
- package/dist/components/Annotations/constants.d.ts.map +1 -0
- package/dist/components/Annotations/constants.js +15 -0
- package/dist/components/Annotations/constants.js.map +1 -0
- package/dist/components/Annotations/index.d.ts +3 -0
- package/dist/components/Annotations/index.d.ts.map +1 -0
- package/dist/components/Annotations/index.js +16 -0
- package/dist/components/Annotations/index.js.map +1 -0
- package/dist/components/CalculationSelector/CalculationSelector.d.ts +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.js +2 -2
- package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +2 -3
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js +2 -2
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +2 -2
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -3
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +100 -15
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/MultiQueryEditor/index.d.ts +1 -0
- package/dist/components/MultiQueryEditor/index.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/index.js +1 -0
- package/dist/components/MultiQueryEditor/index.js.map +1 -1
- package/dist/components/MultiQueryEditor/utils.d.ts +8 -0
- package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -0
- package/dist/{utils/action.js → components/MultiQueryEditor/utils.js} +8 -12
- package/dist/components/MultiQueryEditor/utils.js.map +1 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +1 -1
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +1 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +5 -8
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +1 -1
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -1
- 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 +12 -16
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts +12 -0
- package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts.map +1 -0
- package/dist/components/PluginRegistry/getPluginSearchHelper.js +88 -0
- package/dist/components/PluginRegistry/getPluginSearchHelper.js.map +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -6
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +15 -13
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js +1 -1
- package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -3
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.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.d.ts +9 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +117 -31
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/ValidationProvider.d.ts +4 -2
- package/dist/context/ValidationProvider.d.ts.map +1 -1
- package/dist/context/ValidationProvider.js +10 -4
- package/dist/context/ValidationProvider.js.map +1 -1
- package/dist/model/alerts-queries.d.ts +33 -0
- package/dist/model/alerts-queries.d.ts.map +1 -0
- package/dist/model/alerts-queries.js +15 -0
- package/dist/model/alerts-queries.js.map +1 -0
- package/dist/model/annotations.d.ts +28 -0
- package/dist/model/annotations.d.ts.map +1 -0
- package/dist/model/annotations.js +17 -0
- package/dist/model/annotations.js.map +1 -0
- package/dist/model/calculations.d.ts +45 -0
- package/dist/model/calculations.d.ts.map +1 -0
- package/dist/model/calculations.js +165 -0
- package/dist/model/calculations.js.map +1 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +4 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +3 -2
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +2 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/log-queries.d.ts +2 -1
- package/dist/model/log-queries.d.ts.map +1 -1
- package/dist/model/log-queries.js.map +1 -1
- package/dist/model/plugin-loading.d.ts.map +1 -1
- package/dist/model/plugin-loading.js +24 -8
- package/dist/model/plugin-loading.js.map +1 -1
- package/dist/model/plugins.d.ts +23 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js +4 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/model/silences-queries.d.ts +33 -0
- package/dist/model/silences-queries.d.ts.map +1 -0
- package/dist/model/silences-queries.js +15 -0
- package/dist/model/silences-queries.js.map +1 -0
- package/dist/model/time-series-queries.d.ts +11 -1
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js +4 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/trace-queries.d.ts +2 -3
- package/dist/model/trace-queries.d.ts.map +1 -1
- package/dist/model/trace-queries.js.map +1 -1
- package/dist/remote/PersesPlugin.types.d.ts +2 -0
- package/dist/remote/PersesPlugin.types.d.ts.map +1 -1
- package/dist/remote/PersesPlugin.types.js.map +1 -1
- package/dist/remote/PluginLoaderComponent.js +1 -1
- package/dist/remote/PluginLoaderComponent.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts +7 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +46 -10
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +28 -5
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +35 -26
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +4 -4
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +0 -82
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/RouterProvider.js +1 -1
- package/dist/runtime/RouterProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +2 -2
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/alerts-queries.d.ts +11 -0
- package/dist/runtime/alerts-queries.d.ts.map +1 -0
- package/dist/runtime/alerts-queries.js +89 -0
- package/dist/runtime/alerts-queries.js.map +1 -0
- package/dist/runtime/annotations.d.ts +6 -0
- package/dist/runtime/annotations.d.ts.map +1 -0
- package/dist/runtime/annotations.js +129 -0
- package/dist/runtime/annotations.js.map +1 -0
- package/dist/runtime/datasources.d.ts +6 -0
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/item-actions.js +1 -1
- package/dist/runtime/item-actions.js.map +1 -1
- package/dist/runtime/log-queries.js +4 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +2 -2
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +12 -3
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/profile-queries.js +4 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/silences-queries.d.ts +11 -0
- package/dist/runtime/silences-queries.d.ts.map +1 -0
- package/dist/runtime/silences-queries.js +89 -0
- package/dist/runtime/silences-queries.js.map +1 -0
- package/dist/runtime/time-series-queries.js +4 -1
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.js +4 -1
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/test/mock-data.d.ts +3 -1
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +45 -0
- package/dist/test/mock-data.js.map +1 -1
- package/dist/test/render.js +1 -1
- package/dist/test/render.js.map +1 -1
- package/dist/test/test-plugins/bert/index.d.ts +12 -6
- package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
- package/dist/test/test-plugins/bert/index.js +6 -2
- package/dist/test/test-plugins/bert/index.js.map +1 -1
- package/dist/test/test-plugins/ernie/index.d.ts +8 -6
- package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
- package/dist/test/test-plugins/ernie/index.js +6 -2
- package/dist/test/test-plugins/ernie/index.js.map +1 -1
- package/dist/test/test-plugins/index.js +2 -2
- package/dist/test/test-plugins/index.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +2 -2
- package/dist/test/utils.js.map +1 -1
- package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
- package/dist/test-utils/mock-plugin-registry.js +8 -2
- package/dist/test-utils/mock-plugin-registry.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +7 -6
- package/dist/cjs/runtime/QueryCountProvider.js +0 -83
- package/dist/runtime/QueryCountProvider.d.ts +0 -9
- package/dist/runtime/QueryCountProvider.d.ts.map +0 -1
- package/dist/runtime/QueryCountProvider.js.map +0 -1
- package/dist/utils/action.d.ts +0 -4
- package/dist/utils/action.d.ts.map +0 -1
- package/dist/utils/action.js.map +0 -1
|
@@ -29,7 +29,11 @@ const _ChevronRight = /*#__PURE__*/ _interop_require_default(require("mdi-materi
|
|
|
29
29
|
const _react = require("react");
|
|
30
30
|
const _Alert = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Alert"));
|
|
31
31
|
const _components = require("@perses-dev/components");
|
|
32
|
+
const _Pencil = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Pencil"));
|
|
33
|
+
const _Check = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Check"));
|
|
34
|
+
const _Close = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Close"));
|
|
32
35
|
const _PluginEditor = require("../PluginEditor");
|
|
36
|
+
const _utils = require("./utils");
|
|
33
37
|
function _interop_require_default(obj) {
|
|
34
38
|
return obj && obj.__esModule ? obj : {
|
|
35
39
|
default: obj
|
|
@@ -37,6 +41,16 @@ function _interop_require_default(obj) {
|
|
|
37
41
|
}
|
|
38
42
|
const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
39
43
|
const { queryTypes, index, query, queryResult, filteredQueryPlugins, isCollapsed, onDelete, onChange, onQueryRun, onCollapseExpand } = props;
|
|
44
|
+
// The displayed name is always derived from props so it stays in sync with the
|
|
45
|
+
// current query/index, even when queries are added, removed or reordered.
|
|
46
|
+
const displayedName = query.spec.name ?? (0, _utils.defaultQueryName)(index);
|
|
47
|
+
const [isEditingName, setIsEditingName] = (0, _react.useState)(false);
|
|
48
|
+
function handleNameSave(name) {
|
|
49
|
+
setIsEditingName(false);
|
|
50
|
+
onChange(index, (0, _immer.produce)(query, (draft)=>{
|
|
51
|
+
draft.spec.name = name;
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
40
54
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
41
55
|
spacing: 1,
|
|
42
56
|
children: [
|
|
@@ -49,19 +63,40 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
|
|
|
49
63
|
children: [
|
|
50
64
|
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
51
65
|
direction: "row",
|
|
66
|
+
gap: 1,
|
|
67
|
+
sx: {
|
|
68
|
+
width: '100%'
|
|
69
|
+
},
|
|
52
70
|
children: [
|
|
53
71
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
54
72
|
size: "small",
|
|
73
|
+
sx: {
|
|
74
|
+
width: 'fit-content',
|
|
75
|
+
height: 'fit-content'
|
|
76
|
+
},
|
|
55
77
|
onClick: ()=>onCollapseExpand(index),
|
|
56
78
|
children: isCollapsed ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronRight.default, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronDown.default, {})
|
|
57
79
|
}),
|
|
58
|
-
/*#__PURE__*/ (0, _jsxruntime.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
81
|
+
direction: "row",
|
|
82
|
+
gap: 1,
|
|
83
|
+
alignItems: "center",
|
|
84
|
+
alignContent: "center",
|
|
85
|
+
sx: {
|
|
86
|
+
width: '100%',
|
|
87
|
+
'&:hover button': {
|
|
88
|
+
visibility: 'visible'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
children: isEditingName ? /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryNameInput, {
|
|
92
|
+
initialName: displayedName,
|
|
93
|
+
onSave: handleNameSave,
|
|
94
|
+
onCancel: ()=>setIsEditingName(false)
|
|
95
|
+
}, displayedName) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
96
|
+
variant: "overline",
|
|
97
|
+
component: "h4",
|
|
98
|
+
children: displayedName
|
|
99
|
+
})
|
|
65
100
|
})
|
|
66
101
|
]
|
|
67
102
|
}),
|
|
@@ -105,11 +140,24 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
|
|
|
105
140
|
]
|
|
106
141
|
})
|
|
107
142
|
}),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
144
|
+
direction: "row",
|
|
145
|
+
children: [
|
|
146
|
+
!isEditingName && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
147
|
+
"aria-label": "edit query name",
|
|
148
|
+
size: "small",
|
|
149
|
+
onClick: ()=>setIsEditingName(true),
|
|
150
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Pencil.default, {
|
|
151
|
+
fontSize: "small"
|
|
152
|
+
})
|
|
153
|
+
}),
|
|
154
|
+
onDelete && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
155
|
+
"aria-label": "delete query",
|
|
156
|
+
size: "small",
|
|
157
|
+
onClick: ()=>onDelete && onDelete(index),
|
|
158
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_DeleteOutline.default, {})
|
|
159
|
+
})
|
|
160
|
+
]
|
|
113
161
|
})
|
|
114
162
|
]
|
|
115
163
|
})
|
|
@@ -127,6 +175,43 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
|
|
|
127
175
|
}, index);
|
|
128
176
|
});
|
|
129
177
|
QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
178
|
+
/**
|
|
179
|
+
* Self-contained input to edit a query name. The draft value is local state seeded from
|
|
180
|
+
* `initialName`; callers reset it by changing the `key` (remounting) rather than syncing
|
|
181
|
+
* with an useEffect.
|
|
182
|
+
*/ function QueryNameInput({ initialName, onSave, onCancel }) {
|
|
183
|
+
const [draftName, setDraftName] = (0, _react.useState)(initialName);
|
|
184
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
185
|
+
size: "small",
|
|
186
|
+
variant: "outlined",
|
|
187
|
+
label: "Query name",
|
|
188
|
+
"aria-label": "query name",
|
|
189
|
+
value: draftName,
|
|
190
|
+
onChange: (e)=>setDraftName(e.target.value),
|
|
191
|
+
fullWidth: true,
|
|
192
|
+
InputProps: {
|
|
193
|
+
endAdornment: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.InputAdornment, {
|
|
194
|
+
position: "end",
|
|
195
|
+
children: [
|
|
196
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
197
|
+
size: "small",
|
|
198
|
+
"aria-label": "cancel edit",
|
|
199
|
+
onClick: onCancel,
|
|
200
|
+
edge: "end",
|
|
201
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Close.default, {})
|
|
202
|
+
}),
|
|
203
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
|
|
204
|
+
size: "small",
|
|
205
|
+
"aria-label": "save query name",
|
|
206
|
+
onClick: ()=>onSave(draftName),
|
|
207
|
+
edge: "end",
|
|
208
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Check.default, {})
|
|
209
|
+
})
|
|
210
|
+
]
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
130
215
|
/**
|
|
131
216
|
* Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.
|
|
132
217
|
* This will allow user to select a plugin extending from the given supported query types, and then edit the plugin
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./MultiQueryEditor"), exports);
|
|
18
|
+
_export_star(require("./utils"), exports);
|
|
18
19
|
function _export_star(from, to) {
|
|
19
20
|
Object.keys(from).forEach(function(k) {
|
|
20
21
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -21,23 +21,16 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
get
|
|
25
|
-
return
|
|
24
|
+
get defaultQueryName () {
|
|
25
|
+
return defaultQueryName;
|
|
26
26
|
},
|
|
27
|
-
get
|
|
28
|
-
return
|
|
27
|
+
get generateQueryNames () {
|
|
28
|
+
return generateQueryNames;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
if (isDraft && action === 'create') return 'Add';
|
|
34
|
-
if (!isDraft && action === 'create') return 'Create';
|
|
35
|
-
if (action === 'update') return 'Edit';
|
|
36
|
-
return '';
|
|
31
|
+
function defaultQueryName(index) {
|
|
32
|
+
return `Query #${index + 1}`;
|
|
37
33
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
if (isDraft && action === 'update') return 'Apply';
|
|
41
|
-
if (!isDraft) return 'Save';
|
|
42
|
-
return '';
|
|
34
|
+
function generateQueryNames(definitions) {
|
|
35
|
+
return definitions.map((queryDef, index)=>queryDef.spec.name ?? defaultQueryName(index));
|
|
43
36
|
}
|
|
@@ -109,11 +109,8 @@ const PanelSpecEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
109
109
|
})
|
|
110
110
|
})
|
|
111
111
|
});
|
|
112
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
tabs: tabs
|
|
116
|
-
}, tabs.length)
|
|
117
|
-
});
|
|
112
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_OptionsEditorTabs.OptionsEditorTabs, {
|
|
113
|
+
tabs: tabs
|
|
114
|
+
}, tabs.length);
|
|
118
115
|
});
|
|
119
116
|
PanelSpecEditor.displayName = 'PanelSpecEditor';
|
|
@@ -25,6 +25,7 @@ const _react = require("react");
|
|
|
25
25
|
const _runtime = require("../../runtime");
|
|
26
26
|
const _utils = require("../../utils");
|
|
27
27
|
const _pluginindexes = require("./plugin-indexes");
|
|
28
|
+
const _getPluginSearchHelper = require("./getPluginSearchHelper");
|
|
28
29
|
function PluginRegistry(props) {
|
|
29
30
|
const { pluginLoader: { getInstalledPlugins, importPluginModule }, children, defaultPluginKinds } = props;
|
|
30
31
|
const getPluginIndexes = (0, _pluginindexes.usePluginIndexes)(getInstalledPlugins);
|
|
@@ -42,23 +43,18 @@ function PluginRegistry(props) {
|
|
|
42
43
|
}
|
|
43
44
|
return request;
|
|
44
45
|
});
|
|
45
|
-
const getPlugin = (0, _react.useCallback)(async (
|
|
46
|
-
// Get the indexes of the installed plugins
|
|
46
|
+
const getPlugin = (0, _react.useCallback)(async (compoundKeyObj)=>{
|
|
47
47
|
const pluginIndexes = await getPluginIndexes();
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const { kind, name } = compoundKeyObj;
|
|
49
|
+
const candidateKeys = (0, _getPluginSearchHelper.resolvePluginKeys)(pluginIndexes.pluginResourcesByNameKindRegistryVersion.keys(), compoundKeyObj);
|
|
50
|
+
for (const resourceKey of candidateKeys){
|
|
51
|
+
const resource = pluginIndexes.pluginResourcesByNameKindRegistryVersion.get(resourceKey);
|
|
52
|
+
if (!resource) continue;
|
|
53
|
+
const pluginModule = await loadPluginModule(resource);
|
|
54
|
+
const plugin = pluginModule?.[resourceKey];
|
|
55
|
+
if (plugin) return plugin;
|
|
53
56
|
}
|
|
54
|
-
|
|
55
|
-
const pluginModule = await loadPluginModule(resource);
|
|
56
|
-
// We currently assume that plugin modules will have named exports that match the kinds they handle
|
|
57
|
-
const plugin = pluginModule[name];
|
|
58
|
-
if (plugin === undefined) {
|
|
59
|
-
throw new Error(`The ${name} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`);
|
|
60
|
-
}
|
|
61
|
-
return plugin;
|
|
57
|
+
throw new Error(`A ${name} plugin for kind '${kind}' is not installed`);
|
|
62
58
|
}, [
|
|
63
59
|
getPluginIndexes,
|
|
64
60
|
loadPluginModule
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "resolvePluginKeys", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return resolvePluginKeys;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _semver = require("semver");
|
|
24
|
+
const _model = require("../../model");
|
|
25
|
+
const PLUGIN_LOOKUP_PRECEDENCE_LOGIC = {
|
|
26
|
+
registryOverVersion: false
|
|
27
|
+
};
|
|
28
|
+
const resolvePluginKeys = (allKeys, query, precedenceLogic = PLUGIN_LOOKUP_PRECEDENCE_LOGIC)=>{
|
|
29
|
+
const { kind, name, version, registry } = query;
|
|
30
|
+
const candidates = [];
|
|
31
|
+
// Exact match first when version or registry is specified
|
|
32
|
+
if (version || registry) {
|
|
33
|
+
candidates.push((0, _model.getPluginModuleCompoundKey)({
|
|
34
|
+
kind,
|
|
35
|
+
name,
|
|
36
|
+
registry,
|
|
37
|
+
version
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const latestWithRegistry = {
|
|
41
|
+
key: '',
|
|
42
|
+
version: ''
|
|
43
|
+
};
|
|
44
|
+
const latestWithoutRegistry = {
|
|
45
|
+
key: '',
|
|
46
|
+
version: ''
|
|
47
|
+
};
|
|
48
|
+
const prefix = `${kind}:${name}:`;
|
|
49
|
+
for (const key of allKeys){
|
|
50
|
+
if (!key.startsWith(prefix)) continue;
|
|
51
|
+
const split = key.split(':');
|
|
52
|
+
if (split.length !== 4) {
|
|
53
|
+
console.warn(`An invalid Plugin Resource key detected during default plugin lookup: ${key}`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const [, , reg, ver] = split;
|
|
57
|
+
if (!ver) {
|
|
58
|
+
console.warn(`An invalid Plugin Resource key detected during default plugin lookup: ${key}`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (reg) {
|
|
62
|
+
if (!latestWithRegistry.key || (0, _semver.gt)(ver, latestWithRegistry.version)) {
|
|
63
|
+
latestWithRegistry.key = key;
|
|
64
|
+
latestWithRegistry.version = ver;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
if (!latestWithoutRegistry.key || (0, _semver.gt)(ver, latestWithoutRegistry.version)) {
|
|
68
|
+
latestWithoutRegistry.key = key;
|
|
69
|
+
latestWithoutRegistry.version = ver;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Determine the best fallback key from the two buckets
|
|
74
|
+
let fallbackKey;
|
|
75
|
+
if (latestWithRegistry.key && latestWithoutRegistry.key) {
|
|
76
|
+
const { registryOverVersion } = precedenceLogic;
|
|
77
|
+
if ((0, _semver.gt)(latestWithRegistry.version, latestWithoutRegistry.version)) {
|
|
78
|
+
fallbackKey = latestWithRegistry.key;
|
|
79
|
+
} else if ((0, _semver.gt)(latestWithoutRegistry.version, latestWithRegistry.version)) {
|
|
80
|
+
fallbackKey = latestWithoutRegistry.key;
|
|
81
|
+
} else {
|
|
82
|
+
// Versions are equal — use the tie-breaker
|
|
83
|
+
fallbackKey = registryOverVersion ? latestWithRegistry.key : latestWithoutRegistry.key;
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
fallbackKey = latestWithRegistry.key || latestWithoutRegistry.key || undefined;
|
|
87
|
+
}
|
|
88
|
+
if (fallbackKey && !candidates.includes(fallbackKey)) {
|
|
89
|
+
candidates.push(fallbackKey);
|
|
90
|
+
}
|
|
91
|
+
return candidates;
|
|
92
|
+
};
|
|
@@ -21,14 +21,15 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
get
|
|
25
|
-
return
|
|
24
|
+
get getPluginModuleCompoundKey () {
|
|
25
|
+
return _model.getPluginModuleCompoundKey;
|
|
26
26
|
},
|
|
27
27
|
get usePluginIndexes () {
|
|
28
28
|
return usePluginIndexes;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
const _react = require("react");
|
|
32
|
+
const _model = require("../../model");
|
|
32
33
|
const _utils = require("../../utils");
|
|
33
34
|
function usePluginIndexes(getInstalledPlugins) {
|
|
34
35
|
// Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
|
|
@@ -36,17 +37,22 @@ function usePluginIndexes(getInstalledPlugins) {
|
|
|
36
37
|
const createPluginIndexes = (0, _utils.useEvent)(async ()=>{
|
|
37
38
|
const installedPlugins = await getInstalledPlugins();
|
|
38
39
|
// Create the two indexes from the installed plugins
|
|
39
|
-
const
|
|
40
|
+
const pluginResourcesByNameKindRegistryVersion = new Map();
|
|
40
41
|
const pluginMetadataByKind = new Map();
|
|
41
42
|
for (const resource of installedPlugins){
|
|
43
|
+
const { metadata: { version, registry } } = resource;
|
|
42
44
|
for (const pluginMetadata of resource.spec.plugins){
|
|
43
45
|
const { kind, spec: { name } } = pluginMetadata;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const key = (0, _model.getPluginModuleCompoundKey)({
|
|
47
|
+
kind,
|
|
48
|
+
name,
|
|
49
|
+
registry,
|
|
50
|
+
version
|
|
51
|
+
});
|
|
52
|
+
if (pluginResourcesByNameKindRegistryVersion.has(key)) {
|
|
53
|
+
console.warn(`Got more than one ${kind} plugin for kind ${name}, registry '${registry || 'undefined'}', and version '${version || 'undefined'}'`);
|
|
48
54
|
}
|
|
49
|
-
|
|
55
|
+
pluginResourcesByNameKindRegistryVersion.set(key, resource);
|
|
50
56
|
// Index the metadata by plugin type
|
|
51
57
|
let list = pluginMetadataByKind.get(kind);
|
|
52
58
|
if (list === undefined) {
|
|
@@ -60,7 +66,7 @@ function usePluginIndexes(getInstalledPlugins) {
|
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
return {
|
|
63
|
-
|
|
69
|
+
pluginResourcesByNameKindRegistryVersion,
|
|
64
70
|
pluginMetadataByKind
|
|
65
71
|
};
|
|
66
72
|
});
|
|
@@ -72,7 +78,7 @@ function usePluginIndexes(getInstalledPlugins) {
|
|
|
72
78
|
request = createPluginIndexes();
|
|
73
79
|
pluginIndexesCache.current = request;
|
|
74
80
|
// Remove failed requests from the cache so they can potentially be retried
|
|
75
|
-
request.catch(()=>pluginIndexesCache.current
|
|
81
|
+
request.catch(()=>pluginIndexesCache.current = undefined);
|
|
76
82
|
}
|
|
77
83
|
return request;
|
|
78
84
|
}, [
|
|
@@ -80,6 +86,3 @@ function usePluginIndexes(getInstalledPlugins) {
|
|
|
80
86
|
]);
|
|
81
87
|
return getPluginIndexes;
|
|
82
88
|
}
|
|
83
|
-
function getTypeAndKindKey(kind, name) {
|
|
84
|
-
return `${kind}:${name}`;
|
|
85
|
-
}
|
|
@@ -27,7 +27,6 @@ const _components = require("@perses-dev/components");
|
|
|
27
27
|
const _reacthookform = require("react-hook-form");
|
|
28
28
|
const _zod = require("@hookform/resolvers/zod");
|
|
29
29
|
const _reactquery = require("@tanstack/react-query");
|
|
30
|
-
const _utils = require("../../../utils");
|
|
31
30
|
const _PluginEditor = require("../../PluginEditor");
|
|
32
31
|
const _context = require("../../../context");
|
|
33
32
|
const _variablemodel = require("../variable-model");
|
|
@@ -395,8 +394,8 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
395
394
|
}
|
|
396
395
|
function VariableEditorForm({ initialVariableDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete }) {
|
|
397
396
|
const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
|
|
398
|
-
const titleAction = (0,
|
|
399
|
-
const submitText = (0,
|
|
397
|
+
const titleAction = (0, _components.getTitleAction)(action, isDraft);
|
|
398
|
+
const submitText = (0, _components.getSubmitText)(action, isDraft);
|
|
400
399
|
const { variableEditorSchema } = (0, _context.useValidationSchemas)();
|
|
401
400
|
const form = (0, _reacthookform.useForm)({
|
|
402
401
|
resolver: (0, _zod.zodResolver)(variableEditorSchema),
|
|
@@ -32,9 +32,13 @@ _export(exports, {
|
|
|
32
32
|
},
|
|
33
33
|
get useListVariablePluginValues () {
|
|
34
34
|
return useListVariablePluginValues;
|
|
35
|
+
},
|
|
36
|
+
get useResolveListVariableValues () {
|
|
37
|
+
return useResolveListVariableValues;
|
|
35
38
|
}
|
|
36
39
|
});
|
|
37
40
|
const _reactquery = require("@tanstack/react-query");
|
|
41
|
+
const _react = require("react");
|
|
38
42
|
const _runtime = require("../../runtime");
|
|
39
43
|
function filterVariableList(data, capturedRegexp) {
|
|
40
44
|
const result = [];
|
|
@@ -61,54 +65,136 @@ function filterVariableList(data, capturedRegexp) {
|
|
|
61
65
|
}
|
|
62
66
|
return result;
|
|
63
67
|
}
|
|
64
|
-
function
|
|
65
|
-
const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
|
|
68
|
+
function useVariablePluginContext() {
|
|
66
69
|
const datasourceStore = (0, _runtime.useDatasourceStore)();
|
|
67
70
|
const allVariables = (0, _runtime.useAllVariableValues)();
|
|
68
71
|
const { absoluteTimeRange: timeRange } = (0, _runtime.useTimeRange)();
|
|
69
|
-
|
|
72
|
+
return {
|
|
70
73
|
timeRange,
|
|
71
74
|
datasourceStore,
|
|
72
75
|
variables: allVariables
|
|
73
76
|
};
|
|
74
|
-
|
|
77
|
+
}
|
|
78
|
+
const getVariableQueryConfig = (definition, variablePluginCtx, variablePlugin, enabled, onFetched)=>{
|
|
75
79
|
const capturingRegexp = definition.spec.capturingRegexp !== undefined ? new RegExp(definition.spec.capturingRegexp, 'g') : undefined;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
|
|
79
|
-
dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;
|
|
80
|
-
}
|
|
81
|
-
// Exclude self variable to avoid circular dependency
|
|
82
|
-
dependsOnVariables = dependsOnVariables.filter((v)=>v !== definition.spec.name);
|
|
83
|
-
const variables = (0, _runtime.useAllVariableValues)(dependsOnVariables);
|
|
84
|
-
let waitToLoad = false;
|
|
85
|
-
if (dependsOnVariables) {
|
|
86
|
-
waitToLoad = dependsOnVariables.some((v)=>variables[v]?.loading);
|
|
87
|
-
}
|
|
88
|
-
const variablesValueKey = getVariableValuesKey(variables);
|
|
89
|
-
return (0, _reactquery.useQuery)({
|
|
80
|
+
const variablesValueKey = getVariableValuesKey(variablePluginCtx.variables);
|
|
81
|
+
return {
|
|
90
82
|
queryKey: [
|
|
91
83
|
'variable',
|
|
92
84
|
definition,
|
|
93
|
-
timeRange,
|
|
85
|
+
variablePluginCtx.timeRange,
|
|
94
86
|
variablesValueKey
|
|
95
87
|
],
|
|
96
88
|
queryFn: async ({ signal })=>{
|
|
97
|
-
const resp = await variablePlugin?.getVariableOptions(spec,
|
|
98
|
-
datasourceStore,
|
|
99
|
-
variables,
|
|
100
|
-
timeRange
|
|
101
|
-
}, signal);
|
|
89
|
+
const resp = await variablePlugin?.getVariableOptions(definition.spec.plugin.spec, variablePluginCtx, signal);
|
|
102
90
|
if (!resp?.data?.length) {
|
|
91
|
+
onFetched?.(definition.spec.name, [], definition);
|
|
103
92
|
return [];
|
|
104
93
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return filterVariableList(resp.data, capturingRegexp);
|
|
94
|
+
const options = capturingRegexp ? filterVariableList(resp.data, capturingRegexp) : resp.data;
|
|
95
|
+
onFetched?.(definition.spec.name, options, definition);
|
|
96
|
+
return options;
|
|
109
97
|
},
|
|
110
|
-
enabled
|
|
98
|
+
enabled
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
function resolveDependsOnVariables(variablePlugin, variablePluginCtx, definition) {
|
|
102
|
+
if (variablePlugin?.dependsOn) {
|
|
103
|
+
const dependencies = variablePlugin.dependsOn(definition.spec.plugin.spec, variablePluginCtx);
|
|
104
|
+
return dependencies.variables ? dependencies.variables.filter((v)=>v !== definition.spec.name) : []; // Exclude self variable to avoid circular dependency and default to empty array to avoid deadlock
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
function useListVariablePluginValues(definition) {
|
|
109
|
+
const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
|
|
110
|
+
const variablePluginCtx = useVariablePluginContext();
|
|
111
|
+
const dependsOnVariables = resolveDependsOnVariables(variablePlugin, variablePluginCtx, definition);
|
|
112
|
+
const dependentVariables = (0, _runtime.useAllVariableValues)(dependsOnVariables);
|
|
113
|
+
const waitToLoad = dependsOnVariables.some((v)=>dependentVariables[v]?.loading);
|
|
114
|
+
const ctx = {
|
|
115
|
+
...variablePluginCtx,
|
|
116
|
+
variables: dependentVariables
|
|
117
|
+
};
|
|
118
|
+
return (0, _reactquery.useQuery)(getVariableQueryConfig(definition, ctx, variablePlugin, !!variablePlugin && !waitToLoad));
|
|
119
|
+
}
|
|
120
|
+
function resolveDefaultValue(definition, options) {
|
|
121
|
+
const { defaultValue, allowMultiple } = definition.spec;
|
|
122
|
+
if (defaultValue !== undefined && defaultValue !== null) {
|
|
123
|
+
return defaultValue;
|
|
124
|
+
}
|
|
125
|
+
if (options[0]?.value) {
|
|
126
|
+
const first = options[0].value;
|
|
127
|
+
return allowMultiple ? [
|
|
128
|
+
first
|
|
129
|
+
] : first;
|
|
130
|
+
}
|
|
131
|
+
return allowMultiple ? [] : '';
|
|
132
|
+
}
|
|
133
|
+
function useResolveListVariableValues(variableDefinitions) {
|
|
134
|
+
const { timeRange, datasourceStore, variables: outerVariableValues } = useVariablePluginContext();
|
|
135
|
+
const listVariables = (0, _react.useMemo)(()=>variableDefinitions.filter((v)=>v.kind === 'ListVariable'), [
|
|
136
|
+
variableDefinitions
|
|
137
|
+
]);
|
|
138
|
+
const pluginResults = (0, _runtime.usePlugins)('Variable', listVariables.map((d)=>({
|
|
139
|
+
kind: d.spec.plugin.kind
|
|
140
|
+
})));
|
|
141
|
+
// Resolved variable state. Updated by onFetched when queries resolve.
|
|
142
|
+
// Needed because of dependencies between variables that require multiple rounds of fetching.
|
|
143
|
+
const [resolvedVariables, setResolvedVariables] = (0, _react.useState)({});
|
|
144
|
+
const allVariables = (0, _react.useMemo)(()=>{
|
|
145
|
+
return {
|
|
146
|
+
...outerVariableValues,
|
|
147
|
+
...resolvedVariables
|
|
148
|
+
};
|
|
149
|
+
}, [
|
|
150
|
+
outerVariableValues,
|
|
151
|
+
resolvedVariables
|
|
152
|
+
]);
|
|
153
|
+
const onFetched = (0, _react.useCallback)((name, options, definition)=>{
|
|
154
|
+
setResolvedVariables((prev)=>({
|
|
155
|
+
...prev,
|
|
156
|
+
[name]: {
|
|
157
|
+
value: resolveDefaultValue(definition, options),
|
|
158
|
+
loading: false,
|
|
159
|
+
options
|
|
160
|
+
}
|
|
161
|
+
}));
|
|
162
|
+
}, []);
|
|
163
|
+
const queryResults = (0, _reactquery.useQueries)({
|
|
164
|
+
queries: listVariables.map((definition, index)=>{
|
|
165
|
+
const plugin = pluginResults[index]?.data;
|
|
166
|
+
const isPluginLoading = pluginResults[index]?.isLoading ?? true;
|
|
167
|
+
const dependsOn = resolveDependsOnVariables(plugin, {
|
|
168
|
+
timeRange,
|
|
169
|
+
datasourceStore,
|
|
170
|
+
variables: allVariables
|
|
171
|
+
}, definition);
|
|
172
|
+
const hasPendingDeps = dependsOn.some((v)=>resolvedVariables[v] === undefined && listVariables.some((lv)=>lv.spec.name === v) || allVariables[v]?.loading);
|
|
173
|
+
const dependentVariables = {};
|
|
174
|
+
for (const v of dependsOn){
|
|
175
|
+
const state = allVariables[v];
|
|
176
|
+
if (state) {
|
|
177
|
+
dependentVariables[v] = state;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const ctx = {
|
|
181
|
+
timeRange,
|
|
182
|
+
datasourceStore,
|
|
183
|
+
variables: dependentVariables
|
|
184
|
+
};
|
|
185
|
+
return getVariableQueryConfig(definition, ctx, plugin, !hasPendingDeps && !isPluginLoading, onFetched);
|
|
186
|
+
})
|
|
111
187
|
});
|
|
188
|
+
const initialVariableValues = (0, _react.useMemo)(()=>Object.fromEntries(Object.entries(allVariables).filter(([, state])=>state?.value !== undefined).map(([name, state])=>[
|
|
189
|
+
name,
|
|
190
|
+
state.value
|
|
191
|
+
])), [
|
|
192
|
+
allVariables
|
|
193
|
+
]);
|
|
194
|
+
return {
|
|
195
|
+
initialVariableValues,
|
|
196
|
+
isLoading: queryResults.some((r)=>r.isLoading)
|
|
197
|
+
};
|
|
112
198
|
}
|
|
113
199
|
function getVariableValuesKey(v) {
|
|
114
200
|
return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
+
_export_star(require("./Annotations"), exports);
|
|
17
18
|
_export_star(require("./CalculationSelector"), exports);
|
|
18
19
|
_export_star(require("./DatasourceEditorForm"), exports);
|
|
19
20
|
_export_star(require("./DatasourceSelect"), exports);
|