@perses-dev/plugin-system 0.54.0-beta.0 → 0.54.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/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/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/context/ValidationProvider.js +3 -3
- package/dist/cjs/model/alerts-queries.js +16 -0
- package/dist/cjs/model/calculations.js +178 -0
- package/dist/cjs/model/index.js +3 -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 +38 -9
- package/dist/cjs/remote/remotePluginLoader.js +28 -5
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +18 -2
- package/dist/cjs/runtime/DataQueriesProvider/model.js +30 -4
- package/dist/cjs/runtime/UsageMetricsProvider.js +2 -2
- package/dist/cjs/runtime/alerts-queries.js +101 -0
- package/dist/cjs/runtime/index.js +2 -0
- 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/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 +2 -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 +1 -1
- 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.js +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- 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.js +1 -1
- 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/context/ValidationProvider.d.ts +1 -1
- package/dist/context/ValidationProvider.d.ts.map +1 -1
- package/dist/context/ValidationProvider.js +2 -2
- 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/{utils/action.js → model/alerts-queries.js} +2 -14
- package/dist/model/alerts-queries.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 +3 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +3 -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/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 +21 -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/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 +38 -9
- 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 +19 -3
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +30 -4
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/QueryCountProvider.js +1 -1
- package/dist/runtime/QueryCountProvider.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/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -0
- 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 -1
- 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 +6 -5
- package/dist/cjs/utils/action.js +0 -43
- 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
|
@@ -22,8 +22,8 @@ Object.defineProperty(exports, "CalculationSelector", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _components = require("@perses-dev/components");
|
|
25
|
-
const
|
|
26
|
-
const CALC_OPTIONS = Object.entries(
|
|
25
|
+
const _model = require("../../model");
|
|
26
|
+
const CALC_OPTIONS = Object.entries(_model.CALCULATIONS_CONFIG).map(([id, config])=>{
|
|
27
27
|
return {
|
|
28
28
|
id: id,
|
|
29
29
|
...config
|
|
@@ -33,7 +33,7 @@ function CalculationSelector({ value, onChange }) {
|
|
|
33
33
|
const handleCalculationChange = (_, newValue)=>{
|
|
34
34
|
onChange(newValue.id);
|
|
35
35
|
};
|
|
36
|
-
const calcConfig =
|
|
36
|
+
const calcConfig = _model.CALCULATIONS_CONFIG[value];
|
|
37
37
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
38
38
|
label: "Calculation",
|
|
39
39
|
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
@@ -27,13 +27,12 @@ const _components = require("@perses-dev/components");
|
|
|
27
27
|
const _react = require("react");
|
|
28
28
|
const _reacthookform = require("react-hook-form");
|
|
29
29
|
const _context = require("../../context");
|
|
30
|
-
const _utils = require("../../utils");
|
|
31
30
|
const _PluginEditor = require("../PluginEditor");
|
|
32
31
|
function DatasourceEditorForm(props) {
|
|
33
32
|
const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;
|
|
34
33
|
const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
|
|
35
|
-
const titleAction = (0,
|
|
36
|
-
const submitText = (0,
|
|
34
|
+
const titleAction = (0, _components.getTitleAction)(action, isDraft);
|
|
35
|
+
const submitText = (0, _components.getSubmitText)(action, isDraft);
|
|
37
36
|
const { datasourceEditorSchema } = (0, _context.useValidationSchemas)();
|
|
38
37
|
const form = (0, _reacthookform.useForm)({
|
|
39
38
|
resolver: (0, _zod.zodResolver)(datasourceEditorSchema),
|
|
@@ -22,7 +22,6 @@ Object.defineProperty(exports, "LegendOptionsEditor", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
|
-
const _core = require("@perses-dev/core");
|
|
26
25
|
const _components = require("@perses-dev/components");
|
|
27
26
|
const _react = require("react");
|
|
28
27
|
const _model = require("../../model");
|
|
@@ -42,7 +41,7 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
42
41
|
const handleLegendShowChange = (_, checked)=>{
|
|
43
42
|
// legend is hidden when legend obj is undefined
|
|
44
43
|
const legendValue = checked === true ? {
|
|
45
|
-
position:
|
|
44
|
+
position: _components.DEFAULT_LEGEND.position
|
|
46
45
|
} : undefined;
|
|
47
46
|
onChange(legendValue);
|
|
48
47
|
};
|
|
@@ -69,10 +68,10 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
69
68
|
});
|
|
70
69
|
};
|
|
71
70
|
const isValidLegend = (0, _model.validateLegendSpec)(value);
|
|
72
|
-
const currentPosition = (0,
|
|
71
|
+
const currentPosition = (0, _components.getLegendPosition)(value?.position);
|
|
73
72
|
const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
74
|
-
const currentMode = (0,
|
|
75
|
-
const currentSize = (0,
|
|
73
|
+
const currentMode = (0, _components.getLegendMode)(value?.mode);
|
|
74
|
+
const currentSize = (0, _components.getLegendSize)(value?.size);
|
|
76
75
|
const legendSizeConfig = _model.LEGEND_SIZE_CONFIG[currentSize];
|
|
77
76
|
const legendValuesConfig = (0, _react.useMemo)(()=>{
|
|
78
77
|
const currentValues = value?.values;
|
|
@@ -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(',');
|
|
@@ -34,7 +34,7 @@ _export(exports, {
|
|
|
34
34
|
const _jsxruntime = require("react/jsx-runtime");
|
|
35
35
|
const _react = require("react");
|
|
36
36
|
const _spec = require("@perses-dev/spec");
|
|
37
|
-
const
|
|
37
|
+
const _client = require("@perses-dev/client");
|
|
38
38
|
const ValidationSchemasContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
|
|
39
39
|
function useValidationSchemas() {
|
|
40
40
|
const ctx = (0, _react.useContext)(ValidationSchemasContext);
|
|
@@ -44,11 +44,11 @@ function useValidationSchemas() {
|
|
|
44
44
|
return ctx;
|
|
45
45
|
}
|
|
46
46
|
function ValidationProvider({ children }) {
|
|
47
|
-
const [datasourceEditorSchema, setDatasourceEditorSchema] = (0, _react.useState)(
|
|
47
|
+
const [datasourceEditorSchema, setDatasourceEditorSchema] = (0, _react.useState)(_client.datasourceDefinitionSchema);
|
|
48
48
|
const [panelEditorSchema, setPanelEditorSchema] = (0, _react.useState)(_spec.panelEditorSchema); // TODO I don't get why this does not compile
|
|
49
49
|
const [variableEditorSchema, setVariableEditorSchema] = (0, _react.useState)(_spec.variableDefinitionSchema);
|
|
50
50
|
function setDatasourceEditorSchemaPlugin(pluginSchema) {
|
|
51
|
-
setDatasourceEditorSchema((0,
|
|
51
|
+
setDatasourceEditorSchema((0, _client.buildDatasourceDefinitionSchema)(pluginSchema));
|
|
52
52
|
}
|
|
53
53
|
function setPanelEditorSchemaPlugin(pluginSchema) {
|
|
54
54
|
setPanelEditorSchema((0, _spec.buildPanelEditorSchema)(pluginSchema));
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
});
|