@perses-dev/plugin-system 0.37.2 → 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 (61) hide show
  1. package/dist/cjs/components/PluginEditor/PluginEditor.js +4 -2
  2. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +459 -0
  3. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
  4. package/dist/cjs/components/Variables/VariableEditorForm/index.js +29 -0
  5. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +102 -0
  6. package/dist/cjs/components/Variables/index.js +29 -0
  7. package/dist/cjs/components/Variables/variable-model.js +117 -0
  8. package/dist/cjs/components/index.js +1 -0
  9. package/dist/cjs/constants/index.js +28 -0
  10. package/dist/cjs/constants/user-interface-text.js +25 -0
  11. package/dist/cjs/index.js +1 -0
  12. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  13. package/dist/components/PluginEditor/PluginEditor.js +4 -2
  14. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  15. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  16. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  17. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  18. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +12 -0
  19. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  20. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +414 -0
  21. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  22. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
  23. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
  24. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
  25. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
  26. package/dist/components/Variables/VariableEditorForm/index.d.ts +3 -0
  27. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  28. package/dist/components/Variables/VariableEditorForm/index.js +16 -0
  29. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  30. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +23 -0
  31. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  32. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +90 -0
  33. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  34. package/dist/components/Variables/index.d.ts +3 -0
  35. package/dist/components/Variables/index.d.ts.map +1 -0
  36. package/dist/components/Variables/index.js +16 -0
  37. package/dist/components/Variables/index.js.map +1 -0
  38. package/dist/components/Variables/variable-model.d.ts +17 -0
  39. package/dist/components/Variables/variable-model.d.ts.map +1 -0
  40. package/dist/components/Variables/variable-model.js +105 -0
  41. package/dist/components/Variables/variable-model.js.map +1 -0
  42. package/dist/components/index.d.ts +1 -0
  43. package/dist/components/index.d.ts.map +1 -1
  44. package/dist/components/index.js +1 -0
  45. package/dist/components/index.js.map +1 -1
  46. package/dist/constants/index.d.ts +2 -0
  47. package/dist/constants/index.d.ts.map +1 -0
  48. package/dist/constants/index.js +15 -0
  49. package/dist/constants/index.js.map +1 -0
  50. package/dist/constants/user-interface-text.d.ts +5 -0
  51. package/dist/constants/user-interface-text.d.ts.map +1 -0
  52. package/dist/constants/user-interface-text.js +19 -0
  53. package/dist/constants/user-interface-text.js.map +1 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +1 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/model/plugin-base.d.ts +1 -0
  59. package/dist/model/plugin-base.d.ts.map +1 -1
  60. package/dist/model/plugin-base.js.map +1 -1
  61. package/package.json +4 -4
@@ -25,7 +25,7 @@ const _pluginSpecEditor = require("../PluginSpecEditor");
25
25
  const _pluginEditorApi = require("./plugin-editor-api");
26
26
  function PluginEditor(props) {
27
27
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
- const { value , pluginType , pluginKindLabel , onChange: _ , ...others } = props;
28
+ const { value , pluginType , pluginKindLabel , onChange: _ , isReadonly , ...others } = props;
29
29
  const { pendingKind , isLoading , error , onKindChange , onSpecChange } = (0, _pluginEditorApi.usePluginEditor)(props);
30
30
  var ref;
31
31
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
@@ -49,6 +49,7 @@ function PluginEditor(props) {
49
49
  label: pluginKindLabel,
50
50
  pluginType: pluginType,
51
51
  value: pendingKind !== '' ? pendingKind : value.kind,
52
+ readOnly: isReadonly,
52
53
  onChange: onKindChange
53
54
  }),
54
55
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormHelperText, {
@@ -60,7 +61,8 @@ function PluginEditor(props) {
60
61
  pluginType: pluginType,
61
62
  pluginKind: value.kind,
62
63
  value: value.spec,
63
- onChange: onSpecChange
64
+ onChange: onSpecChange,
65
+ isReadonly: isReadonly
64
66
  })
65
67
  ]
66
68
  });
@@ -0,0 +1,459 @@
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 _components = require("@perses-dev/components");
26
+ const _variableModel = require("../variable-model");
27
+ const _pluginEditor = require("../../PluginEditor");
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 , action ='update' } = props;
91
+ const initialState = (0, _variableEditorFormModel.getInitialState)(initialVariableDefinition);
92
+ const [state, setState] = (0, _useImmer.useImmer)(initialState);
93
+ const validation = (0, _react.useMemo)(()=>getValidation(state), [
94
+ state
95
+ ]);
96
+ const [isDiscardDialogStateOpened, setDiscardDialogStateOpened] = (0, _react.useState)(false);
97
+ const [previewKey, setPreviewKey] = (0, _react.useState)(0);
98
+ const refreshPreview = ()=>{
99
+ setPreviewKey((prev)=>prev + 1);
100
+ };
101
+ /** We use the `previewKey` that we increment to know when to explicitly update the
102
+ * spec that will be used for preview. The reason why we do this is to avoid
103
+ * having to re-fetch the values when the user is still editing the spec.
104
+ */ const previewSpec = (0, _react.useMemo)(()=>{
105
+ return (0, _variableEditorFormModel.getVariableDefinitionFromState)(state);
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps
107
+ }, [
108
+ previewKey
109
+ ]);
110
+ const title = (0, _react.useMemo)(()=>{
111
+ if (action === 'read') return 'View Variable';
112
+ if (action === 'create') return 'Create Variable';
113
+ if (action === 'update') return 'Edit Variable';
114
+ return '';
115
+ }, [
116
+ action
117
+ ]);
118
+ // When user click on cancel, several possibilities:
119
+ // - create action: ask for discard approval
120
+ // - update action: ask for discard approval if changed
121
+ // - read action: don´t ask for discard approval
122
+ const handleCancel = (0, _react.useCallback)(()=>{
123
+ if (action === 'create' || action === 'update' && JSON.stringify(initialState) !== JSON.stringify(state)) {
124
+ setDiscardDialogStateOpened(true);
125
+ } else {
126
+ onCancel();
127
+ }
128
+ }, [
129
+ state,
130
+ initialState,
131
+ action,
132
+ setDiscardDialogStateOpened,
133
+ onCancel
134
+ ]);
135
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
136
+ children: [
137
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
138
+ sx: {
139
+ display: 'flex',
140
+ alignItems: 'center',
141
+ padding: (theme)=>theme.spacing(1, 2),
142
+ borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
143
+ },
144
+ children: [
145
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
146
+ variant: "h2",
147
+ children: title
148
+ }),
149
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
150
+ direction: "row",
151
+ spacing: 1,
152
+ sx: {
153
+ marginLeft: 'auto'
154
+ },
155
+ children: [
156
+ action !== 'read' && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
157
+ disabled: !validation.isValid,
158
+ variant: "contained",
159
+ onClick: ()=>{
160
+ onChange((0, _variableEditorFormModel.getVariableDefinitionFromState)(state));
161
+ },
162
+ children: (0, _material.capitalize)(action)
163
+ }),
164
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
165
+ color: "secondary",
166
+ variant: "outlined",
167
+ onClick: handleCancel,
168
+ children: action === 'read' ? 'Close' : 'Cancel'
169
+ })
170
+ ]
171
+ })
172
+ ]
173
+ }),
174
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
175
+ padding: 2,
176
+ sx: {
177
+ overflowY: 'scroll'
178
+ },
179
+ children: [
180
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
181
+ container: true,
182
+ spacing: 2,
183
+ mb: 2,
184
+ children: [
185
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
186
+ item: true,
187
+ xs: 8,
188
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
189
+ required: true,
190
+ error: !!validation.name,
191
+ fullWidth: true,
192
+ label: "Name",
193
+ value: state.name,
194
+ helperText: validation.name,
195
+ InputProps: {
196
+ readOnly: action === 'update' || action === 'read'
197
+ },
198
+ onChange: (v)=>{
199
+ setState((draft)=>{
200
+ draft.name = 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.jsx)(_material.TextField, {
209
+ fullWidth: true,
210
+ label: "Display Label",
211
+ value: state.title || '',
212
+ InputProps: {
213
+ readOnly: action === 'read'
214
+ },
215
+ onChange: (v)=>{
216
+ setState((draft)=>{
217
+ draft.title = v.target.value;
218
+ });
219
+ }
220
+ })
221
+ }),
222
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
223
+ item: true,
224
+ xs: 8,
225
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
226
+ fullWidth: true,
227
+ label: "Description",
228
+ value: state.description,
229
+ InputProps: {
230
+ readOnly: action === 'read'
231
+ },
232
+ onChange: (v)=>{
233
+ setState((draft)=>{
234
+ draft.description = v.target.value;
235
+ });
236
+ }
237
+ })
238
+ }),
239
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
240
+ item: true,
241
+ xs: 4,
242
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
243
+ fullWidth: true,
244
+ children: [
245
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
246
+ id: "variable-type-select-label",
247
+ children: "Type"
248
+ }),
249
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
250
+ labelId: "variable-type-select-label",
251
+ id: "variable-type-select",
252
+ label: "Type",
253
+ value: state.kind,
254
+ readOnly: action === 'read',
255
+ onChange: (v)=>{
256
+ setState((draft)=>{
257
+ draft.kind = v.target.value;
258
+ });
259
+ },
260
+ children: _variableModel.VARIABLE_TYPES.map((v)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
261
+ value: v.kind,
262
+ children: v.label
263
+ }, v.kind))
264
+ })
265
+ ]
266
+ })
267
+ })
268
+ ]
269
+ }),
270
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {}),
271
+ state.kind === 'TextVariable' && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
272
+ children: [
273
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
274
+ py: 1,
275
+ variant: "subtitle1",
276
+ children: "Text Options"
277
+ }),
278
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
279
+ spacing: 2,
280
+ children: [
281
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
282
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variablePreview.VariablePreview, {
283
+ values: [
284
+ state.textVariableFields.value
285
+ ]
286
+ })
287
+ }),
288
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
289
+ label: "Value",
290
+ value: state.textVariableFields.value,
291
+ InputProps: {
292
+ readOnly: action === 'read'
293
+ },
294
+ onChange: (v)=>{
295
+ setState((draft)=>{
296
+ draft.textVariableFields.value = v.target.value;
297
+ });
298
+ }
299
+ })
300
+ ]
301
+ })
302
+ ]
303
+ }),
304
+ state.kind === 'ListVariable' && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
305
+ children: [
306
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
307
+ py: 1,
308
+ variant: "subtitle1",
309
+ children: "List Options"
310
+ }),
311
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
312
+ spacing: 2,
313
+ mb: 2,
314
+ children: [
315
+ state.listVariableFields.plugin.kind ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
316
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
317
+ FallbackComponent: FallbackPreview,
318
+ resetKeys: [
319
+ previewSpec
320
+ ],
321
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variablePreview.VariableListPreview, {
322
+ definition: previewSpec,
323
+ onRefresh: refreshPreview
324
+ })
325
+ })
326
+ }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variablePreview.VariablePreview, {
327
+ isLoading: true
328
+ }),
329
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
330
+ children: [
331
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ClickAwayListener, {
332
+ onClickAway: ()=>refreshPreview(),
333
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {})
334
+ }),
335
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginEditor.PluginEditor, {
336
+ width: "100%",
337
+ pluginType: "Variable",
338
+ pluginKindLabel: "Source",
339
+ value: state.listVariableFields.plugin,
340
+ isReadonly: action === 'read',
341
+ onChange: (val)=>{
342
+ setState((draft)=>{
343
+ draft.listVariableFields.plugin = val;
344
+ });
345
+ }
346
+ })
347
+ ]
348
+ }),
349
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
350
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
351
+ label: "Capturing Regexp Filter",
352
+ value: state.listVariableFields.capturing_regexp || '',
353
+ InputProps: {
354
+ readOnly: action === 'read'
355
+ },
356
+ onChange: (e)=>{
357
+ setState((draft)=>{
358
+ if (e.target.value) {
359
+ // TODO: do a better fix, if empty string => it should skip the filter
360
+ draft.listVariableFields.capturing_regexp = e.target.value;
361
+ } else {
362
+ draft.listVariableFields.capturing_regexp = undefined;
363
+ }
364
+ });
365
+ },
366
+ helperText: "Optional, if you want to filter on captured result."
367
+ })
368
+ })
369
+ ]
370
+ }),
371
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {}),
372
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
373
+ py: 1,
374
+ variant: "subtitle1",
375
+ children: "Dropdown Options"
376
+ }),
377
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
378
+ spacing: "2",
379
+ children: [
380
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
381
+ children: [
382
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
383
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
384
+ checked: state.listVariableFields.allowMultiple,
385
+ readOnly: action === 'read',
386
+ onChange: (e)=>{
387
+ if (action === 'read') return; // ReadOnly prop is not blocking user interaction...
388
+ setState((draft)=>{
389
+ draft.listVariableFields.allowMultiple = e.target.checked;
390
+ });
391
+ }
392
+ }),
393
+ label: "Allow Multiple Values"
394
+ }),
395
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
396
+ variant: "caption",
397
+ children: "Enables multiple values to be selected at the same time"
398
+ })
399
+ ]
400
+ }),
401
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
402
+ children: [
403
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
404
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
405
+ checked: state.listVariableFields.allowAll,
406
+ readOnly: action === 'read',
407
+ onChange: (e)=>{
408
+ if (action === 'read') return; // ReadOnly prop is not blocking user interaction...
409
+ setState((draft)=>{
410
+ draft.listVariableFields.allowAll = e.target.checked;
411
+ });
412
+ }
413
+ }),
414
+ label: "Allow All option"
415
+ }),
416
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
417
+ mb: 1,
418
+ variant: "caption",
419
+ children: "Enables an option to include all variable values"
420
+ }),
421
+ state.listVariableFields.allowAll && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
422
+ label: "Custom All Value",
423
+ value: state.listVariableFields.customAllValue,
424
+ InputProps: {
425
+ readOnly: action === 'read'
426
+ },
427
+ onChange: (e)=>{
428
+ setState((draft)=>{
429
+ if (e.target.value) {
430
+ draft.listVariableFields.customAllValue = e.target.value;
431
+ } else {
432
+ draft.listVariableFields.customAllValue = undefined;
433
+ }
434
+ });
435
+ },
436
+ helperText: "When All is selected, this value will be used"
437
+ })
438
+ ]
439
+ })
440
+ ]
441
+ })
442
+ ]
443
+ })
444
+ ]
445
+ }),
446
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.DiscardChangesConfirmationDialog, {
447
+ description: "Are you sure you want to discard these changes? Changes cannot be recovered.",
448
+ isOpen: isDiscardDialogStateOpened,
449
+ onCancel: ()=>{
450
+ setDiscardDialogStateOpened(false);
451
+ },
452
+ onDiscardChanges: ()=>{
453
+ setDiscardDialogStateOpened(false);
454
+ onCancel();
455
+ }
456
+ })
457
+ ]
458
+ });
459
+ }
@@ -0,0 +1,178 @@
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
+ }