@perses-dev/plugin-system 0.49.0-rc.1 → 0.50.0-rc.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 (157) 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/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +16 -1
  6. package/dist/cjs/runtime/UsageMetricsProvider.js +99 -0
  7. package/dist/cjs/runtime/index.js +1 -0
  8. package/dist/components/CalculationSelector/CalculationSelector.d.ts +2 -1
  9. package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
  10. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  11. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +4 -3
  12. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  13. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +14 -61
  14. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  15. package/dist/components/DatasourceSelect.d.ts +3 -2
  16. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  17. package/dist/components/DatasourceSelect.js.map +1 -1
  18. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +3 -1
  19. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  20. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -2
  21. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  22. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +2 -1
  23. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  24. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  25. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +2 -1
  26. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  27. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  28. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +2 -2
  29. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -1
  30. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  31. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +2 -2
  32. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -1
  33. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  34. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts +3 -3
  35. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts.map +1 -1
  36. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  37. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +2 -1
  38. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  39. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +1 -1
  40. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  41. package/dist/components/PluginEditor/PluginEditor.d.ts +2 -1
  42. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  43. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  44. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -1
  45. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  46. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  47. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  48. package/dist/components/PluginRegistry/PluginRegistry.d.ts +2 -2
  49. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  50. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  51. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  52. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  53. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +2 -1
  54. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  55. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  56. package/dist/components/ProjectSelect.d.ts +2 -1
  57. package/dist/components/ProjectSelect.d.ts.map +1 -1
  58. package/dist/components/ProjectSelect.js.map +1 -1
  59. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
  60. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  61. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  62. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -3
  63. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  64. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +12 -61
  65. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  66. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +3 -2
  67. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  68. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  69. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +2 -2
  70. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  71. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  72. package/dist/components/Variables/variable-model.d.ts +2 -1
  73. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  74. package/dist/components/Variables/variable-model.js.map +1 -1
  75. package/dist/context/ProjectStoreProvider.d.ts +2 -2
  76. package/dist/context/ProjectStoreProvider.d.ts.map +1 -1
  77. package/dist/context/ProjectStoreProvider.js.map +1 -1
  78. package/dist/context/ValidationProvider.d.ts +2 -2
  79. package/dist/context/ValidationProvider.d.ts.map +1 -1
  80. package/dist/context/ValidationProvider.js.map +1 -1
  81. package/dist/context/query-params.d.ts.map +1 -1
  82. package/dist/context/query-params.js.map +1 -1
  83. package/dist/model/legend.d.ts.map +1 -1
  84. package/dist/model/legend.js.map +1 -1
  85. package/dist/model/plugin-loading.js.map +1 -1
  86. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +2 -2
  87. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  88. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +16 -1
  89. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  90. package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
  91. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  92. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  93. package/dist/runtime/QueryCountProvider.d.ts.map +1 -1
  94. package/dist/runtime/QueryCountProvider.js.map +1 -1
  95. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +2 -2
  96. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  97. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  98. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +2 -2
  99. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +1 -1
  100. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +1 -1
  101. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +2 -2
  102. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -1
  103. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  104. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -1
  105. package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -1
  106. package/dist/runtime/UsageMetricsProvider.d.ts +25 -0
  107. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -0
  108. package/dist/runtime/UsageMetricsProvider.js +77 -0
  109. package/dist/runtime/UsageMetricsProvider.js.map +1 -0
  110. package/dist/runtime/builtin-variables.d.ts.map +1 -1
  111. package/dist/runtime/builtin-variables.js.map +1 -1
  112. package/dist/runtime/datasources.d.ts +4 -3
  113. package/dist/runtime/datasources.d.ts.map +1 -1
  114. package/dist/runtime/datasources.js.map +1 -1
  115. package/dist/runtime/index.d.ts +1 -0
  116. package/dist/runtime/index.d.ts.map +1 -1
  117. package/dist/runtime/index.js +1 -0
  118. package/dist/runtime/index.js.map +1 -1
  119. package/dist/runtime/plugin-registry.d.ts +5 -5
  120. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  121. package/dist/runtime/plugin-registry.js.map +1 -1
  122. package/dist/runtime/time-series-queries.d.ts +3 -3
  123. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  124. package/dist/runtime/time-series-queries.js.map +1 -1
  125. package/dist/runtime/trace-queries.d.ts +4 -3
  126. package/dist/runtime/trace-queries.d.ts.map +1 -1
  127. package/dist/runtime/trace-queries.js +1 -1
  128. package/dist/runtime/trace-queries.js.map +1 -1
  129. package/dist/runtime/variables.js.map +1 -1
  130. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +2 -1
  131. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +1 -1
  132. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
  133. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +2 -1
  134. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  135. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  136. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +2 -1
  137. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +1 -1
  138. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -1
  139. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts +2 -1
  140. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
  141. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  142. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +2 -1
  143. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +1 -1
  144. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -1
  145. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +2 -1
  146. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -1
  147. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  148. package/dist/test/render.d.ts +3 -3
  149. package/dist/test/render.d.ts.map +1 -1
  150. package/dist/test/render.js.map +1 -1
  151. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  152. package/dist/test/test-plugins/bert/index.js.map +1 -1
  153. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  154. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  155. package/dist/utils/variables.d.ts.map +1 -1
  156. package/dist/utils/variables.js.map +1 -1
  157. 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
  }),
@@ -38,6 +38,7 @@ const _jsxruntime = require("react/jsx-runtime");
38
38
  const _react = require("react");
39
39
  const _timeseriesqueries = require("../time-series-queries");
40
40
  const _tracequeries = require("../trace-queries");
41
+ const _UsageMetricsProvider = require("../UsageMetricsProvider");
41
42
  const _model = require("./model");
42
43
  const DataQueriesContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
43
44
  function useDataQueriesContext() {
@@ -82,6 +83,7 @@ function DataQueriesProvider(props) {
82
83
  }
83
84
  };
84
85
  });
86
+ const usageMetrics = (0, _UsageMetricsProvider.useUsageMetrics)();
85
87
  // Filter definitions for time series query and other future query plugins
86
88
  const timeSeriesQueries = queryDefinitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
87
89
  const timeSeriesResults = (0, _timeseriesqueries.useTimeSeriesQueries)(timeSeriesQueries, options, queryOptions);
@@ -99,6 +101,17 @@ function DataQueriesProvider(props) {
99
101
  ...(0, _model.transformQueryResults)(timeSeriesResults, timeSeriesQueries),
100
102
  ...(0, _model.transformQueryResults)(traceResults, traceQueries)
101
103
  ];
104
+ if (queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) {
105
+ for (const result of mergedQueryResults){
106
+ if (!result.isLoading && !result.isFetching && !result.error) {
107
+ usageMetrics.markQuery(result.definition, 'success');
108
+ } else if (result.error) {
109
+ usageMetrics.markQuery(result.definition, 'error');
110
+ } else {
111
+ usageMetrics.markQuery(result.definition, 'pending');
112
+ }
113
+ }
114
+ }
102
115
  return {
103
116
  queryResults: mergedQueryResults,
104
117
  isFetching: mergedQueryResults.some((result)=>result.isFetching),
@@ -111,7 +124,9 @@ function DataQueriesProvider(props) {
111
124
  timeSeriesResults,
112
125
  traceQueries,
113
126
  traceResults,
114
- refetchAll
127
+ refetchAll,
128
+ queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled,
129
+ usageMetrics
115
130
  ]);
116
131
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(DataQueriesContext.Provider, {
117
132
  value: ctx,
@@ -0,0 +1,99 @@
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
+ UsageMetricsContext: function() {
25
+ return UsageMetricsContext;
26
+ },
27
+ UsageMetricsProvider: function() {
28
+ return UsageMetricsProvider;
29
+ },
30
+ useUsageMetrics: function() {
31
+ return useUsageMetrics;
32
+ },
33
+ useUsageMetricsContext: function() {
34
+ return useUsageMetricsContext;
35
+ }
36
+ });
37
+ const _jsxruntime = require("react/jsx-runtime");
38
+ const _core = require("@perses-dev/core");
39
+ const _react = require("react");
40
+ const UsageMetricsContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
41
+ const useUsageMetricsContext = ()=>{
42
+ return (0, _react.useContext)(UsageMetricsContext);
43
+ };
44
+ const useUsageMetrics = ()=>{
45
+ const ctx = useUsageMetricsContext();
46
+ return {
47
+ markQuery: (definition, newState)=>{
48
+ if (ctx === undefined) {
49
+ return;
50
+ }
51
+ const definitionKey = JSON.stringify(definition);
52
+ if (ctx.pendingQueries.has(definitionKey) && newState === 'pending') {
53
+ // Never allow transitions back to pending, to avoid re-sending stats on a re-render.
54
+ return;
55
+ }
56
+ if (ctx.pendingQueries.get(definitionKey) !== newState) {
57
+ ctx.pendingQueries.set(definitionKey, newState);
58
+ if (newState === 'error') {
59
+ ctx.renderErrorCount += 1;
60
+ }
61
+ const allDone = [
62
+ ...ctx.pendingQueries.values()
63
+ ].every((p)=>p !== 'pending');
64
+ if (ctx.renderDurationMs === 0 && allDone) {
65
+ ctx.renderDurationMs = Date.now() - ctx.startRenderTime;
66
+ submitMetrics(ctx);
67
+ }
68
+ }
69
+ }
70
+ };
71
+ };
72
+ const submitMetrics = async (stats)=>{
73
+ await (0, _core.fetch)('/api/v1/view', {
74
+ method: 'POST',
75
+ headers: {
76
+ 'Content-Type': 'application/json'
77
+ },
78
+ body: JSON.stringify({
79
+ project: stats.project,
80
+ dashboard: stats.dashboard,
81
+ render_time: stats.renderDurationMs / 1000,
82
+ render_errors: stats.renderErrorCount
83
+ })
84
+ });
85
+ };
86
+ const UsageMetricsProvider = ({ project, dashboard, children })=>{
87
+ const ctx = {
88
+ project: project,
89
+ dashboard: dashboard,
90
+ renderErrorCount: 0,
91
+ startRenderTime: Date.now(),
92
+ renderDurationMs: 0,
93
+ pendingQueries: new Map()
94
+ };
95
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(UsageMetricsContext.Provider, {
96
+ value: ctx,
97
+ children: children
98
+ });
99
+ };
@@ -23,6 +23,7 @@ _export_star(require("./time-series-queries"), exports);
23
23
  _export_star(require("./trace-queries"), exports);
24
24
  _export_star(require("./DataQueriesProvider"), exports);
25
25
  _export_star(require("./QueryCountProvider"), exports);
26
+ _export_star(require("./UsageMetricsProvider"), exports);
26
27
  function _export_star(from, to) {
27
28
  Object.keys(from).forEach(function(k) {
28
29
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -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
  }),