@perses-dev/dashboards 0.30.0 → 0.32.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.
- package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +5 -22
- package/dist/cjs/components/EditJsonButton/EditJsonButton.js +1 -0
- package/dist/cjs/components/GridLayout/GridTitle.js +30 -9
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +92 -0
- package/dist/cjs/components/SaveChangesConfirmationDialog/index.js +28 -0
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +80 -0
- package/dist/cjs/components/SaveDashboardButton/index.js +28 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +123 -197
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/cjs/components/Variables/index.js +1 -0
- package/dist/cjs/components/index.js +2 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +9 -0
- package/dist/cjs/context/DashboardProvider/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/save-changes-dialog-slice.js +33 -0
- package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +56 -7
- package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +2 -0
- package/dist/cjs/context/TemplateVariableProvider/utils.js +44 -0
- package/dist/cjs/test/render.js +35 -13
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +6 -23
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/EditJsonButton/EditJsonButton.js +1 -0
- package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +30 -9
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +3 -0
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -0
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +86 -0
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -0
- package/dist/components/SaveChangesConfirmationDialog/index.d.ts +2 -0
- package/dist/components/SaveChangesConfirmationDialog/index.d.ts.map +1 -0
- package/dist/components/SaveChangesConfirmationDialog/index.js +15 -0
- package/dist/components/SaveChangesConfirmationDialog/index.js.map +1 -0
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +10 -0
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -0
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +74 -0
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -0
- package/dist/components/SaveDashboardButton/index.d.ts +2 -0
- package/dist/components/SaveDashboardButton/index.d.ts.map +1 -0
- package/dist/components/SaveDashboardButton/index.js +15 -0
- package/dist/components/SaveDashboardButton/index.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -2
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +126 -195
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -0
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +2 -0
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +2 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +5 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +8 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +1 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js +1 -0
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +15 -0
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js +27 -0
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -0
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +10 -0
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +51 -7
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.js +2 -0
- package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -1
- package/dist/context/TemplateVariableProvider/utils.d.ts +7 -0
- package/dist/context/TemplateVariableProvider/utils.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/utils.js +40 -0
- package/dist/context/TemplateVariableProvider/utils.js.map +1 -0
- package/dist/stories/decorators/WithDashboard.js.map +1 -1
- package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
- package/dist/stories/decorators/WithTemplateVariables.js.map +1 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +35 -13
- package/dist/test/render.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +3 -2
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/package.json +7 -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
|
|
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)(
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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: ()=>
|
|
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:
|
|
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:
|
|
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,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,80 @@
|
|
|
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 = async ()=>{
|
|
59
|
+
if (onSave) {
|
|
60
|
+
try {
|
|
61
|
+
setSavingDashboard(true);
|
|
62
|
+
await onSave(dashboard);
|
|
63
|
+
closeSaveChangesConfirmationDialog();
|
|
64
|
+
setEditMode(false);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
throw new Error(`An error occurred while saving the dashboard. ${error}`);
|
|
67
|
+
} finally{
|
|
68
|
+
setSavingDashboard(false);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
setEditMode(false);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
75
|
+
variant: variant,
|
|
76
|
+
onClick: onSaveButtonClick,
|
|
77
|
+
disabled: isDisabled || isSavingDashboard,
|
|
78
|
+
children: "Save"
|
|
79
|
+
});
|
|
80
|
+
};
|
|
@@ -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
|
+
}
|