@perses-dev/plugin-system 0.46.0 → 0.47.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 +70 -99
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -1
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +49 -19
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +1 -0
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +10 -71
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +408 -376
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +2 -2
- package/dist/cjs/components/Variables/variable-model.js +24 -22
- package/dist/cjs/context/ProjectStoreProvider.js +7 -4
- package/dist/cjs/context/ValidationProvider.js +69 -0
- package/dist/cjs/context/index.js +1 -0
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/runtime/QueryCountProvider.js +83 -0
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +100 -0
- package/dist/cjs/runtime/TimeRangeProvider/index.js +2 -1
- package/dist/cjs/runtime/builtin-variables.js +1 -1
- package/dist/cjs/runtime/datasources.js +22 -13
- package/dist/cjs/runtime/index.js +3 -2
- package/dist/cjs/runtime/plugin-registry.js +33 -22
- package/dist/cjs/runtime/time-series-queries.js +3 -3
- package/dist/cjs/runtime/trace-queries.js +5 -1
- package/dist/cjs/runtime/{template-variables.js → variables.js} +19 -19
- package/dist/cjs/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +8 -8
- package/dist/cjs/stories/shared-utils/decorators/index.js +2 -2
- package/dist/cjs/test/mock-data.js +25 -4
- package/dist/cjs/test/render.js +1 -9
- package/dist/cjs/test/test-plugins/bert/index.js +20 -19
- package/dist/cjs/utils/variables.js +23 -23
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +2 -2
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +71 -100
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -3
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.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/PanelSpecEditor/PanelSpecEditor.d.ts +3 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +50 -20
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -0
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -2
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +12 -70
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +411 -379
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +2 -2
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +25 -23
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/context/ProjectStoreProvider.d.ts.map +1 -1
- package/dist/context/ProjectStoreProvider.js +7 -4
- package/dist/context/ProjectStoreProvider.js.map +1 -1
- package/dist/context/ValidationProvider.d.ts +19 -0
- package/dist/context/ValidationProvider.d.ts.map +1 -0
- package/dist/context/ValidationProvider.js +52 -0
- package/dist/context/ValidationProvider.js.map +1 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/model/panels.d.ts +2 -2
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/QueryCountProvider.d.ts +9 -0
- package/dist/runtime/QueryCountProvider.d.ts.map +1 -0
- package/dist/{validation/duration.js → runtime/QueryCountProvider.js} +13 -4
- package/dist/runtime/QueryCountProvider.js.map +1 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +32 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +82 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -0
- package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
- package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/index.js +2 -1
- package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
- package/dist/runtime/builtin-variables.d.ts +1 -1
- package/dist/runtime/builtin-variables.d.ts.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.map +1 -1
- package/dist/runtime/datasources.js +22 -13
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +33 -22
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts +2 -2
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +3 -3
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +5 -1
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/{template-variables.d.ts → variables.d.ts} +4 -4
- package/dist/runtime/variables.d.ts.map +1 -0
- package/dist/runtime/{template-variables.js → variables.js} +18 -17
- package/dist/runtime/variables.js.map +1 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +12 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +9 -9
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -0
- package/dist/stories/shared-utils/decorators/index.d.ts +1 -1
- package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/index.js +2 -2
- package/dist/stories/shared-utils/decorators/index.js.map +1 -1
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +25 -4
- package/dist/test/mock-data.js.map +1 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +1 -9
- package/dist/test/render.js.map +1 -1
- package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
- package/dist/test/test-plugins/bert/index.js +20 -19
- package/dist/test/test-plugins/bert/index.js.map +1 -1
- package/dist/utils/variables.d.ts +4 -4
- package/dist/utils/variables.d.ts.map +1 -1
- package/dist/utils/variables.js +18 -18
- package/dist/utils/variables.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/validation/datasource.js +0 -30
- package/dist/cjs/validation/duration.js +0 -25
- package/dist/cjs/validation/index.js +0 -34
- package/dist/cjs/validation/resource.js +0 -24
- package/dist/cjs/validation/role.js +0 -86
- package/dist/cjs/validation/rolebinding.js +0 -55
- package/dist/cjs/validation/secret.js +0 -176
- package/dist/cjs/validation/user.js +0 -46
- package/dist/cjs/validation/variable.js +0 -48
- package/dist/runtime/template-variables.d.ts.map +0 -1
- package/dist/runtime/template-variables.js.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts +0 -12
- package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +0 -1
- package/dist/validation/datasource.d.ts +0 -19
- package/dist/validation/datasource.d.ts.map +0 -1
- package/dist/validation/datasource.js +0 -22
- package/dist/validation/datasource.js.map +0 -1
- package/dist/validation/duration.d.ts +0 -3
- package/dist/validation/duration.d.ts.map +0 -1
- package/dist/validation/duration.js.map +0 -1
- package/dist/validation/index.d.ts +0 -6
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js +0 -19
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/resource.d.ts +0 -3
- package/dist/validation/resource.d.ts.map +0 -1
- package/dist/validation/resource.js +0 -16
- package/dist/validation/resource.js.map +0 -1
- package/dist/validation/role.d.ts +0 -228
- package/dist/validation/role.d.ts.map +0 -1
- package/dist/validation/role.js +0 -67
- package/dist/validation/role.js.map +0 -1
- package/dist/validation/rolebinding.d.ts +0 -137
- package/dist/validation/rolebinding.d.ts.map +0 -1
- package/dist/validation/rolebinding.js +0 -47
- package/dist/validation/rolebinding.js.map +0 -1
- package/dist/validation/secret.d.ts +0 -964
- package/dist/validation/secret.d.ts.map +0 -1
- package/dist/validation/secret.js +0 -157
- package/dist/validation/secret.js.map +0 -1
- package/dist/validation/user.d.ts +0 -93
- package/dist/validation/user.d.ts.map +0 -1
- package/dist/validation/user.js +0 -38
- package/dist/validation/user.js.map +0 -1
- package/dist/validation/variable.d.ts +0 -96
- package/dist/validation/variable.d.ts.map +0 -1
- package/dist/validation/variable.js +0 -40
- package/dist/validation/variable.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -14,28 +14,28 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "WithPluginSystemVariables", {
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: function() {
|
|
20
|
-
return
|
|
20
|
+
return WithPluginSystemVariables;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _runtime = require("../../../runtime");
|
|
25
25
|
// Type guard because storybook types parameters as `any`
|
|
26
|
-
function
|
|
26
|
+
function isWithVariableParameter(parameter) {
|
|
27
27
|
return !!parameter && typeof parameter === 'object' && 'props' in parameter;
|
|
28
28
|
}
|
|
29
|
-
const
|
|
30
|
-
const initParameter = context.parameters.
|
|
29
|
+
const WithPluginSystemVariables = (Story, context)=>{
|
|
30
|
+
const initParameter = context.parameters.withPluginSystemVariables;
|
|
31
31
|
const defaultValue = {
|
|
32
32
|
state: {}
|
|
33
33
|
};
|
|
34
|
-
const parameter =
|
|
34
|
+
const parameter = isWithVariableParameter(initParameter) ? initParameter : {
|
|
35
35
|
props: defaultValue
|
|
36
36
|
};
|
|
37
37
|
const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
|
|
38
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.
|
|
38
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.VariableContext.Provider, {
|
|
39
39
|
value: props,
|
|
40
40
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Story, {})
|
|
41
41
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -18,7 +18,7 @@ _export_star(require("./WithDataQueries"), exports);
|
|
|
18
18
|
_export_star(require("./WithPluginRegistry"), exports);
|
|
19
19
|
_export_star(require("./WithPluginSystemBuiltinVariables"), exports);
|
|
20
20
|
_export_star(require("./WithPluginSystemDatasourceStore"), exports);
|
|
21
|
-
_export_star(require("./
|
|
21
|
+
_export_star(require("./WithPluginSystemVariables"), exports);
|
|
22
22
|
_export_star(require("./WithTimeRange"), exports);
|
|
23
23
|
function _export_star(from, to) {
|
|
24
24
|
Object.keys(from).forEach(function(k) {
|
|
@@ -64,14 +64,35 @@ const MOCK_TIME_SERIES_DATA = {
|
|
|
64
64
|
]
|
|
65
65
|
};
|
|
66
66
|
const MOCK_TRACE_DATA = {
|
|
67
|
-
|
|
67
|
+
searchResult: [
|
|
68
68
|
{
|
|
69
69
|
durationMs: 1120,
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
serviceStats: {
|
|
71
|
+
'shop-backend': {
|
|
72
|
+
spanCount: 4,
|
|
73
|
+
errorCount: 0
|
|
74
|
+
},
|
|
75
|
+
'cart-service': {
|
|
76
|
+
spanCount: 2,
|
|
77
|
+
errorCount: 0
|
|
78
|
+
},
|
|
79
|
+
'article-service': {
|
|
80
|
+
spanCount: 2,
|
|
81
|
+
errorCount: 0
|
|
82
|
+
},
|
|
83
|
+
'auth-service': {
|
|
84
|
+
spanCount: 1,
|
|
85
|
+
errorCount: 0
|
|
86
|
+
},
|
|
87
|
+
postgres: {
|
|
88
|
+
spanCount: 1,
|
|
89
|
+
errorCount: 0
|
|
90
|
+
}
|
|
91
|
+
},
|
|
72
92
|
startTimeUnixMs: 1699916103945861,
|
|
73
93
|
traceId: '95ba9202315c29c801b5aa41452aa775',
|
|
74
|
-
|
|
94
|
+
rootServiceName: 'shop-backend',
|
|
95
|
+
rootTraceName: 'article-to-cart'
|
|
75
96
|
}
|
|
76
97
|
],
|
|
77
98
|
metadata: {
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -25,13 +25,6 @@ const _react = require("@testing-library/react");
|
|
|
25
25
|
const _reactquery = require("@tanstack/react-query");
|
|
26
26
|
const _PluginRegistry = require("../components/PluginRegistry");
|
|
27
27
|
const _testplugins = require("./test-plugins");
|
|
28
|
-
const testLogger = {
|
|
29
|
-
log: console.log,
|
|
30
|
-
warn: console.warn,
|
|
31
|
-
error: ()=>{
|
|
32
|
-
// Don't log network errors in tests to the console
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
28
|
function renderWithContext(ui, renderOptions, contextOptions) {
|
|
36
29
|
// Create a new QueryClient for each test to avoid caching issues
|
|
37
30
|
const queryClient = new _reactquery.QueryClient({
|
|
@@ -40,8 +33,7 @@ function renderWithContext(ui, renderOptions, contextOptions) {
|
|
|
40
33
|
refetchOnWindowFocus: false,
|
|
41
34
|
retry: false
|
|
42
35
|
}
|
|
43
|
-
}
|
|
44
|
-
logger: testLogger
|
|
36
|
+
}
|
|
45
37
|
});
|
|
46
38
|
var _contextOptions_defaultPluginKinds;
|
|
47
39
|
return (0, _react.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
|
|
@@ -60,30 +60,31 @@ const BertPanel1 = {
|
|
|
60
60
|
option1: ''
|
|
61
61
|
})
|
|
62
62
|
};
|
|
63
|
+
function BertPanel2Editor({ value, onChange }) {
|
|
64
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
65
|
+
children: [
|
|
66
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("label", {
|
|
67
|
+
htmlFor: "editor-input",
|
|
68
|
+
children: "BertPanel2 editor"
|
|
69
|
+
}),
|
|
70
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("input", {
|
|
71
|
+
type: "text",
|
|
72
|
+
id: "editor-input",
|
|
73
|
+
value: value.option2,
|
|
74
|
+
onChange: (e)=>onChange({
|
|
75
|
+
...value,
|
|
76
|
+
option2: e.target.value
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
63
82
|
const BertPanel2 = {
|
|
64
83
|
PanelComponent: ()=>null,
|
|
65
84
|
panelOptionsEditorComponents: [
|
|
66
85
|
{
|
|
67
86
|
label: 'Settings',
|
|
68
|
-
content:
|
|
69
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
70
|
-
children: [
|
|
71
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("label", {
|
|
72
|
-
htmlFor: "editor-input",
|
|
73
|
-
children: "BertPanel2 editor"
|
|
74
|
-
}),
|
|
75
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("input", {
|
|
76
|
-
type: "text",
|
|
77
|
-
id: "editor-input",
|
|
78
|
-
value: value.option2,
|
|
79
|
-
onChange: (e)=>onChange({
|
|
80
|
-
...value,
|
|
81
|
-
option2: e.target.value
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
]
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
+
content: BertPanel2Editor
|
|
87
88
|
},
|
|
88
89
|
{
|
|
89
90
|
label: 'Custom Tab',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -21,18 +21,18 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
|
|
25
|
-
return
|
|
24
|
+
parseVariables: function() {
|
|
25
|
+
return parseVariables;
|
|
26
26
|
},
|
|
27
|
-
|
|
28
|
-
return
|
|
27
|
+
replaceVariable: function() {
|
|
28
|
+
return replaceVariable;
|
|
29
29
|
},
|
|
30
|
-
|
|
31
|
-
return
|
|
30
|
+
replaceVariables: function() {
|
|
31
|
+
return replaceVariables;
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
function
|
|
35
|
-
const variables =
|
|
34
|
+
function replaceVariables(text, variableState) {
|
|
35
|
+
const variables = parseVariables(text);
|
|
36
36
|
let finalText = text;
|
|
37
37
|
variables// Sorting variables by their length.
|
|
38
38
|
// In order to not have a variable name have contained in another variable name.
|
|
@@ -40,34 +40,34 @@ function replaceTemplateVariables(text, variableState) {
|
|
|
40
40
|
.sort((a, b)=>b.length - a.length).forEach((v)=>{
|
|
41
41
|
const variable = variableState[v];
|
|
42
42
|
if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
|
|
43
|
-
finalText =
|
|
43
|
+
finalText = replaceVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
return finalText;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
const
|
|
48
|
+
function replaceVariable(text, varName, variableValue) {
|
|
49
|
+
const variableSyntax = '$' + varName;
|
|
50
|
+
const alternativeVariableSyntax = '${' + varName + '}';
|
|
51
51
|
let replaceString = '';
|
|
52
|
-
if (Array.isArray(
|
|
53
|
-
replaceString = `(${
|
|
52
|
+
if (Array.isArray(variableValue)) {
|
|
53
|
+
replaceString = `(${variableValue.join('|')})`; // regex style
|
|
54
54
|
}
|
|
55
|
-
if (typeof
|
|
56
|
-
replaceString =
|
|
55
|
+
if (typeof variableValue === 'string') {
|
|
56
|
+
replaceString = variableValue;
|
|
57
57
|
}
|
|
58
|
-
text = text.replaceAll(
|
|
59
|
-
return text.replaceAll(
|
|
58
|
+
text = text.replaceAll(variableSyntax, replaceString);
|
|
59
|
+
return text.replaceAll(alternativeVariableSyntax, replaceString);
|
|
60
60
|
}
|
|
61
|
-
// This regular expression is designed to identify variable references in a
|
|
61
|
+
// This regular expression is designed to identify variable references in a string.
|
|
62
62
|
// It supports two formats for referencing variables:
|
|
63
63
|
// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\w+ matches one or more word characters).
|
|
64
64
|
// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\w+ matches one or more word characters) in the curly braces.
|
|
65
65
|
// 3. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.
|
|
66
66
|
// TODO: Fix this lint error
|
|
67
67
|
// eslint-disable-next-line no-useless-escape
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const regex =
|
|
68
|
+
const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
|
|
69
|
+
const parseVariables = (text)=>{
|
|
70
|
+
const regex = VARIABLE_REGEX;
|
|
71
71
|
const matches = new Set();
|
|
72
72
|
let match;
|
|
73
73
|
while((match = regex.exec(text)) !== null){
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Action, DatasourceDefinition
|
|
1
|
+
import { Action, DatasourceDefinition } from '@perses-dev/core';
|
|
2
2
|
import { DispatchWithoutAction } from 'react';
|
|
3
3
|
interface DatasourceEditorFormProps {
|
|
4
4
|
initialDatasourceDefinition: DatasourceDefinition;
|
|
5
5
|
initialAction: Action;
|
|
6
6
|
isDraft: boolean;
|
|
7
7
|
isReadonly?: boolean;
|
|
8
|
-
onSave: (
|
|
8
|
+
onSave: (def: DatasourceDefinition) => void;
|
|
9
9
|
onClose: DispatchWithoutAction;
|
|
10
10
|
onDelete?: DispatchWithoutAction;
|
|
11
11
|
}
|
|
@@ -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":"AAaA,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,qBAAqB,EAAY,MAAM,OAAO,CAAC;AAQxD,UAAU,yBAAyB;IACjC,2BAA2B,EAAE,oBAAoB,CAAC;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,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,2CAuOpE"}
|
|
@@ -11,79 +11,52 @@
|
|
|
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, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import { useImmer } from 'use-immer';
|
|
15
14
|
import { Box, Button, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';
|
|
16
|
-
import {
|
|
15
|
+
import { useState } from 'react';
|
|
17
16
|
import { DiscardChangesConfirmationDialog } from '@perses-dev/components';
|
|
18
17
|
import { Controller, FormProvider, useForm } from 'react-hook-form';
|
|
19
18
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
20
19
|
import { PluginEditor } from '../PluginEditor';
|
|
21
20
|
import { getSubmitText, getTitleAction } from '../../utils';
|
|
22
|
-
import {
|
|
23
|
-
/**
|
|
24
|
-
* This preprocessing ensures that we always have a defined object for the `display` property
|
|
25
|
-
* @param datasource
|
|
26
|
-
*/ function getInitialState(datasourceDefinition) {
|
|
27
|
-
var _datasourceDefinition_spec_display, _datasourceDefinition_spec_display1;
|
|
28
|
-
var _datasourceDefinition_spec_display_name, _datasourceDefinition_spec_display_description;
|
|
29
|
-
const patchedDisplay = {
|
|
30
|
-
name: (_datasourceDefinition_spec_display_name = (_datasourceDefinition_spec_display = datasourceDefinition.spec.display) === null || _datasourceDefinition_spec_display === void 0 ? void 0 : _datasourceDefinition_spec_display.name) !== null && _datasourceDefinition_spec_display_name !== void 0 ? _datasourceDefinition_spec_display_name : '',
|
|
31
|
-
description: (_datasourceDefinition_spec_display_description = (_datasourceDefinition_spec_display1 = datasourceDefinition.spec.display) === null || _datasourceDefinition_spec_display1 === void 0 ? void 0 : _datasourceDefinition_spec_display1.description) !== null && _datasourceDefinition_spec_display_description !== void 0 ? _datasourceDefinition_spec_display_description : ''
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
name: datasourceDefinition.name,
|
|
35
|
-
spec: {
|
|
36
|
-
...datasourceDefinition.spec,
|
|
37
|
-
display: patchedDisplay
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
21
|
+
import { useValidationSchemas } from '../../context';
|
|
41
22
|
export function DatasourceEditorForm(props) {
|
|
42
|
-
var _state_spec_display, _state_spec_display1;
|
|
43
23
|
const { initialDatasourceDefinition, initialAction, isDraft, isReadonly, onSave, onClose, onDelete } = props;
|
|
44
|
-
const initialState = getInitialState(initialDatasourceDefinition);
|
|
45
|
-
const [state, setState] = useImmer(initialState);
|
|
46
24
|
const [isDiscardDialogOpened, setDiscardDialogOpened] = useState(false);
|
|
47
25
|
const [action, setAction] = useState(initialAction);
|
|
48
26
|
const titleAction = getTitleAction(action, isDraft);
|
|
49
27
|
const submitText = getSubmitText(action, isDraft);
|
|
28
|
+
const { datasourceEditorSchema } = useValidationSchemas();
|
|
50
29
|
const form = useForm({
|
|
51
|
-
resolver: zodResolver(
|
|
30
|
+
resolver: zodResolver(datasourceEditorSchema),
|
|
52
31
|
mode: 'onBlur',
|
|
53
|
-
defaultValues:
|
|
54
|
-
name: state.name,
|
|
55
|
-
title: (_state_spec_display = state.spec.display) === null || _state_spec_display === void 0 ? void 0 : _state_spec_display.name,
|
|
56
|
-
description: (_state_spec_display1 = state.spec.display) === null || _state_spec_display1 === void 0 ? void 0 : _state_spec_display1.description,
|
|
57
|
-
default: state.spec.default
|
|
58
|
-
}
|
|
32
|
+
defaultValues: initialDatasourceDefinition
|
|
59
33
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
34
|
+
/*
|
|
35
|
+
* Remove empty fields that are optional
|
|
36
|
+
*/ function clearFormData(data) {
|
|
37
|
+
var _result_spec_display, _result_spec_display1;
|
|
38
|
+
const result = {
|
|
39
|
+
...data
|
|
40
|
+
};
|
|
41
|
+
if (((_result_spec_display = result.spec.display) === null || _result_spec_display === void 0 ? void 0 : _result_spec_display.name) === undefined && ((_result_spec_display1 = result.spec.display) === null || _result_spec_display1 === void 0 ? void 0 : _result_spec_display1.description) === undefined) {
|
|
42
|
+
delete result.spec.display;
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
const processForm = (data)=>{
|
|
47
|
+
onSave(clearFormData(data));
|
|
70
48
|
};
|
|
71
49
|
// When user click on cancel, several possibilities:
|
|
72
50
|
// - create action: ask for discard approval
|
|
73
51
|
// - update action: ask for discard approval if changed
|
|
74
52
|
// - read action: don´t ask for discard approval
|
|
75
|
-
|
|
76
|
-
if (JSON.stringify(
|
|
53
|
+
function handleCancel() {
|
|
54
|
+
if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {
|
|
77
55
|
setDiscardDialogOpened(true);
|
|
78
56
|
} else {
|
|
79
57
|
onClose();
|
|
80
58
|
}
|
|
81
|
-
}
|
|
82
|
-
state,
|
|
83
|
-
initialState,
|
|
84
|
-
setDiscardDialogOpened,
|
|
85
|
-
onClose
|
|
86
|
-
]);
|
|
59
|
+
}
|
|
87
60
|
return /*#__PURE__*/ _jsxs(FormProvider, {
|
|
88
61
|
...form,
|
|
89
62
|
children: [
|
|
@@ -175,10 +148,12 @@ export function DatasourceEditorForm(props) {
|
|
|
175
148
|
item: true,
|
|
176
149
|
xs: 4,
|
|
177
150
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
151
|
+
control: form.control,
|
|
178
152
|
name: "name",
|
|
179
|
-
render: ({ field, fieldState })
|
|
153
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ {
|
|
180
154
|
var _fieldState_error;
|
|
181
|
-
|
|
155
|
+
var _field_value;
|
|
156
|
+
return _jsx(TextField, {
|
|
182
157
|
...field,
|
|
183
158
|
required: true,
|
|
184
159
|
fullWidth: true,
|
|
@@ -193,11 +168,9 @@ export function DatasourceEditorForm(props) {
|
|
|
193
168
|
},
|
|
194
169
|
error: !!fieldState.error,
|
|
195
170
|
helperText: (_fieldState_error = fieldState.error) === null || _fieldState_error === void 0 ? void 0 : _fieldState_error.message,
|
|
171
|
+
value: (_field_value = field.value) !== null && _field_value !== void 0 ? _field_value : '',
|
|
196
172
|
onChange: (event)=>{
|
|
197
173
|
field.onChange(event);
|
|
198
|
-
setState((draft)=>{
|
|
199
|
-
draft.name = event.target.value;
|
|
200
|
-
});
|
|
201
174
|
}
|
|
202
175
|
});
|
|
203
176
|
}
|
|
@@ -207,10 +180,12 @@ export function DatasourceEditorForm(props) {
|
|
|
207
180
|
item: true,
|
|
208
181
|
xs: 8,
|
|
209
182
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
210
|
-
|
|
211
|
-
|
|
183
|
+
control: form.control,
|
|
184
|
+
name: "spec.display.name",
|
|
185
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ {
|
|
212
186
|
var _fieldState_error;
|
|
213
|
-
|
|
187
|
+
var _field_value;
|
|
188
|
+
return _jsx(TextField, {
|
|
214
189
|
...field,
|
|
215
190
|
fullWidth: true,
|
|
216
191
|
name: "title",
|
|
@@ -223,13 +198,9 @@ export function DatasourceEditorForm(props) {
|
|
|
223
198
|
},
|
|
224
199
|
error: !!fieldState.error,
|
|
225
200
|
helperText: (_fieldState_error = fieldState.error) === null || _fieldState_error === void 0 ? void 0 : _fieldState_error.message,
|
|
201
|
+
value: (_field_value = field.value) !== null && _field_value !== void 0 ? _field_value : '',
|
|
226
202
|
onChange: (event)=>{
|
|
227
|
-
|
|
228
|
-
field.onChange(event);
|
|
229
|
-
if (draft.spec.display) {
|
|
230
|
-
draft.spec.display.name = event.target.value;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
203
|
+
field.onChange(event);
|
|
233
204
|
}
|
|
234
205
|
});
|
|
235
206
|
}
|
|
@@ -239,10 +210,12 @@ export function DatasourceEditorForm(props) {
|
|
|
239
210
|
item: true,
|
|
240
211
|
xs: 12,
|
|
241
212
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
242
|
-
|
|
243
|
-
|
|
213
|
+
control: form.control,
|
|
214
|
+
name: "spec.display.description",
|
|
215
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ {
|
|
244
216
|
var _fieldState_error;
|
|
245
|
-
|
|
217
|
+
var _field_value;
|
|
218
|
+
return _jsx(TextField, {
|
|
246
219
|
...field,
|
|
247
220
|
fullWidth: true,
|
|
248
221
|
name: "description",
|
|
@@ -255,13 +228,9 @@ export function DatasourceEditorForm(props) {
|
|
|
255
228
|
},
|
|
256
229
|
error: !!fieldState.error,
|
|
257
230
|
helperText: (_fieldState_error = fieldState.error) === null || _fieldState_error === void 0 ? void 0 : _fieldState_error.message,
|
|
231
|
+
value: (_field_value = field.value) !== null && _field_value !== void 0 ? _field_value : '',
|
|
258
232
|
onChange: (event)=>{
|
|
259
233
|
field.onChange(event);
|
|
260
|
-
setState((draft)=>{
|
|
261
|
-
if (draft.spec.display) {
|
|
262
|
-
draft.spec.display.description = event.target.value;
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
234
|
}
|
|
266
235
|
});
|
|
267
236
|
}
|
|
@@ -276,28 +245,26 @@ export function DatasourceEditorForm(props) {
|
|
|
276
245
|
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
277
246
|
children: [
|
|
278
247
|
/*#__PURE__*/ _jsx(Controller, {
|
|
279
|
-
|
|
248
|
+
control: form.control,
|
|
249
|
+
name: "spec.default",
|
|
280
250
|
render: ({ field })=>/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
281
|
-
|
|
251
|
+
label: "Set as default",
|
|
282
252
|
control: /*#__PURE__*/ _jsx(Switch, {
|
|
283
|
-
|
|
253
|
+
...field,
|
|
254
|
+
checked: !!field.value,
|
|
284
255
|
readOnly: action === 'read',
|
|
285
256
|
onChange: (event)=>{
|
|
286
257
|
if (action === 'read') return; // ReadOnly prop is not blocking user interaction...
|
|
287
258
|
field.onChange(event);
|
|
288
|
-
setState((draft)=>{
|
|
289
|
-
draft.spec.default = event.target.checked;
|
|
290
|
-
});
|
|
291
259
|
}
|
|
292
|
-
})
|
|
293
|
-
label: "Set as default"
|
|
260
|
+
})
|
|
294
261
|
})
|
|
295
262
|
}),
|
|
296
263
|
/*#__PURE__*/ _jsxs(Typography, {
|
|
297
264
|
variant: "caption",
|
|
298
265
|
children: [
|
|
299
266
|
"Whether this datasource should be the default ",
|
|
300
|
-
|
|
267
|
+
form.getValues().spec.plugin.kind,
|
|
301
268
|
" to be used"
|
|
302
269
|
]
|
|
303
270
|
})
|
|
@@ -312,26 +279,30 @@ export function DatasourceEditorForm(props) {
|
|
|
312
279
|
variant: "h3",
|
|
313
280
|
children: "Plugin Options"
|
|
314
281
|
}),
|
|
315
|
-
/*#__PURE__*/ _jsx(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
282
|
+
/*#__PURE__*/ _jsx(Controller, {
|
|
283
|
+
control: form.control,
|
|
284
|
+
name: "spec.plugin",
|
|
285
|
+
render: ({ field })=>/*#__PURE__*/ _jsx(PluginEditor, {
|
|
286
|
+
width: "100%",
|
|
287
|
+
pluginTypes: [
|
|
288
|
+
'Datasource'
|
|
289
|
+
],
|
|
290
|
+
pluginKindLabel: "Source",
|
|
291
|
+
value: {
|
|
292
|
+
selection: {
|
|
293
|
+
type: 'Datasource',
|
|
294
|
+
kind: field.value.kind
|
|
295
|
+
},
|
|
296
|
+
spec: field.value.spec
|
|
297
|
+
},
|
|
298
|
+
isReadonly: action === 'read',
|
|
299
|
+
onChange: (v)=>{
|
|
300
|
+
field.onChange({
|
|
301
|
+
kind: v.selection.kind,
|
|
302
|
+
spec: v.spec
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
})
|
|
335
306
|
})
|
|
336
307
|
]
|
|
337
308
|
}),
|