@perses-dev/dashboards 0.30.0 → 0.31.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 (93) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +5 -22
  2. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +1 -0
  3. package/dist/cjs/components/GridLayout/GridTitle.js +30 -9
  4. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +88 -0
  5. package/dist/cjs/components/SaveChangesConfirmationDialog/index.js +28 -0
  6. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +78 -0
  7. package/dist/cjs/components/SaveDashboardButton/index.js +28 -0
  8. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +123 -197
  9. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
  10. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
  11. package/dist/cjs/components/Variables/index.js +1 -0
  12. package/dist/cjs/components/index.js +1 -0
  13. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -0
  14. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +9 -0
  15. package/dist/cjs/context/DashboardProvider/save-changes-dialog-slice.js +33 -0
  16. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +56 -7
  17. package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +2 -0
  18. package/dist/cjs/context/TemplateVariableProvider/utils.js +37 -0
  19. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  20. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  21. package/dist/components/DashboardToolbar/DashboardToolbar.js +6 -23
  22. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  23. package/dist/components/EditJsonButton/EditJsonButton.js +1 -0
  24. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  25. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  26. package/dist/components/GridLayout/GridTitle.js +30 -9
  27. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  28. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +3 -0
  29. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -0
  30. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +82 -0
  31. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -0
  32. package/dist/components/SaveChangesConfirmationDialog/index.d.ts +2 -0
  33. package/dist/components/SaveChangesConfirmationDialog/index.d.ts.map +1 -0
  34. package/dist/components/SaveChangesConfirmationDialog/index.js +15 -0
  35. package/dist/components/SaveChangesConfirmationDialog/index.js.map +1 -0
  36. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +10 -0
  37. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -0
  38. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +72 -0
  39. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -0
  40. package/dist/components/SaveDashboardButton/index.d.ts +2 -0
  41. package/dist/components/SaveDashboardButton/index.d.ts.map +1 -0
  42. package/dist/components/SaveDashboardButton/index.js +15 -0
  43. package/dist/components/SaveDashboardButton/index.js.map +1 -0
  44. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -2
  45. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  46. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +126 -195
  47. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  48. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
  49. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
  50. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
  51. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
  52. package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
  53. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditorForm/index.js +1 -0
  55. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  56. package/dist/components/Variables/index.d.ts +1 -0
  57. package/dist/components/Variables/index.d.ts.map +1 -1
  58. package/dist/components/Variables/index.js +1 -0
  59. package/dist/components/Variables/index.js.map +1 -1
  60. package/dist/components/index.d.ts +1 -0
  61. package/dist/components/index.d.ts.map +1 -1
  62. package/dist/components/index.js +1 -0
  63. package/dist/components/index.js.map +1 -1
  64. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  65. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  66. package/dist/context/DashboardProvider/DashboardProvider.js +2 -0
  67. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  68. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +5 -0
  69. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  70. package/dist/context/DashboardProvider/dashboard-provider-api.js +8 -0
  71. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  72. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +15 -0
  73. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -0
  74. package/dist/context/DashboardProvider/save-changes-dialog-slice.js +27 -0
  75. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -0
  76. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +4 -0
  77. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  78. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +51 -7
  79. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  80. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -1
  81. package/dist/context/TemplateVariableProvider/hydrationUtils.js +2 -0
  82. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -1
  83. package/dist/context/TemplateVariableProvider/utils.d.ts +4 -0
  84. package/dist/context/TemplateVariableProvider/utils.d.ts.map +1 -0
  85. package/dist/context/TemplateVariableProvider/utils.js +33 -0
  86. package/dist/context/TemplateVariableProvider/utils.js.map +1 -0
  87. package/dist/stories/decorators/WithDashboard.js.map +1 -1
  88. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
  89. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -1
  90. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  91. package/dist/views/ViewDashboard/DashboardApp.js +3 -2
  92. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  93. package/package.json +6 -6
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "DashboardToolbar", {
19
19
  get: ()=>DashboardToolbar
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _react = require("react");
23
22
  const _material = require("@mui/material");
24
23
  const _components = require("@perses-dev/components");
25
24
  const _context = require("../../context");
@@ -30,31 +29,17 @@ const _timeRangeControls = require("../TimeRangeControls");
30
29
  const _variables = require("../Variables");
31
30
  const _editButton = require("../EditButton");
32
31
  const _editJsonButton = require("../EditJsonButton");
32
+ const _saveDashboardButton = require("../SaveDashboardButton");
33
33
  const _dashboardStickyToolbar = require("../DashboardStickyToolbar");
34
34
  const DashboardToolbar = (props)=>{
35
35
  const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , isReadonly , onEditButtonClick , onCancelButtonClick , onSave , } = props;
36
- const dashboard = (0, _context.useDashboard)();
37
- const { isEditMode , setEditMode } = (0, _context.useEditMode)();
36
+ const { isEditMode } = (0, _context.useEditMode)();
38
37
  const isBiggerThanMd = (0, _material.useMediaQuery)((0, _material.useTheme)().breakpoints.up('md'));
39
38
  const isBiggerThanSm = (0, _material.useMediaQuery)((0, _material.useTheme)().breakpoints.up('sm'));
40
- const [isSavingDashboard, setSavingDashboard] = (0, _react.useState)(false);
41
39
  const dashboardTitle = dashboardTitleComponent ? dashboardTitleComponent : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
42
40
  variant: "h2",
43
41
  children: dashboardName
44
42
  });
45
- const onSaveButtonClick = ()=>{
46
- if (onSave !== undefined) {
47
- setSavingDashboard(true);
48
- onSave(dashboard.dashboard).then(()=>{
49
- setSavingDashboard(false);
50
- setEditMode(false);
51
- }).catch(()=>{
52
- setSavingDashboard(false);
53
- });
54
- } else {
55
- setEditMode(false);
56
- }
57
- };
58
43
  const testId = 'dashboard-toolbar';
59
44
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
60
45
  children: isEditMode ? /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
@@ -82,11 +67,9 @@ const DashboardToolbar = (props)=>{
82
67
  },
83
68
  children: "Dashboard managed via code only. Download JSON and commit changes to save."
84
69
  }),
85
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
86
- variant: "contained",
87
- onClick: onSaveButtonClick,
88
- disabled: isReadonly || isSavingDashboard,
89
- children: "Save"
70
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_saveDashboardButton.SaveDashboardButton, {
71
+ onSave: onSave,
72
+ isDisabled: isReadonly
90
73
  }),
91
74
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
92
75
  variant: "outlined",
@@ -34,6 +34,7 @@ const EditJsonButton = ()=>{
34
34
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
35
35
  description: _constants.TOOLTIP_TEXT.editJson,
36
36
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_toolbarIconButton.ToolbarIconButton, {
37
+ "aria-label": _constants.TOOLTIP_TEXT.editJson,
37
38
  variant: "outlined",
38
39
  onClick: ()=>openEditJsonDialog(),
39
40
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_codeBraces.default, {})
@@ -42,24 +42,25 @@ function GridTitle(props) {
42
42
  const { isEditMode } = (0, _context.useEditMode)();
43
43
  const text = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
44
44
  variant: "h2",
45
- sx: {
46
- marginLeft: collapse !== undefined ? 1 : undefined
47
- },
48
45
  children: title
49
46
  });
50
47
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
48
+ onClick: collapse === null || collapse === void 0 ? void 0 : collapse.onToggleOpen,
51
49
  sx: {
52
50
  display: 'flex',
53
51
  justifyContent: 'start',
54
52
  alignItems: 'center',
55
53
  padding: (theme)=>theme.spacing(1),
54
+ cursor: collapse ? 'pointer' : 'auto',
56
55
  backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.paper : palette.background.default
57
56
  },
58
57
  "data-testid": "panel-group-header",
59
58
  children: collapse ? /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
60
59
  children: [
61
60
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
62
- onClick: collapse.onToggleOpen,
61
+ sx: {
62
+ marginRight: 1
63
+ },
63
64
  "aria-label": `${collapse.isOpen ? 'collapse' : 'expand'} group ${title}`,
64
65
  children: collapse.isOpen ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_chevronDown.default, {}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_chevronRight.default, {})
65
66
  }),
@@ -72,7 +73,11 @@ function GridTitle(props) {
72
73
  description: _constants.TOOLTIP_TEXT.addPanelToGroup,
73
74
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
74
75
  "aria-label": _constants.ARIA_LABEL_TEXT.addPanelToGroup(title),
75
- onClick: openAddPanel,
76
+ onClick: (e)=>{
77
+ // Don't trigger expand/collapse
78
+ e.stopPropagation();
79
+ openAddPanel();
80
+ },
76
81
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_chartBoxPlusOutline.default, {})
77
82
  })
78
83
  }),
@@ -80,7 +85,11 @@ function GridTitle(props) {
80
85
  description: _constants.TOOLTIP_TEXT.editGroup,
81
86
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
82
87
  "aria-label": _constants.ARIA_LABEL_TEXT.editGroup(title),
83
- onClick: openEditPanelGroup,
88
+ onClick: (e)=>{
89
+ // Don't trigger expand/collapse
90
+ e.stopPropagation();
91
+ openEditPanelGroup();
92
+ },
84
93
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencilOutline.default, {})
85
94
  })
86
95
  }),
@@ -88,7 +97,11 @@ function GridTitle(props) {
88
97
  description: _constants.TOOLTIP_TEXT.deleteGroup,
89
98
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
90
99
  "aria-label": _constants.ARIA_LABEL_TEXT.deleteGroup(title),
91
- onClick: ()=>openDeletePanelGroupDialog(panelGroupId),
100
+ onClick: (e)=>{
101
+ // Don't trigger expand/collapse
102
+ e.stopPropagation();
103
+ openDeletePanelGroupDialog(panelGroupId);
104
+ },
92
105
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_deleteOutline.default, {})
93
106
  })
94
107
  }),
@@ -97,7 +110,11 @@ function GridTitle(props) {
97
110
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
98
111
  "aria-label": _constants.ARIA_LABEL_TEXT.moveGroupDown(title),
99
112
  disabled: moveDown === undefined,
100
- onClick: moveDown,
113
+ onClick: (e)=>{
114
+ // Don't trigger expand/collapse
115
+ e.stopPropagation();
116
+ moveDown && moveDown();
117
+ },
101
118
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_arrowDown.default, {})
102
119
  })
103
120
  }),
@@ -106,7 +123,11 @@ function GridTitle(props) {
106
123
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
107
124
  "aria-label": _constants.ARIA_LABEL_TEXT.moveGroupUp(title),
108
125
  disabled: moveUp === undefined,
109
- onClick: moveUp,
126
+ onClick: (e)=>{
127
+ // Don't trigger expand/collapse
128
+ e.stopPropagation();
129
+ moveUp && moveUp();
130
+ },
110
131
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_arrowUp.default, {})
111
132
  })
112
133
  })
@@ -0,0 +1,88 @@
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 { saveChangesConfirmationDialog: dialog } = (0, _context.useSaveChangesConfirmationDialog)();
32
+ const isOpen = dialog !== undefined;
33
+ const { timeRange } = (0, _pluginSystem.useTimeRange)();
34
+ const currentTimeRangeText = (0, _core.isRelativeTimeRange)(timeRange) ? `(Last ${timeRange.pastDuration})` : '(Absolute time ranges can not be saved)';
35
+ const timeRangeInfoText = `Save current time range as new default ${currentTimeRangeText}`;
36
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog, {
37
+ open: isOpen,
38
+ children: dialog !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
39
+ children: [
40
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog.Header, {
41
+ onClose: ()=>dialog.onCancel(),
42
+ children: "Save Dashboard"
43
+ }),
44
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_components.Dialog.Content, {
45
+ children: [
46
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
47
+ marginBottom: 2,
48
+ children: dialog.description || _core.SAVE_DEFAULTS_DIALOG_TEXT
49
+ }),
50
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormGroup, {
51
+ children: [
52
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
53
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Checkbox, {
54
+ disabled: !(0, _core.isRelativeTimeRange)(timeRange),
55
+ checked: saveDefaultTimeRange && (0, _core.isRelativeTimeRange)(timeRange),
56
+ onChange: (e)=>setSaveDefaultTimeRange(e.target.checked)
57
+ }),
58
+ label: timeRangeInfoText
59
+ }),
60
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControlLabel, {
61
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Checkbox, {
62
+ checked: saveDefaultVariables,
63
+ onChange: (e)=>setSaveDefaultVariables(e.target.checked)
64
+ }),
65
+ label: "Save current variable values as new default."
66
+ })
67
+ ]
68
+ })
69
+ ]
70
+ }),
71
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_components.Dialog.Actions, {
72
+ children: [
73
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog.PrimaryButton, {
74
+ onClick: ()=>{
75
+ return dialog.onSaveChanges(saveDefaultTimeRange, saveDefaultVariables);
76
+ },
77
+ children: "Save Changes"
78
+ }),
79
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Dialog.SecondaryButton, {
80
+ onClick: ()=>dialog.onCancel(),
81
+ children: "Cancel"
82
+ })
83
+ ]
84
+ })
85
+ ]
86
+ })
87
+ });
88
+ };
@@ -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,78 @@
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 } = (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 = ()=>{
59
+ if (onSave !== undefined) {
60
+ setSavingDashboard(true);
61
+ onSave(dashboard).then(()=>{
62
+ setSavingDashboard(false);
63
+ closeSaveChangesConfirmationDialog();
64
+ setEditMode(false);
65
+ }).catch(()=>{
66
+ setSavingDashboard(false);
67
+ });
68
+ } else {
69
+ setEditMode(false);
70
+ }
71
+ };
72
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
73
+ variant: variant,
74
+ onClick: onSaveButtonClick,
75
+ disabled: isDisabled || isSavingDashboard,
76
+ children: "Save"
77
+ });
78
+ };
@@ -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
+ }