@perses-dev/plugin-system 0.52.0-rc.1 → 0.53.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/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +4 -3
- package/dist/cjs/components/DatasourceSelect/index.js +30 -0
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +73 -73
- package/dist/cjs/components/PluginEditor/PluginEditor.js +9 -10
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +6 -3
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +47 -0
- package/dist/cjs/components/Variables/variable-model.js +3 -3
- package/dist/cjs/components/index.js +0 -1
- package/dist/cjs/context/index.js +0 -1
- package/dist/cjs/remote/remotePluginLoader.js +19 -4
- package/dist/cjs/runtime/TimeRangeProvider/query-params.js +27 -27
- package/dist/cjs/runtime/UsageMetricsProvider.js +4 -3
- package/dist/cjs/runtime/time-series-queries.js +4 -4
- package/dist/cjs/test/mock-data.js +158 -0
- package/dist/components/{DatasourceSelect.d.ts → DatasourceSelect/DatasourceSelect.d.ts} +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -0
- package/dist/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +4 -3
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -0
- package/dist/components/DatasourceSelect/index.d.ts +2 -0
- package/dist/components/DatasourceSelect/index.d.ts.map +1 -0
- package/dist/components/DatasourceSelect/index.js +15 -0
- package/dist/components/DatasourceSelect/index.js.map +1 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +75 -75
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +9 -10
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -4
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +6 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +44 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/variable-model.js +3 -3
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -1
- package/dist/components/index.js.map +1 -1
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -1
- package/dist/context/index.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +1 -1
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/variables.d.ts +1 -1
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts +18 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +22 -4
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.d.ts +12 -7
- package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +23 -20
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts +3 -1
- package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +4 -3
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +4 -4
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/test/mock-data.d.ts +134 -0
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +135 -0
- package/dist/test/mock-data.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/components/ProjectSelect.js +0 -96
- package/dist/cjs/context/ProjectStoreProvider.js +0 -81
- package/dist/cjs/context/query-params.js +0 -49
- package/dist/components/DatasourceSelect.d.ts.map +0 -1
- package/dist/components/DatasourceSelect.js.map +0 -1
- package/dist/components/ProjectSelect.d.ts +0 -15
- package/dist/components/ProjectSelect.d.ts.map +0 -1
- package/dist/components/ProjectSelect.js +0 -91
- package/dist/components/ProjectSelect.js.map +0 -1
- package/dist/context/ProjectStoreProvider.d.ts +0 -16
- package/dist/context/ProjectStoreProvider.d.ts.map +0 -1
- package/dist/context/ProjectStoreProvider.js +0 -59
- package/dist/context/ProjectStoreProvider.js.map +0 -1
- package/dist/context/query-params.d.ts +0 -5
- package/dist/context/query-params.d.ts.map +0 -1
- package/dist/context/query-params.js +0 -41
- package/dist/context/query-params.js.map +0 -1
|
@@ -47,8 +47,8 @@ const _jsxruntime = require("react/jsx-runtime");
|
|
|
47
47
|
const _react = require("react");
|
|
48
48
|
const _OpenInNew = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/OpenInNew"));
|
|
49
49
|
const _material = require("@mui/material");
|
|
50
|
-
const _runtime = require("
|
|
51
|
-
const _utils = require("
|
|
50
|
+
const _runtime = require("../../runtime");
|
|
51
|
+
const _utils = require("../../utils");
|
|
52
52
|
function _interop_require_default(obj) {
|
|
53
53
|
return obj && obj.__esModule ? obj : {
|
|
54
54
|
default: obj
|
|
@@ -61,7 +61,7 @@ const emptyDatasourceOption = {
|
|
|
61
61
|
value: ''
|
|
62
62
|
};
|
|
63
63
|
function DatasourceSelect(props) {
|
|
64
|
-
const { datasourcePluginKind, value, project, onChange, ...others } = props;
|
|
64
|
+
const { datasourcePluginKind, value, project, readOnly, onChange, ...others } = props;
|
|
65
65
|
const { data, isLoading } = (0, _runtime.useListDatasourceSelectItems)(datasourcePluginKind, project);
|
|
66
66
|
const variables = (0, _runtime.useVariableValues)();
|
|
67
67
|
const defaultValue = (0, _react.useMemo)(()=>{
|
|
@@ -132,6 +132,7 @@ function DatasourceSelect(props) {
|
|
|
132
132
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
133
133
|
const fakeActionEvent = ()=>{};
|
|
134
134
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Autocomplete, {
|
|
135
|
+
readOnly: readOnly,
|
|
135
136
|
options: options,
|
|
136
137
|
renderInput: (params)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
137
138
|
...params,
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
_export_star(require("./DatasourceSelect"), exports);
|
|
18
|
+
function _export_star(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
21
|
+
Object.defineProperty(to, k, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return from[k];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return from;
|
|
30
|
+
}
|
|
@@ -32,12 +32,6 @@ const POSITION_OPTIONS = Object.entries(_model.LEGEND_POSITIONS_CONFIG).map(([id
|
|
|
32
32
|
...config
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
|
-
const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config])=>{
|
|
36
|
-
return {
|
|
37
|
-
id: id,
|
|
38
|
-
...config
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
35
|
const SIZE_OPTIONS = Object.entries(_model.LEGEND_SIZE_CONFIG).map(([id, config])=>{
|
|
42
36
|
return {
|
|
43
37
|
id: id,
|
|
@@ -58,13 +52,6 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
58
52
|
position: newValue.id
|
|
59
53
|
});
|
|
60
54
|
};
|
|
61
|
-
const handleLegendModeChange = (_, newValue)=>{
|
|
62
|
-
onChange({
|
|
63
|
-
...value,
|
|
64
|
-
position: currentPosition,
|
|
65
|
-
mode: newValue.id
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
55
|
const handleLegendSizeChange = (_, newValue)=>{
|
|
69
56
|
onChange({
|
|
70
57
|
...value,
|
|
@@ -85,7 +72,6 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
85
72
|
const currentPosition = (0, _core.getLegendPosition)(value?.position);
|
|
86
73
|
const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
87
74
|
const currentMode = (0, _core.getLegendMode)(value?.mode);
|
|
88
|
-
const legendModeConfig = _model.LEGEND_MODE_CONFIG[currentMode];
|
|
89
75
|
const currentSize = (0, _core.getLegendSize)(value?.size);
|
|
90
76
|
const legendSizeConfig = _model.LEGEND_SIZE_CONFIG[currentSize];
|
|
91
77
|
const legendValuesConfig = (0, _react.useMemo)(()=>{
|
|
@@ -147,65 +133,79 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
147
133
|
onChange: handleLegendShowChange
|
|
148
134
|
})
|
|
149
135
|
}),
|
|
150
|
-
/*#__PURE__*/ (0, _jsxruntime.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
136
|
+
value && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
137
|
+
children: [
|
|
138
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
139
|
+
label: "Position",
|
|
140
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
141
|
+
value: {
|
|
142
|
+
...legendPositionConfig,
|
|
143
|
+
id: currentPosition
|
|
144
|
+
},
|
|
145
|
+
options: POSITION_OPTIONS,
|
|
146
|
+
onChange: handleLegendPositionChange,
|
|
147
|
+
disableClearable: true
|
|
148
|
+
})
|
|
149
|
+
}),
|
|
150
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
151
|
+
label: "Mode",
|
|
152
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ToggleButtonGroup, {
|
|
153
|
+
color: "primary",
|
|
154
|
+
exclusive: true,
|
|
155
|
+
value: currentMode,
|
|
156
|
+
"aria-label": "Mode",
|
|
157
|
+
onChange: (__, newValue)=>{
|
|
158
|
+
onChange({
|
|
159
|
+
...value,
|
|
160
|
+
position: currentPosition,
|
|
161
|
+
mode: newValue
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
children: Object.entries(_model.LEGEND_MODE_CONFIG).map(([modeId, config])=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ToggleButton, {
|
|
165
|
+
value: modeId,
|
|
166
|
+
selected: currentMode === modeId,
|
|
167
|
+
"aria-label": `display ${modeId} mode`,
|
|
168
|
+
children: config.label
|
|
169
|
+
}, modeId))
|
|
170
|
+
})
|
|
171
|
+
}),
|
|
172
|
+
currentMode === 'table' && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
173
|
+
children: [
|
|
174
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
175
|
+
label: "Size",
|
|
176
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
177
|
+
value: {
|
|
178
|
+
...legendSizeConfig,
|
|
179
|
+
id: currentSize
|
|
180
|
+
},
|
|
181
|
+
options: SIZE_OPTIONS,
|
|
182
|
+
onChange: handleLegendSizeChange,
|
|
183
|
+
// TODO: enable sizes for list mode when we normalize the layout of
|
|
184
|
+
// lists to more closely match tables.
|
|
185
|
+
disableClearable: true
|
|
186
|
+
})
|
|
187
|
+
}),
|
|
188
|
+
showValuesEditor && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
189
|
+
label: "Values",
|
|
190
|
+
control: // For some reason, the inferred option type doesn't always seem to work
|
|
191
|
+
// quite right when `multiple` is true. Explicitly setting the generics
|
|
192
|
+
// to work around this.
|
|
193
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
194
|
+
multiple: true,
|
|
195
|
+
disableCloseOnSelect: true,
|
|
196
|
+
disableClearable: true,
|
|
197
|
+
value: legendValuesConfig,
|
|
198
|
+
options: valueOptions,
|
|
199
|
+
onChange: handleLegendValueChange,
|
|
200
|
+
limitTags: 1,
|
|
201
|
+
ChipProps: {
|
|
202
|
+
size: 'small'
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
]
|
|
207
|
+
})
|
|
208
|
+
]
|
|
209
209
|
})
|
|
210
210
|
]
|
|
211
211
|
});
|
|
@@ -80,13 +80,16 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
80
80
|
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
81
81
|
sx: {
|
|
82
82
|
display: 'flex',
|
|
83
|
-
flexDirection: 'row'
|
|
83
|
+
flexDirection: 'row',
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
justifyContent: 'space-between',
|
|
86
|
+
gap: 1,
|
|
87
|
+
mb: 1
|
|
84
88
|
},
|
|
85
89
|
children: [
|
|
86
90
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginKindSelect.PluginKindSelect, {
|
|
87
91
|
fullWidth: false,
|
|
88
92
|
sx: {
|
|
89
|
-
mb: 2,
|
|
90
93
|
minWidth: 120
|
|
91
94
|
},
|
|
92
95
|
margin: "dense",
|
|
@@ -94,8 +97,10 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
94
97
|
pluginTypes: pluginTypes,
|
|
95
98
|
disabled: isLoading,
|
|
96
99
|
value: pendingSelection ? pendingSelection : value.selection,
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
slotProps: {
|
|
101
|
+
input: {
|
|
102
|
+
readOnly: isReadonly
|
|
103
|
+
}
|
|
99
104
|
},
|
|
100
105
|
error: !!error,
|
|
101
106
|
helperText: error?.message,
|
|
@@ -104,12 +109,6 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
104
109
|
withRunQueryButton && !isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
|
|
105
110
|
"data-testid": "run_query_button",
|
|
106
111
|
variant: "contained",
|
|
107
|
-
sx: {
|
|
108
|
-
marginTop: 1.5,
|
|
109
|
-
marginBottom: 1.5,
|
|
110
|
-
paddingTop: 0.5,
|
|
111
|
-
marginLeft: 'auto'
|
|
112
|
-
},
|
|
113
112
|
startIcon: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Reload.default, {}),
|
|
114
113
|
onClick: runQueryHandler,
|
|
115
114
|
children: "Run Query"
|
|
@@ -27,6 +27,9 @@ const _runtime = require("../../runtime");
|
|
|
27
27
|
const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
28
28
|
const { pluginTypes, value: propValue, onChange, ...others } = props;
|
|
29
29
|
const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginTypes);
|
|
30
|
+
const sortedData = (0, _react.useMemo)(()=>data?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name)), [
|
|
31
|
+
data
|
|
32
|
+
]);
|
|
30
33
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
31
34
|
const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
|
|
32
35
|
const handleChange = (event)=>{
|
|
@@ -37,9 +40,9 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
37
40
|
return '';
|
|
38
41
|
}
|
|
39
42
|
const selectedValue = optionValueToSelection(selected);
|
|
40
|
-
return
|
|
43
|
+
return sortedData?.find((v)=>v.kind === selectedValue.type && v.spec.name === selectedValue.kind)?.spec.display.name;
|
|
41
44
|
}, [
|
|
42
|
-
|
|
45
|
+
sortedData
|
|
43
46
|
]);
|
|
44
47
|
// TODO: Does this need a loading indicator of some kind?
|
|
45
48
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.TextField, {
|
|
@@ -58,7 +61,7 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
58
61
|
value: "",
|
|
59
62
|
children: "Loading..."
|
|
60
63
|
}),
|
|
61
|
-
|
|
64
|
+
sortedData?.map((metadata)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
62
65
|
"data-testid": "option",
|
|
63
66
|
value: selectionToOptionValue({
|
|
64
67
|
type: metadata.kind,
|
|
@@ -32,6 +32,7 @@ const _context = require("../../../context");
|
|
|
32
32
|
const _variablemodel = require("../variable-model");
|
|
33
33
|
const _runtime = require("../../../runtime");
|
|
34
34
|
const _VariablePreview = require("./VariablePreview");
|
|
35
|
+
const _variableeditorformmodel = require("./variable-editor-form-model");
|
|
35
36
|
function FallbackPreview() {
|
|
36
37
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
37
38
|
children: "Error previewing values"
|
|
@@ -117,6 +118,10 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
117
118
|
control: control,
|
|
118
119
|
name: 'spec.allowAllValue'
|
|
119
120
|
});
|
|
121
|
+
const sortMethod = (0, _reacthookform.useWatch)({
|
|
122
|
+
control: control,
|
|
123
|
+
name: 'spec.sort'
|
|
124
|
+
});
|
|
120
125
|
// When variable kind is selected we need to provide default values
|
|
121
126
|
// TODO: check if react-hook-form has a better way to do this
|
|
122
127
|
const values = form.getValues();
|
|
@@ -126,6 +131,15 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
126
131
|
if (values.spec.allowMultiple === undefined) {
|
|
127
132
|
form.setValue('spec.allowMultiple', false);
|
|
128
133
|
}
|
|
134
|
+
if (!values.spec.plugin) {
|
|
135
|
+
form.setValue('spec.plugin', {
|
|
136
|
+
kind: 'StaticListVariable',
|
|
137
|
+
spec: {}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (!values.spec.sort) {
|
|
141
|
+
form.setValue('spec.sort', 'none');
|
|
142
|
+
}
|
|
129
143
|
const { refresh } = (0, _runtime.useTimeRange)();
|
|
130
144
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
131
145
|
children: [
|
|
@@ -138,18 +152,17 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
138
152
|
spacing: 2,
|
|
139
153
|
mb: 2,
|
|
140
154
|
children: [
|
|
141
|
-
|
|
155
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
142
156
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
|
|
143
157
|
FallbackComponent: FallbackPreview,
|
|
144
158
|
resetKeys: [
|
|
145
159
|
previewSpec
|
|
146
160
|
],
|
|
147
161
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_VariablePreview.VariableListPreview, {
|
|
162
|
+
sortMethod: sortMethod,
|
|
148
163
|
definition: previewSpec
|
|
149
164
|
})
|
|
150
165
|
})
|
|
151
|
-
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_VariablePreview.VariablePreview, {
|
|
152
|
-
isLoading: true
|
|
153
166
|
}),
|
|
154
167
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
155
168
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
|
|
@@ -215,7 +228,7 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
215
228
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
|
|
216
229
|
control: control,
|
|
217
230
|
name: "spec.sort",
|
|
218
|
-
render: ({ field, fieldState })=>/*#__PURE__*/ (0, _jsxruntime.
|
|
231
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
219
232
|
select: true,
|
|
220
233
|
...field,
|
|
221
234
|
fullWidth: true,
|
|
@@ -232,36 +245,14 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
232
245
|
onChange: (event)=>{
|
|
233
246
|
field.onChange(event);
|
|
234
247
|
},
|
|
235
|
-
children:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}),
|
|
244
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
245
|
-
value: "alphabetical-desc",
|
|
246
|
-
children: "Alphabetical, desc"
|
|
247
|
-
}),
|
|
248
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
249
|
-
value: "numerical-asc",
|
|
250
|
-
children: "Numerical, asc"
|
|
251
|
-
}),
|
|
252
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
253
|
-
value: "numerical-desc",
|
|
254
|
-
children: "Numerical, desc"
|
|
255
|
-
}),
|
|
256
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
257
|
-
value: "alphabetical-ci-asc",
|
|
258
|
-
children: "Alphabetical, case-insensitive, asc"
|
|
259
|
-
}),
|
|
260
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
261
|
-
value: "alphabetical-ci-desc",
|
|
262
|
-
children: "Alphabetical, case-insensitive, desc"
|
|
263
|
-
})
|
|
264
|
-
]
|
|
248
|
+
children: Object.keys(_variableeditorformmodel.SORT_METHODS).map((key)=>{
|
|
249
|
+
if (!_variableeditorformmodel.SORT_METHODS[key]) return null;
|
|
250
|
+
const { label } = _variableeditorformmodel.SORT_METHODS[key];
|
|
251
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
252
|
+
value: key,
|
|
253
|
+
children: label
|
|
254
|
+
}, key);
|
|
255
|
+
})
|
|
265
256
|
})
|
|
266
257
|
})
|
|
267
258
|
})
|
|
@@ -35,6 +35,7 @@ const _components = require("@perses-dev/components");
|
|
|
35
35
|
const _ClipboardOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ClipboardOutline"));
|
|
36
36
|
const _constants = require("../../../constants");
|
|
37
37
|
const _variablemodel = require("../variable-model");
|
|
38
|
+
const _variableeditorformmodel = require("./variable-editor-form-model");
|
|
38
39
|
function _interop_require_default(obj) {
|
|
39
40
|
return obj && obj.__esModule ? obj : {
|
|
40
41
|
default: obj
|
|
@@ -93,6 +94,33 @@ function VariablePreview(props) {
|
|
|
93
94
|
if (values && values?.length > 0 && maxValues) {
|
|
94
95
|
notShown = values.length - maxValues;
|
|
95
96
|
}
|
|
97
|
+
const variablePreviewState = (0, _react.useMemo)(()=>{
|
|
98
|
+
if (isLoading) {
|
|
99
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
100
|
+
width: "100%",
|
|
101
|
+
sx: {
|
|
102
|
+
alignItems: 'center',
|
|
103
|
+
justifyContent: 'center'
|
|
104
|
+
},
|
|
105
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {})
|
|
106
|
+
});
|
|
107
|
+
} else if (error) {
|
|
108
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
|
|
109
|
+
severity: "error",
|
|
110
|
+
children: error
|
|
111
|
+
});
|
|
112
|
+
} else if (!values?.length) {
|
|
113
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
|
|
114
|
+
severity: "info",
|
|
115
|
+
children: "No results"
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}, [
|
|
120
|
+
error,
|
|
121
|
+
isLoading,
|
|
122
|
+
values
|
|
123
|
+
]);
|
|
96
124
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
97
125
|
children: [
|
|
98
126
|
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
@@ -130,22 +158,7 @@ function VariablePreview(props) {
|
|
|
130
158
|
m: 2
|
|
131
159
|
},
|
|
132
160
|
children: [
|
|
133
|
-
|
|
134
|
-
severity: "error",
|
|
135
|
-
children: error
|
|
136
|
-
}),
|
|
137
|
-
values?.length === 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
|
|
138
|
-
severity: "info",
|
|
139
|
-
children: "No results"
|
|
140
|
-
}),
|
|
141
|
-
isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
142
|
-
width: "100%",
|
|
143
|
-
sx: {
|
|
144
|
-
alignItems: 'center',
|
|
145
|
-
justifyContent: 'center'
|
|
146
|
-
},
|
|
147
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {})
|
|
148
|
-
}),
|
|
161
|
+
variablePreviewState,
|
|
149
162
|
values?.slice(0, maxValues).map((val, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
|
|
150
163
|
size: "small",
|
|
151
164
|
label: val
|
|
@@ -163,17 +176,18 @@ function VariablePreview(props) {
|
|
|
163
176
|
});
|
|
164
177
|
}
|
|
165
178
|
function VariableListPreview(props) {
|
|
166
|
-
const { definition } = props;
|
|
179
|
+
const { definition, sortMethod } = props;
|
|
167
180
|
const { data, isFetching, error } = (0, _variablemodel.useListVariablePluginValues)(definition);
|
|
168
181
|
const errorMessage = error?.message;
|
|
182
|
+
const result = !sortMethod || sortMethod === 'none' || !data ? data : _variableeditorformmodel.SORT_METHODS[sortMethod].sort(data);
|
|
169
183
|
const variablePreview = (0, _react.useMemo)(()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(VariablePreview, {
|
|
170
|
-
values:
|
|
184
|
+
values: result?.map((val)=>val.label || val.value),
|
|
171
185
|
isLoading: isFetching,
|
|
172
186
|
error: errorMessage
|
|
173
187
|
}), [
|
|
174
188
|
errorMessage,
|
|
175
189
|
isFetching,
|
|
176
|
-
|
|
190
|
+
result
|
|
177
191
|
]);
|
|
178
192
|
return variablePreview;
|
|
179
193
|
}
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./VariableEditorForm"), exports);
|
|
18
18
|
_export_star(require("./VariablePreview"), exports);
|
|
19
|
+
_export_star(require("./variable-editor-form-model"), exports);
|
|
19
20
|
function _export_star(from, to) {
|
|
20
21
|
Object.keys(from).forEach(function(k) {
|
|
21
22
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -21,6 +21,9 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
+
SORT_METHODS: function() {
|
|
25
|
+
return SORT_METHODS;
|
|
26
|
+
},
|
|
24
27
|
getInitialState: function() {
|
|
25
28
|
return getInitialState;
|
|
26
29
|
},
|
|
@@ -28,6 +31,50 @@ _export(exports, {
|
|
|
28
31
|
return getVariableDefinitionFromState;
|
|
29
32
|
}
|
|
30
33
|
});
|
|
34
|
+
const SORT_METHODS = {
|
|
35
|
+
none: {
|
|
36
|
+
label: 'None',
|
|
37
|
+
sort: (input)=>{
|
|
38
|
+
return input.slice();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
'alphabetical-asc': {
|
|
42
|
+
label: 'Alphabetical, asc',
|
|
43
|
+
sort: (input)=>{
|
|
44
|
+
return input.slice().sort((a, b)=>a.label > b.label ? 1 : -1);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
'alphabetical-desc': {
|
|
48
|
+
label: 'Alphabetical, desc',
|
|
49
|
+
sort: (input)=>{
|
|
50
|
+
return input.slice().sort((a, b)=>a.label > b.label ? -1 : 1);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
'numerical-asc': {
|
|
54
|
+
label: 'Numerical, asc',
|
|
55
|
+
sort: (input)=>{
|
|
56
|
+
return input.slice().sort((a, b)=>parseInt(a.label) > parseInt(b.label) ? 1 : -1);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
'numerical-desc': {
|
|
60
|
+
label: 'Numerical, desc',
|
|
61
|
+
sort: (input)=>{
|
|
62
|
+
return input.slice().sort((a, b)=>parseInt(a.label) < parseInt(b.label) ? 1 : -1);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
'alphabetical-ci-asc': {
|
|
66
|
+
label: 'Alphabetical, case-insensitive, asc',
|
|
67
|
+
sort: (input)=>{
|
|
68
|
+
return input.slice().sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
'alphabetical-ci-desc': {
|
|
72
|
+
label: 'Alphabetical, case-insensitive, desc',
|
|
73
|
+
sort: (input)=>{
|
|
74
|
+
return input.slice().sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? -1 : 1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
31
78
|
function getInitialState(initialVariableDefinition) {
|
|
32
79
|
const textVariableFields = {
|
|
33
80
|
value: initialVariableDefinition.spec.value ?? '',
|
|
@@ -93,13 +93,13 @@ function useListVariablePluginValues(definition) {
|
|
|
93
93
|
timeRange,
|
|
94
94
|
refreshKey
|
|
95
95
|
],
|
|
96
|
-
queryFn: async ()=>{
|
|
96
|
+
queryFn: async ({ signal })=>{
|
|
97
97
|
const resp = await variablePlugin?.getVariableOptions(spec, {
|
|
98
98
|
datasourceStore,
|
|
99
99
|
variables,
|
|
100
100
|
timeRange
|
|
101
|
-
});
|
|
102
|
-
if (resp
|
|
101
|
+
}, signal);
|
|
102
|
+
if (!resp?.data?.length) {
|
|
103
103
|
return [];
|
|
104
104
|
}
|
|
105
105
|
if (!capturingRegexp) {
|
|
@@ -29,7 +29,6 @@ _export_star(require("./PluginRegistry"), exports);
|
|
|
29
29
|
_export_star(require("./PluginSpecEditor"), exports);
|
|
30
30
|
_export_star(require("./TimeRangeControls"), exports);
|
|
31
31
|
_export_star(require("./Variables"), exports);
|
|
32
|
-
_export_star(require("./ProjectSelect"), exports);
|
|
33
32
|
_export_star(require("./MetricLabelInput"), exports);
|
|
34
33
|
function _export_star(from, to) {
|
|
35
34
|
Object.keys(from).forEach(function(k) {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_export_star(require("./ProjectStoreProvider"), exports);
|
|
18
17
|
_export_star(require("./ValidationProvider"), exports);
|
|
19
18
|
function _export_star(from, to) {
|
|
20
19
|
Object.keys(from).forEach(function(k) {
|