@perses-dev/plugin-system 0.49.0 → 0.50.0-rc.1

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 (148) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +52 -58
  2. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -2
  3. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +1 -1
  4. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +10 -59
  5. package/dist/components/CalculationSelector/CalculationSelector.d.ts +2 -1
  6. package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
  7. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  8. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +4 -3
  9. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  10. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +14 -61
  11. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  12. package/dist/components/DatasourceSelect.d.ts +3 -2
  13. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  14. package/dist/components/DatasourceSelect.js.map +1 -1
  15. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +3 -1
  16. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  17. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -2
  18. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  19. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +2 -1
  20. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  21. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  22. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +2 -1
  23. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  24. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  25. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +2 -2
  26. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -1
  27. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  28. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +2 -2
  29. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -1
  30. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  31. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts +3 -3
  32. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts.map +1 -1
  33. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  34. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +2 -1
  35. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  36. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +1 -1
  37. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  38. package/dist/components/PluginEditor/PluginEditor.d.ts +2 -1
  39. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  40. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  41. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -1
  42. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  43. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  44. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  45. package/dist/components/PluginRegistry/PluginRegistry.d.ts +2 -2
  46. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  47. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  48. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  49. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  50. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +2 -1
  51. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  52. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  53. package/dist/components/ProjectSelect.d.ts +2 -1
  54. package/dist/components/ProjectSelect.d.ts.map +1 -1
  55. package/dist/components/ProjectSelect.js.map +1 -1
  56. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
  57. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  58. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  59. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -3
  60. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  61. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +12 -61
  62. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  63. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +3 -2
  64. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  65. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  66. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +2 -2
  67. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  68. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  69. package/dist/components/Variables/variable-model.d.ts +2 -1
  70. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  71. package/dist/components/Variables/variable-model.js.map +1 -1
  72. package/dist/context/ProjectStoreProvider.d.ts +2 -2
  73. package/dist/context/ProjectStoreProvider.d.ts.map +1 -1
  74. package/dist/context/ProjectStoreProvider.js.map +1 -1
  75. package/dist/context/ValidationProvider.d.ts +2 -2
  76. package/dist/context/ValidationProvider.d.ts.map +1 -1
  77. package/dist/context/ValidationProvider.js.map +1 -1
  78. package/dist/context/query-params.d.ts.map +1 -1
  79. package/dist/context/query-params.js.map +1 -1
  80. package/dist/model/legend.d.ts.map +1 -1
  81. package/dist/model/legend.js.map +1 -1
  82. package/dist/model/plugin-loading.js.map +1 -1
  83. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +2 -2
  84. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  85. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  86. package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
  87. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  88. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  89. package/dist/runtime/QueryCountProvider.d.ts.map +1 -1
  90. package/dist/runtime/QueryCountProvider.js.map +1 -1
  91. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +2 -2
  92. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  93. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  94. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +2 -2
  95. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +1 -1
  96. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +1 -1
  97. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +2 -2
  98. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -1
  99. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  100. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -1
  101. package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -1
  102. package/dist/runtime/UsageMetricsProvider.d.ts +2 -2
  103. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
  104. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  105. package/dist/runtime/builtin-variables.d.ts.map +1 -1
  106. package/dist/runtime/builtin-variables.js.map +1 -1
  107. package/dist/runtime/datasources.d.ts +4 -3
  108. package/dist/runtime/datasources.d.ts.map +1 -1
  109. package/dist/runtime/datasources.js.map +1 -1
  110. package/dist/runtime/plugin-registry.d.ts +5 -5
  111. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  112. package/dist/runtime/plugin-registry.js.map +1 -1
  113. package/dist/runtime/time-series-queries.d.ts +3 -3
  114. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  115. package/dist/runtime/time-series-queries.js.map +1 -1
  116. package/dist/runtime/trace-queries.d.ts +4 -3
  117. package/dist/runtime/trace-queries.d.ts.map +1 -1
  118. package/dist/runtime/trace-queries.js +1 -1
  119. package/dist/runtime/trace-queries.js.map +1 -1
  120. package/dist/runtime/variables.js.map +1 -1
  121. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +2 -1
  122. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +1 -1
  123. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
  124. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +2 -1
  125. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  126. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  127. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +2 -1
  128. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +1 -1
  129. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -1
  130. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts +2 -1
  131. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
  132. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  133. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +2 -1
  134. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +1 -1
  135. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -1
  136. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +2 -1
  137. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -1
  138. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  139. package/dist/test/render.d.ts +3 -3
  140. package/dist/test/render.d.ts.map +1 -1
  141. package/dist/test/render.js.map +1 -1
  142. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  143. package/dist/test/test-plugins/bert/index.js.map +1 -1
  144. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  145. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  146. package/dist/utils/variables.d.ts.map +1 -1
  147. package/dist/utils/variables.js.map +1 -1
  148. package/package.json +5 -5
@@ -22,17 +22,57 @@ Object.defineProperty(exports, "DatasourceEditorForm", {
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
24
  const _material = require("@mui/material");
25
- const _react = require("react");
25
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
26
26
  const _components = require("@perses-dev/components");
27
27
  const _reacthookform = require("react-hook-form");
28
28
  const _zod = require("@hookform/resolvers/zod");
29
29
  const _PluginEditor = require("../PluginEditor");
30
30
  const _utils = require("../../utils");
31
31
  const _context = require("../../context");
32
+ function _getRequireWildcardCache(nodeInterop) {
33
+ if (typeof WeakMap !== "function") return null;
34
+ var cacheBabelInterop = new WeakMap();
35
+ var cacheNodeInterop = new WeakMap();
36
+ return (_getRequireWildcardCache = function(nodeInterop) {
37
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
38
+ })(nodeInterop);
39
+ }
40
+ function _interop_require_wildcard(obj, nodeInterop) {
41
+ if (!nodeInterop && obj && obj.__esModule) {
42
+ return obj;
43
+ }
44
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
45
+ return {
46
+ default: obj
47
+ };
48
+ }
49
+ var cache = _getRequireWildcardCache(nodeInterop);
50
+ if (cache && cache.has(obj)) {
51
+ return cache.get(obj);
52
+ }
53
+ var newObj = {
54
+ __proto__: null
55
+ };
56
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
57
+ for(var key in obj){
58
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
59
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
60
+ if (desc && (desc.get || desc.set)) {
61
+ Object.defineProperty(newObj, key, desc);
62
+ } else {
63
+ newObj[key] = obj[key];
64
+ }
65
+ }
66
+ }
67
+ newObj.default = obj;
68
+ if (cache) {
69
+ cache.set(obj, newObj);
70
+ }
71
+ return newObj;
72
+ }
32
73
  function DatasourceEditorForm(props) {
33
- const { initialDatasourceDefinition, initialAction, isDraft, isReadonly, onSave, onClose, onDelete } = props;
74
+ const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;
34
75
  const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
35
- const [action, setAction] = (0, _react.useState)(initialAction);
36
76
  const titleAction = (0, _utils.getTitleAction)(action, isDraft);
37
77
  const submitText = (0, _utils.getSubmitText)(action, isDraft);
38
78
  const { datasourceEditorSchema } = (0, _context.useValidationSchemas)();
@@ -85,61 +125,15 @@ function DatasourceEditorForm(props) {
85
125
  " Datasource"
86
126
  ]
87
127
  }),
88
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
89
- direction: "row",
90
- spacing: 1,
91
- sx: {
92
- marginLeft: 'auto'
93
- },
94
- children: action === 'read' ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
95
- children: [
96
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
97
- disabled: isReadonly,
98
- variant: "contained",
99
- onClick: ()=>setAction('update'),
100
- children: "Edit"
101
- }),
102
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
103
- color: "error",
104
- disabled: isReadonly,
105
- variant: "outlined",
106
- onClick: onDelete,
107
- children: "Delete"
108
- }),
109
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {
110
- orientation: "vertical",
111
- flexItem: true,
112
- sx: (theme)=>({
113
- borderColor: theme.palette.grey['500'],
114
- '&.MuiDivider-root': {
115
- marginLeft: 2,
116
- marginRight: 1
117
- }
118
- })
119
- }),
120
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
121
- color: "secondary",
122
- variant: "outlined",
123
- onClick: onClose,
124
- children: "Close"
125
- })
126
- ]
127
- }) : /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
128
- children: [
129
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
130
- variant: "contained",
131
- disabled: !form.formState.isValid,
132
- onClick: form.handleSubmit(processForm),
133
- children: submitText
134
- }),
135
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
136
- color: "secondary",
137
- variant: "outlined",
138
- onClick: handleCancel,
139
- children: "Cancel"
140
- })
141
- ]
142
- })
128
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FormActions, {
129
+ action: action,
130
+ submitText: submitText,
131
+ isReadonly: isReadonly,
132
+ isValid: form.formState.isValid,
133
+ onActionChange: onActionChange,
134
+ onSubmit: form.handleSubmit(processForm),
135
+ onDelete: onDelete,
136
+ onCancel: handleCancel
143
137
  })
144
138
  ]
145
139
  }),
@@ -49,7 +49,7 @@ const VALUE_OPTIONS = Object.entries(_model.LEGEND_VALUE_CONFIG).map(([id, confi
49
49
  ...config
50
50
  };
51
51
  });
52
- function LegendOptionsEditor({ value, onChange }) {
52
+ function LegendOptionsEditor({ value, onChange, showValuesEditor = true }) {
53
53
  const handleLegendShowChange = (_, checked)=>{
54
54
  // legend is hidden when legend obj is undefined
55
55
  const legendValue = checked === true ? {
@@ -161,7 +161,7 @@ function LegendOptionsEditor({ value, onChange }) {
161
161
  disableClearable: true
162
162
  })
163
163
  }),
164
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
164
+ showValuesEditor && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
165
165
  label: "Values",
166
166
  control: // For some reason, the inferred option type doesn't always seem to work
167
167
  // quite right when `multiple` is true. Explicitly setting the generics
@@ -96,7 +96,7 @@ function PanelSpecEditor(props) {
96
96
  maxHeight: "80vh",
97
97
  value: panelDefinition,
98
98
  onChange: (json)=>{
99
- field.onChange(json);
99
+ field.onChange(JSON.parse(json));
100
100
  onJSONChange(json);
101
101
  }
102
102
  })
@@ -431,10 +431,8 @@ function ListVariableEditorForm({ action, control }) {
431
431
  ]
432
432
  });
433
433
  }
434
- function VariableEditorForm(props) {
435
- const { initialVariableDefinition, initialAction, isDraft, isReadonly, onSave, onClose, onDelete } = props;
434
+ function VariableEditorForm({ initialVariableDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete }) {
436
435
  const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
437
- const [action, setAction] = (0, _react.useState)(initialAction);
438
436
  const titleAction = (0, _utils.getTitleAction)(action, isDraft);
439
437
  const submitText = (0, _utils.getSubmitText)(action, isDraft);
440
438
  const { variableEditorSchema } = (0, _context.useValidationSchemas)();
@@ -490,62 +488,15 @@ function VariableEditorForm(props) {
490
488
  " Variable"
491
489
  ]
492
490
  }),
493
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
494
- direction: "row",
495
- spacing: 1,
496
- sx: {
497
- marginLeft: 'auto'
498
- },
499
- children: action === 'read' ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
500
- children: [
501
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
502
- disabled: isReadonly,
503
- variant: "contained",
504
- onClick: ()=>setAction('update'),
505
- children: "Edit"
506
- }),
507
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
508
- color: "error",
509
- disabled: isReadonly,
510
- variant: "outlined",
511
- onClick: onDelete,
512
- children: "Delete"
513
- }),
514
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {
515
- orientation: "vertical",
516
- flexItem: true,
517
- sx: (theme)=>({
518
- borderColor: theme.palette.grey['500'],
519
- '&.MuiDivider-root': {
520
- marginLeft: 2,
521
- marginRight: 1
522
- }
523
- })
524
- }),
525
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
526
- color: "secondary",
527
- variant: "outlined",
528
- onClick: onClose,
529
- children: "Close"
530
- })
531
- ]
532
- }) : /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
533
- children: [
534
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
535
- type: "submit",
536
- variant: "contained",
537
- disabled: !form.formState.isValid,
538
- onClick: form.handleSubmit(processForm),
539
- children: submitText
540
- }),
541
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
542
- color: "secondary",
543
- variant: "outlined",
544
- onClick: handleCancel,
545
- children: "Cancel"
546
- })
547
- ]
548
- })
491
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FormActions, {
492
+ action: action,
493
+ submitText: submitText,
494
+ isReadonly: isReadonly,
495
+ isValid: form.formState.isValid,
496
+ onActionChange: onActionChange,
497
+ onSubmit: form.handleSubmit(processForm),
498
+ onDelete: onDelete,
499
+ onCancel: handleCancel
549
500
  })
550
501
  ]
551
502
  }),
@@ -1,7 +1,8 @@
1
1
  import { CalculationType } from '@perses-dev/core';
2
+ import { ReactElement } from 'react';
2
3
  export interface CalculationSelectorProps {
3
4
  value: CalculationType;
4
5
  onChange: (unit: CalculationType) => void;
5
6
  }
6
- export declare function CalculationSelector({ value, onChange }: CalculationSelectorProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function CalculationSelector({ value, onChange }: CalculationSelectorProps): ReactElement;
7
8
  //# sourceMappingURL=CalculationSelector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CalculationSelector.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.tsx"],"names":[],"mappings":"AAcA,OAAO,EAA0C,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAU3F,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,2CAuBhF"}
1
+ {"version":3,"file":"CalculationSelector.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.tsx"],"names":[],"mappings":"AAcA,OAAO,EAA0C,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAUrC,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,GAAG,YAAY,CAuB/F"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 { OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport { CALCULATIONS_CONFIG, CalculationConfig, CalculationType } from '@perses-dev/core';\n\ntype AutocompleteCalculationOption = CalculationConfig & { id: CalculationType };\nconst CALC_OPTIONS: AutocompleteCalculationOption[] = Object.entries(CALCULATIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as CalculationType,\n ...config,\n };\n});\n\nexport interface CalculationSelectorProps {\n value: CalculationType;\n onChange: (unit: CalculationType) => void;\n}\n\nexport function CalculationSelector({ value, onChange }: CalculationSelectorProps) {\n const handleCalculationChange = (_: unknown, newValue: AutocompleteCalculationOption) => {\n onChange(newValue.id);\n };\n\n const calcConfig = CALCULATIONS_CONFIG[value];\n\n return (\n <OptionsEditorControl\n label=\"Calculation\"\n control={\n <SettingsAutocomplete\n value={{\n ...calcConfig,\n id: value,\n }}\n options={CALC_OPTIONS}\n onChange={handleCalculationChange}\n disableClearable\n />\n }\n />\n );\n}\n"],"names":["OptionsEditorControl","SettingsAutocomplete","CALCULATIONS_CONFIG","CALC_OPTIONS","Object","entries","map","id","config","CalculationSelector","value","onChange","handleCalculationChange","_","newValue","calcConfig","label","control","options","disableClearable"],"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,SAASA,oBAAoB,EAAEC,oBAAoB,QAAQ,yBAAyB;AACpF,SAASC,mBAAmB,QAA4C,mBAAmB;AAG3F,MAAMC,eAAgDC,OAAOC,OAAO,CAACH,qBAAqBI,GAAG,CAAC,CAAC,CAACC,IAAIC,OAAO;IACzG,OAAO;QACLD,IAAIA;QACJ,GAAGC,MAAM;IACX;AACF;AAOA,OAAO,SAASC,oBAAoB,EAAEC,KAAK,EAAEC,QAAQ,EAA4B;IAC/E,MAAMC,0BAA0B,CAACC,GAAYC;QAC3CH,SAASG,SAASP,EAAE;IACtB;IAEA,MAAMQ,aAAab,mBAAmB,CAACQ,MAAM;IAE7C,qBACE,KAACV;QACCgB,OAAM;QACNC,uBACE,KAAChB;YACCS,OAAO;gBACL,GAAGK,UAAU;gBACbR,IAAIG;YACN;YACAQ,SAASf;YACTQ,UAAUC;YACVO,gBAAgB;;;AAK1B"}
1
+ {"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 { OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport { CALCULATIONS_CONFIG, CalculationConfig, CalculationType } from '@perses-dev/core';\nimport { ReactElement } from 'react';\n\ntype AutocompleteCalculationOption = CalculationConfig & { id: CalculationType };\nconst CALC_OPTIONS: AutocompleteCalculationOption[] = Object.entries(CALCULATIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as CalculationType,\n ...config,\n };\n});\n\nexport interface CalculationSelectorProps {\n value: CalculationType;\n onChange: (unit: CalculationType) => void;\n}\n\nexport function CalculationSelector({ value, onChange }: CalculationSelectorProps): ReactElement {\n const handleCalculationChange = (_: unknown, newValue: AutocompleteCalculationOption): void => {\n onChange(newValue.id);\n };\n\n const calcConfig = CALCULATIONS_CONFIG[value];\n\n return (\n <OptionsEditorControl\n label=\"Calculation\"\n control={\n <SettingsAutocomplete\n value={{\n ...calcConfig,\n id: value,\n }}\n options={CALC_OPTIONS}\n onChange={handleCalculationChange}\n disableClearable\n />\n }\n />\n );\n}\n"],"names":["OptionsEditorControl","SettingsAutocomplete","CALCULATIONS_CONFIG","CALC_OPTIONS","Object","entries","map","id","config","CalculationSelector","value","onChange","handleCalculationChange","_","newValue","calcConfig","label","control","options","disableClearable"],"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,SAASA,oBAAoB,EAAEC,oBAAoB,QAAQ,yBAAyB;AACpF,SAASC,mBAAmB,QAA4C,mBAAmB;AAI3F,MAAMC,eAAgDC,OAAOC,OAAO,CAACH,qBAAqBI,GAAG,CAAC,CAAC,CAACC,IAAIC,OAAO;IACzG,OAAO;QACLD,IAAIA;QACJ,GAAGC,MAAM;IACX;AACF;AAOA,OAAO,SAASC,oBAAoB,EAAEC,KAAK,EAAEC,QAAQ,EAA4B;IAC/E,MAAMC,0BAA0B,CAACC,GAAYC;QAC3CH,SAASG,SAASP,EAAE;IACtB;IAEA,MAAMQ,aAAab,mBAAmB,CAACQ,MAAM;IAE7C,qBACE,KAACV;QACCgB,OAAM;QACNC,uBACE,KAAChB;YACCS,OAAO;gBACL,GAAGK,UAAU;gBACbR,IAAIG;YACN;YACAQ,SAASf;YACTQ,UAAUC;YACVO,gBAAgB;;;AAK1B"}
@@ -1,14 +1,15 @@
1
1
  import { Action, DatasourceDefinition } from '@perses-dev/core';
2
- import { DispatchWithoutAction } from 'react';
2
+ import { DispatchWithoutAction, ReactElement } from 'react';
3
3
  interface DatasourceEditorFormProps {
4
4
  initialDatasourceDefinition: DatasourceDefinition;
5
- initialAction: Action;
5
+ action: Action;
6
6
  isDraft: boolean;
7
7
  isReadonly?: boolean;
8
+ onActionChange?: (action: Action) => void;
8
9
  onSave: (def: DatasourceDefinition) => void;
9
10
  onClose: DispatchWithoutAction;
10
11
  onDelete?: DispatchWithoutAction;
11
12
  }
12
- export declare function DatasourceEditorForm(props: DatasourceEditorFormProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function DatasourceEditorForm(props: DatasourceEditorFormProps): ReactElement;
13
14
  export {};
14
15
  //# sourceMappingURL=DatasourceEditorForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DatasourceEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,qBAAqB,EAAY,MAAM,OAAO,CAAC;AAQxD,UAAU,yBAAyB;IACjC,2BAA2B,EAAE,oBAAoB,CAAC;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,2CAuOpE"}
1
+ {"version":3,"file":"DatasourceEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAc,EAAE,qBAAqB,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAQ7E,UAAU,yBAAyB;IACjC,2BAA2B,EAAE,oBAAoB,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,YAAY,CA6MnF"}
@@ -10,19 +10,18 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { Box, Button, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';
15
- import { useState } from 'react';
16
- import { DiscardChangesConfirmationDialog } from '@perses-dev/components';
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';
15
+ import React, { useState } from 'react';
16
+ import { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';
17
17
  import { Controller, FormProvider, useForm } from 'react-hook-form';
18
18
  import { zodResolver } from '@hookform/resolvers/zod';
19
19
  import { PluginEditor } from '../PluginEditor';
20
20
  import { getSubmitText, getTitleAction } from '../../utils';
21
21
  import { useValidationSchemas } from '../../context';
22
22
  export function DatasourceEditorForm(props) {
23
- const { initialDatasourceDefinition, initialAction, isDraft, isReadonly, onSave, onClose, onDelete } = props;
23
+ const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;
24
24
  const [isDiscardDialogOpened, setDiscardDialogOpened] = useState(false);
25
- const [action, setAction] = useState(initialAction);
26
25
  const titleAction = getTitleAction(action, isDraft);
27
26
  const submitText = getSubmitText(action, isDraft);
28
27
  const { datasourceEditorSchema } = useValidationSchemas();
@@ -75,61 +74,15 @@ export function DatasourceEditorForm(props) {
75
74
  " Datasource"
76
75
  ]
77
76
  }),
78
- /*#__PURE__*/ _jsx(Stack, {
79
- direction: "row",
80
- spacing: 1,
81
- sx: {
82
- marginLeft: 'auto'
83
- },
84
- children: action === 'read' ? /*#__PURE__*/ _jsxs(_Fragment, {
85
- children: [
86
- /*#__PURE__*/ _jsx(Button, {
87
- disabled: isReadonly,
88
- variant: "contained",
89
- onClick: ()=>setAction('update'),
90
- children: "Edit"
91
- }),
92
- /*#__PURE__*/ _jsx(Button, {
93
- color: "error",
94
- disabled: isReadonly,
95
- variant: "outlined",
96
- onClick: onDelete,
97
- children: "Delete"
98
- }),
99
- /*#__PURE__*/ _jsx(Divider, {
100
- orientation: "vertical",
101
- flexItem: true,
102
- sx: (theme)=>({
103
- borderColor: theme.palette.grey['500'],
104
- '&.MuiDivider-root': {
105
- marginLeft: 2,
106
- marginRight: 1
107
- }
108
- })
109
- }),
110
- /*#__PURE__*/ _jsx(Button, {
111
- color: "secondary",
112
- variant: "outlined",
113
- onClick: onClose,
114
- children: "Close"
115
- })
116
- ]
117
- }) : /*#__PURE__*/ _jsxs(_Fragment, {
118
- children: [
119
- /*#__PURE__*/ _jsx(Button, {
120
- variant: "contained",
121
- disabled: !form.formState.isValid,
122
- onClick: form.handleSubmit(processForm),
123
- children: submitText
124
- }),
125
- /*#__PURE__*/ _jsx(Button, {
126
- color: "secondary",
127
- variant: "outlined",
128
- onClick: handleCancel,
129
- children: "Cancel"
130
- })
131
- ]
132
- })
77
+ /*#__PURE__*/ _jsx(FormActions, {
78
+ action: action,
79
+ submitText: submitText,
80
+ isReadonly: isReadonly,
81
+ isValid: form.formState.isValid,
82
+ onActionChange: onActionChange,
83
+ onSubmit: form.handleSubmit(processForm),
84
+ onDelete: onDelete,
85
+ onCancel: handleCancel
133
86
  })
134
87
  ]
135
88
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.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 { Action, DatasourceDefinition } from '@perses-dev/core';\nimport { Box, Button, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';\nimport { DispatchWithoutAction, useState } from 'react';\nimport { DiscardChangesConfirmationDialog } from '@perses-dev/components';\nimport { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { PluginEditor } from '../PluginEditor';\nimport { getSubmitText, getTitleAction } from '../../utils';\nimport { useValidationSchemas } from '../../context';\n\ninterface DatasourceEditorFormProps {\n initialDatasourceDefinition: DatasourceDefinition;\n initialAction: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onSave: (def: DatasourceDefinition) => void;\n onClose: DispatchWithoutAction;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function DatasourceEditorForm(props: DatasourceEditorFormProps) {\n const { initialDatasourceDefinition, initialAction, isDraft, isReadonly, onSave, onClose, onDelete } = props;\n\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const [action, setAction] = useState(initialAction);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { datasourceEditorSchema } = useValidationSchemas();\n const form = useForm<DatasourceDefinition>({\n resolver: zodResolver(datasourceEditorSchema),\n mode: 'onBlur',\n defaultValues: initialDatasourceDefinition,\n });\n\n /*\n * Remove empty fields that are optional\n */\n function clearFormData(data: DatasourceDefinition): DatasourceDefinition {\n const result = { ...data };\n if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<DatasourceDefinition> = (data: DatasourceDefinition) => {\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel() {\n if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Datasource</Typography>\n <Stack direction=\"row\" spacing={1} sx={{ marginLeft: 'auto' }}>\n {action === 'read' ? (\n <>\n <Button disabled={isReadonly} variant=\"contained\" onClick={() => setAction('update')}>\n Edit\n </Button>\n <Button color=\"error\" disabled={isReadonly} variant=\"outlined\" onClick={onDelete}>\n Delete\n </Button>\n <Divider\n orientation=\"vertical\"\n flexItem\n sx={(theme) => ({\n borderColor: theme.palette.grey['500'],\n '&.MuiDivider-root': {\n marginLeft: 2,\n marginRight: 1,\n },\n })}\n />\n <Button color=\"secondary\" variant=\"outlined\" onClick={onClose}>\n Close\n </Button>\n </>\n ) : (\n <>\n <Button variant=\"contained\" disabled={!form.formState.isValid} onClick={form.handleSubmit(processForm)}>\n {submitText}\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </>\n )}\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n name=\"name\"\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"title\"\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={12}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"description\"\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={6} sx={{ paddingTop: '5px !important' }}>\n <Stack>\n <Controller\n control={form.control}\n name=\"spec.default\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Set as default\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">\n Whether this datasource should be the default {form.getValues().spec.plugin.kind} to be used\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n <Divider />\n <Typography py={1} variant=\"h3\">\n Plugin Options\n </Typography>\n <Controller\n control={form.control}\n name=\"spec.plugin\"\n render={({ field }) => (\n <PluginEditor\n width=\"100%\"\n pluginTypes={['Datasource']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Datasource',\n kind: field.value.kind,\n },\n spec: field.value.spec,\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n )}\n />\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard your changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => setDiscardDialogOpened(false)}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["Box","Button","Divider","FormControlLabel","Grid","Stack","Switch","TextField","Typography","useState","DiscardChangesConfirmationDialog","Controller","FormProvider","useForm","zodResolver","PluginEditor","getSubmitText","getTitleAction","useValidationSchemas","DatasourceEditorForm","props","initialDatasourceDefinition","initialAction","isDraft","isReadonly","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","action","setAction","titleAction","submitText","datasourceEditorSchema","form","resolver","mode","defaultValues","clearFormData","data","result","spec","display","name","undefined","description","processForm","handleCancel","JSON","stringify","getValues","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","direction","marginLeft","disabled","onClick","color","orientation","flexItem","borderColor","grey","marginRight","formState","isValid","handleSubmit","overflowY","container","mb","item","xs","control","render","field","fieldState","required","fullWidth","label","InputLabelProps","shrink","InputProps","readOnly","error","helperText","message","value","onChange","event","paddingTop","checked","plugin","kind","py","width","pluginTypes","pluginKindLabel","selection","type","v","isOpen","onCancel","onDiscardChanges"],"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;;AAGjC,SAASA,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AACnH,SAAgCC,QAAQ,QAAQ,QAAQ;AACxD,SAASC,gCAAgC,QAAQ,yBAAyB;AAC1E,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,QAAQ,kBAAkB;AACnF,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,QAAQ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AAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,KAAClE;gCACCsF,OAAM;gCACNC,aAAa;oCAAC;iCAAa;gCAC3BC,iBAAgB;gCAChBV,OAAO;oCACLW,WAAW;wCACTC,MAAM;wCACNN,MAAMlB,MAAMY,KAAK,CAACM,IAAI;oCACxB;oCACAzD,MAAMuC,MAAMY,KAAK,CAACnD,IAAI;gCACxB;gCACAlB,YAAYM,WAAW;gCACvBgE,UAAU,CAACY;oCACTzB,MAAMa,QAAQ,CAAC;wCAAEK,MAAMO,EAAEF,SAAS,CAACL,IAAI;wCAAEzD,MAAMgE,EAAEhE,IAAI;oCAAC;gCACxD;;;;;0BAKR,KAAChC;gBACCoC,aAAY;gBACZ6D,QAAQ/E;gBACRgF,UAAU,IAAM/E,uBAAuB;gBACvCgF,kBAAkB;oBAChBhF,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
1
+ {"version":3,"sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.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 { Action, DatasourceDefinition } from '@perses-dev/core';\nimport { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';\nimport React, { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';\nimport { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { PluginEditor } from '../PluginEditor';\nimport { getSubmitText, getTitleAction } from '../../utils';\nimport { useValidationSchemas } from '../../context';\n\ninterface DatasourceEditorFormProps {\n initialDatasourceDefinition: DatasourceDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: DatasourceDefinition) => void;\n onClose: DispatchWithoutAction;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function DatasourceEditorForm(props: DatasourceEditorFormProps): ReactElement {\n const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;\n\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { datasourceEditorSchema } = useValidationSchemas();\n const form = useForm<DatasourceDefinition>({\n resolver: zodResolver(datasourceEditorSchema),\n mode: 'onBlur',\n defaultValues: initialDatasourceDefinition,\n });\n\n /*\n * Remove empty fields that are optional\n */\n function clearFormData(data: DatasourceDefinition): DatasourceDefinition {\n const result = { ...data };\n if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<DatasourceDefinition> = (data: DatasourceDefinition) => {\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Datasource</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n name=\"name\"\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"title\"\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={12}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"description\"\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={6} sx={{ paddingTop: '5px !important' }}>\n <Stack>\n <Controller\n control={form.control}\n name=\"spec.default\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Set as default\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">\n Whether this datasource should be the default {form.getValues().spec.plugin.kind} to be used\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n <Divider />\n <Typography py={1} variant=\"h3\">\n Plugin Options\n </Typography>\n <Controller\n control={form.control}\n name=\"spec.plugin\"\n render={({ field }) => (\n <PluginEditor\n width=\"100%\"\n pluginTypes={['Datasource']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Datasource',\n kind: field.value.kind,\n },\n spec: field.value.spec,\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n )}\n />\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard your changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => setDiscardDialogOpened(false)}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["Box","Divider","FormControlLabel","Grid","Stack","Switch","TextField","Typography","React","useState","DiscardChangesConfirmationDialog","FormActions","Controller","FormProvider","useForm","zodResolver","PluginEditor","getSubmitText","getTitleAction","useValidationSchemas","DatasourceEditorForm","props","initialDatasourceDefinition","action","isDraft","isReadonly","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","datasourceEditorSchema","form","resolver","mode","defaultValues","clearFormData","data","result","spec","display","name","undefined","description","processForm","handleCancel","JSON","stringify","getValues","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","mb","item","xs","control","render","field","fieldState","required","fullWidth","label","InputLabelProps","shrink","InputProps","disabled","readOnly","error","helperText","message","value","onChange","event","paddingTop","checked","plugin","kind","py","width","pluginTypes","pluginKindLabel","selection","type","v","isOpen","onDiscardChanges"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAs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+B,MAAMa,KAAK,CAAC5C,IAAI;gCACxB;gCACAjB,YAAYF,WAAW;gCACvBgE,UAAU,CAACY;oCACT1B,MAAMc,QAAQ,CAAC;wCAAEK,MAAMO,EAAEF,SAAS,CAACL,IAAI;wCAAElD,MAAMyD,EAAEzD,IAAI;oCAAC;gCACxD;;;;;0BAKR,KAAChC;gBACCoC,aAAY;gBACZsD,QAAQtE;gBACRmC,UAAU,IAAMlC,uBAAuB;gBACvCsE,kBAAkB;oBAChBtE,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
@@ -1,5 +1,6 @@
1
1
  import { SelectProps } from '@mui/material';
2
2
  import { DatasourceSelector } from '@perses-dev/core';
3
+ import { ReactElement } from 'react';
3
4
  type OmittedMuiProps = 'children' | 'value' | 'onChange';
4
5
  export interface DatasourceSelectProps extends Omit<SelectProps<string>, OmittedMuiProps> {
5
6
  value: DatasourceSelector;
@@ -11,11 +12,11 @@ export interface DatasourceSelectProps extends Omit<SelectProps<string>, Omitted
11
12
  * Displays a MUI input for selecting a Datasource of a particular kind. Note: The 'value' and `onChange` handler for
12
13
  * the input deal with a `DatasourceSelector`.
13
14
  */
14
- export declare function DatasourceSelect(props: DatasourceSelectProps): import("react/jsx-runtime").JSX.Element;
15
+ export declare function DatasourceSelect(props: DatasourceSelectProps): ReactElement;
15
16
  export declare function DatasourceName(props: {
16
17
  name: string;
17
18
  overridden?: boolean;
18
19
  overriding?: boolean;
19
- }): import("react/jsx-runtime").JSX.Element;
20
+ }): ReactElement;
20
21
  export {};
21
22
  //# sourceMappingURL=DatasourceSelect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../src/components/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAU,WAAW,EAAiE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAMtD,KAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG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EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,YAAY,CAahH"}
@@ -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 { Select, SelectProps, MenuItem, Stack, Divider, ListItemText, Chip, IconButton, Box } from '@mui/material';\nimport { DatasourceSelector } from '@perses-dev/core';\nimport { useMemo } from 'react';\nimport { DatasourceSelectItemSelector, useListDatasourceSelectItems } from '../runtime';\n\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\nexport interface DatasourceSelectProps extends Omit<SelectProps<string>, OmittedMuiProps> {\n value: DatasourceSelector;\n onChange: (next: DatasourceSelector) => 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) {\n const { datasourcePluginKind, value, project, onChange, ...others } = props;\n const { data, isLoading } = useListDatasourceSelectItems(datasourcePluginKind, project);\n // Rebuild the group of the value if not provided\n const defaultValue = useMemo(() => {\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 // Convert the datasource list into menu items with name/group?/value strings that the Select input can work with\n const menuItems = useMemo(() => {\n return (data ?? []).map((itemGroup) => ({\n group: itemGroup.group,\n editLink: itemGroup.editLink,\n items: itemGroup.items.map((item) => ({\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 }, [data]);\n\n // While loading available values, just use an empty string so MUI select doesn't warn about values out of range\n const optionValue = isLoading ? '' : selectorToOptionValue(defaultValue);\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange: SelectProps<string>['onChange'] = (e) => {\n const next = optionValueToSelector(e.target.value);\n onChange(next);\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 = () => {};\n\n // TODO:\n // - Does this need a loading indicator of some kind?\n // - The group's edit link is not clickable once selected.\n // - The group's edit link is disabled if datasource is overridden.\n // Ref: https://github.com/mui/material-ui/issues/36572\n return (\n <Select {...others} value={optionValue} onChange={handleChange}>\n {menuItems.map((menuItemGroup) => [\n <Divider key={`${menuItemGroup.group}-divider`} />,\n ...menuItemGroup.items.map((menuItem) => (\n <MenuItem key={menuItem.value} value={menuItem.value} disabled={menuItem.overridden || !menuItem.saved}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\">\n <ListItemText>\n <DatasourceName\n name={menuItem.name}\n overridden={menuItem.overridden}\n overriding={menuItem.overriding}\n />\n </ListItemText>\n {!menuItem.saved && <ListItemText>Save the dashboard to enable this datasource</ListItemText>}\n <ListItemText style={{ textAlign: 'right' }}>\n {menuItemGroup.group && menuItemGroup.group.length > 0 && (\n <Chip\n disabled={false}\n label={menuItemGroup.group}\n size=\"small\"\n onDelete={menuItemGroup.editLink ? fakeActionEvent : undefined}\n deleteIcon={\n menuItemGroup.editLink ? (\n <IconButton href={menuItemGroup.editLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n ) : undefined\n }\n />\n )}\n </ListItemText>\n </Stack>\n </MenuItem>\n )),\n ])}\n </Select>\n );\n}\n\nexport function DatasourceName(props: { name: string; overridden?: boolean; overriding?: boolean }) {\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): string {\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): DatasourceSelector {\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"],"names":["OpenInNewIcon","Select","MenuItem","Stack","Divider","ListItemText","Chip","IconButton","Box","useMemo","useListDatasourceSelectItems","DatasourceSelect","props","datasourcePluginKind","value","project","onChange","others","data","isLoading","defaultValue","group","flatMap","itemGroup","items","find","item","kind","selector","name","overridden","menuItems","map","editLink","overriding","saved","selectorToOptionValue","optionValue","handleChange","e","next","optionValueToSelector","target","fakeActionEvent","menuItemGroup","menuItem","disabled","direction","alignItems","justifyContent","width","DatasourceName","style","textAlign","length","label","size","onDelete","undefined","deleteIcon","href","fontSize","display","fontWeight","color","theme","palette","primary","main","OPTION_VALUE_DELIMIT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AACH;IAChC,MAAM1C,OAAO4C,KAAK,CAAC,EAAE;IACrB,MAAM1C,OAAO0C,KAAK,CAAC,EAAE;IACrB,IAAI5C,SAAS+B,aAAa7B,SAAS6B,WAAW;QAC5C,MAAM,IAAIe,MAAM;IAClB;IACA,OAAO;QACL9C;QACAE,MAAMA,SAAS,KAAK6B,YAAY7B;IAClC;AACF"}
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 { Select, SelectProps, MenuItem, Stack, Divider, ListItemText, Chip, IconButton, Box } from '@mui/material';\nimport { DatasourceSelector } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport { DatasourceSelectItemSelector, useListDatasourceSelectItems } from '../runtime';\n\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\nexport interface DatasourceSelectProps extends Omit<SelectProps<string>, OmittedMuiProps> {\n value: DatasourceSelector;\n onChange: (next: DatasourceSelector) => 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 // Rebuild the group of the value if not provided\n const defaultValue = useMemo(() => {\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 // Convert the datasource list into menu items with name/group?/value strings that the Select input can work with\n const menuItems = useMemo(() => {\n return (data ?? []).map((itemGroup) => ({\n group: itemGroup.group,\n editLink: itemGroup.editLink,\n items: itemGroup.items.map((item) => ({\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 }, [data]);\n\n // While loading available values, just use an empty string so MUI select doesn't warn about values out of range\n const optionValue = isLoading ? '' : selectorToOptionValue(defaultValue);\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange: SelectProps<string>['onChange'] = (e) => {\n const next = optionValueToSelector(e.target.value);\n onChange(next);\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 // TODO:\n // - Does this need a loading indicator of some kind?\n // - The group's edit link is not clickable once selected.\n // - The group's edit link is disabled if datasource is overridden.\n // Ref: https://github.com/mui/material-ui/issues/36572\n return (\n <Select {...others} value={optionValue} onChange={handleChange}>\n {menuItems.map((menuItemGroup) => [\n <Divider key={`${menuItemGroup.group}-divider`} />,\n ...menuItemGroup.items.map((menuItem) => (\n <MenuItem key={menuItem.value} value={menuItem.value} disabled={menuItem.overridden || !menuItem.saved}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\">\n <ListItemText>\n <DatasourceName\n name={menuItem.name}\n overridden={menuItem.overridden}\n overriding={menuItem.overriding}\n />\n </ListItemText>\n {!menuItem.saved && <ListItemText>Save the dashboard to enable this datasource</ListItemText>}\n <ListItemText style={{ textAlign: 'right' }}>\n {menuItemGroup.group && menuItemGroup.group.length > 0 && (\n <Chip\n disabled={false}\n label={menuItemGroup.group}\n size=\"small\"\n onDelete={menuItemGroup.editLink ? fakeActionEvent : undefined}\n deleteIcon={\n menuItemGroup.editLink ? (\n <IconButton href={menuItemGroup.editLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n ) : undefined\n }\n />\n )}\n </ListItemText>\n </Stack>\n </MenuItem>\n )),\n ])}\n </Select>\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): string {\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): DatasourceSelector {\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"],"names":["OpenInNewIcon","Select","MenuItem","Stack","Divider","ListItemText","Chip","IconButton","Box","useMemo","useListDatasourceSelectItems","DatasourceSelect","props","datasourcePluginKind","value","project","onChange","others","data","isLoading","defaultValue","group","flatMap","itemGroup","items","find","item","kind","selector","name","overridden","menuItems","map","editLink","overriding","saved","selectorToOptionValue","optionValue","handleChange","e","next","optionValueToSelector","target","fakeActionEvent","menuItemGroup","menuItem","disabled","direction","alignItems","justifyContent","width","DatasourceName","style","textAlign","length","label","size","onDelete","undefined","deleteIcon","href","fontSize","display","fontWeight","color","theme","palette","primary","main","OPTION_VALUE_DELIMITER","join","words","split","Error"],"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,SAASC,MAAM,EAAeC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAAEC,IAAI,EAAEC,UAAU,EAAEC,GAAG,QAAQ,gBAAgB;AAEnH,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAAuCC,4BAA4B,QAAQ,aAAa;AAaxF;;;CAGC,GACD,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,oBAAoB,EAAEC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGC,QAAQ,GAAGL;IACtE,MAAM,EAAEM,IAAI,EAAEC,SAAS,EAAE,GAAGT,6BAA6BG,sBAAsBE;IAC/E,iDAAiD;IACjD,MAAMK,eAAeX,QAAQ;YACb;QAAd,MAAMY,SAAQ,gBAAA,AAACH,CAAAA,iBAAAA,kBAAAA,OAAQ,EAAE,AAAD,EACrBI,OAAO,CAAC,CAACC,YAAcA,UAAUC,KAAK,EACtCC,IAAI,CAAC,CAACC;YACL,OAAOZ,MAAMa,IAAI,KAAKD,KAAKE,QAAQ,CAACD,IAAI,IAAIb,MAAMe,IAAI,KAAKH,KAAKE,QAAQ,CAACC,IAAI,IAAI,CAACH,KAAKI,UAAU;QACnG,gBAJY,oCAAA,cAIRF,QAAQ,CAACP,KAAK;QACpB,OAAO;YAAE,GAAGP,KAAK;YAAEO;QAAM;IA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iBAAAA,SAASC,IAAI,cAAbD,4BAAAA,iBAAiB;KAAG,CAAC0C,IAAI,CAACD;AACzE;AAEA;;;;CAIC,GACD,SAAS5B,sBAAsBJ,WAAmB;IAChD,MAAMkC,QAAQlC,YAAYmC,KAAK,CAACH;IAChC,MAAM1C,OAAO4C,KAAK,CAAC,EAAE;IACrB,MAAM1C,OAAO0C,KAAK,CAAC,EAAE;IACrB,IAAI5C,SAAS+B,aAAa7B,SAAS6B,WAAW;QAC5C,MAAM,IAAIe,MAAM;IAClB;IACA,OAAO;QACL9C;QACAE,MAAMA,SAAS,KAAK6B,YAAY7B;IAClC;AACF"}
@@ -1,7 +1,9 @@
1
+ import { ReactElement } from 'react';
1
2
  import { LegendSpecOptions } from '../../model';
2
3
  export interface LegendOptionsEditorProps {
3
4
  value?: LegendSpecOptions;
4
5
  onChange: (legend?: LegendSpecOptions) => void;
6
+ showValuesEditor?: boolean;
5
7
  }
6
- export declare function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function LegendOptionsEditor({ value, onChange, showValuesEditor, }: LegendOptionsEditorProps): ReactElement;
7
9
  //# sourceMappingURL=LegendOptionsEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAGL,iBAAiB,EAMlB,MAAM,aAAa,CAAC;AAqCrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,2CAwIhF"}
1
+ {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAGL,iBAAiB,EAMlB,MAAM,aAAa,CAAC;AAqCrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC/C,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,gBAAuB,GACxB,EAAE,wBAAwB,GAAG,YAAY,CA0IzC"}
@@ -39,7 +39,7 @@ const VALUE_OPTIONS = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config])=>{
39
39
  ...config
40
40
  };
41
41
  });
42
- export function LegendOptionsEditor({ value, onChange }) {
42
+ export function LegendOptionsEditor({ value, onChange, showValuesEditor = true }) {
43
43
  const handleLegendShowChange = (_, checked)=>{
44
44
  // legend is hidden when legend obj is undefined
45
45
  const legendValue = checked === true ? {
@@ -151,7 +151,7 @@ export function LegendOptionsEditor({ value, onChange }) {
151
151
  disableClearable: true
152
152
  })
153
153
  }),
154
- /*#__PURE__*/ _jsx(OptionsEditorControl, {
154
+ showValuesEditor && /*#__PURE__*/ _jsx(OptionsEditorControl, {
155
155
  label: "Values",
156
156
  control: // For some reason, the inferred option type doesn't always seem to work
157
157
  // quite right when `multiple` is true. Explicitly setting the generics