@perses-dev/plugin-system 0.51.0-rc.0 → 0.51.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/DatasourceSelect.js +8 -10
- package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +5 -2
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +2 -2
- package/dist/cjs/components/Variables/variable-model.js +4 -2
- package/dist/cjs/remote/PluginRuntime.js +18 -10
- package/dist/cjs/runtime/time-series-queries.js +2 -1
- package/dist/cjs/test/render-hook.js +31 -0
- package/dist/cjs/test/render.js +4 -21
- package/dist/cjs/test/utils.js +49 -0
- package/dist/components/DatasourceSelect.d.ts +13 -1
- package/dist/components/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect.js +2 -2
- package/dist/components/DatasourceSelect.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +5 -2
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +2 -2
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +4 -2
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +18 -10
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +3 -2
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/test/render-hook.d.ts +8 -0
- package/dist/test/render-hook.d.ts.map +1 -0
- package/dist/test/render-hook.js +26 -0
- package/dist/test/render-hook.js.map +1 -0
- package/dist/test/render.d.ts +1 -5
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +4 -21
- package/dist/test/render.js.map +1 -1
- package/dist/test/utils.d.ts +9 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +41 -0
- package/dist/test/utils.js.map +1 -0
- package/package.json +5 -5
|
@@ -33,6 +33,12 @@ _export(exports, {
|
|
|
33
33
|
isVariableDatasource: function() {
|
|
34
34
|
return isVariableDatasource;
|
|
35
35
|
},
|
|
36
|
+
optionValueToSelector: function() {
|
|
37
|
+
return optionValueToSelector;
|
|
38
|
+
},
|
|
39
|
+
selectorToOptionValue: function() {
|
|
40
|
+
return selectorToOptionValue;
|
|
41
|
+
},
|
|
36
42
|
useDatasourceSelectValueToSelector: function() {
|
|
37
43
|
return useDatasourceSelectValueToSelector;
|
|
38
44
|
}
|
|
@@ -198,11 +204,7 @@ function DatasourceName(props) {
|
|
|
198
204
|
}
|
|
199
205
|
// Delimiter used to stringify/parse option values
|
|
200
206
|
const OPTION_VALUE_DELIMITER = '_____';
|
|
201
|
-
|
|
202
|
-
* Given a DatasourceSelectItemSelector,
|
|
203
|
-
* returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.
|
|
204
|
-
* @param selector
|
|
205
|
-
*/ function selectorToOptionValue(selector) {
|
|
207
|
+
function selectorToOptionValue(selector) {
|
|
206
208
|
if (isVariableDatasource(selector)) {
|
|
207
209
|
return `${DATASOURCE_VARIABLE_VALUE_PREFIX}${selector}`;
|
|
208
210
|
}
|
|
@@ -212,11 +214,7 @@ const OPTION_VALUE_DELIMITER = '_____';
|
|
|
212
214
|
selector.name ?? ''
|
|
213
215
|
].join(OPTION_VALUE_DELIMITER);
|
|
214
216
|
}
|
|
215
|
-
|
|
216
|
-
* Given an option value name like `{kind}_____{group}_____{name}`,
|
|
217
|
-
* returns a DatasourceSelector to be used by the query data model.
|
|
218
|
-
* @param optionValue
|
|
219
|
-
*/ function optionValueToSelector(optionValue) {
|
|
217
|
+
function optionValueToSelector(optionValue) {
|
|
220
218
|
if (optionValue.startsWith(DATASOURCE_VARIABLE_VALUE_PREFIX)) {
|
|
221
219
|
return optionValue.split(DATASOURCE_VARIABLE_VALUE_PREFIX)[1];
|
|
222
220
|
}
|
|
@@ -78,6 +78,10 @@ function HTTPSettingsEditor(props) {
|
|
|
78
78
|
const { value, onChange, isReadonly, initialSpecDirect, initialSpecProxy } = props;
|
|
79
79
|
const strDirect = 'Direct access';
|
|
80
80
|
const strProxy = 'Proxy';
|
|
81
|
+
// Initialize Proxy mode by default, if neither direct nor proxy mode is selected.
|
|
82
|
+
if (!value.directUrl && !value.proxy) {
|
|
83
|
+
Object.assign(value, initialSpecProxy);
|
|
84
|
+
}
|
|
81
85
|
// utilitary function used for headers when renaming a property
|
|
82
86
|
// -> TODO it would be cleaner to manipulate headers as an intermediary list instead, to avoid doing this.
|
|
83
87
|
const buildNewHeaders = (oldHeaders, oldName, newName)=>{
|
|
@@ -487,8 +491,7 @@ function HTTPSettingsEditor(props) {
|
|
|
487
491
|
// bug in case the tabs get eventually swapped in the future.
|
|
488
492
|
const directModeId = tabs.findIndex((tab)=>tab.label === strDirect);
|
|
489
493
|
const proxyModeId = tabs.findIndex((tab)=>tab.label === strProxy);
|
|
490
|
-
//
|
|
491
|
-
// Otherwise (create datasource), set defaultTab to Direct access.
|
|
494
|
+
// Set defaultTab to the mode that this datasource is currently relying on.
|
|
492
495
|
const defaultTab = value.proxy ? proxyModeId : directModeId;
|
|
493
496
|
// For better user experience, save previous states in mind for both mode.
|
|
494
497
|
// This avoids losing everything when the user changes their mind back.
|
|
@@ -43,7 +43,7 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
43
43
|
const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
|
|
44
44
|
const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
|
|
45
45
|
const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(defaultQueryType, defaultQueryKind, {
|
|
46
|
-
|
|
46
|
+
useErrorBoundary: true,
|
|
47
47
|
enabled: true
|
|
48
48
|
});
|
|
49
49
|
// This default query definition is used if no query is provided initially or when we add a new query
|
|
@@ -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, isLoading, 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 (isLoading) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
42
|
if (plugin === undefined) {
|
|
@@ -73,11 +73,13 @@ function useListVariablePluginValues(definition) {
|
|
|
73
73
|
};
|
|
74
74
|
const spec = definition.spec.plugin.spec;
|
|
75
75
|
const capturingRegexp = definition.spec.capturingRegexp !== undefined ? new RegExp(definition.spec.capturingRegexp, 'g') : undefined;
|
|
76
|
-
let dependsOnVariables;
|
|
76
|
+
let dependsOnVariables = Object.keys(allVariables); // Default to all variables
|
|
77
77
|
if (variablePlugin?.dependsOn) {
|
|
78
78
|
const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
|
|
79
|
-
dependsOnVariables = dependencies.variables;
|
|
79
|
+
dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;
|
|
80
80
|
}
|
|
81
|
+
// Exclude self variable to avoid circular dependency
|
|
82
|
+
dependsOnVariables = dependsOnVariables.filter((v)=>v !== definition.spec.name);
|
|
81
83
|
const variables = (0, _runtime.useAllVariableValues)(dependsOnVariables);
|
|
82
84
|
let waitToLoad = false;
|
|
83
85
|
if (dependsOnVariables) {
|
|
@@ -112,11 +112,11 @@ const getPluginRuntime = ()=>{
|
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
'@tanstack/react-query': {
|
|
115
|
-
version: '
|
|
115
|
+
version: '4.39.1',
|
|
116
116
|
lib: ()=>_reactquery,
|
|
117
117
|
shareConfig: {
|
|
118
118
|
singleton: true,
|
|
119
|
-
requiredVersion: '^
|
|
119
|
+
requiredVersion: '^4.39.1'
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
'react-hook-form': {
|
|
@@ -135,36 +135,44 @@ const getPluginRuntime = ()=>{
|
|
|
135
135
|
requiredVersion: '^5.5.0'
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
|
+
'@perses-dev/core': {
|
|
139
|
+
version: '0.51.0-rc.1',
|
|
140
|
+
lib: ()=>require('@perses-dev/core'),
|
|
141
|
+
shareConfig: {
|
|
142
|
+
singleton: true,
|
|
143
|
+
requiredVersion: '^0.51.0-rc.1'
|
|
144
|
+
}
|
|
145
|
+
},
|
|
138
146
|
'@perses-dev/components': {
|
|
139
|
-
version: '0.51.0-
|
|
147
|
+
version: '0.51.0-rc.1',
|
|
140
148
|
lib: ()=>require('@perses-dev/components'),
|
|
141
149
|
shareConfig: {
|
|
142
150
|
singleton: true,
|
|
143
|
-
requiredVersion: '^0.51.0-
|
|
151
|
+
requiredVersion: '^0.51.0-rc.1'
|
|
144
152
|
}
|
|
145
153
|
},
|
|
146
154
|
'@perses-dev/plugin-system': {
|
|
147
|
-
version: '0.51.0-
|
|
155
|
+
version: '0.51.0-rc.1',
|
|
148
156
|
lib: ()=>require('@perses-dev/plugin-system'),
|
|
149
157
|
shareConfig: {
|
|
150
158
|
singleton: true,
|
|
151
|
-
requiredVersion: '^0.51.0-
|
|
159
|
+
requiredVersion: '^0.51.0-rc.1'
|
|
152
160
|
}
|
|
153
161
|
},
|
|
154
162
|
'@perses-dev/explore': {
|
|
155
|
-
version: '0.51.0-
|
|
163
|
+
version: '0.51.0-rc.1',
|
|
156
164
|
lib: ()=>require('@perses-dev/explore'),
|
|
157
165
|
shareConfig: {
|
|
158
166
|
singleton: true,
|
|
159
|
-
requiredVersion: '^0.51.0-
|
|
167
|
+
requiredVersion: '^0.51.0-rc.1'
|
|
160
168
|
}
|
|
161
169
|
},
|
|
162
170
|
'@perses-dev/dashboards': {
|
|
163
|
-
version: '0.51.0-
|
|
171
|
+
version: '0.51.0-rc.1',
|
|
164
172
|
lib: ()=>require('@perses-dev/dashboards'),
|
|
165
173
|
shareConfig: {
|
|
166
174
|
singleton: true,
|
|
167
|
-
requiredVersion: '^0.51.0-
|
|
175
|
+
requiredVersion: '^0.51.0-rc.1'
|
|
168
176
|
}
|
|
169
177
|
},
|
|
170
178
|
// Below are the shared modules that are used by the plugins, this can be part of the SDK
|
|
@@ -38,11 +38,11 @@ _export(exports, {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
const _reactquery = require("@tanstack/react-query");
|
|
41
|
-
const _variables = require("./variables");
|
|
42
41
|
const _TimeRangeProvider = require("./TimeRangeProvider");
|
|
43
42
|
const _datasources = require("./datasources");
|
|
44
43
|
const _pluginregistry = require("./plugin-registry");
|
|
45
44
|
const _utils = require("./utils");
|
|
45
|
+
const _variables = require("./variables");
|
|
46
46
|
const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';
|
|
47
47
|
function getQueryOptions({ plugin, definition, context }) {
|
|
48
48
|
const { timeRange, datasourceStore, suggestedStepMs, mode, variableState, refreshKey } = context;
|
|
@@ -115,6 +115,7 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
|
|
|
115
115
|
context
|
|
116
116
|
});
|
|
117
117
|
return {
|
|
118
|
+
...queryOptions,
|
|
118
119
|
enabled: (queryOptions?.enabled ?? true) && queryEnabled,
|
|
119
120
|
queryKey: queryKey,
|
|
120
121
|
queryFn: async ()=>{
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "renderHookWithContext", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return renderHookWithContext;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _react = require("@testing-library/react");
|
|
24
|
+
const _utils = require("./utils");
|
|
25
|
+
function renderHookWithContext(callback, contextOptions, renderHookOptions) {
|
|
26
|
+
const wrapper = (0, _utils.getTestContextWrapper)(contextOptions);
|
|
27
|
+
return (0, _react.renderHook)(callback, {
|
|
28
|
+
wrapper,
|
|
29
|
+
...renderHookOptions
|
|
30
|
+
});
|
|
31
|
+
}
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -22,27 +22,10 @@ Object.defineProperty(exports, "renderWithContext", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _react = require("@testing-library/react");
|
|
25
|
-
const
|
|
26
|
-
const _PluginRegistry = require("../components/PluginRegistry");
|
|
27
|
-
const _testplugins = require("./test-plugins");
|
|
25
|
+
const _utils = require("./utils");
|
|
28
26
|
function renderWithContext(ui, renderOptions, contextOptions) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
queries: {
|
|
33
|
-
refetchOnWindowFocus: false,
|
|
34
|
-
retry: false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return (0, _react.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
|
|
39
|
-
client: queryClient,
|
|
40
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginRegistry.PluginRegistry, {
|
|
41
|
-
pluginLoader: _testplugins.testPluginLoader,
|
|
42
|
-
defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
|
|
43
|
-
TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
|
|
44
|
-
},
|
|
45
|
-
children: ui
|
|
46
|
-
})
|
|
27
|
+
const Wrapper = (0, _utils.getTestContextWrapper)(contextOptions);
|
|
28
|
+
return (0, _react.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(Wrapper, {
|
|
29
|
+
children: ui
|
|
47
30
|
}), renderOptions);
|
|
48
31
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "getTestContextWrapper", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return getTestContextWrapper;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
+
const _reactquery = require("@tanstack/react-query");
|
|
25
|
+
const _components = require("../components");
|
|
26
|
+
const _testplugins = require("./test-plugins");
|
|
27
|
+
function getTestContextWrapper(contextOptions) {
|
|
28
|
+
// Create a new QueryClient for each test to avoid caching issues
|
|
29
|
+
const queryClient = new _reactquery.QueryClient({
|
|
30
|
+
defaultOptions: {
|
|
31
|
+
queries: {
|
|
32
|
+
refetchOnWindowFocus: false,
|
|
33
|
+
retry: false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return function Wrapper({ children }) {
|
|
38
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
|
|
39
|
+
client: queryClient,
|
|
40
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PluginRegistry, {
|
|
41
|
+
pluginLoader: _testplugins.testPluginLoader,
|
|
42
|
+
defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
|
|
43
|
+
TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
|
|
44
|
+
},
|
|
45
|
+
children: children
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OutlinedSelectProps, BaseSelectProps } from '@mui/material';
|
|
2
2
|
import { DatasourceSelector, VariableName } from '@perses-dev/core';
|
|
3
3
|
import { ReactElement } from 'react';
|
|
4
|
-
import { DatasourceSelectItemGroup, VariableStateMap } from '../runtime';
|
|
4
|
+
import { DatasourceSelectItemGroup, DatasourceSelectItemSelector, VariableStateMap } from '../runtime';
|
|
5
5
|
type OmittedMuiProps = 'children' | 'value' | 'onChange';
|
|
6
6
|
export type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;
|
|
7
7
|
export interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {
|
|
@@ -20,6 +20,18 @@ export declare function DatasourceName(props: {
|
|
|
20
20
|
overridden?: boolean;
|
|
21
21
|
overriding?: boolean;
|
|
22
22
|
}): ReactElement;
|
|
23
|
+
/**
|
|
24
|
+
* Given a DatasourceSelectItemSelector,
|
|
25
|
+
* returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.
|
|
26
|
+
* @param selector
|
|
27
|
+
*/
|
|
28
|
+
export declare function selectorToOptionValue(selector: DatasourceSelectItemSelector | VariableName): string;
|
|
29
|
+
/**
|
|
30
|
+
* Given an option value name like `{kind}_____{group}_____{name}`,
|
|
31
|
+
* returns a DatasourceSelector to be used by the query data model.
|
|
32
|
+
* @param optionValue
|
|
33
|
+
*/
|
|
34
|
+
export declare function optionValueToSelector(optionValue: string): DatasourceSelectValue;
|
|
23
35
|
export declare function isVariableDatasource(value: DatasourceSelectValue | undefined): value is VariableName;
|
|
24
36
|
export declare const datasourceSelectValueToSelector: (value: DatasourceSelectValue | undefined, variables: VariableStateMap, datasourceSelectItemGroups: DatasourceSelectItemGroup[] | undefined) => DatasourceSelector | undefined;
|
|
25
37
|
export declare const useDatasourceSelectValueToSelector: (value: DatasourceSelectValue, datasourcePluginKind: string) => DatasourceSelector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../src/components/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAML,mBAAmB,EACnB,eAAe,EAGhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAEL,y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KAAK,EAAE,qBAAqB,GAAG,SAAS,GAAG,KAAK,IAAI,YAAY,CAEpG;AAED,eAAO,MAAM,+BAA+B,UACnC,qBAAqB,GAAG,SAAS,aAC7B,gBAAgB,8BACC,yBAAyB,EAAE,GAAG,SAAS,KAClE,kBAAkB,GAAG,SA4BvB,CAAC;AAEF,eAAO,MAAM,kCAAkC,UACtC,qBAAqB,wBACN,MAAM,KAC3B,kBAQF,CAAC"}
|
|
@@ -174,7 +174,7 @@ const OPTION_VALUE_DELIMITER = '_____';
|
|
|
174
174
|
* Given a DatasourceSelectItemSelector,
|
|
175
175
|
* returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.
|
|
176
176
|
* @param selector
|
|
177
|
-
*/ function selectorToOptionValue(selector) {
|
|
177
|
+
*/ export function selectorToOptionValue(selector) {
|
|
178
178
|
if (isVariableDatasource(selector)) {
|
|
179
179
|
return `${DATASOURCE_VARIABLE_VALUE_PREFIX}${selector}`;
|
|
180
180
|
}
|
|
@@ -188,7 +188,7 @@ const OPTION_VALUE_DELIMITER = '_____';
|
|
|
188
188
|
* Given an option value name like `{kind}_____{group}_____{name}`,
|
|
189
189
|
* returns a DatasourceSelector to be used by the query data model.
|
|
190
190
|
* @param optionValue
|
|
191
|
-
*/ function optionValueToSelector(optionValue) {
|
|
191
|
+
*/ export function optionValueToSelector(optionValue) {
|
|
192
192
|
if (optionValue.startsWith(DATASOURCE_VARIABLE_VALUE_PREFIX)) {
|
|
193
193
|
return optionValue.split(DATASOURCE_VARIABLE_VALUE_PREFIX)[1];
|
|
194
194
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/DatasourceSelect.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 OpenInNewIcon from 'mdi-material-ui/OpenInNew';\nimport {\n Stack,\n ListItemText,\n Chip,\n IconButton,\n Box,\n OutlinedSelectProps,\n BaseSelectProps,\n Autocomplete,\n TextField,\n} from '@mui/material';\nimport { DatasourceSelector, VariableName } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport {\n DatasourceSelectItem,\n DatasourceSelectItemGroup,\n DatasourceSelectItemSelector,\n useListDatasourceSelectItems,\n useVariableValues,\n VariableStateMap,\n} from '../runtime';\nimport { parseVariables } from '../utils';\n\nconst DATASOURCE_VARIABLE_VALUE_PREFIX = '__DATASOURCE_VARIABLE_VALUE__';\nconst VARIABLE_IDENTIFIER = '$';\n// Props on MUI Select that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\ntype DataSourceOption = {\n groupEditLink?: string;\n groupLabel?: string;\n value: string;\n} & Omit<DatasourceSelectItem, 'selector'> &\n Omit<DatasourceSelectItem['selector'], 'kind'>;\n\nconst emptyDatasourceOption: DataSourceOption = { name: '', value: '' };\n\nexport type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;\n\nexport interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {\n value: DatasourceSelectValue;\n onChange: (next: DatasourceSelectValue) => void;\n datasourcePluginKind: string;\n project?: string;\n}\n\n/**\n * Displays a MUI input for selecting a Datasource of a particular kind. Note: The 'value' and `onChange` handler for\n * the input deal with a `DatasourceSelector`.\n */\nexport function DatasourceSelect(props: DatasourceSelectProps): ReactElement {\n const { datasourcePluginKind, value, project, onChange, ...others } = props;\n const { data, isLoading } = useListDatasourceSelectItems(datasourcePluginKind, project);\n const variables = useVariableValues();\n\n const defaultValue = useMemo<VariableName | DatasourceSelectItemSelector>(() => {\n if (isVariableDatasource(value)) {\n return value;\n }\n\n const group = (data ?? [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((item) => {\n return value.kind === item.selector.kind && value.name === item.selector.name && !item.overridden;\n })?.selector.group;\n return { ...value, group };\n }, [value, data]);\n\n const options = useMemo<DataSourceOption[]>(() => {\n const datasourceOptions = (data || []).flatMap<DataSourceOption>((itemGroup) =>\n itemGroup.items.map<DataSourceOption>((item) => ({\n groupLabel: itemGroup.group,\n groupEditLink: itemGroup.editLink,\n name: item.name,\n overriding: item.overriding,\n overridden: item.overridden,\n saved: item.saved ?? true,\n group: item.selector.group,\n value: selectorToOptionValue(item.selector),\n }))\n );\n\n const datasourceOptionsMap = new Map(datasourceOptions.map((option) => [option.name, option]));\n\n const variableOptions = Object.entries(variables).flatMap<DataSourceOption>(([name, variable]) => {\n if (Array.isArray(variable.value)) return [];\n\n const associatedDatasource = datasourceOptionsMap.get(variable.value ?? '');\n if (!associatedDatasource) return [];\n\n return {\n groupLabel: 'Variables',\n name: `${VARIABLE_IDENTIFIER}${name}`,\n saved: true,\n value: `${DATASOURCE_VARIABLE_VALUE_PREFIX}${VARIABLE_IDENTIFIER}${name}`,\n };\n });\n\n return [...datasourceOptions, ...variableOptions];\n }, [data, variables]);\n\n // While loading available values, just use an empty datasource option so MUI select doesn't warn about values out of range\n const optionValue = isLoading\n ? emptyDatasourceOption\n : options.find((option) => option.value === selectorToOptionValue(defaultValue));\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange = (selectedOption: DataSourceOption | null): void => {\n if (selectedOption) {\n const next = optionValueToSelector(selectedOption?.value || '');\n onChange(next);\n } else {\n onChange({ kind: datasourcePluginKind });\n }\n };\n\n // We use a fake action event when we click on the action of the chip (hijack the \"delete\" feature).\n // This is because the href link action is on the `deleteIcon` property already, but the `onDelete` property\n // controls its visibility.\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const fakeActionEvent = (): void => {};\n\n return (\n <Autocomplete<DataSourceOption>\n options={options}\n renderInput={(params) => <TextField {...params} label={others.label} placeholder=\"\" />}\n groupBy={(option) => option.groupLabel || 'No group'}\n getOptionLabel={(option) => {\n return option.name;\n }}\n onChange={(_, v) => handleChange(v)}\n value={optionValue}\n renderOption={(props, option) => {\n return (\n <li {...props} key={option.value}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\">\n <ListItemText>\n <DatasourceName name={option.name} overridden={option.overridden} overriding={option.overriding} />\n </ListItemText>\n {!option.saved && <ListItemText>Save the dashboard to enable this datasource</ListItemText>}\n <ListItemText style={{ textAlign: 'right' }}>\n {option.groupLabel && option.groupLabel.length > 0 && (\n <Chip\n disabled={false}\n label={option.groupLabel}\n size=\"small\"\n onDelete={option.groupEditLink ? fakeActionEvent : undefined}\n deleteIcon={\n option.groupEditLink ? (\n <IconButton href={option.groupEditLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n ) : undefined\n }\n />\n )}\n </ListItemText>\n </Stack>\n </li>\n );\n }}\n />\n );\n}\n\nexport function DatasourceName(props: { name: string; overridden?: boolean; overriding?: boolean }): ReactElement {\n const { name, overridden, overriding } = props;\n return (\n <>\n {`${name} `}\n {!overridden && overriding && (\n <Box display=\"inline\" fontWeight=\"normal\" color={(theme) => theme.palette.primary.main}>\n (overriding)\n </Box>\n )}\n {overridden && '(overridden)'}\n </>\n );\n}\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a DatasourceSelectItemSelector,\n * returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.\n * @param selector\n */\nfunction selectorToOptionValue(selector: DatasourceSelectItemSelector | VariableName): string {\n if (isVariableDatasource(selector)) {\n return `${DATASOURCE_VARIABLE_VALUE_PREFIX}${selector}`;\n }\n return [selector.kind, selector.group ?? '', selector.name ?? ''].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{kind}_____{group}_____{name}`,\n * returns a DatasourceSelector to be used by the query data model.\n * @param optionValue\n */\nfunction optionValueToSelector(optionValue: string): DatasourceSelectValue {\n if (optionValue.startsWith(DATASOURCE_VARIABLE_VALUE_PREFIX)) {\n return optionValue.split(DATASOURCE_VARIABLE_VALUE_PREFIX)[1]!;\n }\n\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const kind = words[0];\n const name = words[2];\n if (kind === undefined || name === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n kind,\n name: name === '' ? undefined : name,\n };\n}\n\nexport function isVariableDatasource(value: DatasourceSelectValue | undefined): value is VariableName {\n return typeof value === 'string' && value.startsWith(VARIABLE_IDENTIFIER);\n}\n\nexport const datasourceSelectValueToSelector = (\n value: DatasourceSelectValue | undefined,\n variables: VariableStateMap,\n datasourceSelectItemGroups: DatasourceSelectItemGroup[] | undefined\n): DatasourceSelector | undefined => {\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n const [variableName] = parseVariables(value);\n const variable = variables[variableName ?? ''];\n\n // If the variable is not defined or if its value is an array, we cannot determine a selector and return undefined\n if (!variable || Array.isArray(variable.value)) {\n return undefined;\n }\n\n const associatedDatasource = (datasourceSelectItemGroups || [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((datasource) => datasource.name === variable.value);\n\n // If the variable value is not a datasource, we cannot determine a selector and return undefined\n if (associatedDatasource === undefined) {\n return undefined;\n }\n\n const datasourceSelector: DatasourceSelector = {\n kind: associatedDatasource.selector.kind,\n name: associatedDatasource.selector.name,\n };\n\n return datasourceSelector;\n};\n\nexport const useDatasourceSelectValueToSelector = (\n value: DatasourceSelectValue,\n datasourcePluginKind: string\n): DatasourceSelector => {\n const { data } = useListDatasourceSelectItems(datasourcePluginKind);\n const variables = useVariableValues();\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n return datasourceSelectValueToSelector(value, variables, data) ?? { kind: datasourcePluginKind };\n};\n"],"names":["OpenInNewIcon","Stack","ListItemText","Chip","IconButton","Box","Autocomplete","TextField","useMemo","useListDatasourceSelectItems","useVariableValues","parseVariables","DATASOURCE_VARIABLE_VALUE_PREFIX","VARIABLE_IDENTIFIER","emptyDatasourceOption","name","value","DatasourceSelect","props","datasourcePluginKind","project","onChange","others","data","isLoading","variables","defaultValue","isVariableDatasource","group","flatMap","itemGroup","items","find","item","kind","selector","overridden","options","datasourceOptions","map","groupLabel","groupEditLink","editLink","overriding","saved","selectorToOptionValue","datasourceOptionsMap","Map","option","variableOptions","Object","entries","variable","Array","isArray","associatedDatasource","get","optionValue","handleChange","selectedOption","next","optionValueToSelector","fakeActionEvent","renderInput","params","label","placeholder","groupBy","getOptionLabel","_","v","renderOption","li","key","direction","alignItems","justifyContent","width","DatasourceName","style","textAlign","length","disabled","size","onDelete","undefined","deleteIcon","href","target","fontSize","display","fontWeight","color","theme","palette","primary","main","OPTION_VALUE_DELIMITER","join","startsWith","split","words","Error","datasourceSelectValueToSelector","datasourceSelectItemGroups","variableName","datasource","datasourceSelector","useDatasourceSelectValueToSelector"],"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;;;AAEjC,OAAOA,mBAAmB,4BAA4B;AACtD,SACEC,KAAK,EACLC,YAAY,EACZC,IAAI,EACJC,UAAU,EACVC,GAAG,EAGHC,YAAY,EACZC,SAAS,QACJ,gBAAgB;AAEvB,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAIEC,4BAA4B,EAC5BC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,cAAc,QAAQ,WAAW;AAE1C,MAAMC,mCAAmC;AACzC,MAAMC,sBAAsB;AAY5B,MAAMC,wBAA0C;IAAEC,MAAM;IAAIC,OAAO;AAAG;AAWtE;;;CAGC,GACD,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,oBAAoB,EAAE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EA,MAAM,EAAEI,IAAI,EAAE,GAAGd,6BAA6BU;IAC9C,MAAMM,YAAYf;IAClB,IAAI,CAACiB,qBAAqBX,QAAQ;QAChC,OAAOA;IACT;IAEA,OAAOuF,gCAAgCvF,OAAOS,WAAWF,SAAS;QAAEW,MAAMf;IAAqB;AACjG,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/components/DatasourceSelect.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 OpenInNewIcon from 'mdi-material-ui/OpenInNew';\nimport {\n Stack,\n ListItemText,\n Chip,\n IconButton,\n Box,\n OutlinedSelectProps,\n BaseSelectProps,\n Autocomplete,\n TextField,\n} from '@mui/material';\nimport { DatasourceSelector, VariableName } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport {\n DatasourceSelectItem,\n DatasourceSelectItemGroup,\n DatasourceSelectItemSelector,\n useListDatasourceSelectItems,\n useVariableValues,\n VariableStateMap,\n} from '../runtime';\nimport { parseVariables } from '../utils';\n\nconst DATASOURCE_VARIABLE_VALUE_PREFIX = '__DATASOURCE_VARIABLE_VALUE__';\nconst VARIABLE_IDENTIFIER = '$';\n// Props on MUI Select that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\ntype DataSourceOption = {\n groupEditLink?: string;\n groupLabel?: string;\n value: string;\n} & Omit<DatasourceSelectItem, 'selector'> &\n Omit<DatasourceSelectItem['selector'], 'kind'>;\n\nconst emptyDatasourceOption: DataSourceOption = { name: '', value: '' };\n\nexport type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;\n\nexport interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {\n value: DatasourceSelectValue;\n onChange: (next: DatasourceSelectValue) => void;\n datasourcePluginKind: string;\n project?: string;\n}\n\n/**\n * Displays a MUI input for selecting a Datasource of a particular kind. Note: The 'value' and `onChange` handler for\n * the input deal with a `DatasourceSelector`.\n */\nexport function DatasourceSelect(props: DatasourceSelectProps): ReactElement {\n const { datasourcePluginKind, value, project, onChange, ...others } = props;\n const { data, isLoading } = useListDatasourceSelectItems(datasourcePluginKind, project);\n const variables = useVariableValues();\n\n const defaultValue = useMemo<VariableName | DatasourceSelectItemSelector>(() => {\n if (isVariableDatasource(value)) {\n return value;\n }\n\n const group = (data ?? [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((item) => {\n return value.kind === item.selector.kind && value.name === item.selector.name && !item.overridden;\n })?.selector.group;\n return { ...value, group };\n }, [value, data]);\n\n const options = useMemo<DataSourceOption[]>(() => {\n const datasourceOptions = (data || []).flatMap<DataSourceOption>((itemGroup) =>\n itemGroup.items.map<DataSourceOption>((item) => ({\n groupLabel: itemGroup.group,\n groupEditLink: itemGroup.editLink,\n name: item.name,\n overriding: item.overriding,\n overridden: item.overridden,\n saved: item.saved ?? true,\n group: item.selector.group,\n value: selectorToOptionValue(item.selector),\n }))\n );\n\n const datasourceOptionsMap = new Map(datasourceOptions.map((option) => [option.name, option]));\n\n const variableOptions = Object.entries(variables).flatMap<DataSourceOption>(([name, variable]) => {\n if (Array.isArray(variable.value)) return [];\n\n const associatedDatasource = datasourceOptionsMap.get(variable.value ?? '');\n if (!associatedDatasource) return [];\n\n return {\n groupLabel: 'Variables',\n name: `${VARIABLE_IDENTIFIER}${name}`,\n saved: true,\n value: `${DATASOURCE_VARIABLE_VALUE_PREFIX}${VARIABLE_IDENTIFIER}${name}`,\n };\n });\n\n return [...datasourceOptions, ...variableOptions];\n }, [data, variables]);\n\n // While loading available values, just use an empty datasource option so MUI select doesn't warn about values out of range\n const optionValue = isLoading\n ? emptyDatasourceOption\n : options.find((option) => option.value === selectorToOptionValue(defaultValue));\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange = (selectedOption: DataSourceOption | null): void => {\n if (selectedOption) {\n const next = optionValueToSelector(selectedOption?.value || '');\n onChange(next);\n } else {\n onChange({ kind: datasourcePluginKind });\n }\n };\n\n // We use a fake action event when we click on the action of the chip (hijack the \"delete\" feature).\n // This is because the href link action is on the `deleteIcon` property already, but the `onDelete` property\n // controls its visibility.\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const fakeActionEvent = (): void => {};\n\n return (\n <Autocomplete<DataSourceOption>\n options={options}\n renderInput={(params) => <TextField {...params} label={others.label} placeholder=\"\" />}\n groupBy={(option) => option.groupLabel || 'No group'}\n getOptionLabel={(option) => {\n return option.name;\n }}\n onChange={(_, v) => handleChange(v)}\n value={optionValue}\n renderOption={(props, option) => {\n return (\n <li {...props} key={option.value}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\">\n <ListItemText>\n <DatasourceName name={option.name} overridden={option.overridden} overriding={option.overriding} />\n </ListItemText>\n {!option.saved && <ListItemText>Save the dashboard to enable this datasource</ListItemText>}\n <ListItemText style={{ textAlign: 'right' }}>\n {option.groupLabel && option.groupLabel.length > 0 && (\n <Chip\n disabled={false}\n label={option.groupLabel}\n size=\"small\"\n onDelete={option.groupEditLink ? fakeActionEvent : undefined}\n deleteIcon={\n option.groupEditLink ? (\n <IconButton href={option.groupEditLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n ) : undefined\n }\n />\n )}\n </ListItemText>\n </Stack>\n </li>\n );\n }}\n />\n );\n}\n\nexport function DatasourceName(props: { name: string; overridden?: boolean; overriding?: boolean }): ReactElement {\n const { name, overridden, overriding } = props;\n return (\n <>\n {`${name} `}\n {!overridden && overriding && (\n <Box display=\"inline\" fontWeight=\"normal\" color={(theme) => theme.palette.primary.main}>\n (overriding)\n </Box>\n )}\n {overridden && '(overridden)'}\n </>\n );\n}\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a DatasourceSelectItemSelector,\n * returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.\n * @param selector\n */\nexport function selectorToOptionValue(selector: DatasourceSelectItemSelector | VariableName): string {\n if (isVariableDatasource(selector)) {\n return `${DATASOURCE_VARIABLE_VALUE_PREFIX}${selector}`;\n }\n return [selector.kind, selector.group ?? '', selector.name ?? ''].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{kind}_____{group}_____{name}`,\n * returns a DatasourceSelector to be used by the query data model.\n * @param optionValue\n */\nexport function optionValueToSelector(optionValue: string): DatasourceSelectValue {\n if (optionValue.startsWith(DATASOURCE_VARIABLE_VALUE_PREFIX)) {\n return optionValue.split(DATASOURCE_VARIABLE_VALUE_PREFIX)[1]!;\n }\n\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const kind = words[0];\n const name = words[2];\n if (kind === undefined || name === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n kind,\n name: name === '' ? undefined : name,\n };\n}\n\nexport function isVariableDatasource(value: DatasourceSelectValue | undefined): value is VariableName {\n return typeof value === 'string' && value.startsWith(VARIABLE_IDENTIFIER);\n}\n\nexport const datasourceSelectValueToSelector = (\n value: DatasourceSelectValue | undefined,\n variables: VariableStateMap,\n datasourceSelectItemGroups: DatasourceSelectItemGroup[] | undefined\n): DatasourceSelector | undefined => {\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n const [variableName] = parseVariables(value);\n const variable = variables[variableName ?? ''];\n\n // If the variable is not defined or if its value is an array, we cannot determine a selector and return undefined\n if (!variable || Array.isArray(variable.value)) {\n return undefined;\n }\n\n const associatedDatasource = (datasourceSelectItemGroups || [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((datasource) => datasource.name === variable.value);\n\n // If the variable value is not a datasource, we cannot determine a selector and return undefined\n if (associatedDatasource === undefined) {\n return undefined;\n }\n\n const datasourceSelector: DatasourceSelector = {\n kind: associatedDatasource.selector.kind,\n name: associatedDatasource.selector.name,\n };\n\n return datasourceSelector;\n};\n\nexport const useDatasourceSelectValueToSelector = (\n value: DatasourceSelectValue,\n datasourcePluginKind: string\n): DatasourceSelector => {\n const { data } = useListDatasourceSelectItems(datasourcePluginKind);\n const variables = useVariableValues();\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n return datasourceSelectValueToSelector(value, variables, data) ?? { kind: datasourcePluginKind };\n};\n"],"names":["OpenInNewIcon","Stack","ListItemText","Chip","IconButton","Box","Autocomplete","TextField","useMemo","useListDatasourceSelectItems","useVariableValues","parseVariables","DATASOURCE_VARIABLE_VALUE_PREFIX","VARIABLE_IDENTIFIER","emptyDatasourceOption","name","value","DatasourceSelect","props","datasourcePluginKind","project","onChange","others","data","isLoading","variables","defaultValue","isVariableDatasource","group","flatMap","itemGroup","items","find","item","kind","selector","overridden","options","datasourceOptions","map","groupLabel","groupEditLink","editLink","overriding","saved","selectorToOptionValue","datasourceOptionsMap","Map","option","variableOptions","Object","entries","variable","Array","isArray","associatedDatasource","get","optionValue","handleChange","selectedOption","next","optionValueToSelector","fakeActionEvent","renderInput","params","label","placeholder","groupBy","getOptionLabel","_","v","renderOption","li","key","direction","alignItems","justifyContent","width","DatasourceName","style","textAlign","length","disabled","size","onDelete","undefined","deleteIcon","href","target","fontSize","display","fontWeight","color","theme","palette","primary","main","OPTION_VALUE_DELIMITER","join","startsWith","split","words","Error","datasourceSelectValueToSelector","datasourceSelectItemGroups","variableName","datasource","datasourceSelector","useDatasourceSelectValueToSelector"],"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;;;A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OAAOqE;IACT;IAEA,MAAM9B,uBAAuB,AAACiD,CAAAA,8BAA8B,EAAE,AAAD,EAC1D3E,OAAO,CAAC,CAACC,YAAcA,UAAUC,KAAK,EACtCC,IAAI,CAAC,CAAC0E,aAAeA,WAAW3F,IAAI,KAAKqC,SAASpC,KAAK;IAE1D,iGAAiG;IACjG,IAAIuC,yBAAyB8B,WAAW;QACtC,OAAOA;IACT;IAEA,MAAMsB,qBAAyC;QAC7CzE,MAAMqB,qBAAqBpB,QAAQ,CAACD,IAAI;QACxCnB,MAAMwC,qBAAqBpB,QAAQ,CAACpB,IAAI;IAC1C;IAEA,OAAO4F;AACT,EAAE;AAEF,OAAO,MAAMC,qCAAqC,CAChD5F,OACAG;IAEA,MAAM,EAAEI,IAAI,EAAE,GAAGd,6BAA6BU;IAC9C,MAAMM,YAAYf;IAClB,IAAI,CAACiB,qBAAqBX,QAAQ;QAChC,OAAOA;IACT;IAEA,OAAOuF,gCAAgCvF,OAAOS,WAAWF,SAAS;QAAEW,MAAMf;IAAqB;AACjG,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTTPSettingsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/HTTPSettingsEditor/HTTPSettingsEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAc,EAAY,YAAY,EAAY,MAAM,OAAO,CAAC;AAOhE,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,gBAAgB,EAAE,kBAAkB,CAAC;CACtC;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"HTTPSettingsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/HTTPSettingsEditor/HTTPSettingsEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAc,EAAY,YAAY,EAAY,MAAM,OAAO,CAAC;AAOhE,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,gBAAgB,EAAE,kBAAkB,CAAC;CACtC;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,YAAY,CA4b1E"}
|
|
@@ -22,6 +22,10 @@ export function HTTPSettingsEditor(props) {
|
|
|
22
22
|
const { value, onChange, isReadonly, initialSpecDirect, initialSpecProxy } = props;
|
|
23
23
|
const strDirect = 'Direct access';
|
|
24
24
|
const strProxy = 'Proxy';
|
|
25
|
+
// Initialize Proxy mode by default, if neither direct nor proxy mode is selected.
|
|
26
|
+
if (!value.directUrl && !value.proxy) {
|
|
27
|
+
Object.assign(value, initialSpecProxy);
|
|
28
|
+
}
|
|
25
29
|
// utilitary function used for headers when renaming a property
|
|
26
30
|
// -> TODO it would be cleaner to manipulate headers as an intermediary list instead, to avoid doing this.
|
|
27
31
|
const buildNewHeaders = (oldHeaders, oldName, newName)=>{
|
|
@@ -431,8 +435,7 @@ export function HTTPSettingsEditor(props) {
|
|
|
431
435
|
// bug in case the tabs get eventually swapped in the future.
|
|
432
436
|
const directModeId = tabs.findIndex((tab)=>tab.label === strDirect);
|
|
433
437
|
const proxyModeId = tabs.findIndex((tab)=>tab.label === strProxy);
|
|
434
|
-
//
|
|
435
|
-
// Otherwise (create datasource), set defaultTab to Direct access.
|
|
438
|
+
// Set defaultTab to the mode that this datasource is currently relying on.
|
|
436
439
|
const defaultTab = value.proxy ? proxyModeId : directModeId;
|
|
437
440
|
// For better user experience, save previous states in mind for both mode.
|
|
438
441
|
// This avoids losing everything when the user changes their mind back.
|