@perses-dev/dashboards 0.0.0-snapshot-color-palette-gen-test-0ebddd6 → 0.0.0-snapshot-saving-defaults-refinements-1b25cec

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 (212) hide show
  1. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +79 -0
  2. package/dist/cjs/{stories/decorators/WithQueryParams.js → components/DashboardStickyToolbar/index.js} +11 -12
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -24
  4. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +1 -0
  5. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +5 -0
  6. package/dist/cjs/components/GridLayout/GridItemContent.js +22 -4
  7. package/dist/cjs/components/GridLayout/GridLayout.js +31 -2
  8. package/dist/cjs/components/GridLayout/GridTitle.js +30 -9
  9. package/dist/cjs/components/Panel/Panel.js +2 -2
  10. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +41 -34
  11. package/dist/cjs/components/PanelDrawer/PanelPreview.js +32 -18
  12. package/dist/cjs/components/PanelDrawer/usePanelEditor.js +87 -0
  13. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +92 -0
  14. package/dist/cjs/components/SaveChangesConfirmationDialog/index.js +28 -0
  15. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +81 -0
  16. package/dist/cjs/components/SaveDashboardButton/index.js +28 -0
  17. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +5 -5
  18. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +124 -198
  19. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
  20. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
  21. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -8
  22. package/dist/cjs/components/Variables/VariableList.js +16 -55
  23. package/dist/cjs/components/Variables/index.js +1 -0
  24. package/dist/cjs/components/index.js +3 -0
  25. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +9 -8
  26. package/dist/cjs/context/DashboardProvider/common.js +26 -6
  27. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +13 -4
  28. package/dist/cjs/context/DashboardProvider/index.js +1 -0
  29. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +8 -32
  30. package/dist/cjs/context/DashboardProvider/save-changes-dialog-slice.js +33 -0
  31. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +56 -7
  32. package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +2 -0
  33. package/dist/cjs/context/TemplateVariableProvider/utils.js +44 -0
  34. package/dist/cjs/context/useDashboard.js +4 -4
  35. package/dist/cjs/stories/decorators/WithDatasourceStore.js +2 -47
  36. package/dist/cjs/stories/decorators/index.js +0 -4
  37. package/dist/cjs/test/datasource-provider.js +70 -0
  38. package/dist/cjs/test/index.js +1 -0
  39. package/dist/cjs/test/plugin-registry.js +11 -5
  40. package/dist/cjs/test/render.js +35 -13
  41. package/dist/cjs/test/testDashboard.js +79 -79
  42. package/dist/cjs/utils/index.js +1 -0
  43. package/dist/cjs/{stories/decorators/WithQueryClient.js → utils/time.js} +9 -11
  44. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  45. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts +9 -0
  46. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -0
  47. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +68 -0
  48. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -0
  49. package/dist/components/DashboardStickyToolbar/index.d.ts +2 -0
  50. package/dist/components/DashboardStickyToolbar/index.d.ts.map +1 -0
  51. package/dist/{stories/decorators/WithQueryClient.js → components/DashboardStickyToolbar/index.js} +2 -10
  52. package/dist/components/DashboardStickyToolbar/index.js.map +1 -0
  53. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
  54. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  55. package/dist/components/DashboardToolbar/DashboardToolbar.js +10 -26
  56. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  57. package/dist/components/EditJsonButton/EditJsonButton.js +1 -0
  58. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  59. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -1
  60. package/dist/components/EditJsonDialog/EditJsonDialog.js +5 -0
  61. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  62. package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
  63. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  64. package/dist/components/GridLayout/GridItemContent.js +22 -4
  65. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  66. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  67. package/dist/components/GridLayout/GridLayout.js +31 -2
  68. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  69. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  70. package/dist/components/GridLayout/GridTitle.js +30 -9
  71. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  72. package/dist/components/Panel/Panel.d.ts +1 -1
  73. package/dist/components/Panel/Panel.d.ts.map +1 -1
  74. package/dist/components/Panel/Panel.js +3 -3
  75. package/dist/components/Panel/Panel.js.map +1 -1
  76. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  77. package/dist/components/PanelDrawer/PanelEditorForm.js +42 -35
  78. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  79. package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -1
  80. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  81. package/dist/components/PanelDrawer/PanelPreview.js +32 -18
  82. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  83. package/dist/components/PanelDrawer/usePanelEditor.d.ts +15 -0
  84. package/dist/components/PanelDrawer/usePanelEditor.d.ts.map +1 -0
  85. package/dist/components/PanelDrawer/usePanelEditor.js +84 -0
  86. package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -0
  87. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +3 -0
  88. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -0
  89. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +86 -0
  90. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -0
  91. package/dist/components/SaveChangesConfirmationDialog/index.d.ts +2 -0
  92. package/dist/components/SaveChangesConfirmationDialog/index.d.ts.map +1 -0
  93. package/dist/{stories/decorators/WithQueryParams.js → components/SaveChangesConfirmationDialog/index.js} +2 -10
  94. package/dist/components/SaveChangesConfirmationDialog/index.js.map +1 -0
  95. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +10 -0
  96. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -0
  97. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +75 -0
  98. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -0
  99. package/dist/components/SaveDashboardButton/index.d.ts +2 -0
  100. package/dist/components/SaveDashboardButton/index.d.ts.map +1 -0
  101. package/dist/components/SaveDashboardButton/index.js +15 -0
  102. package/dist/components/SaveDashboardButton/index.js.map +1 -0
  103. package/dist/components/TimeRangeControls/TimeRangeControls.js +6 -6
  104. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  105. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -2
  106. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  107. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +127 -196
  108. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  109. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
  110. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
  111. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
  112. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
  113. package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
  114. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
  115. package/dist/components/Variables/VariableEditorForm/index.js +1 -0
  116. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  117. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  118. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -8
  119. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  120. package/dist/components/Variables/VariableList.d.ts +1 -7
  121. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  122. package/dist/components/Variables/VariableList.js +18 -52
  123. package/dist/components/Variables/VariableList.js.map +1 -1
  124. package/dist/components/Variables/index.d.ts +1 -0
  125. package/dist/components/Variables/index.d.ts.map +1 -1
  126. package/dist/components/Variables/index.js +1 -0
  127. package/dist/components/Variables/index.js.map +1 -1
  128. package/dist/components/index.d.ts +3 -0
  129. package/dist/components/index.d.ts.map +1 -1
  130. package/dist/components/index.js +3 -0
  131. package/dist/components/index.js.map +1 -1
  132. package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -3
  133. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  134. package/dist/context/DashboardProvider/DashboardProvider.js +9 -8
  135. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  136. package/dist/context/DashboardProvider/common.d.ts +3 -0
  137. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  138. package/dist/context/DashboardProvider/common.js +17 -2
  139. package/dist/context/DashboardProvider/common.js.map +1 -1
  140. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +6 -1
  141. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  142. package/dist/context/DashboardProvider/dashboard-provider-api.js +11 -3
  143. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  144. package/dist/context/DashboardProvider/index.d.ts +1 -0
  145. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  146. package/dist/context/DashboardProvider/index.js +1 -0
  147. package/dist/context/DashboardProvider/index.js.map +1 -1
  148. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +3 -6
  149. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  150. package/dist/context/DashboardProvider/panel-editor-slice.js +9 -33
  151. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  152. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +15 -0
  153. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -0
  154. package/dist/context/DashboardProvider/save-changes-dialog-slice.js +27 -0
  155. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -0
  156. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +10 -0
  157. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  158. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +51 -7
  159. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  160. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -1
  161. package/dist/context/TemplateVariableProvider/hydrationUtils.js +2 -0
  162. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -1
  163. package/dist/context/TemplateVariableProvider/utils.d.ts +7 -0
  164. package/dist/context/TemplateVariableProvider/utils.d.ts.map +1 -0
  165. package/dist/context/TemplateVariableProvider/utils.js +40 -0
  166. package/dist/context/TemplateVariableProvider/utils.js.map +1 -0
  167. package/dist/context/useDashboard.d.ts.map +1 -1
  168. package/dist/context/useDashboard.js +4 -4
  169. package/dist/context/useDashboard.js.map +1 -1
  170. package/dist/stories/decorators/WithDashboard.js.map +1 -1
  171. package/dist/stories/decorators/WithDatasourceStore.js +1 -46
  172. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
  173. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -1
  174. package/dist/stories/decorators/index.js +0 -4
  175. package/dist/stories/decorators/index.js.map +1 -1
  176. package/dist/test/datasource-provider.d.ts +6 -0
  177. package/dist/test/datasource-provider.d.ts.map +1 -0
  178. package/dist/test/datasource-provider.js +60 -0
  179. package/dist/test/datasource-provider.js.map +1 -0
  180. package/dist/test/index.d.ts +1 -0
  181. package/dist/test/index.d.ts.map +1 -1
  182. package/dist/test/index.js +1 -0
  183. package/dist/test/index.js.map +1 -1
  184. package/dist/test/plugin-registry.d.ts.map +1 -1
  185. package/dist/test/plugin-registry.js +11 -5
  186. package/dist/test/plugin-registry.js.map +1 -1
  187. package/dist/test/render.d.ts.map +1 -1
  188. package/dist/test/render.js +35 -13
  189. package/dist/test/render.js.map +1 -1
  190. package/dist/test/testDashboard.js +79 -79
  191. package/dist/test/testDashboard.js.map +1 -1
  192. package/dist/utils/index.d.ts +1 -0
  193. package/dist/utils/index.d.ts.map +1 -1
  194. package/dist/utils/index.js +1 -0
  195. package/dist/utils/index.js.map +1 -1
  196. package/dist/utils/time.d.ts +5 -0
  197. package/dist/utils/time.d.ts.map +1 -0
  198. package/dist/utils/time.js +23 -0
  199. package/dist/utils/time.js.map +1 -0
  200. package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -1
  201. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  202. package/dist/views/ViewDashboard/DashboardApp.js +3 -2
  203. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  204. package/package.json +7 -6
  205. package/dist/cjs/stories/decorators/WithPluginRegistry.js +0 -91
  206. package/dist/cjs/stories/decorators/WithTimeRange.js +0 -38
  207. package/dist/stories/decorators/WithPluginRegistry.js +0 -46
  208. package/dist/stories/decorators/WithPluginRegistry.js.map +0 -1
  209. package/dist/stories/decorators/WithQueryClient.js.map +0 -1
  210. package/dist/stories/decorators/WithQueryParams.js.map +0 -1
  211. package/dist/stories/decorators/WithTimeRange.js +0 -32
  212. package/dist/stories/decorators/WithTimeRange.js.map +0 -1
@@ -0,0 +1,87 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "usePanelEditor", {
18
+ enumerable: true,
19
+ get: ()=>usePanelEditor
20
+ });
21
+ const _react = require("react");
22
+ const usePanelEditor = (panelDefinition)=>{
23
+ const { display , plugin: pluginDefinition , queries: initialQueries } = panelDefinition.spec;
24
+ const [name, setName] = (0, _react.useState)(display.name);
25
+ const [description, setDescription] = (0, _react.useState)(display.description);
26
+ const [plugin, setPlugin] = (0, _react.useState)(pluginDefinition);
27
+ // need to keep track of prevQueries if switching from a panel with no queries (ex: markdown) to one with queries
28
+ const [prevQueries, setPrevQueries] = (0, _react.useState)(initialQueries);
29
+ const [currentQueries, setCurrentQueries] = (0, _react.useState)(initialQueries);
30
+ /**
31
+ * If hideQueryEditor is true, set panelDefinition.spec.queries to undefined.
32
+ * If hideQueryEditor is false and query is undefined, set panelDefinition.spec.queries to previous queries.
33
+ */ const setQueries = (0, _react.useCallback)((queries, hideQueryEditor)=>{
34
+ if (hideQueryEditor) {
35
+ setPrevQueries(currentQueries);
36
+ setCurrentQueries(undefined);
37
+ } else {
38
+ setCurrentQueries(queries === undefined ? prevQueries : queries);
39
+ }
40
+ }, [
41
+ setCurrentQueries,
42
+ currentQueries,
43
+ setPrevQueries,
44
+ prevQueries
45
+ ]);
46
+ // reset panel definition
47
+ const setPanelDefinition = (0, _react.useCallback)((panelDefinition)=>{
48
+ const { display , plugin , queries } = panelDefinition.spec;
49
+ setName(display.name);
50
+ setDescription(display.description);
51
+ setPlugin(plugin);
52
+ setQueries(queries);
53
+ }, [
54
+ setName,
55
+ setDescription,
56
+ setPlugin,
57
+ setQueries
58
+ ]);
59
+ return (0, _react.useMemo)(()=>({
60
+ panelDefinition: {
61
+ kind: 'Panel',
62
+ spec: {
63
+ display: {
64
+ name,
65
+ description
66
+ },
67
+ plugin,
68
+ queries: currentQueries
69
+ }
70
+ },
71
+ setName,
72
+ setDescription,
73
+ setQueries,
74
+ setPlugin,
75
+ setPanelDefinition
76
+ }), [
77
+ name,
78
+ description,
79
+ plugin,
80
+ currentQueries,
81
+ setName,
82
+ setDescription,
83
+ setQueries,
84
+ setPlugin,
85
+ setPanelDefinition
86
+ ]);
87
+ };
@@ -0,0 +1,92 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "SaveChangesConfirmationDialog", {
18
+ enumerable: true,
19
+ get: ()=>SaveChangesConfirmationDialog
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _pluginSystem = require("@perses-dev/plugin-system");
25
+ const _core = require("@perses-dev/core");
26
+ const _components = require("@perses-dev/components");
27
+ const _context = require("../../context");
28
+ const SaveChangesConfirmationDialog = ()=>{
29
+ const [saveDefaultTimeRange, setSaveDefaultTimeRange] = (0, _react.useState)(true);
30
+ const [saveDefaultVariables, setSaveDefaultVariables] = (0, _react.useState)(true);
31
+ const { getSavedVariablesStatus } = (0, _context.useTemplateVariableActions)();
32
+ const { isSavedVariableModified , modifiedVariableNames } = getSavedVariablesStatus();
33
+ const { saveChangesConfirmationDialog: dialog } = (0, _context.useSaveChangesConfirmationDialog)();
34
+ const isOpen = dialog !== undefined;
35
+ const { timeRange } = (0, _pluginSystem.useTimeRange)();
36
+ const currentTimeRangeText = (0, _core.isRelativeTimeRange)(timeRange) ? `(Last ${timeRange.pastDuration})` : '(Absolute time ranges can not be saved)';
37
+ const saveTimeRangeText = `Save current time range as new default ${currentTimeRangeText}`;
38
+ const saveVariablesText = `Save current variable values as new default (${modifiedVariableNames.length > 0 ? modifiedVariableNames.join(', ') : 'No modified variables'})`;
39
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog, {
40
+ open: isOpen,
41
+ children: dialog !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
42
+ children: [
43
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog.Header, {
44
+ onClose: ()=>dialog.onCancel(),
45
+ children: "Save Dashboard"
46
+ }),
47
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_components.Dialog.Content, {
48
+ children: [
49
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
50
+ marginBottom: 2,
51
+ children: dialog.description || _core.SAVE_DEFAULTS_DIALOG_TEXT
52
+ }),
53
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormGroup, {
54
+ children: [
55
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
56
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Checkbox, {
57
+ disabled: !(0, _core.isRelativeTimeRange)(timeRange),
58
+ checked: saveDefaultTimeRange && (0, _core.isRelativeTimeRange)(timeRange),
59
+ onChange: (e)=>setSaveDefaultTimeRange(e.target.checked)
60
+ }),
61
+ label: saveTimeRangeText
62
+ }),
63
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
64
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Checkbox, {
65
+ disabled: !isSavedVariableModified,
66
+ checked: saveDefaultVariables && isSavedVariableModified,
67
+ onChange: (e)=>setSaveDefaultVariables(e.target.checked)
68
+ }),
69
+ label: saveVariablesText
70
+ })
71
+ ]
72
+ })
73
+ ]
74
+ }),
75
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_components.Dialog.Actions, {
76
+ children: [
77
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog.PrimaryButton, {
78
+ onClick: ()=>{
79
+ return dialog.onSaveChanges(saveDefaultTimeRange, saveDefaultVariables);
80
+ },
81
+ children: "Save Changes"
82
+ }),
83
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog.SecondaryButton, {
84
+ onClick: ()=>dialog.onCancel(),
85
+ children: "Cancel"
86
+ })
87
+ ]
88
+ })
89
+ ]
90
+ })
91
+ });
92
+ };
@@ -0,0 +1,28 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./SaveChangesConfirmationDialog"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -0,0 +1,81 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "SaveDashboardButton", {
18
+ enumerable: true,
19
+ get: ()=>SaveDashboardButton
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _core = require("@perses-dev/core");
25
+ const _pluginSystem = require("@perses-dev/plugin-system");
26
+ const _context = require("../../context");
27
+ const SaveDashboardButton = ({ onSave , isDisabled , variant ='contained' })=>{
28
+ const [isSavingDashboard, setSavingDashboard] = (0, _react.useState)(false);
29
+ const { dashboard , setDashboard } = (0, _context.useDashboard)();
30
+ const { getSavedVariablesStatus , setVariableDefaultValues } = (0, _context.useTemplateVariableActions)();
31
+ const { isSavedVariableModified } = getSavedVariablesStatus();
32
+ const { timeRange } = (0, _pluginSystem.useTimeRange)();
33
+ const { setEditMode } = (0, _context.useEditMode)();
34
+ const { openSaveChangesConfirmationDialog , closeSaveChangesConfirmationDialog } = (0, _context.useSaveChangesConfirmationDialog)();
35
+ const onSaveButtonClick = ()=>{
36
+ const isSavedDurationModified = (0, _core.isRelativeTimeRange)(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;
37
+ // Save dashboard if active timeRange from plugin-system is relative and different than currently saved
38
+ if (isSavedDurationModified || isSavedVariableModified) {
39
+ openSaveChangesConfirmationDialog({
40
+ onSaveChanges: (saveDefaultTimeRange, saveDefaultVariables)=>{
41
+ if ((0, _core.isRelativeTimeRange)(timeRange) && saveDefaultTimeRange === true) {
42
+ dashboard.spec.duration = timeRange.pastDuration;
43
+ }
44
+ if (saveDefaultVariables === true) {
45
+ const variables = setVariableDefaultValues();
46
+ dashboard.spec.variables = variables;
47
+ }
48
+ saveDashboard();
49
+ },
50
+ onCancel: ()=>{
51
+ closeSaveChangesConfirmationDialog();
52
+ }
53
+ });
54
+ } else {
55
+ saveDashboard();
56
+ }
57
+ };
58
+ const saveDashboard = async ()=>{
59
+ if (onSave) {
60
+ try {
61
+ setSavingDashboard(true);
62
+ await onSave(dashboard);
63
+ closeSaveChangesConfirmationDialog();
64
+ setEditMode(false);
65
+ setDashboard(dashboard);
66
+ } catch (error) {
67
+ throw new Error(`An error occurred while saving the dashboard. ${error}`);
68
+ } finally{
69
+ setSavingDashboard(false);
70
+ }
71
+ } else {
72
+ setEditMode(false);
73
+ }
74
+ };
75
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
76
+ variant: variant,
77
+ onClick: onSaveButtonClick,
78
+ disabled: isDisabled || isSavingDashboard,
79
+ children: "Save"
80
+ });
81
+ };
@@ -0,0 +1,28 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./SaveDashboardButton"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -98,17 +98,17 @@ const DEFAULT_HEIGHT = '34px';
98
98
  function TimeRangeControls({ heightPx , showRefresh =true }) {
99
99
  const { timeRange , setTimeRange , refresh } = (0, _pluginSystem.useTimeRange)();
100
100
  // TODO: Remove this since it couples to the dashboard context
101
- const defaultTimeRange = (0, _context.useDefaultTimeRange)();
101
+ const dashboardDuration = (0, _context.useDashboardDuration)();
102
102
  // Convert height to a string, then use the string for styling
103
103
  const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;
104
104
  // add time shortcut if one does not match duration from dashboard JSON
105
- if (!TIME_OPTIONS.some((option)=>option.value.pastDuration === defaultTimeRange.pastDuration)) {
106
- if ((0, _core.isDurationString)(defaultTimeRange.pastDuration)) {
105
+ if (!TIME_OPTIONS.some((option)=>option.value.pastDuration === dashboardDuration)) {
106
+ if ((0, _core.isDurationString)(dashboardDuration)) {
107
107
  TIME_OPTIONS.push({
108
108
  value: {
109
- pastDuration: defaultTimeRange.pastDuration
109
+ pastDuration: dashboardDuration
110
110
  },
111
- display: `Last ${defaultTimeRange.pastDuration}`
111
+ display: `Last ${dashboardDuration}`
112
112
  });
113
113
  }
114
114
  }