@perses-dev/dashboards 0.12.0 → 0.14.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/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
- package/dist/cjs/components/Dashboard/index.js +28 -0
- package/dist/cjs/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +15 -34
- package/dist/cjs/components/DashboardToolbar/index.js +28 -0
- package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +2 -3
- package/dist/cjs/components/DeletePanelDialog/index.js +28 -0
- package/dist/cjs/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
- package/dist/cjs/components/DeletePanelGroupDialog/index.js +28 -0
- package/dist/cjs/components/GridLayout/GridItemContent.js +11 -1
- package/dist/cjs/components/Panel/Panel.js +30 -89
- package/dist/cjs/components/Panel/Panel.test.js +93 -47
- package/dist/cjs/components/Panel/PanelHeader.js +116 -0
- package/dist/cjs/components/Panel/index.js +0 -1
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -2
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -15
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +7 -5
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
- package/dist/cjs/components/PanelGroupDialog/index.js +0 -1
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
- package/dist/cjs/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +67 -0
- package/dist/cjs/components/UnsavedChangesConfirmationDialog/index.js +28 -0
- package/dist/cjs/components/Variables/Variable.js +18 -11
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +24 -18
- package/dist/cjs/context/DashboardProvider/common.js +1 -1
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +2 -4
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +47 -52
- package/dist/cjs/context/DashboardProvider/panel-slice.js +2 -13
- package/dist/cjs/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
- package/dist/cjs/context/TemplateVariableProvider/index.js +28 -0
- package/dist/cjs/context/TemplateVariableProvider/query-params.js +79 -0
- package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +82 -0
- package/dist/cjs/context/index.js +1 -1
- package/dist/cjs/context/{useDashboardSpec.js → useDashboard.js} +20 -16
- package/dist/cjs/test/plugin-registry.js +14 -54
- package/dist/cjs/test/render.js +6 -2
- package/dist/cjs/utils/component-ids.js +31 -0
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +42 -11
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +4 -3
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/components/{Dashboard.d.ts → Dashboard/Dashboard.d.ts} +0 -0
- package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
- package/dist/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
- package/dist/components/Dashboard/Dashboard.js.map +1 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/index.d.ts.map +1 -0
- package/dist/components/Dashboard/index.js +15 -0
- package/dist/components/Dashboard/index.js.map +1 -0
- package/dist/components/{DashboardToolbar.d.ts → DashboardToolbar/DashboardToolbar.d.ts} +3 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
- package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +11 -30
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -0
- package/dist/components/DashboardToolbar/index.d.ts +2 -0
- package/dist/components/DashboardToolbar/index.d.ts.map +1 -0
- package/dist/components/DashboardToolbar/index.js +15 -0
- package/dist/components/DashboardToolbar/index.js.map +1 -0
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +3 -0
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +1 -2
- package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -0
- package/dist/components/DeletePanelDialog/index.d.ts +2 -0
- package/dist/components/DeletePanelDialog/index.d.ts.map +1 -0
- package/dist/components/DeletePanelDialog/index.js +15 -0
- package/dist/components/DeletePanelDialog/index.js.map +1 -0
- package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.d.ts +0 -0
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- package/dist/components/DeletePanelGroupDialog/index.d.ts +2 -0
- package/dist/components/DeletePanelGroupDialog/index.d.ts.map +1 -0
- package/dist/components/DeletePanelGroupDialog/index.js +15 -0
- package/dist/components/DeletePanelGroupDialog/index.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +12 -2
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +3 -3
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +32 -91
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +95 -49
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts +16 -0
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -0
- package/dist/components/Panel/PanelHeader.js +105 -0
- package/dist/components/Panel/PanelHeader.js.map +1 -0
- package/dist/components/Panel/index.d.ts +0 -1
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +0 -1
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +1 -2
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +10 -16
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +8 -6
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/PanelGroupDialog/index.d.ts +0 -1
- package/dist/components/PanelGroupDialog/index.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/index.js +0 -1
- package/dist/components/PanelGroupDialog/index.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts +8 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +56 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts +2 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.js +15 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +19 -12
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -4
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +26 -20
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +1 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +1 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +2 -4
- 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.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -15
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +38 -49
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +0 -9
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.js +2 -13
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
- package/dist/context/{TemplateVariableProvider.d.ts → TemplateVariableProvider/TemplateVariableProvider.d.ts} +0 -0
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider/index.d.ts +2 -0
- package/dist/context/TemplateVariableProvider/index.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/index.js +15 -0
- package/dist/context/TemplateVariableProvider/index.js.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.d.ts +12 -0
- package/dist/context/TemplateVariableProvider/query-params.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.js +64 -0
- package/dist/context/TemplateVariableProvider/query-params.js.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts +2 -0
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.test.js +80 -0
- package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts +6 -0
- package/dist/context/useDashboard.d.ts.map +1 -0
- package/dist/context/{useDashboardSpec.js → useDashboard.js} +19 -15
- package/dist/context/useDashboard.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -11
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +12 -49
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +6 -2
- package/dist/test/render.js.map +1 -1
- package/dist/utils/component-ids.d.ts +8 -0
- package/dist/utils/component-ids.d.ts.map +1 -0
- package/dist/utils/component-ids.js +27 -0
- package/dist/utils/component-ids.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +42 -6
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +4 -3
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +5 -4
- package/dist/components/Dashboard.d.ts.map +0 -1
- package/dist/components/Dashboard.js.map +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +0 -1
- package/dist/components/DashboardToolbar.js.map +0 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +0 -4
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +0 -1
- package/dist/components/Panel/DeletePanelDialog.js.map +0 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +0 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +0 -1
- package/dist/context/TemplateVariableProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider.js.map +0 -1
- package/dist/context/useDashboardSpec.d.ts +0 -11
- package/dist/context/useDashboardSpec.d.ts.map +0 -1
- package/dist/context/useDashboardSpec.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright 2022 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, "PanelHeader", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PanelHeader
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _components = require("@perses-dev/components");
|
|
24
|
+
const _informationOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/InformationOutline"));
|
|
25
|
+
const _pencilOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PencilOutline"));
|
|
26
|
+
const _deleteOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DeleteOutline"));
|
|
27
|
+
const _dragVertical = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DragVertical"));
|
|
28
|
+
function _interopRequireDefault(obj) {
|
|
29
|
+
return obj && obj.__esModule ? obj : {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function PanelHeader({ id , title , description , editHandlers , isHovered , sx , ...rest }) {
|
|
34
|
+
const titleElementId = `${id}-title`;
|
|
35
|
+
const descriptionTooltipId = `${id}-description`;
|
|
36
|
+
// Don't show any actions unless panel is hovered
|
|
37
|
+
let action = undefined;
|
|
38
|
+
if (isHovered) {
|
|
39
|
+
if (editHandlers !== undefined) {
|
|
40
|
+
// If there are edit handlers, always just show the edit buttons
|
|
41
|
+
action = /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
42
|
+
direction: "row",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
spacing: 0.5,
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
|
|
47
|
+
"aria-label": "edit panel",
|
|
48
|
+
size: "small",
|
|
49
|
+
onClick: editHandlers.onEditPanelClick,
|
|
50
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencilOutline.default, {})
|
|
51
|
+
}),
|
|
52
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
|
|
53
|
+
"aria-label": "delete panel",
|
|
54
|
+
size: "small",
|
|
55
|
+
onClick: editHandlers.onDeletePanelClick,
|
|
56
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_deleteOutline.default, {})
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
|
|
59
|
+
"aria-label": "drag handle",
|
|
60
|
+
size: "small",
|
|
61
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dragVertical.default, {
|
|
62
|
+
className: "drag-handle",
|
|
63
|
+
sx: {
|
|
64
|
+
cursor: 'grab'
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
} else if (description !== undefined) {
|
|
71
|
+
// If there aren't edit handlers and we have a description, show a button with a tooltip for the panel description
|
|
72
|
+
action = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
|
|
73
|
+
id: descriptionTooltipId,
|
|
74
|
+
description: description,
|
|
75
|
+
placement: _components.TooltipPlacement.Bottom,
|
|
76
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
|
|
77
|
+
"aria-label": "Panel Description",
|
|
78
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_informationOutline.default, {
|
|
79
|
+
"aria-describedby": "info-tooltip",
|
|
80
|
+
"aria-hidden": false,
|
|
81
|
+
sx: {
|
|
82
|
+
color: (theme)=>theme.palette.grey[700]
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.CardHeader, {
|
|
90
|
+
id: id,
|
|
91
|
+
component: "header",
|
|
92
|
+
"aria-labelledby": titleElementId,
|
|
93
|
+
"aria-describedby": descriptionTooltipId,
|
|
94
|
+
disableTypography: true,
|
|
95
|
+
title: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
96
|
+
id: titleElementId,
|
|
97
|
+
variant: "subtitle1",
|
|
98
|
+
sx: {
|
|
99
|
+
whiteSpace: 'nowrap',
|
|
100
|
+
overflow: 'hidden',
|
|
101
|
+
textOverflow: 'ellipsis'
|
|
102
|
+
},
|
|
103
|
+
children: title
|
|
104
|
+
}),
|
|
105
|
+
action: action,
|
|
106
|
+
sx: (0, _components.combineSx)((theme)=>({
|
|
107
|
+
padding: theme.spacing(1),
|
|
108
|
+
borderBottom: `solid 1px ${theme.palette.divider}`
|
|
109
|
+
}), sx),
|
|
110
|
+
...rest
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const HeaderIconButton = (0, _material.styled)(_material.IconButton)(({ theme })=>({
|
|
114
|
+
borderRadius: theme.shape.borderRadius,
|
|
115
|
+
padding: '4px'
|
|
116
|
+
}));
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./Panel"), exports);
|
|
18
|
-
_exportStar(require("./DeletePanelDialog"), exports);
|
|
19
18
|
function _exportStar(from, to) {
|
|
20
19
|
Object.keys(from).forEach(function(k) {
|
|
21
20
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -56,8 +56,7 @@ const PanelDrawer = ()=>{
|
|
|
56
56
|
sx: {
|
|
57
57
|
display: 'flex',
|
|
58
58
|
alignItems: 'center',
|
|
59
|
-
|
|
60
|
-
paddingBottom: (theme)=>theme.spacing(2),
|
|
59
|
+
padding: (theme)=>theme.spacing(1, 2),
|
|
61
60
|
borderBottom: (theme)=>`1px solid ${theme.palette.grey[100]}`
|
|
62
61
|
},
|
|
63
62
|
children: [
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
19
18
|
const _react = require("@testing-library/react");
|
|
20
19
|
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
21
20
|
const _testUtils = require("react-dom/test-utils");
|
|
@@ -29,21 +28,16 @@ function _interopRequireDefault(obj) {
|
|
|
29
28
|
}
|
|
30
29
|
describe('Panel Drawer', ()=>{
|
|
31
30
|
const renderPanelDrawer = ()=>{
|
|
32
|
-
const { addMockPlugin , pluginRegistryProps } = (0, _test.mockPluginRegistryProps)();
|
|
33
|
-
addMockPlugin('Panel', 'TimeSeriesChart', _test.FAKE_PANEL_PLUGIN);
|
|
34
31
|
const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
|
|
35
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
|
|
45
|
-
]
|
|
46
|
-
})
|
|
32
|
+
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_dashboardProvider.DashboardProvider, {
|
|
33
|
+
initialState: {
|
|
34
|
+
dashboardResource: (0, _test.getTestDashboard)(),
|
|
35
|
+
isEditMode: true
|
|
36
|
+
},
|
|
37
|
+
children: [
|
|
38
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
|
|
39
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
|
|
40
|
+
]
|
|
47
41
|
}));
|
|
48
42
|
const { value: storeApi } = store;
|
|
49
43
|
if (storeApi === undefined) {
|
|
@@ -73,16 +73,18 @@ function PanelEditorForm(props) {
|
|
|
73
73
|
};
|
|
74
74
|
var _title, ref1;
|
|
75
75
|
return(// Grid maxHeight allows user to scroll inside Drawer to see all content
|
|
76
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
76
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
77
|
+
component: "form",
|
|
77
78
|
id: panelEditorFormId,
|
|
78
79
|
onSubmit: handleSubmit,
|
|
80
|
+
sx: {
|
|
81
|
+
flex: 1,
|
|
82
|
+
overflowY: 'scroll',
|
|
83
|
+
padding: (theme)=>theme.spacing(2)
|
|
84
|
+
},
|
|
79
85
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
|
|
80
86
|
container: true,
|
|
81
87
|
spacing: 2,
|
|
82
|
-
sx: {
|
|
83
|
-
overflowY: 'scroll',
|
|
84
|
-
maxHeight: '90vh'
|
|
85
|
-
},
|
|
86
88
|
children: [
|
|
87
89
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
88
90
|
item: true,
|
|
@@ -21,34 +21,27 @@ Object.defineProperty(exports, "PanelPreview", {
|
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _material = require("@mui/material");
|
|
23
23
|
const _panel = require("../Panel");
|
|
24
|
-
function PanelPreview({ name , description , kind , spec
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
spec
|
|
36
|
-
}
|
|
24
|
+
function PanelPreview({ name , description , kind , spec }) {
|
|
25
|
+
const definition = {
|
|
26
|
+
kind: 'Panel',
|
|
27
|
+
spec: {
|
|
28
|
+
display: {
|
|
29
|
+
name,
|
|
30
|
+
description: description === '' ? undefined : description
|
|
31
|
+
},
|
|
32
|
+
plugin: {
|
|
33
|
+
kind,
|
|
34
|
+
spec
|
|
37
35
|
}
|
|
38
|
-
},
|
|
39
|
-
// TODO: this shouldn't be necessary for preview
|
|
40
|
-
panelGroupItemId: {
|
|
41
|
-
panelGroupId: groupId,
|
|
42
|
-
panelGroupItemLayoutId: ''
|
|
43
36
|
}
|
|
44
37
|
};
|
|
45
|
-
if (
|
|
38
|
+
if (kind === '') {
|
|
46
39
|
return null;
|
|
47
40
|
}
|
|
48
41
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
49
42
|
height: 300,
|
|
50
43
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panel.Panel, {
|
|
51
|
-
|
|
44
|
+
definition: definition
|
|
52
45
|
})
|
|
53
46
|
});
|
|
54
47
|
}
|
|
@@ -31,7 +31,7 @@ describe('Add Panel Group', ()=>{
|
|
|
31
31
|
const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
|
|
32
32
|
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_context.DashboardProvider, {
|
|
33
33
|
initialState: {
|
|
34
|
-
|
|
34
|
+
dashboardResource: (0, _test.getTestDashboard)(),
|
|
35
35
|
isEditMode: true
|
|
36
36
|
},
|
|
37
37
|
children: [
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./PanelGroupDialog"), exports);
|
|
18
|
-
_exportStar(require("./DeletePanelGroupDialog"), exports);
|
|
19
18
|
function _exportStar(from, to) {
|
|
20
19
|
Object.keys(from).forEach(function(k) {
|
|
21
20
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
package/dist/cjs/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright 2022 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, "UnsavedChangesConfirmationDialog", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>UnsavedChangesConfirmationDialog
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _close = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Close"));
|
|
24
|
+
function _interopRequireDefault(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const UnsavedChangesConfirmationDialog = ({ isOpen , onSave , onClose })=>{
|
|
30
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Dialog, {
|
|
31
|
+
open: isOpen,
|
|
32
|
+
children: [
|
|
33
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogTitle, {
|
|
34
|
+
children: "Unsaved Changes"
|
|
35
|
+
}),
|
|
36
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
37
|
+
"aria-label": "Close",
|
|
38
|
+
onClick: onClose,
|
|
39
|
+
sx: (theme)=>({
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: theme.spacing(0.5),
|
|
42
|
+
right: theme.spacing(0.5)
|
|
43
|
+
}),
|
|
44
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_close.default, {})
|
|
45
|
+
}),
|
|
46
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogContent, {
|
|
47
|
+
sx: {
|
|
48
|
+
width: '500px'
|
|
49
|
+
},
|
|
50
|
+
children: "You have unsaved changes in this dashboard. Would you like to save these changes?"
|
|
51
|
+
}),
|
|
52
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.DialogActions, {
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
55
|
+
variant: "contained",
|
|
56
|
+
onClick: onSave,
|
|
57
|
+
children: "Save"
|
|
58
|
+
}),
|
|
59
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
60
|
+
onClick: onClose,
|
|
61
|
+
children: "Cancel"
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2022 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("./UnsavedChangesConfirmationDialog"), 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
|
+
}
|
|
@@ -75,14 +75,17 @@ function ListVariable({ name }) {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
const variablesValueKey = getVariableValuesKey(variables);
|
|
78
|
+
const { timeRange } = (0, _pluginSystem.useTimeRange)();
|
|
78
79
|
const variablesOptionsQuery = (0, _reactQuery.useQuery)([
|
|
79
80
|
name,
|
|
80
81
|
definition,
|
|
81
|
-
variablesValueKey
|
|
82
|
+
variablesValueKey,
|
|
83
|
+
timeRange
|
|
82
84
|
], async ()=>{
|
|
83
85
|
const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
|
|
84
86
|
datasourceStore,
|
|
85
|
-
variables
|
|
87
|
+
variables,
|
|
88
|
+
timeRange
|
|
86
89
|
}));
|
|
87
90
|
var ref;
|
|
88
91
|
return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
|
|
@@ -128,22 +131,26 @@ function ListVariable({ name }) {
|
|
|
128
131
|
options,
|
|
129
132
|
allowAllValue
|
|
130
133
|
]);
|
|
131
|
-
(0, _react.
|
|
132
|
-
const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
|
|
133
|
-
const valueIsInOptions = Boolean(finalOptions.find((v)=>{
|
|
134
|
+
const valueIsInOptions = (0, _react.useMemo)(()=>Boolean(finalOptions.find((v)=>{
|
|
134
135
|
if (allowMultiple) {
|
|
135
136
|
return value.includes(v.value);
|
|
136
137
|
}
|
|
137
138
|
return value === v.value;
|
|
138
|
-
}))
|
|
139
|
+
})), [
|
|
140
|
+
finalOptions,
|
|
141
|
+
value,
|
|
142
|
+
allowMultiple
|
|
143
|
+
]);
|
|
144
|
+
let selectValue = value;
|
|
145
|
+
if (!valueIsInOptions) {
|
|
146
|
+
selectValue = allowMultiple ? [] : '';
|
|
147
|
+
}
|
|
148
|
+
(0, _react.useEffect)(()=>{
|
|
149
|
+
const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
|
|
139
150
|
// If there is no value but there are options, set the value to the first option.
|
|
140
151
|
if (!value && firstOption) {
|
|
141
152
|
setVariableValue(name, firstOption.value);
|
|
142
153
|
}
|
|
143
|
-
// If there is a value but it's not in the options, select the first value or set to null
|
|
144
|
-
if (value && !valueIsInOptions && !definition.spec.default_value) {
|
|
145
|
-
setVariableValue(name, (firstOption === null || firstOption === void 0 ? void 0 : firstOption.value) || null);
|
|
146
|
-
}
|
|
147
154
|
}, [
|
|
148
155
|
finalOptions,
|
|
149
156
|
setVariableValue,
|
|
@@ -167,7 +174,7 @@ function ListVariable({ name }) {
|
|
|
167
174
|
},
|
|
168
175
|
id: name,
|
|
169
176
|
label: name,
|
|
170
|
-
value:
|
|
177
|
+
value: selectValue,
|
|
171
178
|
onChange: (e)=>{
|
|
172
179
|
// Must be selected
|
|
173
180
|
if (e.target.value === null || e.target.value.length === 0) {
|
|
@@ -15,11 +15,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./Dashboard"), exports);
|
|
18
|
+
_exportStar(require("./DashboardToolbar"), exports);
|
|
19
|
+
_exportStar(require("./DeletePanelDialog"), exports);
|
|
20
|
+
_exportStar(require("./DeletePanelGroupDialog"), exports);
|
|
18
21
|
_exportStar(require("./GridLayout"), exports);
|
|
19
22
|
_exportStar(require("./Panel"), exports);
|
|
20
23
|
_exportStar(require("./PanelDrawer"), exports);
|
|
21
24
|
_exportStar(require("./PanelGroupDialog"), exports);
|
|
22
25
|
_exportStar(require("./TimeRangeControls"), exports);
|
|
26
|
+
_exportStar(require("./UnsavedChangesConfirmationDialog"), exports);
|
|
23
27
|
_exportStar(require("./Variables"), exports);
|
|
24
28
|
function _exportStar(from, to) {
|
|
25
29
|
Object.keys(from).forEach(function(k) {
|
|
@@ -51,10 +51,20 @@ function useDashboardStore(selector) {
|
|
|
51
51
|
return (0, _zustand.useStore)(store, selector, _shallow.default);
|
|
52
52
|
}
|
|
53
53
|
function DashboardProvider(props) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const createDashboardStore = (0, _react.useCallback)(initStore, [
|
|
55
|
+
props
|
|
56
|
+
]);
|
|
57
|
+
const [store] = (0, _react.useState)(createDashboardStore(props)); // prevent calling createDashboardStore every time it rerenders
|
|
58
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardContext.Provider, {
|
|
59
|
+
value: store,
|
|
60
|
+
children: props.children
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function initStore(props) {
|
|
64
|
+
const { initialState: { dashboardResource , isEditMode } , } = props;
|
|
65
|
+
const { spec: { layouts , panels , duration } , metadata , } = dashboardResource;
|
|
66
|
+
const store = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
|
|
67
|
+
const [set] = args;
|
|
58
68
|
return {
|
|
59
69
|
...(0, _panelGroupSlice.createPanelGroupSlice)(layouts)(...args),
|
|
60
70
|
...(0, _panelSlice.createPanelSlice)(panels)(...args),
|
|
@@ -62,27 +72,23 @@ function DashboardProvider(props) {
|
|
|
62
72
|
...(0, _deletePanelGroupSlice.createDeletePanelGroupSlice)(...args),
|
|
63
73
|
...(0, _panelEditorSlice.createPanelEditorSlice)()(...args),
|
|
64
74
|
...(0, _deletePanelSlice.createDeletePanelSlice)()(...args),
|
|
75
|
+
metadata,
|
|
65
76
|
defaultTimeRange: {
|
|
66
|
-
pastDuration:
|
|
77
|
+
pastDuration: duration
|
|
67
78
|
},
|
|
68
79
|
isEditMode: !!isEditMode,
|
|
69
80
|
setEditMode: (isEditMode)=>set({
|
|
70
81
|
isEditMode
|
|
71
82
|
}),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
savePanels();
|
|
80
|
-
savePanelGroups();
|
|
83
|
+
setDashboard: ({ spec: { panels , layouts } })=>{
|
|
84
|
+
set((state)=>{
|
|
85
|
+
const { panelGroups , panelGroupOrder } = (0, _panelGroupSlice.convertLayoutsToPanelGroups)(layouts);
|
|
86
|
+
state.panels = panels;
|
|
87
|
+
state.panelGroups = panelGroups;
|
|
88
|
+
state.panelGroupOrder = panelGroupOrder;
|
|
89
|
+
});
|
|
81
90
|
}
|
|
82
91
|
};
|
|
83
92
|
})));
|
|
84
|
-
return
|
|
85
|
-
value: dashboardStore,
|
|
86
|
-
children: children
|
|
87
|
-
});
|
|
93
|
+
return store;
|
|
88
94
|
}
|
|
@@ -44,13 +44,11 @@ function useEditMode() {
|
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
46
|
function useDashboardActions() {
|
|
47
|
-
const
|
|
48
|
-
const reset = (0, _dashboardProvider.useDashboardStore)((store)=>store.reset);
|
|
47
|
+
const setDashboard = (0, _dashboardProvider.useDashboardStore)((store)=>store.setDashboard);
|
|
49
48
|
const openAddPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanelGroup);
|
|
50
49
|
const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
|
|
51
50
|
return {
|
|
52
|
-
|
|
53
|
-
reset,
|
|
51
|
+
setDashboard,
|
|
54
52
|
openAddPanelGroup,
|
|
55
53
|
openAddPanel: ()=>openAddPanel(undefined)
|
|
56
54
|
};
|
|
@@ -14,65 +14,24 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
createPanelGroupSlice: ()=>createPanelGroupSlice,
|
|
25
|
+
convertLayoutsToPanelGroups: ()=>convertLayoutsToPanelGroups
|
|
20
26
|
});
|
|
21
27
|
const _core = require("@perses-dev/core");
|
|
22
28
|
const _common = require("./common");
|
|
23
29
|
function createPanelGroupSlice(layouts) {
|
|
24
|
-
|
|
25
|
-
const panelGroups = {};
|
|
26
|
-
const panelGroupIdOrder = [];
|
|
27
|
-
for (const layout of layouts){
|
|
28
|
-
var ref, ref1, ref2;
|
|
29
|
-
const itemLayouts = [];
|
|
30
|
-
const itemPanelKeys = {};
|
|
31
|
-
// Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
|
|
32
|
-
for (const item of layout.spec.items){
|
|
33
|
-
const panelGroupLayoutId = (0, _common.generateId)().toString();
|
|
34
|
-
itemLayouts.push({
|
|
35
|
-
i: panelGroupLayoutId,
|
|
36
|
-
w: item.width,
|
|
37
|
-
h: item.height,
|
|
38
|
-
x: item.x,
|
|
39
|
-
y: item.y
|
|
40
|
-
});
|
|
41
|
-
itemPanelKeys[panelGroupLayoutId] = (0, _core.getPanelKeyFromRef)(item.content);
|
|
42
|
-
}
|
|
43
|
-
// Create the panel group and keep track of the ID order
|
|
44
|
-
const panelGroupId = (0, _common.generateId)();
|
|
45
|
-
panelGroups[panelGroupId] = {
|
|
46
|
-
id: panelGroupId,
|
|
47
|
-
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
48
|
-
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
49
|
-
itemLayouts,
|
|
50
|
-
itemPanelKeys
|
|
51
|
-
};
|
|
52
|
-
panelGroupIdOrder.push(panelGroupId);
|
|
53
|
-
}
|
|
30
|
+
const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
|
|
54
31
|
// Return the state creator function for Zustand
|
|
55
32
|
return (set)=>({
|
|
56
33
|
panelGroups,
|
|
57
|
-
panelGroupOrder
|
|
58
|
-
previousPanelGroupState: {
|
|
59
|
-
panelGroups,
|
|
60
|
-
panelGroupIdOrder
|
|
61
|
-
},
|
|
62
|
-
savePanelGroups () {
|
|
63
|
-
set((state)=>{
|
|
64
|
-
state.previousPanelGroupState = {
|
|
65
|
-
panelGroups: state.panelGroups,
|
|
66
|
-
panelGroupIdOrder: state.panelGroupOrder
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
resetPanelGroups () {
|
|
71
|
-
set((state)=>{
|
|
72
|
-
state.panelGroups = state.previousPanelGroupState.panelGroups;
|
|
73
|
-
state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
|
|
74
|
-
});
|
|
75
|
-
},
|
|
34
|
+
panelGroupOrder,
|
|
76
35
|
swapPanelGroups (x, y) {
|
|
77
36
|
set((state)=>{
|
|
78
37
|
if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
|
|
@@ -101,3 +60,39 @@ function createPanelGroupSlice(layouts) {
|
|
|
101
60
|
}
|
|
102
61
|
});
|
|
103
62
|
}
|
|
63
|
+
function convertLayoutsToPanelGroups(layouts) {
|
|
64
|
+
// Convert the initial layouts from the JSON
|
|
65
|
+
const panelGroups = {};
|
|
66
|
+
const panelGroupIdOrder = [];
|
|
67
|
+
for (const layout of layouts){
|
|
68
|
+
var ref, ref1, ref2;
|
|
69
|
+
const itemLayouts = [];
|
|
70
|
+
const itemPanelKeys = {};
|
|
71
|
+
// Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
|
|
72
|
+
for (const item of layout.spec.items){
|
|
73
|
+
const panelGroupLayoutId = (0, _common.generateId)().toString();
|
|
74
|
+
itemLayouts.push({
|
|
75
|
+
i: panelGroupLayoutId,
|
|
76
|
+
w: item.width,
|
|
77
|
+
h: item.height,
|
|
78
|
+
x: item.x,
|
|
79
|
+
y: item.y
|
|
80
|
+
});
|
|
81
|
+
itemPanelKeys[panelGroupLayoutId] = (0, _core.getPanelKeyFromRef)(item.content);
|
|
82
|
+
}
|
|
83
|
+
// Create the panel group and keep track of the ID order
|
|
84
|
+
const panelGroupId = (0, _common.generateId)();
|
|
85
|
+
panelGroups[panelGroupId] = {
|
|
86
|
+
id: panelGroupId,
|
|
87
|
+
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
88
|
+
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
89
|
+
itemLayouts,
|
|
90
|
+
itemPanelKeys
|
|
91
|
+
};
|
|
92
|
+
panelGroupIdOrder.push(panelGroupId);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
panelGroups,
|
|
96
|
+
panelGroupOrder: panelGroupIdOrder
|
|
97
|
+
};
|
|
98
|
+
}
|