@perses-dev/plugin-system 0.50.0 → 0.51.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -71
- package/dist/cjs/components/DatasourceSelect.js +8 -13
- package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +534 -0
- package/dist/cjs/components/HTTPSettingsEditor/index.js +30 -0
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
- package/dist/cjs/components/MetricLabelInput/MetricLabelInput.js +41 -0
- package/dist/cjs/components/MetricLabelInput/index.js +30 -0
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
- package/dist/cjs/components/PluginEditor/PluginEditor.js +10 -6
- package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -5
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +7 -8
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +7 -10
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +17 -14
- package/dist/cjs/components/ProjectSelect.js +2 -3
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
- package/dist/cjs/components/Variables/variable-model.js +4 -7
- package/dist/cjs/components/index.js +2 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/model/explore.js +16 -0
- package/dist/cjs/remote/PersesPlugin.types.js +16 -0
- package/dist/cjs/remote/PluginLoaderComponent.js +75 -0
- package/dist/cjs/remote/PluginRuntime.js +267 -0
- package/dist/cjs/remote/index.js +31 -0
- package/dist/cjs/remote/remotePluginLoader.js +61 -0
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
- package/dist/cjs/runtime/DataQueriesProvider/model.js +4 -7
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
- package/dist/cjs/runtime/builtin-variables.js +1 -1
- package/dist/cjs/runtime/datasources.js +3 -3
- package/dist/cjs/runtime/plugin-registry.js +5 -6
- package/dist/cjs/runtime/time-series-queries.js +11 -18
- package/dist/cjs/runtime/trace-queries.js +1 -2
- package/dist/cjs/runtime/variables.js +10 -28
- package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +1 -1
- package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +1 -67
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +4 -4
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemVariables.js +1 -1
- package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +1 -1
- package/dist/cjs/test/render.js +1 -2
- package/dist/cjs/test-utils/mock-plugin-registry.js +10 -10
- package/dist/cjs/utils/variables.js +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -30
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/DatasourceSelect.d.ts +2 -2
- package/dist/components/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect.js +8 -13
- package/dist/components/DatasourceSelect.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +11 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +480 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -0
- package/dist/components/HTTPSettingsEditor/index.d.ts +2 -0
- package/dist/components/HTTPSettingsEditor/index.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/index.js +15 -0
- package/dist/components/HTTPSettingsEditor/index.js.map +1 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.d.ts +7 -0
- package/dist/components/MetricLabelInput/MetricLabelInput.d.ts.map +1 -0
- package/dist/components/MetricLabelInput/MetricLabelInput.js +33 -0
- package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -0
- package/dist/components/MetricLabelInput/index.d.ts +2 -0
- package/dist/components/MetricLabelInput/index.d.ts.map +1 -0
- package/dist/components/MetricLabelInput/index.js +15 -0
- package/dist/components/MetricLabelInput/index.js.map +1 -0
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
- 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 +10 -6
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +4 -5
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -8
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +7 -10
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -4
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +17 -14
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/ProjectSelect.js +2 -3
- package/dist/components/ProjectSelect.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/variable-model.js +4 -7
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/explore.d.ts +13 -0
- package/dist/model/explore.d.ts.map +1 -0
- package/dist/model/explore.js +17 -0
- package/dist/model/explore.js.map +1 -0
- package/dist/model/panels.d.ts +13 -3
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/plugins.d.ts +31 -17
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/remote/PersesPlugin.types.d.ts +7 -0
- package/dist/remote/PersesPlugin.types.d.ts.map +1 -0
- package/dist/remote/PersesPlugin.types.js +15 -0
- package/dist/remote/PersesPlugin.types.js.map +1 -0
- package/dist/remote/PluginLoaderComponent.d.ts +10 -0
- package/dist/remote/PluginLoaderComponent.d.ts.map +1 -0
- package/dist/remote/PluginLoaderComponent.js +67 -0
- package/dist/remote/PluginLoaderComponent.js.map +1 -0
- package/dist/remote/PluginRuntime.d.ts +11 -0
- package/dist/remote/PluginRuntime.d.ts.map +1 -0
- package/dist/remote/PluginRuntime.js +202 -0
- package/dist/remote/PluginRuntime.js.map +1 -0
- package/dist/remote/index.d.ts +3 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +16 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote/remotePluginLoader.d.ts +3 -0
- package/dist/remote/remotePluginLoader.d.ts.map +1 -0
- package/dist/remote/remotePluginLoader.js +53 -0
- package/dist/remote/remotePluginLoader.js.map +1 -0
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
- 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 +4 -7
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/builtin-variables.js +1 -1
- package/dist/runtime/builtin-variables.js.map +1 -1
- package/dist/runtime/datasources.d.ts +2 -2
- package/dist/runtime/datasources.js +3 -3
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +6 -6
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +5 -6
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/time-series-queries.js +11 -18
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.js +1 -2
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/variables.js +10 -28
- package/dist/runtime/variables.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithDataQueries.js +1 -1
- package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -22
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +4 -4
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.js +1 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
- package/dist/test/render.js +1 -2
- package/dist/test/render.js.map +1 -1
- package/dist/test-utils/mock-plugin-registry.d.ts +5 -3
- package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
- package/dist/test-utils/mock-plugin-registry.js +10 -10
- package/dist/test-utils/mock-plugin-registry.js.map +1 -1
- package/dist/utils/variables.js +1 -1
- package/dist/utils/variables.js.map +1 -1
- package/package.json +6 -5
|
@@ -33,34 +33,35 @@ function _interop_require_default(obj) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function useDefaultQueryDefinition(queryTypes) {
|
|
36
|
-
var _queryPlugins_;
|
|
37
36
|
// Build the default query plugin
|
|
38
37
|
// This will be used only if the queries are empty, to open a starting query
|
|
39
38
|
// Firs the default query type
|
|
40
39
|
const defaultQueryType = queryTypes[0];
|
|
41
40
|
// Then the default plugin kind
|
|
42
41
|
// Use as default the plugin kind explicitly set as default or the first in the list
|
|
43
|
-
const { data: queryPlugins } = (0, _runtime.useListPluginMetadata)(queryTypes);
|
|
42
|
+
const { data: queryPlugins, isLoading } = (0, _runtime.useListPluginMetadata)(queryTypes);
|
|
44
43
|
const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
|
|
45
|
-
|
|
46
|
-
const defaultQueryKind = (_ref = (_defaultPluginKinds_defaultQueryType = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[defaultQueryType]) !== null && _defaultPluginKinds_defaultQueryType !== void 0 ? _defaultPluginKinds_defaultQueryType : queryPlugins === null || queryPlugins === void 0 ? void 0 : (_queryPlugins_ = queryPlugins[0]) === null || _queryPlugins_ === void 0 ? void 0 : _queryPlugins_.kind) !== null && _ref !== void 0 ? _ref : '';
|
|
44
|
+
const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
|
|
47
45
|
const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(defaultQueryType, defaultQueryKind, {
|
|
48
|
-
|
|
46
|
+
throwOnError: true,
|
|
49
47
|
enabled: true
|
|
50
48
|
});
|
|
51
49
|
// This default query definition is used if no query is provided initially or when we add a new query
|
|
52
50
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
defaultInitialQueryDefinition: {
|
|
52
|
+
kind: defaultQueryType,
|
|
53
|
+
spec: {
|
|
54
|
+
plugin: {
|
|
55
|
+
kind: defaultQueryKind,
|
|
56
|
+
spec: defaultQueryPlugin?.createInitialOptions() || {}
|
|
57
|
+
}
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
},
|
|
60
|
+
isLoading
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
|
|
63
|
-
const defaultInitialQueryDefinition = useDefaultQueryDefinition(queryTypes);
|
|
64
|
+
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
|
|
64
65
|
// State for which queries are collapsed
|
|
65
66
|
const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
|
|
66
67
|
// Query handlers
|
|
@@ -113,9 +114,9 @@ function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
|
|
|
113
114
|
});
|
|
114
115
|
};
|
|
115
116
|
// show one query input if queries is empty
|
|
116
|
-
const queryDefinitions = queries.length ? queries : [
|
|
117
|
+
const queryDefinitions = queries.length ? queries : !isLoading ? [
|
|
117
118
|
defaultInitialQueryDefinition
|
|
118
|
-
];
|
|
119
|
+
] : [];
|
|
119
120
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
120
121
|
children: [
|
|
121
122
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
@@ -29,14 +29,14 @@ const _MultiQueryEditor = require("../MultiQueryEditor");
|
|
|
29
29
|
function PanelSpecEditor(props) {
|
|
30
30
|
const { control, panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;
|
|
31
31
|
const { kind } = panelDefinition.spec.plugin;
|
|
32
|
-
const { data: plugin,
|
|
32
|
+
const { data: plugin, isPending, error } = (0, _runtime.usePlugin)('Panel', kind);
|
|
33
33
|
if (error) {
|
|
34
34
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorAlert, {
|
|
35
35
|
error: error
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
// TODO: Proper loading indicator
|
|
39
|
-
if (
|
|
39
|
+
if (isPending) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
42
|
if (plugin === undefined) {
|
|
@@ -50,17 +50,14 @@ function PanelSpecEditor(props) {
|
|
|
50
50
|
content: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
|
|
51
51
|
control: control,
|
|
52
52
|
name: "panelDefinition.spec.queries",
|
|
53
|
-
render: ({ field })
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
queryTypes: (_plugin_supportedQueryTypes = plugin.supportedQueryTypes) !== null && _plugin_supportedQueryTypes !== void 0 ? _plugin_supportedQueryTypes : [],
|
|
57
|
-
queries: (_panelDefinition_spec_queries = panelDefinition.spec.queries) !== null && _panelDefinition_spec_queries !== void 0 ? _panelDefinition_spec_queries : [],
|
|
53
|
+
render: ({ field })=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_MultiQueryEditor.MultiQueryEditor, {
|
|
54
|
+
queryTypes: plugin.supportedQueryTypes ?? [],
|
|
55
|
+
queries: panelDefinition.spec.queries ?? [],
|
|
58
56
|
onChange: (queries)=>{
|
|
59
57
|
field.onChange(queries);
|
|
60
58
|
onQueriesChange(queries);
|
|
61
59
|
}
|
|
62
|
-
})
|
|
63
|
-
}
|
|
60
|
+
})
|
|
64
61
|
})
|
|
65
62
|
});
|
|
66
63
|
}
|
|
@@ -102,9 +99,8 @@ function PanelSpecEditor(props) {
|
|
|
102
99
|
})
|
|
103
100
|
})
|
|
104
101
|
});
|
|
105
|
-
var _panelDefinition_spec_queries;
|
|
106
102
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.QueryCountProvider, {
|
|
107
|
-
queryCount: (
|
|
103
|
+
queryCount: (panelDefinition.spec.queries ?? []).length,
|
|
108
104
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_OptionsEditorTabs.OptionsEditorTabs, {
|
|
109
105
|
tabs: tabs
|
|
110
106
|
}, tabs.length)
|
|
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "PluginEditor", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
|
+
const _components = require("@perses-dev/components");
|
|
25
26
|
const _PluginKindSelect = require("../PluginKindSelect");
|
|
26
27
|
const _PluginSpecEditor = require("../PluginSpecEditor");
|
|
27
28
|
const _plugineditorapi = require("./plugin-editor-api");
|
|
@@ -47,14 +48,17 @@ function PluginEditor(props) {
|
|
|
47
48
|
readOnly: isReadonly
|
|
48
49
|
},
|
|
49
50
|
error: !!error,
|
|
50
|
-
helperText: error
|
|
51
|
+
helperText: error?.message,
|
|
51
52
|
onChange: onSelectionChange
|
|
52
53
|
}),
|
|
53
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
|
|
55
|
+
FallbackComponent: _components.ErrorAlert,
|
|
56
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginSpecEditor.PluginSpecEditor, {
|
|
57
|
+
pluginSelection: value.selection,
|
|
58
|
+
value: value.spec,
|
|
59
|
+
onChange: onSpecChange,
|
|
60
|
+
isReadonly: isReadonly
|
|
61
|
+
})
|
|
58
62
|
})
|
|
59
63
|
]
|
|
60
64
|
});
|
|
@@ -50,7 +50,7 @@ function usePluginEditor(props) {
|
|
|
50
50
|
});
|
|
51
51
|
const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
|
|
52
52
|
const defaultPluginType = pluginTypes[0];
|
|
53
|
-
const defaultPluginKind = defaultPluginType ? defaultPluginKinds
|
|
53
|
+
const defaultPluginKind = defaultPluginType ? defaultPluginKinds?.[defaultPluginType] : undefined;
|
|
54
54
|
const defaultPluginSelection = defaultPluginType && defaultPluginKind ? {
|
|
55
55
|
type: defaultPluginType,
|
|
56
56
|
kind: defaultPluginKind
|
|
@@ -68,7 +68,7 @@ function usePluginEditor(props) {
|
|
|
68
68
|
value.selection,
|
|
69
69
|
defaultPluginKind
|
|
70
70
|
]);
|
|
71
|
-
const { data: plugin, isFetching, error } = (0, _runtime.usePlugin)(pendingSelection
|
|
71
|
+
const { data: plugin, isFetching, error } = (0, _runtime.usePlugin)(pendingSelection?.type, pendingSelection?.kind || '');
|
|
72
72
|
(0, _react.useEffect)(()=>{
|
|
73
73
|
// Nothing to do if no new plugin kind is pending
|
|
74
74
|
if (!pendingSelection) return;
|
|
@@ -78,7 +78,7 @@ function usePluginEditor(props) {
|
|
|
78
78
|
rememberCurrentSpecState();
|
|
79
79
|
onChange({
|
|
80
80
|
selection: pendingSelection,
|
|
81
|
-
spec: plugin.createInitialOptions()
|
|
81
|
+
spec: plugin.createInitialOptions ? plugin.createInitialOptions() : {}
|
|
82
82
|
});
|
|
83
83
|
if (pendingSelection.type === 'Panel') {
|
|
84
84
|
const panelPlugin = plugin;
|
|
@@ -101,9 +101,8 @@ function usePluginEditor(props) {
|
|
|
101
101
|
* When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
|
|
102
102
|
* make the switch.
|
|
103
103
|
*/ const onSelectionChange = (nextSelection)=>{
|
|
104
|
-
var _prevSpecState_current_nextSelection_type;
|
|
105
104
|
// If we already have state for this plugin type/kind from a previous selection, just use it
|
|
106
|
-
const previousState =
|
|
105
|
+
const previousState = prevSpecState.current[nextSelection.type]?.[nextSelection.kind];
|
|
107
106
|
if (previousState !== undefined) {
|
|
108
107
|
rememberCurrentSpecState();
|
|
109
108
|
onChange({
|
|
@@ -30,15 +30,14 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
30
30
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
31
31
|
const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
|
|
32
32
|
const handleChange = (event)=>{
|
|
33
|
-
onChange
|
|
33
|
+
onChange?.(optionValueToSelection(event.target.value));
|
|
34
34
|
};
|
|
35
35
|
const renderValue = (0, _react.useCallback)((selected)=>{
|
|
36
|
-
var _data_find;
|
|
37
36
|
if (selected === '') {
|
|
38
37
|
return '';
|
|
39
38
|
}
|
|
40
39
|
const selectedValue = optionValueToSelection(selected);
|
|
41
|
-
return data
|
|
40
|
+
return data?.find((v)=>v.kind === selectedValue.type && v.spec.name === selectedValue.kind)?.spec.display.name;
|
|
42
41
|
}, [
|
|
43
42
|
data
|
|
44
43
|
]);
|
|
@@ -59,14 +58,14 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
59
58
|
value: "",
|
|
60
59
|
children: "Loading..."
|
|
61
60
|
}),
|
|
62
|
-
data
|
|
61
|
+
data?.map((metadata)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
63
62
|
"data-testid": "option",
|
|
64
63
|
value: selectionToOptionValue({
|
|
65
|
-
type: metadata.
|
|
66
|
-
kind: metadata.
|
|
64
|
+
type: metadata.kind,
|
|
65
|
+
kind: metadata.spec.name
|
|
67
66
|
}),
|
|
68
|
-
children: metadata.display.name
|
|
69
|
-
}, metadata.
|
|
67
|
+
children: metadata.spec.display.name
|
|
68
|
+
}, metadata.kind + metadata.spec.name))
|
|
70
69
|
]
|
|
71
70
|
});
|
|
72
71
|
});
|
|
@@ -42,21 +42,21 @@ function PluginRegistry(props) {
|
|
|
42
42
|
}
|
|
43
43
|
return request;
|
|
44
44
|
});
|
|
45
|
-
const getPlugin = (0, _react.useCallback)(async (
|
|
45
|
+
const getPlugin = (0, _react.useCallback)(async (kind, name)=>{
|
|
46
46
|
// Get the indexes of the installed plugins
|
|
47
47
|
const pluginIndexes = await getPluginIndexes();
|
|
48
48
|
// Figure out what module the plugin is in by looking in the index
|
|
49
|
-
const typeAndKindKey = (0, _pluginindexes.getTypeAndKindKey)(
|
|
50
|
-
const resource = pluginIndexes.
|
|
49
|
+
const typeAndKindKey = (0, _pluginindexes.getTypeAndKindKey)(kind, name);
|
|
50
|
+
const resource = pluginIndexes.pluginResourcesByNameAndKind.get(typeAndKindKey);
|
|
51
51
|
if (resource === undefined) {
|
|
52
|
-
throw new Error(`A ${
|
|
52
|
+
throw new Error(`A ${name} plugin for kind '${kind}' is not installed`);
|
|
53
53
|
}
|
|
54
54
|
// Treat the plugin module as a bunch of named exports that have plugins
|
|
55
55
|
const pluginModule = await loadPluginModule(resource);
|
|
56
56
|
// We currently assume that plugin modules will have named exports that match the kinds they handle
|
|
57
|
-
const plugin = pluginModule[
|
|
57
|
+
const plugin = pluginModule[name];
|
|
58
58
|
if (plugin === undefined) {
|
|
59
|
-
throw new Error(`The ${
|
|
59
|
+
throw new Error(`The ${name} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`);
|
|
60
60
|
}
|
|
61
61
|
return plugin;
|
|
62
62
|
}, [
|
|
@@ -65,10 +65,7 @@ function PluginRegistry(props) {
|
|
|
65
65
|
]);
|
|
66
66
|
const listPluginMetadata = (0, _react.useCallback)(async (pluginTypes)=>{
|
|
67
67
|
const pluginIndexes = await getPluginIndexes();
|
|
68
|
-
return pluginTypes.flatMap((type)=>
|
|
69
|
-
var _pluginIndexes_pluginMetadataByType_get;
|
|
70
|
-
return (_pluginIndexes_pluginMetadataByType_get = pluginIndexes.pluginMetadataByType.get(type)) !== null && _pluginIndexes_pluginMetadataByType_get !== void 0 ? _pluginIndexes_pluginMetadataByType_get : [];
|
|
71
|
-
});
|
|
68
|
+
return pluginTypes.flatMap((type)=>pluginIndexes.pluginMetadataByKind.get(type) ?? []);
|
|
72
69
|
}, [
|
|
73
70
|
getPluginIndexes
|
|
74
71
|
]);
|
|
@@ -36,29 +36,32 @@ function usePluginIndexes(getInstalledPlugins) {
|
|
|
36
36
|
const createPluginIndexes = (0, _core.useEvent)(async ()=>{
|
|
37
37
|
const installedPlugins = await getInstalledPlugins();
|
|
38
38
|
// Create the two indexes from the installed plugins
|
|
39
|
-
const
|
|
40
|
-
const
|
|
39
|
+
const pluginResourcesByNameAndKind = new Map();
|
|
40
|
+
const pluginMetadataByKind = new Map();
|
|
41
41
|
for (const resource of installedPlugins){
|
|
42
42
|
for (const pluginMetadata of resource.spec.plugins){
|
|
43
|
-
const {
|
|
43
|
+
const { kind, spec: { name } } = pluginMetadata;
|
|
44
44
|
// Index the plugin by type and kind to point at the module that contains it
|
|
45
|
-
const key = getTypeAndKindKey(
|
|
46
|
-
if (
|
|
47
|
-
console.warn(`Got more than one ${
|
|
45
|
+
const key = getTypeAndKindKey(kind, name);
|
|
46
|
+
if (pluginResourcesByNameAndKind.has(key)) {
|
|
47
|
+
console.warn(`Got more than one ${kind} plugin for kind ${name}`);
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
pluginResourcesByNameAndKind.set(key, resource);
|
|
50
50
|
// Index the metadata by plugin type
|
|
51
|
-
let list =
|
|
51
|
+
let list = pluginMetadataByKind.get(kind);
|
|
52
52
|
if (list === undefined) {
|
|
53
53
|
list = [];
|
|
54
|
-
|
|
54
|
+
pluginMetadataByKind.set(kind, list);
|
|
55
55
|
}
|
|
56
|
-
list.push(
|
|
56
|
+
list.push({
|
|
57
|
+
...pluginMetadata,
|
|
58
|
+
module: resource.metadata
|
|
59
|
+
});
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
return {
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
pluginResourcesByNameAndKind,
|
|
64
|
+
pluginMetadataByKind
|
|
62
65
|
};
|
|
63
66
|
});
|
|
64
67
|
// De-dupe creating plugin indexes (i.e. requests to get installed plugins)
|
|
@@ -77,6 +80,6 @@ function usePluginIndexes(getInstalledPlugins) {
|
|
|
77
80
|
]);
|
|
78
81
|
return getPluginIndexes;
|
|
79
82
|
}
|
|
80
|
-
function getTypeAndKindKey(
|
|
81
|
-
return `${
|
|
83
|
+
function getTypeAndKindKey(kind, name) {
|
|
84
|
+
return `${kind}:${name}`;
|
|
82
85
|
}
|
|
@@ -56,7 +56,7 @@ function ProjectSelect(props) {
|
|
|
56
56
|
})
|
|
57
57
|
})
|
|
58
58
|
}),
|
|
59
|
-
data
|
|
59
|
+
data?.map((project)=>[
|
|
60
60
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
61
61
|
value: project.metadata.name,
|
|
62
62
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
@@ -79,8 +79,7 @@ function ProjectSelect(props) {
|
|
|
79
79
|
* returns a string value that can be used as a Select input value.
|
|
80
80
|
* @param selector
|
|
81
81
|
*/ function projectToOptionValue(project) {
|
|
82
|
-
|
|
83
|
-
return (_project_metadata_name = project.metadata.name) !== null && _project_metadata_name !== void 0 ? _project_metadata_name : 'none';
|
|
82
|
+
return project.metadata.name ?? 'none';
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
85
|
* Given an option value name,
|