@perses-dev/plugin-system 0.50.1 → 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 +1 -1
- package/dist/cjs/components/MetricLabelInput/index.js +1 -1
- 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 +1 -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.js +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
- package/dist/components/MetricLabelInput/index.js +1 -1
- package/dist/components/MetricLabelInput/index.js.map +1 -1
- 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 +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/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
|
@@ -41,22 +41,14 @@ const _react = require("react");
|
|
|
41
41
|
const _immer = require("immer");
|
|
42
42
|
const _utils = require("../utils");
|
|
43
43
|
const _builtinvariables = require("./builtin-variables");
|
|
44
|
-
function _define_property(obj, key, value) {
|
|
45
|
-
if (key in obj) {
|
|
46
|
-
Object.defineProperty(obj, key, {
|
|
47
|
-
value: value,
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
obj[key] = value;
|
|
54
|
-
}
|
|
55
|
-
return obj;
|
|
56
|
-
}
|
|
57
|
-
let _immerable = _immer.immerable;
|
|
58
44
|
class VariableStoreStateMap {
|
|
59
45
|
/**
|
|
46
|
+
* "Immerable" is mandatory to be able to use this class in an immer context.
|
|
47
|
+
* Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
|
|
48
|
+
*/ [_immer.immerable] = true;
|
|
49
|
+
DEFAULT_LOCAL_SOURCE_NAME = '';
|
|
50
|
+
_state = {};
|
|
51
|
+
/**
|
|
60
52
|
* Get variable state by key.
|
|
61
53
|
* @param key
|
|
62
54
|
*/ get(key) {
|
|
@@ -84,7 +76,6 @@ class VariableStoreStateMap {
|
|
|
84
76
|
* Delete variable state by key.
|
|
85
77
|
* @param key
|
|
86
78
|
*/ delete(key) {
|
|
87
|
-
var _Object_keys;
|
|
88
79
|
const result = this.has(key);
|
|
89
80
|
const sourceName = this._sourceName(key.source);
|
|
90
81
|
const sourceStates = this._state[sourceName];
|
|
@@ -93,25 +84,16 @@ class VariableStoreStateMap {
|
|
|
93
84
|
delete sourceStates[key.name];
|
|
94
85
|
}
|
|
95
86
|
// Delete source state from state if empty
|
|
96
|
-
if (
|
|
87
|
+
if (Object.keys(sourceStates ?? {})?.length === 0) {
|
|
97
88
|
delete this._state[sourceName];
|
|
98
89
|
}
|
|
99
90
|
return result;
|
|
100
91
|
}
|
|
101
92
|
_sourceName(source) {
|
|
102
|
-
return source
|
|
93
|
+
return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;
|
|
103
94
|
}
|
|
104
95
|
_sourceStatesOrEmpty(source) {
|
|
105
|
-
|
|
106
|
-
return (_this__state_this__sourceName = this._state[this._sourceName(source)]) !== null && _this__state_this__sourceName !== void 0 ? _this__state_this__sourceName : {};
|
|
107
|
-
}
|
|
108
|
-
constructor(){
|
|
109
|
-
/**
|
|
110
|
-
* "Immerable" is mandatory to be able to use this class in an immer context.
|
|
111
|
-
* Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
|
|
112
|
-
*/ _define_property(this, _immerable, true);
|
|
113
|
-
_define_property(this, "DEFAULT_LOCAL_SOURCE_NAME", '');
|
|
114
|
-
_define_property(this, "_state", {});
|
|
96
|
+
return this._state[this._sourceName(source)] ?? {};
|
|
115
97
|
}
|
|
116
98
|
}
|
|
117
99
|
const VariableContext = (0, _react.createContext)(undefined);
|
|
@@ -126,7 +108,7 @@ function useVariableValues(names) {
|
|
|
126
108
|
const { state } = useVariableContext();
|
|
127
109
|
const values = (0, _react.useMemo)(()=>{
|
|
128
110
|
const values = {};
|
|
129
|
-
names
|
|
111
|
+
names?.forEach((name)=>{
|
|
130
112
|
const s = state[name];
|
|
131
113
|
if (s) {
|
|
132
114
|
values[name] = s;
|
|
@@ -33,7 +33,7 @@ const WithDataQueries = (Story, context)=>{
|
|
|
33
33
|
definitions: []
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
const props = parameter
|
|
36
|
+
const props = parameter?.props;
|
|
37
37
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DataQueriesProvider, {
|
|
38
38
|
...props,
|
|
39
39
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Story, {})
|
|
@@ -22,75 +22,9 @@ Object.defineProperty(exports, "WithPluginRegistry", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
25
|
-
const _pluginjson = /*#__PURE__*/ _interop_require_default(require("@perses-dev/prometheus-plugin/plugin.json"));
|
|
26
|
-
const _pluginjson1 = /*#__PURE__*/ _interop_require_default(require("@perses-dev/panels-plugin/plugin.json"));
|
|
27
|
-
function _interop_require_default(obj) {
|
|
28
|
-
return obj && obj.__esModule ? obj : {
|
|
29
|
-
default: obj
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
-
if (typeof WeakMap !== "function") return null;
|
|
34
|
-
var cacheBabelInterop = new WeakMap();
|
|
35
|
-
var cacheNodeInterop = new WeakMap();
|
|
36
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
-
})(nodeInterop);
|
|
39
|
-
}
|
|
40
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
41
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
-
return {
|
|
46
|
-
default: obj
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
-
if (cache && cache.has(obj)) {
|
|
51
|
-
return cache.get(obj);
|
|
52
|
-
}
|
|
53
|
-
var newObj = {
|
|
54
|
-
__proto__: null
|
|
55
|
-
};
|
|
56
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
57
|
-
for(var key in obj){
|
|
58
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
59
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
60
|
-
if (desc && (desc.get || desc.set)) {
|
|
61
|
-
Object.defineProperty(newObj, key, desc);
|
|
62
|
-
} else {
|
|
63
|
-
newObj[key] = obj[key];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
newObj.default = obj;
|
|
68
|
-
if (cache) {
|
|
69
|
-
cache.set(obj, newObj);
|
|
70
|
-
}
|
|
71
|
-
return newObj;
|
|
72
|
-
}
|
|
73
|
-
const bundledPluginLoader = (0, _pluginsystem.dynamicImportPluginLoader)([
|
|
74
|
-
{
|
|
75
|
-
resource: _pluginjson.default,
|
|
76
|
-
// This throws an error in CI (but not locally for some reason), likely because
|
|
77
|
-
// this package isn't a dependency for dashboards. We probably do not want to
|
|
78
|
-
// make it one solely for type-checking in storybook.
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
importPlugin: ()=>Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("@perses-dev/prometheus-plugin")))
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
resource: _pluginjson1.default,
|
|
85
|
-
// Same comment as above.
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
importPlugin: ()=>Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("@perses-dev/panels-plugin")))
|
|
89
|
-
}
|
|
90
|
-
]);
|
|
91
25
|
const WithPluginRegistry = (Story)=>{
|
|
92
26
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.PluginRegistry, {
|
|
93
|
-
pluginLoader:
|
|
27
|
+
pluginLoader: (0, _pluginsystem.remotePluginLoader)(),
|
|
94
28
|
defaultPluginKinds: {
|
|
95
29
|
TimeSeriesQuery: 'PrometheusTimeSeriesQuery',
|
|
96
30
|
TraceQuery: 'TempoTraceQuery'
|
|
@@ -34,7 +34,7 @@ const WithPluginSystemBuiltinVariables = (Story, context)=>{
|
|
|
34
34
|
const parameter = isWithBuiltinVariableParameter(initParameter) ? initParameter : {
|
|
35
35
|
props: defaultValue
|
|
36
36
|
};
|
|
37
|
-
const props = parameter
|
|
37
|
+
const props = parameter?.props;
|
|
38
38
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.BuiltinVariableContext.Provider, {
|
|
39
39
|
value: props,
|
|
40
40
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Story, {})
|
|
@@ -60,8 +60,8 @@ const WithPluginSystemDatasourceStore = (Story, context)=>{
|
|
|
60
60
|
}
|
|
61
61
|
throw new Error(`WithDatasourceStore is not configured to support kind: ${selector.kind}`);
|
|
62
62
|
},
|
|
63
|
-
listDatasourceSelectItems: async (
|
|
64
|
-
if (
|
|
63
|
+
listDatasourceSelectItems: async (datasourcePluginName)=>{
|
|
64
|
+
if (datasourcePluginName === 'PrometheusDatasource') {
|
|
65
65
|
return Promise.resolve([
|
|
66
66
|
{
|
|
67
67
|
items: [
|
|
@@ -75,7 +75,7 @@ const WithPluginSystemDatasourceStore = (Story, context)=>{
|
|
|
75
75
|
}
|
|
76
76
|
]);
|
|
77
77
|
}
|
|
78
|
-
throw new Error(`WithDatasourceStore is not configured to support kind: ${
|
|
78
|
+
throw new Error(`WithDatasourceStore is not configured to support kind: ${datasourcePluginName}`);
|
|
79
79
|
},
|
|
80
80
|
getSavedDatasources: ()=>{
|
|
81
81
|
return {};
|
|
@@ -93,7 +93,7 @@ const WithPluginSystemDatasourceStore = (Story, context)=>{
|
|
|
93
93
|
const parameter = isWithDatastoreStoreParameter(initParameter) ? initParameter : {
|
|
94
94
|
props: defaultValue
|
|
95
95
|
};
|
|
96
|
-
const props = parameter
|
|
96
|
+
const props = parameter?.props;
|
|
97
97
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceStoreContext.Provider, {
|
|
98
98
|
value: props,
|
|
99
99
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Story, {})
|
|
@@ -34,7 +34,7 @@ const WithPluginSystemVariables = (Story, context)=>{
|
|
|
34
34
|
const parameter = isWithVariableParameter(initParameter) ? initParameter : {
|
|
35
35
|
props: defaultValue
|
|
36
36
|
};
|
|
37
|
-
const props = parameter
|
|
37
|
+
const props = parameter?.props;
|
|
38
38
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.VariableContext.Provider, {
|
|
39
39
|
value: props,
|
|
40
40
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Story, {})
|
|
@@ -29,7 +29,7 @@ function isWithTimeRangeParameter(parameter) {
|
|
|
29
29
|
const WithTimeRange = (Story, context)=>{
|
|
30
30
|
const initParameter = context.parameters.withTimeRange;
|
|
31
31
|
const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;
|
|
32
|
-
const props = parameter
|
|
32
|
+
const props = parameter?.props;
|
|
33
33
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.TimeRangeProvider, {
|
|
34
34
|
refreshInterval: "0s",
|
|
35
35
|
timeRange: {
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -35,12 +35,11 @@ function renderWithContext(ui, renderOptions, contextOptions) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
var _contextOptions_defaultPluginKinds;
|
|
39
38
|
return (0, _react.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
|
|
40
39
|
client: queryClient,
|
|
41
40
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginRegistry.PluginRegistry, {
|
|
42
41
|
pluginLoader: _testplugins.testPluginLoader,
|
|
43
|
-
defaultPluginKinds:
|
|
42
|
+
defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
|
|
44
43
|
TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
|
|
45
44
|
},
|
|
46
45
|
children: ui
|
|
@@ -33,17 +33,17 @@ function mockPluginRegistry(...mockPlugins) {
|
|
|
33
33
|
kind: 'PluginModule',
|
|
34
34
|
metadata: {
|
|
35
35
|
name: 'Fake Plugin Module for Tests',
|
|
36
|
-
|
|
37
|
-
updatedAt: '',
|
|
38
|
-
version: 0
|
|
36
|
+
version: '0'
|
|
39
37
|
},
|
|
40
38
|
spec: {
|
|
41
39
|
// Add metadata for all mock plugins
|
|
42
|
-
plugins: mockPlugins.map(({
|
|
43
|
-
pluginType,
|
|
40
|
+
plugins: mockPlugins.map(({ kind, spec: { name } })=>({
|
|
44
41
|
kind,
|
|
45
|
-
|
|
46
|
-
name
|
|
42
|
+
spec: {
|
|
43
|
+
name,
|
|
44
|
+
display: {
|
|
45
|
+
name: getMockPluginName(kind, name)
|
|
46
|
+
}
|
|
47
47
|
}
|
|
48
48
|
}))
|
|
49
49
|
}
|
|
@@ -51,7 +51,7 @@ function mockPluginRegistry(...mockPlugins) {
|
|
|
51
51
|
const mockPluginModule = {};
|
|
52
52
|
for (const mockPlugin of mockPlugins){
|
|
53
53
|
// "Export" on the module under the same name as the kind the plugin handles
|
|
54
|
-
mockPluginModule[mockPlugin.
|
|
54
|
+
mockPluginModule[mockPlugin.spec.name] = mockPlugin.plugin;
|
|
55
55
|
}
|
|
56
56
|
const pluginLoader = {
|
|
57
57
|
getInstalledPlugins () {
|
|
@@ -70,6 +70,6 @@ function mockPluginRegistry(...mockPlugins) {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
function getMockPluginName(
|
|
74
|
-
return `${
|
|
73
|
+
function getMockPluginName(kind, name) {
|
|
74
|
+
return `${kind} Plugin for ${name}`;
|
|
75
75
|
}
|
|
@@ -40,7 +40,7 @@ function replaceVariables(text, variableState) {
|
|
|
40
40
|
.sort((a, b)=>b.length - a.length).forEach((v)=>{
|
|
41
41
|
const variable = variableState[v];
|
|
42
42
|
if (variable && variable.value !== undefined) {
|
|
43
|
-
finalText = replaceVariable(finalText, v, variable
|
|
43
|
+
finalText = replaceVariable(finalText, v, variable?.value);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
return finalText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DatasourceEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAMtE,UAAU,yBAAyB;IACjC,2BAA2B,EAAE,oBAAoB,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,YAAY,CA6MnF"}
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
14
15
|
import { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';
|
|
15
|
-
import React, { useState } from 'react';
|
|
16
16
|
import { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';
|
|
17
|
+
import { useState } from 'react';
|
|
17
18
|
import { Controller, FormProvider, useForm } from 'react-hook-form';
|
|
18
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
19
|
-
import { PluginEditor } from '../PluginEditor';
|
|
20
|
-
import { getSubmitText, getTitleAction } from '../../utils';
|
|
21
19
|
import { useValidationSchemas } from '../../context';
|
|
20
|
+
import { getSubmitText, getTitleAction } from '../../utils';
|
|
21
|
+
import { PluginEditor } from '../PluginEditor';
|
|
22
22
|
export function DatasourceEditorForm(props) {
|
|
23
23
|
const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;
|
|
24
24
|
const [isDiscardDialogOpened, setDiscardDialogOpened] = useState(false);
|
|
@@ -33,11 +33,10 @@ export function DatasourceEditorForm(props) {
|
|
|
33
33
|
/*
|
|
34
34
|
* Remove empty fields that are optional
|
|
35
35
|
*/ function clearFormData(data) {
|
|
36
|
-
var _result_spec_display, _result_spec_display1;
|
|
37
36
|
const result = {
|
|
38
37
|
...data
|
|
39
38
|
};
|
|
40
|
-
if (
|
|
39
|
+
if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {
|
|
41
40
|
delete result.spec.display;
|
|
42
41
|
}
|
|
43
42
|
return result;
|
|
@@ -103,10 +102,7 @@ export function DatasourceEditorForm(props) {
|
|
|
103
102
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
104
103
|
control: form.control,
|
|
105
104
|
name: "name",
|
|
106
|
-
render: ({ field, fieldState })
|
|
107
|
-
var _fieldState_error;
|
|
108
|
-
var _field_value;
|
|
109
|
-
return /*#__PURE__*/ _jsx(TextField, {
|
|
105
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
110
106
|
...field,
|
|
111
107
|
required: true,
|
|
112
108
|
fullWidth: true,
|
|
@@ -120,13 +116,12 @@ export function DatasourceEditorForm(props) {
|
|
|
120
116
|
readOnly: action === 'read'
|
|
121
117
|
},
|
|
122
118
|
error: !!fieldState.error,
|
|
123
|
-
helperText:
|
|
124
|
-
value:
|
|
119
|
+
helperText: fieldState.error?.message,
|
|
120
|
+
value: field.value ?? '',
|
|
125
121
|
onChange: (event)=>{
|
|
126
122
|
field.onChange(event);
|
|
127
123
|
}
|
|
128
|
-
})
|
|
129
|
-
}
|
|
124
|
+
})
|
|
130
125
|
})
|
|
131
126
|
}),
|
|
132
127
|
/*#__PURE__*/ _jsx(Grid, {
|
|
@@ -135,10 +130,7 @@ export function DatasourceEditorForm(props) {
|
|
|
135
130
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
136
131
|
control: form.control,
|
|
137
132
|
name: "spec.display.name",
|
|
138
|
-
render: ({ field, fieldState })
|
|
139
|
-
var _fieldState_error;
|
|
140
|
-
var _field_value;
|
|
141
|
-
return /*#__PURE__*/ _jsx(TextField, {
|
|
133
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
142
134
|
...field,
|
|
143
135
|
fullWidth: true,
|
|
144
136
|
name: "title",
|
|
@@ -150,13 +142,12 @@ export function DatasourceEditorForm(props) {
|
|
|
150
142
|
readOnly: action === 'read'
|
|
151
143
|
},
|
|
152
144
|
error: !!fieldState.error,
|
|
153
|
-
helperText:
|
|
154
|
-
value:
|
|
145
|
+
helperText: fieldState.error?.message,
|
|
146
|
+
value: field.value ?? '',
|
|
155
147
|
onChange: (event)=>{
|
|
156
148
|
field.onChange(event);
|
|
157
149
|
}
|
|
158
|
-
})
|
|
159
|
-
}
|
|
150
|
+
})
|
|
160
151
|
})
|
|
161
152
|
}),
|
|
162
153
|
/*#__PURE__*/ _jsx(Grid, {
|
|
@@ -165,10 +156,7 @@ export function DatasourceEditorForm(props) {
|
|
|
165
156
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
166
157
|
control: form.control,
|
|
167
158
|
name: "spec.display.description",
|
|
168
|
-
render: ({ field, fieldState })
|
|
169
|
-
var _fieldState_error;
|
|
170
|
-
var _field_value;
|
|
171
|
-
return /*#__PURE__*/ _jsx(TextField, {
|
|
159
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
172
160
|
...field,
|
|
173
161
|
fullWidth: true,
|
|
174
162
|
name: "description",
|
|
@@ -180,13 +168,12 @@ export function DatasourceEditorForm(props) {
|
|
|
180
168
|
readOnly: action === 'read'
|
|
181
169
|
},
|
|
182
170
|
error: !!fieldState.error,
|
|
183
|
-
helperText:
|
|
184
|
-
value:
|
|
171
|
+
helperText: fieldState.error?.message,
|
|
172
|
+
value: field.value ?? '',
|
|
185
173
|
onChange: (event)=>{
|
|
186
174
|
field.onChange(event);
|
|
187
175
|
}
|
|
188
|
-
})
|
|
189
|
-
}
|
|
176
|
+
})
|
|
190
177
|
})
|
|
191
178
|
}),
|
|
192
179
|
/*#__PURE__*/ _jsx(Grid, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, DatasourceDefinition } from '@perses-dev/core';\nimport { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';\nimport React, { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';\nimport { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { PluginEditor } from '../PluginEditor';\nimport { getSubmitText, getTitleAction } from '../../utils';\nimport { useValidationSchemas } from '../../context';\n\ninterface DatasourceEditorFormProps {\n initialDatasourceDefinition: DatasourceDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: DatasourceDefinition) => void;\n onClose: DispatchWithoutAction;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function DatasourceEditorForm(props: DatasourceEditorFormProps): ReactElement {\n const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;\n\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { datasourceEditorSchema } = useValidationSchemas();\n const form = useForm<DatasourceDefinition>({\n resolver: zodResolver(datasourceEditorSchema),\n mode: 'onBlur',\n defaultValues: initialDatasourceDefinition,\n });\n\n /*\n * Remove empty fields that are optional\n */\n function clearFormData(data: DatasourceDefinition): DatasourceDefinition {\n const result = { ...data };\n if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<DatasourceDefinition> = (data: DatasourceDefinition) => {\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Datasource</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n name=\"name\"\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"title\"\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={12}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"description\"\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={6} sx={{ paddingTop: '5px !important' }}>\n <Stack>\n <Controller\n control={form.control}\n name=\"spec.default\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Set as default\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">\n Whether this datasource should be the default {form.getValues().spec.plugin.kind} to be used\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n <Divider />\n <Typography py={1} variant=\"h3\">\n Plugin Options\n </Typography>\n <Controller\n control={form.control}\n name=\"spec.plugin\"\n render={({ field }) => (\n <PluginEditor\n width=\"100%\"\n pluginTypes={['Datasource']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Datasource',\n kind: field.value.kind,\n },\n spec: field.value.spec,\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n )}\n />\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard your changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => setDiscardDialogOpened(false)}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["Box","Divider","FormControlLabel","Grid","Stack","Switch","TextField","Typography","React","useState","DiscardChangesConfirmationDialog","FormActions","Controller","FormProvider","useForm","zodResolver","PluginEditor","getSubmitText","getTitleAction","useValidationSchemas","DatasourceEditorForm","props","initialDatasourceDefinition","action","isDraft","isReadonly","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","datasourceEditorSchema","form","resolver","mode","defaultValues","clearFormData","data","result","spec","display","name","undefined","description","processForm","handleCancel","JSON","stringify","getValues","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","mb","item","xs","control","render","field","fieldState","required","fullWidth","label","InputLabelProps","shrink","InputProps","disabled","readOnly","error","helperText","message","value","onChange","event","paddingTop","checked","plugin","kind","py","width","pluginTypes","pluginKindLabel","selection","type","v","isOpen","onDiscardChanges"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,GAAG,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAC3G,OAAOC,SAA8CC,QAAQ,QAAQ,QAAQ;AAC7E,SAASC,gCAAgC,EAAEC,WAAW,QAAQ,yBAAyB;AACvF,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,QAAQ,kBAAkB;AACnF,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,aAAa,EAAEC,cAAc,QAAQ,cAAc;AAC5D,SAASC,oBAAoB,QAAQ,gBAAgB;AAarD,OAAO,SAASC,qBAAqBC,KAAgC;IACnE,MAAM,EAAEC,2BAA2B,EAAEC,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAEC,cAAc,EAAEC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGR;IAEhH,MAAM,CAACS,uBAAuBC,uBAAuB,GAAGtB,SAAkB;IAC1E,MAAMuB,cAAcd,eAAeK,QAAQC;IAC3C,MAAMS,aAAahB,cAAcM,QAAQC;IAEzC,MAAM,EAAEU,sBAAsB,EAAE,GAAGf;IACnC,MAAMgB,OAAOrB,QAA8B;QACzCsB,UAAUrB,YAAYmB;QACtBG,MAAM;QACNC,eAAehB;IACjB;IAEA;;GAEC,GACD,SAASiB,cAAc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AGhC,KAAChD;wBACC2D,SAASpC,KAAKoC,OAAO;wBACrB3B,MAAK;wBACL4B,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,KAACzD;gCACC8E,OAAM;gCACNC,aAAa;oCAAC;iCAAa;gCAC3BC,iBAAgB;gCAChBV,OAAO;oCACLW,WAAW;wCACTC,MAAM;wCACNN,MAAMnB,MAAMa,KAAK,CAACM,IAAI;oCACxB;oCACAlD,MAAM+B,MAAMa,KAAK,CAAC5C,IAAI;gCACxB;gCACAjB,YAAYF,WAAW;gCACvBgE,UAAU,CAACY;oCACT1B,MAAMc,QAAQ,CAAC;wCAAEK,MAAMO,EAAEF,SAAS,CAACL,IAAI;wCAAElD,MAAMyD,EAAEzD,IAAI;oCAAC;gCACxD;;;;;0BAKR,KAAChC;gBACCoC,aAAY;gBACZsD,QAAQtE;gBACRmC,UAAU,IAAMlC,uBAAuB;gBACvCsE,kBAAkB;oBAChBtE,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';\nimport { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';\nimport { Action, DatasourceDefinition } from '@perses-dev/core';\nimport { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';\nimport { useValidationSchemas } from '../../context';\nimport { getSubmitText, getTitleAction } from '../../utils';\nimport { PluginEditor } from '../PluginEditor';\n\ninterface DatasourceEditorFormProps {\n initialDatasourceDefinition: DatasourceDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: DatasourceDefinition) => void;\n onClose: DispatchWithoutAction;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function DatasourceEditorForm(props: DatasourceEditorFormProps): ReactElement {\n const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;\n\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { datasourceEditorSchema } = useValidationSchemas();\n const form = useForm<DatasourceDefinition>({\n resolver: zodResolver(datasourceEditorSchema),\n mode: 'onBlur',\n defaultValues: initialDatasourceDefinition,\n });\n\n /*\n * Remove empty fields that are optional\n */\n function clearFormData(data: DatasourceDefinition): DatasourceDefinition {\n const result = { ...data };\n if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<DatasourceDefinition> = (data: DatasourceDefinition) => {\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Datasource</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n name=\"name\"\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"title\"\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={12}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"description\"\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={6} sx={{ paddingTop: '5px !important' }}>\n <Stack>\n <Controller\n control={form.control}\n name=\"spec.default\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Set as default\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">\n Whether this datasource should be the default {form.getValues().spec.plugin.kind} to be used\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n <Divider />\n <Typography py={1} variant=\"h3\">\n Plugin Options\n </Typography>\n <Controller\n control={form.control}\n name=\"spec.plugin\"\n render={({ field }) => (\n <PluginEditor\n width=\"100%\"\n pluginTypes={['Datasource']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Datasource',\n kind: field.value.kind,\n },\n spec: field.value.spec,\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n )}\n />\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard your changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => setDiscardDialogOpened(false)}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["zodResolver","Box","Divider","FormControlLabel","Grid","Stack","Switch","TextField","Typography","DiscardChangesConfirmationDialog","FormActions","useState","Controller","FormProvider","useForm","useValidationSchemas","getSubmitText","getTitleAction","PluginEditor","DatasourceEditorForm","props","initialDatasourceDefinition","action","isDraft","isReadonly","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","datasourceEditorSchema","form","resolver","mode","defaultValues","clearFormData","data","result","spec","display","name","undefined","description","processForm","handleCancel","JSON","stringify","getValues","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","mb","item","xs","control","render","field","fieldState","required","fullWidth","label","InputLabelProps","shrink","InputProps","disabled","readOnly","error","helperText","message","value","onChange","event","paddingTop","checked","plugin","kind","py","width","pluginTypes","pluginKindLabel","selection","type","v","isOpen","onDiscardChanges"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAA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kBAAkB;oBAChBtE,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutlinedSelectProps, BaseSelectProps } from '@mui/material';
|
|
2
2
|
import { DatasourceSelector } from '@perses-dev/core';
|
|
3
3
|
import { ReactElement } from 'react';
|
|
4
4
|
type OmittedMuiProps = 'children' | 'value' | 'onChange';
|
|
5
|
-
export interface DatasourceSelectProps extends Omit<
|
|
5
|
+
export interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {
|
|
6
6
|
value: DatasourceSelector;
|
|
7
7
|
onChange: (next: DatasourceSelector) => void;
|
|
8
8
|
datasourcePluginKind: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../src/components/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../src/components/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAUL,mBAAmB,EACnB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAK9C,KAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IACjH,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY,CAuF3E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,YAAY,CAahH"}
|
|
@@ -23,10 +23,9 @@ import { useListDatasourceSelectItems } from '../runtime';
|
|
|
23
23
|
const { data, isLoading } = useListDatasourceSelectItems(datasourcePluginKind, project);
|
|
24
24
|
// Rebuild the group of the value if not provided
|
|
25
25
|
const defaultValue = useMemo(()=>{
|
|
26
|
-
|
|
27
|
-
const group = (_flatMap_find = (data !== null && data !== void 0 ? data : []).flatMap((itemGroup)=>itemGroup.items).find((item)=>{
|
|
26
|
+
const group = (data ?? []).flatMap((itemGroup)=>itemGroup.items).find((item)=>{
|
|
28
27
|
return value.kind === item.selector.kind && value.name === item.selector.name && !item.overridden;
|
|
29
|
-
})
|
|
28
|
+
})?.selector.group;
|
|
30
29
|
return {
|
|
31
30
|
...value,
|
|
32
31
|
group
|
|
@@ -37,20 +36,17 @@ import { useListDatasourceSelectItems } from '../runtime';
|
|
|
37
36
|
]);
|
|
38
37
|
// Convert the datasource list into menu items with name/group?/value strings that the Select input can work with
|
|
39
38
|
const menuItems = useMemo(()=>{
|
|
40
|
-
return (data
|
|
39
|
+
return (data ?? []).map((itemGroup)=>({
|
|
41
40
|
group: itemGroup.group,
|
|
42
41
|
editLink: itemGroup.editLink,
|
|
43
|
-
items: itemGroup.items.map((item)=>{
|
|
44
|
-
var _item_saved;
|
|
45
|
-
return {
|
|
42
|
+
items: itemGroup.items.map((item)=>({
|
|
46
43
|
name: item.name,
|
|
47
44
|
overriding: item.overriding,
|
|
48
45
|
overridden: item.overridden,
|
|
49
|
-
saved:
|
|
46
|
+
saved: item.saved ?? true,
|
|
50
47
|
group: item.selector.group,
|
|
51
48
|
value: selectorToOptionValue(item.selector)
|
|
52
|
-
}
|
|
53
|
-
})
|
|
49
|
+
}))
|
|
54
50
|
}));
|
|
55
51
|
}, [
|
|
56
52
|
data
|
|
@@ -143,11 +139,10 @@ const OPTION_VALUE_DELIMITER = '_____';
|
|
|
143
139
|
* returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.
|
|
144
140
|
* @param selector
|
|
145
141
|
*/ function selectorToOptionValue(selector) {
|
|
146
|
-
var _selector_group, _selector_name;
|
|
147
142
|
return [
|
|
148
143
|
selector.kind,
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
selector.group ?? '',
|
|
145
|
+
selector.name ?? ''
|
|
151
146
|
].join(OPTION_VALUE_DELIMITER);
|
|
152
147
|
}
|
|
153
148
|
/**
|