@perses-dev/dashboards 0.15.0 → 0.16.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 +2 -0
- package/dist/cjs/components/DownloadButton/DownloadButton.js +109 -0
- package/dist/cjs/{utils/component-ids.js → components/DownloadButton/index.js} +11 -14
- package/dist/cjs/components/GridLayout/GridTitle.js +8 -12
- package/dist/cjs/components/Panel/Panel.js +4 -2
- package/dist/cjs/components/Panel/PanelHeader.js +54 -50
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +23 -0
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +3 -1
- package/dist/cjs/components/Variables/Variable.js +5 -0
- package/dist/cjs/components/Variables/VariableEditor.js +20 -1
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +61 -5
- package/dist/cjs/components/Variables/VariableList.js +5 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +40 -15
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +5 -9
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -1
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +15 -21
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +2 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/DownloadButton/DownloadButton.d.ts +3 -0
- package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -0
- package/dist/components/DownloadButton/DownloadButton.js +60 -0
- package/dist/components/DownloadButton/DownloadButton.js.map +1 -0
- package/dist/components/DownloadButton/index.d.ts +2 -0
- package/dist/components/DownloadButton/index.d.ts.map +1 -0
- package/dist/{utils/component-ids.js → components/DownloadButton/index.js} +2 -14
- package/dist/components/DownloadButton/index.js.map +1 -0
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +8 -12
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +4 -2
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +54 -50
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +23 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +4 -2
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/Variables/Variable.js +5 -0
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +22 -3
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +23 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableList.js +5 -0
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +40 -15
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +5 -9
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +9 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +17 -0
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +15 -21
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +4 -4
- package/dist/utils/component-ids.d.ts +0 -8
- package/dist/utils/component-ids.d.ts.map +0 -1
- package/dist/utils/component-ids.js.map +0 -1
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "createPanelEditorSlice", {
|
|
|
20
20
|
});
|
|
21
21
|
const _functions = require("../../utils/functions");
|
|
22
22
|
const _common = require("./common");
|
|
23
|
+
const _panelGroupSlice = require("./panel-group-slice");
|
|
23
24
|
function createPanelEditorSlice() {
|
|
24
25
|
// Return the state creator function for Zustand that uses the panels provided as intitial state
|
|
25
26
|
return (set, get)=>{
|
|
@@ -51,14 +52,14 @@ function createPanelEditorSlice() {
|
|
|
51
52
|
},
|
|
52
53
|
applyChanges: (next)=>{
|
|
53
54
|
const panelDefinititon = createPanelDefinitionFromEditorValues(next);
|
|
54
|
-
set((
|
|
55
|
-
|
|
55
|
+
set((state)=>{
|
|
56
|
+
state.panels[panelKey] = panelDefinititon;
|
|
56
57
|
// If the panel didn't change groups, nothing else to do
|
|
57
58
|
if (next.groupId === panelGroupId) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
// Move panel to the new group
|
|
61
|
-
const existingGroup =
|
|
62
|
+
const existingGroup = state.panelGroups[panelGroupId];
|
|
62
63
|
if (existingGroup === undefined) {
|
|
63
64
|
throw new Error(`Missing panel group ${panelGroupId}`);
|
|
64
65
|
}
|
|
@@ -72,7 +73,7 @@ function createPanelEditorSlice() {
|
|
|
72
73
|
existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
|
|
73
74
|
delete existingGroup.itemPanelKeys[panelGroupLayoutId];
|
|
74
75
|
// Add item to the end of the new group
|
|
75
|
-
const newGroup =
|
|
76
|
+
const newGroup = state.panelGroups[next.groupId];
|
|
76
77
|
if (newGroup === undefined) {
|
|
77
78
|
throw new Error(`Could not find new group ${next.groupId}`);
|
|
78
79
|
}
|
|
@@ -98,13 +99,13 @@ function createPanelEditorSlice() {
|
|
|
98
99
|
});
|
|
99
100
|
},
|
|
100
101
|
openAddPanel (panelGroupId) {
|
|
101
|
-
// If a panel group isn't supplied, add to the first group
|
|
102
|
+
// If a panel group isn't supplied, add to the first group or create a group if there aren't any
|
|
103
|
+
let newGroup = undefined;
|
|
104
|
+
panelGroupId !== null && panelGroupId !== void 0 ? panelGroupId : panelGroupId = get().panelGroupOrder[0];
|
|
102
105
|
if (panelGroupId === undefined) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
panelGroupId = firstGroupId;
|
|
106
|
+
newGroup = (0, _panelGroupSlice.createEmptyPanelGroup)();
|
|
107
|
+
newGroup.title = 'Panel Group';
|
|
108
|
+
panelGroupId = newGroup.id;
|
|
108
109
|
}
|
|
109
110
|
const editorState = {
|
|
110
111
|
mode: 'Add',
|
|
@@ -119,12 +120,17 @@ function createPanelEditorSlice() {
|
|
|
119
120
|
},
|
|
120
121
|
applyChanges: (next)=>{
|
|
121
122
|
const panelDef = createPanelDefinitionFromEditorValues(next);
|
|
122
|
-
const
|
|
123
|
-
|
|
123
|
+
const uniquePanelKeys = getUniquePanelKeys(get().panels);
|
|
124
|
+
let panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
|
|
125
|
+
// append count if panel key already exists
|
|
126
|
+
if (uniquePanelKeys[panelKey]) {
|
|
127
|
+
panelKey += `-${uniquePanelKeys[panelKey]}`;
|
|
128
|
+
}
|
|
129
|
+
set((state)=>{
|
|
124
130
|
// Add a panel
|
|
125
|
-
|
|
131
|
+
state.panels[panelKey] = panelDef;
|
|
126
132
|
// Also add a panel group item referencing the panel
|
|
127
|
-
const group =
|
|
133
|
+
const group = state.panelGroups[next.groupId];
|
|
128
134
|
if (group === undefined) {
|
|
129
135
|
throw new Error(`Missing panel group ${next.groupId}`);
|
|
130
136
|
}
|
|
@@ -145,8 +151,12 @@ function createPanelEditorSlice() {
|
|
|
145
151
|
});
|
|
146
152
|
}
|
|
147
153
|
};
|
|
148
|
-
// Open the editor with the new state
|
|
149
154
|
set((state)=>{
|
|
155
|
+
// Add the new panel group if one was created for the panel
|
|
156
|
+
if (newGroup !== undefined) {
|
|
157
|
+
(0, _panelGroupSlice.addPanelGroup)(state, newGroup);
|
|
158
|
+
}
|
|
159
|
+
// Open the editor with the new state
|
|
150
160
|
state.panelEditor = editorState;
|
|
151
161
|
});
|
|
152
162
|
}
|
|
@@ -180,3 +190,18 @@ function getYForNewRow(group) {
|
|
|
180
190
|
}
|
|
181
191
|
return newRowY;
|
|
182
192
|
}
|
|
193
|
+
// Find all the unique panel keys
|
|
194
|
+
// ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
|
|
195
|
+
function getUniquePanelKeys(panels) {
|
|
196
|
+
const uniquePanelKeys = {};
|
|
197
|
+
Object.keys(panels).forEach((panelKey)=>{
|
|
198
|
+
const key = panelKey.replace(/-([0-9]+)/, '');
|
|
199
|
+
const count = uniquePanelKeys[key];
|
|
200
|
+
if (count) {
|
|
201
|
+
uniquePanelKeys[key] = count + 1;
|
|
202
|
+
} else {
|
|
203
|
+
uniquePanelKeys[key] = 1;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return uniquePanelKeys;
|
|
207
|
+
}
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "createPanelGroupEditorSlice", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>createPanelGroupEditorSlice
|
|
20
20
|
});
|
|
21
|
-
const
|
|
21
|
+
const _panelGroupSlice = require("./panel-group-slice");
|
|
22
22
|
const createPanelGroupEditorSlice = (set, get)=>({
|
|
23
23
|
panelGroupEditor: undefined,
|
|
24
24
|
openAddPanelGroup: ()=>{
|
|
@@ -30,15 +30,11 @@ const createPanelGroupEditorSlice = (set, get)=>({
|
|
|
30
30
|
isCollapsed: false
|
|
31
31
|
},
|
|
32
32
|
applyChanges (next) {
|
|
33
|
-
const newGroup =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
itemPanelKeys: {},
|
|
37
|
-
...next
|
|
38
|
-
};
|
|
33
|
+
const newGroup = (0, _panelGroupSlice.createEmptyPanelGroup)();
|
|
34
|
+
newGroup.title = next.title;
|
|
35
|
+
newGroup.isCollapsed = next.isCollapsed;
|
|
39
36
|
set((draft)=>{
|
|
40
|
-
draft
|
|
41
|
-
draft.panelGroupOrder.unshift(newGroup.id);
|
|
37
|
+
(0, _panelGroupSlice.addPanelGroup)(draft, newGroup);
|
|
42
38
|
});
|
|
43
39
|
},
|
|
44
40
|
close () {
|
|
@@ -22,7 +22,9 @@ function _export(target, all) {
|
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
24
|
createPanelGroupSlice: ()=>createPanelGroupSlice,
|
|
25
|
-
convertLayoutsToPanelGroups: ()=>convertLayoutsToPanelGroups
|
|
25
|
+
convertLayoutsToPanelGroups: ()=>convertLayoutsToPanelGroups,
|
|
26
|
+
createEmptyPanelGroup: ()=>createEmptyPanelGroup,
|
|
27
|
+
addPanelGroup: ()=>addPanelGroup
|
|
26
28
|
});
|
|
27
29
|
const _core = require("@perses-dev/core");
|
|
28
30
|
const _common = require("./common");
|
|
@@ -96,3 +98,16 @@ function convertLayoutsToPanelGroups(layouts) {
|
|
|
96
98
|
panelGroupOrder: panelGroupIdOrder
|
|
97
99
|
};
|
|
98
100
|
}
|
|
101
|
+
function createEmptyPanelGroup() {
|
|
102
|
+
return {
|
|
103
|
+
id: (0, _common.generateId)(),
|
|
104
|
+
title: undefined,
|
|
105
|
+
isCollapsed: false,
|
|
106
|
+
itemLayouts: [],
|
|
107
|
+
itemPanelKeys: {}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function addPanelGroup(draft, newGroup) {
|
|
111
|
+
draft.panelGroups[newGroup.id] = newGroup;
|
|
112
|
+
draft.panelGroupOrder.unshift(newGroup.id);
|
|
113
|
+
}
|
|
@@ -46,45 +46,40 @@ describe('Panel Groups', ()=>{
|
|
|
46
46
|
};
|
|
47
47
|
it('should delete panel', ()=>{
|
|
48
48
|
renderDashboard();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const deletePanelButton = _react.screen.getByLabelText('delete panel');
|
|
49
|
+
const panelTitle = 'CPU';
|
|
50
|
+
const deletePanelButton = _react.screen.getByLabelText(`delete panel ${panelTitle}`);
|
|
52
51
|
_userEvent.default.click(deletePanelButton);
|
|
53
52
|
_react.screen.getByText('Delete Panel');
|
|
54
53
|
const deleteButton = _react.screen.getByText('Delete');
|
|
55
54
|
_userEvent.default.click(deleteButton);
|
|
56
55
|
// The panel should disappear
|
|
57
|
-
const deletedPanel = _react.screen.queryByText(
|
|
56
|
+
const deletedPanel = _react.screen.queryByText(panelTitle);
|
|
58
57
|
expect(deletedPanel).not.toBeInTheDocument();
|
|
59
58
|
});
|
|
60
59
|
it('should only delete panel from panel group if panel is not referenced more than once', ()=>{
|
|
61
60
|
renderDashboard();
|
|
62
|
-
const
|
|
61
|
+
const panelTitle = 'Disk I/O Utilization';
|
|
62
|
+
const panels = _react.screen.getAllByText(panelTitle);
|
|
63
63
|
expect(panels).toHaveLength(2);
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
_userEvent.default.hover(panel);
|
|
67
|
-
const deletePanelButton = _react.screen.getByLabelText('delete panel');
|
|
64
|
+
const deletePanelButton = _react.screen.getAllByLabelText(`delete panel ${panelTitle}`)[0];
|
|
65
|
+
if (deletePanelButton === undefined) throw new Error('Missing delete button');
|
|
68
66
|
_userEvent.default.click(deletePanelButton);
|
|
69
67
|
_react.screen.getByText('Delete Panel');
|
|
70
68
|
const deleteButton = _react.screen.getByText('Delete');
|
|
71
69
|
_userEvent.default.click(deleteButton);
|
|
72
70
|
// The deleted panel should still be on screen in the other group
|
|
73
|
-
const deletedPanel = _react.screen.queryByText(
|
|
71
|
+
const deletedPanel = _react.screen.queryByText(panelTitle);
|
|
74
72
|
expect(deletedPanel).toBeInTheDocument();
|
|
75
73
|
});
|
|
76
74
|
it('should swap panels', ()=>{
|
|
77
75
|
renderDashboard();
|
|
78
76
|
// should move panel down
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const moveGroupDownBtn = _react.screen.getByLabelText('move group down');
|
|
77
|
+
const groupTitle1 = 'CPU Stats';
|
|
78
|
+
const moveGroupDownBtn = _react.screen.getByLabelText(`move group ${groupTitle1} down`);
|
|
82
79
|
_userEvent.default.click(moveGroupDownBtn);
|
|
83
|
-
_userEvent.default.unhover(moveGroupDownBtn);
|
|
84
80
|
// should move panel up
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const moveGroupUpBtn = _react.screen.getByLabelText('move group up');
|
|
81
|
+
const groupTitle2 = 'Disk Stats';
|
|
82
|
+
const moveGroupUpBtn = _react.screen.getByLabelText(`move group ${groupTitle2} up`);
|
|
88
83
|
_userEvent.default.click(moveGroupUpBtn);
|
|
89
84
|
/* TODO: Figure out how to test this visually without coupling to the store
|
|
90
85
|
const layouts = storeApi.getState().layouts;
|
|
@@ -94,15 +89,14 @@ describe('Panel Groups', ()=>{
|
|
|
94
89
|
*/ });
|
|
95
90
|
it('should delete a panel group', ()=>{
|
|
96
91
|
renderDashboard();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const deleteGroupIcon = _react.screen.getByLabelText('delete group');
|
|
92
|
+
const groupTitle = 'CPU Stats';
|
|
93
|
+
const deleteGroupIcon = _react.screen.getByLabelText(`delete group ${groupTitle}`);
|
|
100
94
|
_userEvent.default.click(deleteGroupIcon);
|
|
101
95
|
_react.screen.getByText('Delete Panel Group');
|
|
102
96
|
const deleteButton = _react.screen.getByText('Delete');
|
|
103
97
|
_userEvent.default.click(deleteButton);
|
|
104
98
|
// should remove group
|
|
105
|
-
const deletedGroup = _react.screen.queryByText(
|
|
99
|
+
const deletedGroup = _react.screen.queryByText(groupTitle);
|
|
106
100
|
expect(deletedGroup).not.toBeInTheDocument();
|
|
107
101
|
// CPU panel should be completely gone since it wasn't in any other group
|
|
108
102
|
let panel = _react.screen.queryByText('CPU');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAuBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBAoF5D,CAAC"}
|
|
@@ -19,6 +19,7 @@ import { ErrorBoundary, ErrorAlert } from '@perses-dev/components';
|
|
|
19
19
|
import { useDashboardActions, useEditMode } from '../../context';
|
|
20
20
|
import { TemplateVariableList } from '../Variables';
|
|
21
21
|
import { TimeRangeControls } from '../TimeRangeControls';
|
|
22
|
+
import { DownloadButton } from '../DownloadButton';
|
|
22
23
|
export const DashboardToolbar = (props)=>{
|
|
23
24
|
const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , onEditButtonClick , onCancelButtonClick } = props;
|
|
24
25
|
const { isEditMode , setEditMode } = useEditMode();
|
|
@@ -122,6 +123,7 @@ export const DashboardToolbar = (props)=>{
|
|
|
122
123
|
},
|
|
123
124
|
children: [
|
|
124
125
|
/*#__PURE__*/ _jsx(TimeRangeControls, {}),
|
|
126
|
+
/*#__PURE__*/ _jsx(DownloadButton, {}),
|
|
125
127
|
isLaptopSize && /*#__PURE__*/ _jsx(Button, {
|
|
126
128
|
variant: "outlined",
|
|
127
129
|
startIcon: /*#__PURE__*/ _jsx(PencilIcon, {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Typography, Stack, Button, Box, useTheme, useMediaQuery } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport AddPanelGroupIcon from 'mdi-material-ui/PlusBoxOutline';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { useDashboardActions, useEditMode } from '../../context';\nimport { TemplateVariableList } from '../Variables';\nimport { TimeRangeControls } from '../TimeRangeControls';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const { dashboardName, dashboardTitleComponent, initialVariableIsSticky, onEditButtonClick, onCancelButtonClick } =\n props;\n\n const { isEditMode, setEditMode } = useEditMode();\n const { openAddPanelGroup, openAddPanel } = useDashboardActions();\n const isLaptopSize = useMediaQuery(useTheme().breakpoints.up('sm'));\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const onSave = () => {\n setEditMode(false);\n };\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={2}>\n <Box sx={{ backgroundColor: (theme) => theme.palette.primary.light + '20' }}>\n <Box padding={2} display=\"flex\">\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button variant=\"contained\" onClick={onSave}>\n Save\n </Button>\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'flex-start',\n padding: (theme) => theme.spacing(2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n <Stack direction={'row'} spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button startIcon={<AddPanelGroupIcon />} onClick={openAddPanelGroup}>\n Add Panel Group\n </Button>\n <Button startIcon={<AddPanelIcon />} onClick={openAddPanel}>\n Add Panel\n </Button>\n <TimeRangeControls />\n </Stack>\n </Box>\n </Stack>\n ) : (\n <Stack spacing={2} padding={2}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={2} sx={{ marginLeft: 'auto' }}>\n <TimeRangeControls />\n {isLaptopSize && (\n <Button\n variant=\"outlined\"\n startIcon={<PencilIcon />}\n onClick={onEditButtonClick}\n sx={{ marginLeft: 'auto' }}\n >\n Edit\n </Button>\n )}\n </Stack>\n </Box>\n <Box paddingY={2}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["Typography","Stack","Button","Box","useTheme","useMediaQuery","PencilIcon","AddPanelGroupIcon","AddPanelIcon","ErrorBoundary","ErrorAlert","useDashboardActions","useEditMode","TemplateVariableList","TimeRangeControls","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","onEditButtonClick","onCancelButtonClick","isEditMode","setEditMode","openAddPanelGroup","openAddPanel","isLaptopSize","breakpoints","up","dashboardTitle","variant","onSave","spacing","sx","backgroundColor","theme","palette","primary","light","padding","display","direction","marginLeft","onClick","width","alignItems","FallbackComponent","startIcon","paddingY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,eAAe,CAAC;AACxF,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,OAAOC,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAOC,YAAY,MAAM,qCAAqC,CAAC;AAC/D,SAASC,aAAa,EAAEC,UAAU,QAAQ,wBAAwB,CAAC;AACnE,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,eAAe,CAAC;AACjE,SAASC,oBAAoB,QAAQ,cAAc,CAAC;AACpD,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Typography, Stack, Button, Box, useTheme, useMediaQuery } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport AddPanelGroupIcon from 'mdi-material-ui/PlusBoxOutline';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { useDashboardActions, useEditMode } from '../../context';\nimport { TemplateVariableList } from '../Variables';\nimport { TimeRangeControls } from '../TimeRangeControls';\nimport { DownloadButton } from '../DownloadButton';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const { dashboardName, dashboardTitleComponent, initialVariableIsSticky, onEditButtonClick, onCancelButtonClick } =\n props;\n\n const { isEditMode, setEditMode } = useEditMode();\n const { openAddPanelGroup, openAddPanel } = useDashboardActions();\n const isLaptopSize = useMediaQuery(useTheme().breakpoints.up('sm'));\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const onSave = () => {\n setEditMode(false);\n };\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={2}>\n <Box sx={{ backgroundColor: (theme) => theme.palette.primary.light + '20' }}>\n <Box padding={2} display=\"flex\">\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button variant=\"contained\" onClick={onSave}>\n Save\n </Button>\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'flex-start',\n padding: (theme) => theme.spacing(2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n <Stack direction={'row'} spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button startIcon={<AddPanelGroupIcon />} onClick={openAddPanelGroup}>\n Add Panel Group\n </Button>\n <Button startIcon={<AddPanelIcon />} onClick={openAddPanel}>\n Add Panel\n </Button>\n <TimeRangeControls />\n </Stack>\n </Box>\n </Stack>\n ) : (\n <Stack spacing={2} padding={2}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={2} sx={{ marginLeft: 'auto' }}>\n <TimeRangeControls />\n <DownloadButton />\n {isLaptopSize && (\n <Button\n variant=\"outlined\"\n startIcon={<PencilIcon />}\n onClick={onEditButtonClick}\n sx={{ marginLeft: 'auto' }}\n >\n Edit\n </Button>\n )}\n </Stack>\n </Box>\n <Box paddingY={2}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["Typography","Stack","Button","Box","useTheme","useMediaQuery","PencilIcon","AddPanelGroupIcon","AddPanelIcon","ErrorBoundary","ErrorAlert","useDashboardActions","useEditMode","TemplateVariableList","TimeRangeControls","DownloadButton","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","onEditButtonClick","onCancelButtonClick","isEditMode","setEditMode","openAddPanelGroup","openAddPanel","isLaptopSize","breakpoints","up","dashboardTitle","variant","onSave","spacing","sx","backgroundColor","theme","palette","primary","light","padding","display","direction","marginLeft","onClick","width","alignItems","FallbackComponent","startIcon","paddingY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,eAAe,CAAC;AACxF,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,O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AC3B,MAACrC,GAAG;oBAAC+B,EAAE,EAAE;wBAAEO,OAAO,EAAE,MAAM;wBAAEI,KAAK,EAAE,MAAM;qBAAE;;wBACxCf,cAAc;sCACf,MAAC7B,KAAK;4BAACyC,SAAS,EAAC,KAAK;4BAACT,OAAO,EAAE,CAAC;4BAAEC,EAAE,EAAE;gCAAES,UAAU,EAAE,MAAM;6BAAE;;8CAC3D,KAAC7B,iBAAiB,KAAG;8CACrB,KAACC,cAAc,KAAG;gCACjBY,YAAY,kBACX,KAACzB,MAAM;oCACL6B,OAAO,EAAC,UAAU;oCAClBiB,SAAS,gBAAE,KAAC1C,UAAU,KAAG;oCACzBsC,OAAO,EAAEvB,iBAAiB;oCAC1Ba,EAAE,EAAE;wCAAES,UAAU,EAAE,MAAM;qCAAE;8CAC3B,MAED;kCAAS,AACV;;0BACK;;kBACJ;8BACN,KAACxC,GAAG;oBAAC8C,QAAQ,EAAE,CAAC;8BACd,cAAA,KAACxC,aAAa;wBAACsC,iBAAiB,EAAErC,UAAU;kCAC1C,cAAA,KAACG,oBAAoB;4BAACO,uBAAuB,EAAEA,uBAAuB;0BAAI;sBAC5D;kBACZ;;UACA,AACT;MACA,CACH;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DownloadButton.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/DownloadButton.tsx"],"names":[],"mappings":";AAmBA,wBAAgB,cAAc,gBA8B7B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import React, { useRef } from 'react';
|
|
15
|
+
import DownloadIcon from 'mdi-material-ui/DownloadOutline';
|
|
16
|
+
import { IconButton, styled } from '@mui/material';
|
|
17
|
+
import { useDashboard } from '../../context';
|
|
18
|
+
// Button to download the dashboard as a JSON file.
|
|
19
|
+
export function DownloadButton() {
|
|
20
|
+
const { dashboard } = useDashboard();
|
|
21
|
+
const hiddenLinkRef = useRef(null);
|
|
22
|
+
const onDownloadButtonClick = ()=>{
|
|
23
|
+
if (!hiddenLinkRef || !hiddenLinkRef.current) return;
|
|
24
|
+
// Create blob URL
|
|
25
|
+
const hiddenLinkUrl = URL.createObjectURL(new Blob([
|
|
26
|
+
JSON.stringify(dashboard)
|
|
27
|
+
], {
|
|
28
|
+
type: 'application/json'
|
|
29
|
+
}));
|
|
30
|
+
// Simulate click
|
|
31
|
+
hiddenLinkRef.current.href = hiddenLinkUrl;
|
|
32
|
+
hiddenLinkRef.current.click();
|
|
33
|
+
// Remove blob URL (for memory management)
|
|
34
|
+
URL.revokeObjectURL(hiddenLinkUrl);
|
|
35
|
+
};
|
|
36
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
37
|
+
children: [
|
|
38
|
+
/*#__PURE__*/ _jsx(DownloadIconButton, {
|
|
39
|
+
title: "Download JSON",
|
|
40
|
+
onClick: onDownloadButtonClick,
|
|
41
|
+
children: /*#__PURE__*/ _jsx(DownloadIcon, {})
|
|
42
|
+
}),
|
|
43
|
+
/*#__PURE__*/ _jsx("a", {
|
|
44
|
+
ref: hiddenLinkRef,
|
|
45
|
+
style: {
|
|
46
|
+
display: 'none'
|
|
47
|
+
},
|
|
48
|
+
download: `${dashboard.metadata.name}.json`
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const DownloadIconButton = styled(IconButton)(({ theme })=>({
|
|
54
|
+
border: `1px solid ${theme.palette.grey[300]}`,
|
|
55
|
+
borderRadius: theme.shape.borderRadius,
|
|
56
|
+
padding: '4px',
|
|
57
|
+
color: theme.palette.grey[900]
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=DownloadButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DownloadButton/DownloadButton.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useRef } from 'react';\nimport DownloadIcon from 'mdi-material-ui/DownloadOutline';\nimport { IconButton, styled } from '@mui/material';\nimport { useDashboard } from '../../context';\n\n// Button to download the dashboard as a JSON file.\nexport function DownloadButton() {\n const { dashboard } = useDashboard();\n const hiddenLinkRef = useRef<HTMLAnchorElement>(null);\n\n const onDownloadButtonClick = () => {\n if (!hiddenLinkRef || !hiddenLinkRef.current) return;\n // Create blob URL\n const hiddenLinkUrl = URL.createObjectURL(\n new Blob([JSON.stringify(dashboard)], {\n type: 'application/json',\n })\n );\n // Simulate click\n hiddenLinkRef.current.href = hiddenLinkUrl;\n hiddenLinkRef.current.click();\n // Remove blob URL (for memory management)\n URL.revokeObjectURL(hiddenLinkUrl);\n };\n\n return (\n <>\n <DownloadIconButton title=\"Download JSON\" onClick={onDownloadButtonClick}>\n <DownloadIcon />\n </DownloadIconButton>\n {/* Hidden link to download the dashboard as a JSON file */}\n {/* eslint-disable jsx-a11y/anchor-has-content */}\n {/* eslint-disable jsx-a11y/anchor-is-valid */}\n <a ref={hiddenLinkRef} style={{ display: 'none' }} download={`${dashboard.metadata.name}.json`} />\n </>\n );\n}\n\nconst DownloadIconButton = styled(IconButton)(({ theme }) => ({\n border: `1px solid ${theme.palette.grey[300]}`,\n borderRadius: theme.shape.borderRadius,\n padding: '4px',\n color: theme.palette.grey[900],\n}));\n"],"names":["React","useRef","DownloadIcon","IconButton","styled","useDashboard","DownloadButton","dashboard","hiddenLinkRef","onDownloadButtonClick","current","hiddenLinkUrl","URL","createObjectURL","Blob","JSON","stringify","type","href","click","revokeObjectURL","DownloadIconButton","title","onClick","a","ref","style","display","download","metadata","name","theme","border","palette","grey","borderRadius","shape","padding","color"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,IAAIC,MAAM,QAAQ,OAAO,CAAC;AACtC,OAAOC,YAAY,MAAM,iCAAiC,CAAC;AAC3D,SAASC,UAAU,EAAEC,MAAM,QAAQ,eAAe,CAAC;AACnD,SAASC,YAAY,QAAQ,eAAe,CAAC;AAE7C,mDAAmD;AACnD,OAAO,SAASC,cAAc,GAAG;IAC/B,MAAM,EAAEC,SAAS,CAAA,EAAE,GAAGF,YAAY,EAAE,AAAC;IACrC,MAAMG,aAAa,GAAGP,MAAM,CAAoB,IAAI,CAAC,AAAC;IAEtD,MAAMQ,qBAAqB,GAAG,IAAM;QAClC,IAAI,CAACD,aAAa,IAAI,CAACA,aAAa,CAACE,OAAO,EAAE,OAAO;QACrD,kBAAkB;QAClB,MAAMC,aAAa,GAAGC,GAAG,CAACC,eAAe,CACvC,IAAIC,IAAI,CAAC;YAACC,IAAI,CAACC,SAAS,CAACT,SAAS,CAAC;SAAC,EAAE;YACpCU,IAAI,EAAE,kBAAkB;SACzB,CAAC,CACH,AAAC;QACF,iBAAiB;QACjBT,aAAa,CAACE,OAAO,CAACQ,IAAI,GAAGP,aAAa,CAAC;QAC3CH,aAAa,CAACE,OAAO,CAACS,KAAK,EAAE,CAAC;QAC9B,0CAA0C;QAC1CP,GAAG,CAACQ,eAAe,CAACT,aAAa,CAAC,CAAC;IACrC,CAAC,AAAC;IAEF,qBACE;;0BACE,KAACU,kBAAkB;gBAACC,KAAK,EAAC,eAAe;gBAACC,OAAO,EAAEd,qBAAqB;0BACtE,cAAA,KAACP,YAAY,KAAG;cACG;0BAIrB,KAACsB,GAAC;gBAACC,GAAG,EAAEjB,aAAa;gBAAEkB,KAAK,EAAE;oBAAEC,OAAO,EAAE,MAAM;iBAAE;gBAAEC,QAAQ,EAAE,CAAC,EAAErB,SAAS,CAACsB,QAAQ,CAACC,IAAI,CAAC,KAAK,CAAC;cAAI;;MACjG,CACH;AACJ,CAAC;AAED,MAAMT,kBAAkB,GAAGjB,MAAM,CAACD,UAAU,CAAC,CAAC,CAAC,EAAE4B,KAAK,CAAA,EAAE,GAAM,CAAA;QAC5DC,MAAM,EAAE,CAAC,UAAU,EAAED,KAAK,CAACE,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9CC,YAAY,EAAEJ,KAAK,CAACK,KAAK,CAACD,YAAY;QACtCE,OAAO,EAAE,KAAK;QACdC,KAAK,EAAEP,KAAK,CAACE,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC;KAC/B,CAAA,AAAC,CAAC,AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAC"}
|
|
@@ -10,18 +10,6 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
|
|
16
|
-
*/ export function useId(prefix) {
|
|
17
|
-
if (globalThis.useIdValue === undefined) {
|
|
18
|
-
globalThis.useIdValue = 0;
|
|
19
|
-
}
|
|
20
|
-
const id = useRef(undefined);
|
|
21
|
-
if (id.current === undefined) {
|
|
22
|
-
id.current = `${prefix}-${globalThis.useIdValue++}`;
|
|
23
|
-
}
|
|
24
|
-
return id.current;
|
|
25
|
-
}
|
|
13
|
+
export * from './DownloadButton';
|
|
26
14
|
|
|
27
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DownloadButton/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DownloadButton';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridTitle.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridTitle.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"GridTitle.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridTitle.tsx"],"names":[],"mappings":";AAqBA,OAAO,EAAqC,YAAY,EAA6B,MAAM,eAAe,CAAC;AAE3G,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,YAAY,EAAE,MAAM,IAAI,CAAC;KAC1B,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAuD9C"}
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import { useState } from 'react';
|
|
15
14
|
import { Box, IconButton, Stack, Typography } from '@mui/material';
|
|
16
15
|
import ExpandedIcon from 'mdi-material-ui/ChevronUp';
|
|
17
16
|
import CollapsedIcon from 'mdi-material-ui/ChevronDown';
|
|
18
|
-
import
|
|
17
|
+
import AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';
|
|
19
18
|
import PencilIcon from 'mdi-material-ui/PencilOutline';
|
|
20
19
|
import ArrowUpIcon from 'mdi-material-ui/ArrowUp';
|
|
21
20
|
import ArrowDownIcon from 'mdi-material-ui/ArrowDown';
|
|
@@ -26,7 +25,6 @@ import { usePanelGroupActions, useEditMode, useDeletePanelGroupDialog } from '..
|
|
|
26
25
|
* and collapsing
|
|
27
26
|
*/ export function GridTitle(props) {
|
|
28
27
|
const { panelGroupId , title , collapse } = props;
|
|
29
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
30
28
|
const { openAddPanel , openEditPanelGroup , moveUp , moveDown } = usePanelGroupActions(panelGroupId);
|
|
31
29
|
const { openDeletePanelGroupDialog } = useDeletePanelGroupDialog();
|
|
32
30
|
const { isEditMode } = useEditMode();
|
|
@@ -45,8 +43,6 @@ import { usePanelGroupActions, useEditMode, useDeletePanelGroupDialog } from '..
|
|
|
45
43
|
padding: (theme)=>theme.spacing(1),
|
|
46
44
|
backgroundColor: (theme)=>theme.palette.background.default
|
|
47
45
|
},
|
|
48
|
-
onMouseEnter: ()=>setIsHovered(true),
|
|
49
|
-
onMouseLeave: ()=>setIsHovered(false),
|
|
50
46
|
children: collapse ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
51
47
|
children: [
|
|
52
48
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
@@ -54,35 +50,35 @@ import { usePanelGroupActions, useEditMode, useDeletePanelGroupDialog } from '..
|
|
|
54
50
|
children: collapse.isOpen ? /*#__PURE__*/ _jsx(ExpandedIcon, {}) : /*#__PURE__*/ _jsx(CollapsedIcon, {})
|
|
55
51
|
}),
|
|
56
52
|
text,
|
|
57
|
-
isEditMode &&
|
|
53
|
+
isEditMode && /*#__PURE__*/ _jsxs(Stack, {
|
|
58
54
|
direction: "row",
|
|
59
55
|
sx: {
|
|
60
56
|
marginLeft: 'auto'
|
|
61
57
|
},
|
|
62
58
|
children: [
|
|
63
59
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
64
|
-
"aria-label":
|
|
60
|
+
"aria-label": `add panel to group ${title}`,
|
|
65
61
|
onClick: openAddPanel,
|
|
66
|
-
children: /*#__PURE__*/ _jsx(
|
|
62
|
+
children: /*#__PURE__*/ _jsx(AddPanelIcon, {})
|
|
67
63
|
}),
|
|
68
64
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
69
|
-
"aria-label":
|
|
65
|
+
"aria-label": `edit group ${title}`,
|
|
70
66
|
onClick: openEditPanelGroup,
|
|
71
67
|
children: /*#__PURE__*/ _jsx(PencilIcon, {})
|
|
72
68
|
}),
|
|
73
69
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
74
|
-
"aria-label":
|
|
70
|
+
"aria-label": `delete group ${title}`,
|
|
75
71
|
onClick: ()=>openDeletePanelGroupDialog(panelGroupId),
|
|
76
72
|
children: /*#__PURE__*/ _jsx(DeleteIcon, {})
|
|
77
73
|
}),
|
|
78
74
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
79
|
-
"aria-label":
|
|
75
|
+
"aria-label": `move group ${title} down`,
|
|
80
76
|
disabled: moveDown === undefined,
|
|
81
77
|
onClick: moveDown,
|
|
82
78
|
children: /*#__PURE__*/ _jsx(ArrowDownIcon, {})
|
|
83
79
|
}),
|
|
84
80
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
85
|
-
"aria-label":
|
|
81
|
+
"aria-label": `move group ${title} up`,
|
|
86
82
|
disabled: moveUp === undefined,
|
|
87
83
|
onClick: moveUp,
|
|
88
84
|
children: /*#__PURE__*/ _jsx(ArrowUpIcon, {})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/GridLayout/GridTitle.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/GridTitle.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, IconButton, Stack, Typography } from '@mui/material';\nimport ExpandedIcon from 'mdi-material-ui/ChevronUp';\nimport CollapsedIcon from 'mdi-material-ui/ChevronDown';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport ArrowUpIcon from 'mdi-material-ui/ArrowUp';\nimport ArrowDownIcon from 'mdi-material-ui/ArrowDown';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport { usePanelGroupActions, useEditMode, PanelGroupId, useDeletePanelGroupDialog } from '../../context';\n\nexport interface GridTitleProps {\n panelGroupId: PanelGroupId;\n title: string;\n collapse?: {\n isOpen: boolean;\n onToggleOpen: () => void;\n };\n}\n\n/**\n * Renders the title for a Grid section, optionally also supporting expanding\n * and collapsing\n */\nexport function GridTitle(props: GridTitleProps) {\n const { panelGroupId, title, collapse } = props;\n\n const { openAddPanel, openEditPanelGroup, moveUp, moveDown } = usePanelGroupActions(panelGroupId);\n const { openDeletePanelGroupDialog } = useDeletePanelGroupDialog();\n const { isEditMode } = useEditMode();\n\n const text = (\n <Typography variant=\"h2\" sx={{ marginLeft: collapse !== undefined ? 1 : undefined }}>\n {title}\n </Typography>\n );\n\n return (\n <Box\n sx={{\n display: 'flex',\n justifyContent: 'start',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1),\n backgroundColor: (theme) => theme.palette.background.default,\n }}\n >\n {collapse ? (\n <>\n <IconButton onClick={collapse.onToggleOpen}>\n {collapse.isOpen ? <ExpandedIcon /> : <CollapsedIcon />}\n </IconButton>\n {text}\n {isEditMode && (\n <Stack direction=\"row\" sx={{ marginLeft: 'auto' }}>\n <IconButton aria-label={`add panel to group ${title}`} onClick={openAddPanel}>\n <AddPanelIcon />\n </IconButton>\n <IconButton aria-label={`edit group ${title}`} onClick={openEditPanelGroup}>\n <PencilIcon />\n </IconButton>\n <IconButton aria-label={`delete group ${title}`} onClick={() => openDeletePanelGroupDialog(panelGroupId)}>\n <DeleteIcon />\n </IconButton>\n <IconButton aria-label={`move group ${title} down`} disabled={moveDown === undefined} onClick={moveDown}>\n <ArrowDownIcon />\n </IconButton>\n <IconButton aria-label={`move group ${title} up`} disabled={moveUp === undefined} onClick={moveUp}>\n <ArrowUpIcon />\n </IconButton>\n </Stack>\n )}\n </>\n ) : (\n // If we don't need expand/collapse, just render the title text\n text\n )}\n </Box>\n );\n}\n"],"names":["Box","IconButton","Stack","Typography","ExpandedIcon","CollapsedIcon","AddPanelIcon","PencilIcon","ArrowUpIcon","ArrowDownIcon","DeleteIcon","usePanelGroupActions","useEditMode","useDeletePanelGroupDialog","GridTitle","props","panelGroupId","title","collapse","openAddPanel","openEditPanelGroup","moveUp","moveDown","openDeletePanelGroupDialog","isEditMode","text","variant","sx","marginLeft","undefined","display","justifyContent","alignItems","padding","theme","spacing","backgroundColor","palette","background","default","onClick","onToggleOpen","isOpen","direction","aria-label","disabled"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACnE,OAAOC,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAOC,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAOC,YAAY,MAAM,qCAAqC,CAAC;AAC/D,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,OAAOC,WAAW,MAAM,yBAAyB,CAAC;AAClD,OAAOC,aAAa,MAAM,2BAA2B,CAAC;AACtD,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,SAASC,oBAAoB,EAAEC,WAAW,EAAgBC,yBAAyB,QAAQ,eAAe,CAAC;AAW3G;;;CAGC,GACD,OAAO,SAASC,SAAS,CAACC,KAAqB,EAAE;IAC/C,MAAM,EAAEC,YAAY,CAAA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AAA,KAACb,YAAY,KAAG;0BACL;sCACb,KAACL,UAAU;4BAAC2C,YAAU,EAAE,CAAC,WAAW,EAAE3B,KAAK,CAAC,CAAC;4BAAEuB,OAAO,EAAEpB,kBAAkB;sCACxE,cAAA,KAACb,UAAU,KAAG;0BACH;sCACb,KAACN,UAAU;4BAAC2C,YAAU,EAAE,CAAC,aAAa,EAAE3B,KAAK,CAAC,CAAC;4BAAEuB,OAAO,EAAE,IAAMjB,0BAA0B,CAACP,YAAY,CAAC;sCACtG,cAAA,KAACN,UAAU,KAAG;0BACH;sCACb,KAACT,UAAU;4BAAC2C,YAAU,EAAE,CAAC,WAAW,EAAE3B,KAAK,CAAC,KAAK,CAAC;4BAAE4B,QAAQ,EAAEvB,QAAQ,KAAKO,SAAS;4BAAEW,OAAO,EAAElB,QAAQ;sCACrG,cAAA,KAACb,aAAa,KAAG;0BACN;sCACb,KAACR,UAAU;4BAAC2C,YAAU,EAAE,CAAC,WAAW,EAAE3B,KAAK,CAAC,GAAG,CAAC;4BAAE4B,QAAQ,EAAExB,MAAM,KAAKQ,SAAS;4BAAEW,OAAO,EAAEnB,MAAM;sCAC/F,cAAA,KAACb,WAAW,KAAG;0BACJ;;kBACP,AACT;;UACA,GAEH,+DAA+D;QAC/DiB,IAAI,AACL;MACG,CACN;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAQ,SAAS,EAAe,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAQ,SAAS,EAAe,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,WAAW,UAAW,SAAQ,SAAS,CAAC,SAAS,CAAC;IACtD,UAAU,EAAE,eAAe,CAAC;IAC5B,YAAY,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,eA2FtC"}
|
|
@@ -14,9 +14,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import { useState, useMemo } from 'react';
|
|
15
15
|
import useResizeObserver from 'use-resize-observer';
|
|
16
16
|
import { useInView } from 'react-intersection-observer';
|
|
17
|
-
import { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';
|
|
17
|
+
import { ErrorBoundary, ErrorAlert, combineSx, useId } from '@perses-dev/components';
|
|
18
18
|
import { Card, CardContent } from '@mui/material';
|
|
19
|
-
import { useId } from '../../utils/component-ids';
|
|
20
19
|
import { PanelHeader } from './PanelHeader';
|
|
21
20
|
import { PanelContent } from './PanelContent';
|
|
22
21
|
/**
|
|
@@ -98,6 +97,9 @@ import { PanelContent } from './PanelContent';
|
|
|
98
97
|
ref: setContentElement,
|
|
99
98
|
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
100
99
|
FallbackComponent: ErrorAlert,
|
|
100
|
+
resetKeys: [
|
|
101
|
+
definition.spec.plugin.spec
|
|
102
|
+
],
|
|
101
103
|
children: inView === true && /*#__PURE__*/ _jsx(PanelContent, {
|
|
102
104
|
panelPluginKind: definition.spec.plugin.kind,
|
|
103
105
|
spec: definition.spec.plugin.spec,
|