@perses-dev/dashboards 0.37.1 → 0.38.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.
Files changed (57) hide show
  1. package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +12 -52
  2. package/dist/cjs/components/GridLayout/index.js +3 -1
  3. package/dist/cjs/components/Variables/TemplateVariable.js +2 -2
  4. package/dist/cjs/components/Variables/VariableEditor.js +17 -6
  5. package/dist/cjs/components/Variables/index.js +0 -2
  6. package/dist/cjs/context/DatasourceStoreProvider.js +22 -18
  7. package/dist/cjs/views/ViewDashboard/DashboardApp.js +1 -1
  8. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts +1 -1
  9. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map +1 -1
  10. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +11 -46
  11. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  12. package/dist/components/GridLayout/index.d.ts +3 -1
  13. package/dist/components/GridLayout/index.d.ts.map +1 -1
  14. package/dist/components/GridLayout/index.js +3 -1
  15. package/dist/components/GridLayout/index.js.map +1 -1
  16. package/dist/components/Variables/TemplateVariable.d.ts.map +1 -1
  17. package/dist/components/Variables/TemplateVariable.js +1 -1
  18. package/dist/components/Variables/TemplateVariable.js.map +1 -1
  19. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  20. package/dist/components/Variables/VariableEditor.js +15 -4
  21. package/dist/components/Variables/VariableEditor.js.map +1 -1
  22. package/dist/components/Variables/index.d.ts +0 -2
  23. package/dist/components/Variables/index.d.ts.map +1 -1
  24. package/dist/components/Variables/index.js +0 -2
  25. package/dist/components/Variables/index.js.map +1 -1
  26. package/dist/context/DatasourceStoreProvider.d.ts +4 -3
  27. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  28. package/dist/context/DatasourceStoreProvider.js +22 -18
  29. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  30. package/dist/views/ViewDashboard/DashboardApp.js +2 -2
  31. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  32. package/package.json +6 -6
  33. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -399
  34. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +0 -178
  35. package/dist/cjs/components/Variables/VariableEditorForm/index.js +0 -29
  36. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -91
  37. package/dist/cjs/components/Variables/variable-model.js +0 -117
  38. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +0 -10
  39. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +0 -1
  40. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -354
  41. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +0 -1
  42. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +0 -16
  43. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +0 -1
  44. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +0 -122
  45. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +0 -1
  46. package/dist/components/Variables/VariableEditorForm/index.d.ts +0 -3
  47. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +0 -1
  48. package/dist/components/Variables/VariableEditorForm/index.js +0 -16
  49. package/dist/components/Variables/VariableEditorForm/index.js.map +0 -1
  50. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +0 -23
  51. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +0 -1
  52. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -79
  53. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +0 -1
  54. package/dist/components/Variables/variable-model.d.ts +0 -16
  55. package/dist/components/Variables/variable-model.d.ts.map +0 -1
  56. package/dist/components/Variables/variable-model.js +0 -105
  57. package/dist/components/Variables/variable-model.js.map +0 -1
@@ -1,399 +0,0 @@
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, "VariableEditForm", {
18
- enumerable: true,
19
- get: ()=>VariableEditForm
20
- });
21
- const _jsxRuntime = require("react/jsx-runtime");
22
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
- const _material = require("@mui/material");
24
- const _useImmer = require("use-immer");
25
- const _pluginSystem = require("@perses-dev/plugin-system");
26
- const _components = require("@perses-dev/components");
27
- const _variableModel = require("../variable-model");
28
- const _variablePreview = require("./VariablePreview");
29
- const _variableEditorFormModel = require("./variable-editor-form-model");
30
- function _getRequireWildcardCache(nodeInterop) {
31
- if (typeof WeakMap !== "function") return null;
32
- var cacheBabelInterop = new WeakMap();
33
- var cacheNodeInterop = new WeakMap();
34
- return (_getRequireWildcardCache = function(nodeInterop) {
35
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
36
- })(nodeInterop);
37
- }
38
- function _interopRequireWildcard(obj, nodeInterop) {
39
- if (!nodeInterop && obj && obj.__esModule) {
40
- return obj;
41
- }
42
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
43
- return {
44
- default: obj
45
- };
46
- }
47
- var cache = _getRequireWildcardCache(nodeInterop);
48
- if (cache && cache.has(obj)) {
49
- return cache.get(obj);
50
- }
51
- var newObj = {};
52
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
53
- for(var key in obj){
54
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
55
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
56
- if (desc && (desc.get || desc.set)) {
57
- Object.defineProperty(newObj, key, desc);
58
- } else {
59
- newObj[key] = obj[key];
60
- }
61
- }
62
- }
63
- newObj.default = obj;
64
- if (cache) {
65
- cache.set(obj, newObj);
66
- }
67
- return newObj;
68
- }
69
- // TODO: Replace with proper validation library
70
- function getValidation(state) {
71
- /** Name validation */ let name = null;
72
- if (!state.name) {
73
- name = 'Name is required';
74
- }
75
- // name can only contain alphanumeric characters and underscores and no spaces
76
- if (state.name && !/^[a-zA-Z0-9_-]+$/.test(state.name)) {
77
- name = 'Name can only contain alphanumeric characters, underscores, and dashes';
78
- }
79
- return {
80
- name,
81
- isValid: !name
82
- };
83
- }
84
- function FallbackPreview() {
85
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
86
- children: "Error previewing values"
87
- });
88
- }
89
- function VariableEditForm(props) {
90
- const { initialVariableDefinition , onChange , onCancel } = props;
91
- const [state, setState] = (0, _useImmer.useImmer)((0, _variableEditorFormModel.getInitialState)(initialVariableDefinition));
92
- const validation = (0, _react.useMemo)(()=>getValidation(state), [
93
- state
94
- ]);
95
- const [previewKey, setPreviewKey] = (0, _react.useState)(0);
96
- const refreshPreview = ()=>{
97
- setPreviewKey((prev)=>prev + 1);
98
- };
99
- /** We use the `previewKey` that we increment to know when to explicitly update the
100
- * spec that will be used for preview. The reason why we do this is to avoid
101
- * having to re-fetch the values when the user is still editing the spec.
102
- */ const previewSpec = (0, _react.useMemo)(()=>{
103
- return (0, _variableEditorFormModel.getVariableDefinitionFromState)(state);
104
- // eslint-disable-next-line react-hooks/exhaustive-deps
105
- }, [
106
- previewKey
107
- ]);
108
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
109
- children: [
110
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
111
- sx: {
112
- display: 'flex',
113
- alignItems: 'center',
114
- padding: (theme)=>theme.spacing(1, 2),
115
- borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
116
- },
117
- children: [
118
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
119
- variant: "h2",
120
- children: "Edit Variable"
121
- }),
122
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
123
- direction: "row",
124
- spacing: 1,
125
- sx: {
126
- marginLeft: 'auto'
127
- },
128
- children: [
129
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
130
- disabled: !validation.isValid,
131
- variant: "contained",
132
- onClick: ()=>{
133
- onChange((0, _variableEditorFormModel.getVariableDefinitionFromState)(state));
134
- },
135
- children: "Update"
136
- }),
137
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
138
- color: "secondary",
139
- variant: "outlined",
140
- onClick: ()=>{
141
- onCancel();
142
- },
143
- children: "Cancel"
144
- })
145
- ]
146
- })
147
- ]
148
- }),
149
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
150
- padding: 2,
151
- sx: {
152
- overflowY: 'scroll'
153
- },
154
- children: [
155
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
156
- container: true,
157
- spacing: 2,
158
- mb: 2,
159
- children: [
160
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
161
- item: true,
162
- xs: 8,
163
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
164
- required: true,
165
- error: !!validation.name,
166
- fullWidth: true,
167
- label: "Name",
168
- value: state.name,
169
- helperText: validation.name,
170
- onChange: (v)=>{
171
- setState((draft)=>{
172
- draft.name = v.target.value;
173
- });
174
- }
175
- })
176
- }),
177
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
178
- item: true,
179
- xs: 4,
180
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
181
- fullWidth: true,
182
- label: "Display Label",
183
- value: state.title || '',
184
- onChange: (v)=>{
185
- setState((draft)=>{
186
- draft.title = v.target.value;
187
- });
188
- }
189
- })
190
- }),
191
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
192
- item: true,
193
- xs: 8,
194
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
195
- fullWidth: true,
196
- label: "Description",
197
- value: state.description,
198
- onChange: (v)=>{
199
- setState((draft)=>{
200
- draft.description = v.target.value;
201
- });
202
- }
203
- })
204
- }),
205
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
206
- item: true,
207
- xs: 4,
208
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
209
- fullWidth: true,
210
- children: [
211
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
212
- id: "variable-type-select-label",
213
- children: "Type"
214
- }),
215
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
216
- labelId: "variable-type-select-label",
217
- id: "variable-type-select",
218
- label: "Type",
219
- value: state.kind,
220
- onChange: (v)=>{
221
- setState((draft)=>{
222
- draft.kind = v.target.value;
223
- });
224
- },
225
- children: _variableModel.VARIABLE_TYPES.map((v)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
226
- value: v.kind,
227
- children: v.label
228
- }, v.kind))
229
- })
230
- ]
231
- })
232
- })
233
- ]
234
- }),
235
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {}),
236
- state.kind === 'TextVariable' && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
237
- children: [
238
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
239
- py: 1,
240
- variant: "subtitle1",
241
- children: "Text Options"
242
- }),
243
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
244
- spacing: 2,
245
- children: [
246
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
247
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variablePreview.VariablePreview, {
248
- values: [
249
- state.textVariableFields.value
250
- ]
251
- })
252
- }),
253
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
254
- label: "Value",
255
- value: state.textVariableFields.value,
256
- onChange: (v)=>{
257
- setState((draft)=>{
258
- draft.textVariableFields.value = v.target.value;
259
- });
260
- }
261
- })
262
- ]
263
- })
264
- ]
265
- }),
266
- state.kind === 'ListVariable' && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
267
- children: [
268
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
269
- py: 1,
270
- variant: "subtitle1",
271
- children: "List Options"
272
- }),
273
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
274
- spacing: 2,
275
- mb: 2,
276
- children: [
277
- state.listVariableFields.plugin.kind ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
278
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
279
- FallbackComponent: FallbackPreview,
280
- resetKeys: [
281
- previewSpec
282
- ],
283
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variablePreview.VariableListPreview, {
284
- definition: previewSpec,
285
- onRefresh: refreshPreview
286
- })
287
- })
288
- }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variablePreview.VariablePreview, {
289
- isLoading: true
290
- }),
291
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
292
- children: [
293
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ClickAwayListener, {
294
- onClickAway: ()=>refreshPreview(),
295
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {})
296
- }),
297
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginEditor, {
298
- width: "100%",
299
- pluginType: "Variable",
300
- pluginKindLabel: "Source",
301
- value: state.listVariableFields.plugin,
302
- onChange: (val)=>{
303
- setState((draft)=>{
304
- draft.listVariableFields.plugin = val;
305
- });
306
- }
307
- })
308
- ]
309
- }),
310
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
311
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
312
- label: "Capturing Regexp Filter",
313
- value: state.listVariableFields.capturing_regexp || '',
314
- onChange: (e)=>{
315
- setState((draft)=>{
316
- if (e.target.value) {
317
- // TODO: do a better fix, if empty string => it should skip the filter
318
- draft.listVariableFields.capturing_regexp = e.target.value;
319
- } else {
320
- draft.listVariableFields.capturing_regexp = undefined;
321
- }
322
- });
323
- },
324
- helperText: "Optional, if you want to filter on captured result."
325
- })
326
- })
327
- ]
328
- }),
329
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {}),
330
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
331
- py: 1,
332
- variant: "subtitle1",
333
- children: "Dropdown Options"
334
- }),
335
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
336
- spacing: "2",
337
- children: [
338
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
339
- children: [
340
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
341
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
342
- checked: state.listVariableFields.allowMultiple,
343
- onChange: (e)=>{
344
- setState((draft)=>{
345
- draft.listVariableFields.allowMultiple = e.target.checked;
346
- });
347
- }
348
- }),
349
- label: "Allow Multiple Values"
350
- }),
351
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
352
- variant: "caption",
353
- children: "Enables multiple values to be selected at the same time"
354
- })
355
- ]
356
- }),
357
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
358
- children: [
359
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
360
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
361
- checked: state.listVariableFields.allowAll,
362
- onChange: (e)=>{
363
- setState((draft)=>{
364
- draft.listVariableFields.allowAll = e.target.checked;
365
- });
366
- }
367
- }),
368
- label: "Allow All option"
369
- }),
370
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
371
- mb: 1,
372
- variant: "caption",
373
- children: "Enables an option to include all variable values"
374
- }),
375
- state.listVariableFields.allowAll && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
376
- label: "Custom All Value",
377
- value: state.listVariableFields.customAllValue,
378
- onChange: (e)=>{
379
- setState((draft)=>{
380
- if (e.target.value) {
381
- draft.listVariableFields.customAllValue = e.target.value;
382
- } else {
383
- draft.listVariableFields.customAllValue = undefined;
384
- }
385
- });
386
- },
387
- helperText: "When All is selected, this value will be used"
388
- })
389
- ]
390
- })
391
- ]
392
- })
393
- ]
394
- })
395
- ]
396
- })
397
- ]
398
- });
399
- }
@@ -1,178 +0,0 @@
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
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- VariablePreview: ()=>VariablePreview,
25
- VariableListPreview: ()=>VariableListPreview
26
- });
27
- const _jsxRuntime = require("react/jsx-runtime");
28
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
29
- const _material = require("@mui/material");
30
- const _components = require("@perses-dev/components");
31
- const _refresh = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Refresh"));
32
- const _clipboardOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/ClipboardOutline"));
33
- const _constants = require("../../../constants");
34
- const _variableModel = require("../variable-model");
35
- function _interopRequireDefault(obj) {
36
- return obj && obj.__esModule ? obj : {
37
- default: obj
38
- };
39
- }
40
- function _getRequireWildcardCache(nodeInterop) {
41
- if (typeof WeakMap !== "function") return null;
42
- var cacheBabelInterop = new WeakMap();
43
- var cacheNodeInterop = new WeakMap();
44
- return (_getRequireWildcardCache = function(nodeInterop) {
45
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
46
- })(nodeInterop);
47
- }
48
- function _interopRequireWildcard(obj, nodeInterop) {
49
- if (!nodeInterop && obj && obj.__esModule) {
50
- return obj;
51
- }
52
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
53
- return {
54
- default: obj
55
- };
56
- }
57
- var cache = _getRequireWildcardCache(nodeInterop);
58
- if (cache && cache.has(obj)) {
59
- return cache.get(obj);
60
- }
61
- var newObj = {};
62
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
63
- for(var key in obj){
64
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
65
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
66
- if (desc && (desc.get || desc.set)) {
67
- Object.defineProperty(newObj, key, desc);
68
- } else {
69
- newObj[key] = obj[key];
70
- }
71
- }
72
- }
73
- newObj.default = obj;
74
- if (cache) {
75
- cache.set(obj, newObj);
76
- }
77
- return newObj;
78
- }
79
- const DEFAULT_MAX_PREVIEW_VALUES = 50;
80
- function VariablePreview(props) {
81
- const { values , onRefresh , isLoading , error } = props;
82
- const [maxValues, setMaxValues] = (0, _react.useState)(DEFAULT_MAX_PREVIEW_VALUES);
83
- const { infoSnackbar } = (0, _components.useSnackbar)();
84
- const showAll = ()=>{
85
- setMaxValues(undefined);
86
- };
87
- let notShown = 0;
88
- if (values && (values === null || values === void 0 ? void 0 : values.length) > 0 && maxValues) {
89
- notShown = values.length - maxValues;
90
- }
91
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
92
- children: [
93
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
94
- direction: "row",
95
- spacing: 1,
96
- alignItems: "center",
97
- mb: 1,
98
- children: [
99
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
100
- variant: "h4",
101
- children: "Preview Values"
102
- }),
103
- onRefresh && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
104
- description: _constants.TOOLTIP_TEXT.refreshVariableValues,
105
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
106
- onClick: onRefresh,
107
- size: "small",
108
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_refresh.default, {})
109
- })
110
- }),
111
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
112
- description: _constants.TOOLTIP_TEXT.copyVariableValues,
113
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
114
- onClick: async ()=>{
115
- if (values === null || values === void 0 ? void 0 : values.length) {
116
- await navigator.clipboard.writeText(values.map((value)=>value).join(', '));
117
- infoSnackbar('Preview values copied to clipboard!');
118
- }
119
- },
120
- size: "small",
121
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_clipboardOutline.default, {})
122
- })
123
- })
124
- ]
125
- }),
126
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Card, {
127
- variant: "outlined",
128
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
129
- sx: {
130
- display: 'flex',
131
- flexWrap: 'wrap',
132
- gap: 1,
133
- m: 2
134
- },
135
- children: [
136
- error && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Alert, {
137
- severity: "error",
138
- children: error
139
- }),
140
- (values === null || values === void 0 ? void 0 : values.length) === 0 && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Alert, {
141
- severity: "info",
142
- children: "No results"
143
- }),
144
- isLoading && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
145
- width: "100%",
146
- sx: {
147
- alignItems: 'center',
148
- justifyContent: 'center'
149
- },
150
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.CircularProgress, {})
151
- }),
152
- values === null || values === void 0 ? void 0 : values.slice(0, maxValues).map((val)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Chip, {
153
- size: "small",
154
- label: val
155
- }, val)),
156
- notShown > 0 && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Chip, {
157
- onClick: showAll,
158
- variant: "outlined",
159
- size: "small",
160
- label: `+${notShown} more`
161
- })
162
- ]
163
- })
164
- })
165
- ]
166
- });
167
- }
168
- function VariableListPreview(props) {
169
- const { definition , onRefresh } = props;
170
- const { data , isFetching , error } = (0, _variableModel.useListVariablePluginValues)(definition);
171
- const errorMessage = error === null || error === void 0 ? void 0 : error.message;
172
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(VariablePreview, {
173
- values: (data === null || data === void 0 ? void 0 : data.map((val)=>val.value)) || [],
174
- onRefresh: onRefresh,
175
- isLoading: isFetching,
176
- error: errorMessage
177
- });
178
- }
@@ -1,29 +0,0 @@
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
- _exportStar(require("./VariableEditorForm"), exports);
18
- _exportStar(require("./VariablePreview"), exports);
19
- function _exportStar(from, to) {
20
- Object.keys(from).forEach(function(k) {
21
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
22
- enumerable: true,
23
- get: function() {
24
- return from[k];
25
- }
26
- });
27
- });
28
- return from;
29
- }