@perses-dev/dashboards 0.11.0 → 0.12.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.js +9 -2
- package/dist/cjs/components/GridLayout/GridLayout.js +14 -16
- package/dist/cjs/components/Panel/DeletePanelDialog.js +2 -4
- package/dist/cjs/components/Panel/Panel.js +8 -9
- package/dist/cjs/components/Panel/Panel.test.js +2 -1
- package/dist/cjs/components/Panel/index.js +1 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +12 -4
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +2 -2
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +15 -15
- package/dist/cjs/components/Variables/VariableEditor.js +7 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +8 -2
- package/dist/cjs/context/DashboardProvider/common.js +10 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +12 -12
- package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +70 -0
- package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +85 -0
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +74 -67
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -19
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +39 -144
- package/dist/cjs/context/DashboardProvider/panel-slice.js +36 -0
- package/dist/cjs/context/useDashboardSpec.js +37 -8
- package/dist/cjs/utils/time-range-params.js +14 -8
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +10 -3
- package/dist/components/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -2
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +16 -18
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +0 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.js +2 -4
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +2 -2
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +7 -8
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +2 -1
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/index.d.ts +1 -0
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +1 -0
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +12 -4
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +2 -2
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +15 -15
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +7 -6
- 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 +9 -5
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +8 -2
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +7 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +8 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +5 -4
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +12 -12
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +23 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.js +64 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts +36 -0
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-slice.js +81 -0
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +2 -1
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +6 -35
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +74 -67
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -8
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -19
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -31
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +40 -145
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +23 -0
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-slice.js +32 -0
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
- package/dist/context/useDashboardSpec.d.ts +10 -2
- package/dist/context/useDashboardSpec.d.ts.map +1 -1
- package/dist/context/useDashboardSpec.js +38 -9
- package/dist/context/useDashboardSpec.js.map +1 -1
- package/dist/utils/time-range-params.d.ts.map +1 -1
- package/dist/utils/time-range-params.js +15 -9
- package/dist/utils/time-range-params.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +0 -1
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/package.json +4 -4
|
@@ -19,27 +19,21 @@ Object.defineProperty(exports, "createPanelEditorSlice", {
|
|
|
19
19
|
get: ()=>createPanelEditorSlice
|
|
20
20
|
});
|
|
21
21
|
const _functions = require("../../utils/functions");
|
|
22
|
-
|
|
22
|
+
const _common = require("./common");
|
|
23
|
+
function createPanelEditorSlice() {
|
|
23
24
|
// Return the state creator function for Zustand that uses the panels provided as intitial state
|
|
24
25
|
return (set, get)=>{
|
|
25
26
|
return {
|
|
26
|
-
previousPanels: panels,
|
|
27
|
-
panels,
|
|
28
27
|
panelEditor: undefined,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
openEditPanel (item) {
|
|
40
|
-
const { panels , getPanelKey } = get();
|
|
41
|
-
// Ask the layout store for the panel key at that location
|
|
42
|
-
const panelKey = getPanelKey(item);
|
|
28
|
+
openEditPanel (panelGroupItemId) {
|
|
29
|
+
var ref;
|
|
30
|
+
const { panels , panelGroups } = get();
|
|
31
|
+
// Figure out the panel key at that location
|
|
32
|
+
const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
|
|
33
|
+
const panelKey = (ref = panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
|
|
34
|
+
if (panelKey === undefined) {
|
|
35
|
+
throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);
|
|
36
|
+
}
|
|
43
37
|
// Find the panel to edit
|
|
44
38
|
const panelToEdit = panels[panelKey];
|
|
45
39
|
if (panelToEdit === undefined) {
|
|
@@ -51,19 +45,46 @@ function createPanelEditorSlice(panels) {
|
|
|
51
45
|
initialValues: {
|
|
52
46
|
name: panelToEdit.spec.display.name,
|
|
53
47
|
description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
54
|
-
groupId:
|
|
48
|
+
groupId: panelGroupItemId.panelGroupId,
|
|
55
49
|
kind: panelToEdit.spec.plugin.kind,
|
|
56
50
|
spec: panelToEdit.spec.plugin.spec
|
|
57
51
|
},
|
|
58
52
|
applyChanges: (next)=>{
|
|
59
53
|
const panelDefinititon = createPanelDefinitionFromEditorValues(next);
|
|
60
|
-
set((
|
|
61
|
-
|
|
54
|
+
set((draft)=>{
|
|
55
|
+
draft.panels[panelKey] = panelDefinititon;
|
|
56
|
+
// If the panel didn't change groups, nothing else to do
|
|
57
|
+
if (next.groupId === panelGroupId) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Move panel to the new group
|
|
61
|
+
const existingGroup = draft.panelGroups[panelGroupId];
|
|
62
|
+
if (existingGroup === undefined) {
|
|
63
|
+
throw new Error(`Missing panel group ${panelGroupId}`);
|
|
64
|
+
}
|
|
65
|
+
const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout)=>layout.i === panelGroupLayoutId);
|
|
66
|
+
const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];
|
|
67
|
+
const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];
|
|
68
|
+
if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {
|
|
69
|
+
throw new Error(`Missing panel group item ${panelGroupLayoutId}`);
|
|
70
|
+
}
|
|
71
|
+
// Remove item from the old group
|
|
72
|
+
existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
|
|
73
|
+
delete existingGroup.itemPanelKeys[panelGroupLayoutId];
|
|
74
|
+
// Add item to the end of the new group
|
|
75
|
+
const newGroup = draft.panelGroups[next.groupId];
|
|
76
|
+
if (newGroup === undefined) {
|
|
77
|
+
throw new Error(`Could not find new group ${next.groupId}`);
|
|
78
|
+
}
|
|
79
|
+
newGroup.itemLayouts.push({
|
|
80
|
+
i: existingLayout.i,
|
|
81
|
+
x: 0,
|
|
82
|
+
y: getYForNewRow(newGroup),
|
|
83
|
+
w: existingLayout.w,
|
|
84
|
+
h: existingLayout.h
|
|
85
|
+
});
|
|
86
|
+
newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;
|
|
62
87
|
});
|
|
63
|
-
// Move the panel to another group if it changed
|
|
64
|
-
if (next.groupId !== item.panelGroupId) {
|
|
65
|
-
get().movePanelToGroup(item, next.groupId);
|
|
66
|
-
}
|
|
67
88
|
},
|
|
68
89
|
close: ()=>{
|
|
69
90
|
set((state)=>{
|
|
@@ -79,7 +100,7 @@ function createPanelEditorSlice(panels) {
|
|
|
79
100
|
openAddPanel (panelGroupId) {
|
|
80
101
|
// If a panel group isn't supplied, add to the first group
|
|
81
102
|
if (panelGroupId === undefined) {
|
|
82
|
-
const firstGroupId = get().
|
|
103
|
+
const firstGroupId = get().panelGroupOrder[0];
|
|
83
104
|
if (firstGroupId === undefined) {
|
|
84
105
|
throw new Error('No panel groups to add a panel to');
|
|
85
106
|
}
|
|
@@ -99,10 +120,24 @@ function createPanelEditorSlice(panels) {
|
|
|
99
120
|
applyChanges: (next)=>{
|
|
100
121
|
const panelDef = createPanelDefinitionFromEditorValues(next);
|
|
101
122
|
const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
|
|
102
|
-
set((
|
|
103
|
-
|
|
123
|
+
set((draft)=>{
|
|
124
|
+
// Add a panel
|
|
125
|
+
draft.panels[panelKey] = panelDef;
|
|
126
|
+
// Also add a panel group item referencing the panel
|
|
127
|
+
const group = draft.panelGroups[next.groupId];
|
|
128
|
+
if (group === undefined) {
|
|
129
|
+
throw new Error(`Missing panel group ${next.groupId}`);
|
|
130
|
+
}
|
|
131
|
+
const layout = {
|
|
132
|
+
i: (0, _common.generateId)().toString(),
|
|
133
|
+
x: 0,
|
|
134
|
+
y: getYForNewRow(group),
|
|
135
|
+
w: 12,
|
|
136
|
+
h: 6
|
|
137
|
+
};
|
|
138
|
+
group.itemLayouts.push(layout);
|
|
139
|
+
group.itemPanelKeys[layout.i] = panelKey;
|
|
104
140
|
});
|
|
105
|
-
get().addPanelToGroup(panelKey, next.groupId);
|
|
106
141
|
},
|
|
107
142
|
close: ()=>{
|
|
108
143
|
set((state)=>{
|
|
@@ -114,45 +149,6 @@ function createPanelEditorSlice(panels) {
|
|
|
114
149
|
set((state)=>{
|
|
115
150
|
state.panelEditor = editorState;
|
|
116
151
|
});
|
|
117
|
-
},
|
|
118
|
-
deletePanels (items) {
|
|
119
|
-
const { mapPanelToPanelGroups , deletePanelInPanelGroup , getPanelKey } = get();
|
|
120
|
-
const map = mapPanelToPanelGroups();
|
|
121
|
-
// get panel key first before deleting panel from panel group since getPanelKey relies on index
|
|
122
|
-
const panels = items.map((panel)=>{
|
|
123
|
-
return {
|
|
124
|
-
...panel,
|
|
125
|
-
panelKey: getPanelKey(panel)
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
panels.forEach(({ panelKey , ...panel })=>{
|
|
129
|
-
var ref;
|
|
130
|
-
deletePanelInPanelGroup(panel);
|
|
131
|
-
// make sure panel is only referenced in one panel group before deleting it from state.panels
|
|
132
|
-
if (map[panelKey] && ((ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.length) === 1) {
|
|
133
|
-
set((state)=>{
|
|
134
|
-
delete state.panels[panelKey];
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
openDeletePanelDialog (item) {
|
|
140
|
-
const { panels , getPanelKey , panelGroups } = get();
|
|
141
|
-
const panelKey = getPanelKey(item);
|
|
142
|
-
set((state)=>{
|
|
143
|
-
var ref, ref1;
|
|
144
|
-
var _name, ref2;
|
|
145
|
-
state.deletePanelDialog = {
|
|
146
|
-
panelGroupItemId: item,
|
|
147
|
-
panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
|
|
148
|
-
panelGroupName: (ref2 = (ref1 = panelGroups[item.panelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref2 !== void 0 ? ref2 : ''
|
|
149
|
-
};
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
closeDeletePanelDialog () {
|
|
153
|
-
set((state)=>{
|
|
154
|
-
state.deletePanelDialog = undefined;
|
|
155
|
-
});
|
|
156
152
|
}
|
|
157
153
|
};
|
|
158
154
|
};
|
|
@@ -173,3 +169,14 @@ function createPanelDefinitionFromEditorValues(editorValues) {
|
|
|
173
169
|
}
|
|
174
170
|
};
|
|
175
171
|
}
|
|
172
|
+
// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present
|
|
173
|
+
function getYForNewRow(group) {
|
|
174
|
+
let newRowY = 0;
|
|
175
|
+
for (const layout of group.itemLayouts){
|
|
176
|
+
const itemMaxY = layout.y + layout.h;
|
|
177
|
+
if (itemMaxY > newRowY) {
|
|
178
|
+
newRowY = itemMaxY;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return newRowY;
|
|
182
|
+
}
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "createPanelGroupEditorSlice", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>createPanelGroupEditorSlice
|
|
20
20
|
});
|
|
21
|
+
const _common = require("./common");
|
|
21
22
|
const createPanelGroupEditorSlice = (set, get)=>({
|
|
22
23
|
panelGroupEditor: undefined,
|
|
23
24
|
openAddPanelGroup: ()=>{
|
|
@@ -30,13 +31,14 @@ const createPanelGroupEditorSlice = (set, get)=>({
|
|
|
30
31
|
},
|
|
31
32
|
applyChanges (next) {
|
|
32
33
|
const newGroup = {
|
|
33
|
-
id:
|
|
34
|
-
|
|
34
|
+
id: (0, _common.generateId)(),
|
|
35
|
+
itemLayouts: [],
|
|
36
|
+
itemPanelKeys: {},
|
|
35
37
|
...next
|
|
36
38
|
};
|
|
37
39
|
set((draft)=>{
|
|
38
40
|
draft.panelGroups[newGroup.id] = newGroup;
|
|
39
|
-
draft.
|
|
41
|
+
draft.panelGroupOrder.unshift(newGroup.id);
|
|
40
42
|
});
|
|
41
43
|
},
|
|
42
44
|
close () {
|
|
@@ -83,20 +85,5 @@ const createPanelGroupEditorSlice = (set, get)=>({
|
|
|
83
85
|
set((draft)=>{
|
|
84
86
|
draft.panelGroupEditor = editor;
|
|
85
87
|
});
|
|
86
|
-
}
|
|
87
|
-
openDeletePanelGroupDialog: (panelGroupId)=>{
|
|
88
|
-
const panelGroup = get().panelGroups[panelGroupId];
|
|
89
|
-
if (panelGroup === undefined) {
|
|
90
|
-
throw new Error(`Panel group with Id ${panelGroupId} not found`);
|
|
91
|
-
}
|
|
92
|
-
set((state)=>{
|
|
93
|
-
state.deletePanelGroupDialog = {
|
|
94
|
-
panelGroupId,
|
|
95
|
-
panelGroupName: panelGroup.title
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
closeDeletePanelGroupDialog: ()=>set((state)=>{
|
|
100
|
-
state.deletePanelGroupDialog = undefined;
|
|
101
|
-
})
|
|
88
|
+
}
|
|
102
89
|
});
|
|
@@ -19,190 +19,85 @@ Object.defineProperty(exports, "createPanelGroupSlice", {
|
|
|
19
19
|
get: ()=>createPanelGroupSlice
|
|
20
20
|
});
|
|
21
21
|
const _core = require("@perses-dev/core");
|
|
22
|
+
const _common = require("./common");
|
|
22
23
|
function createPanelGroupSlice(layouts) {
|
|
23
|
-
//
|
|
24
|
-
let id = -1;
|
|
25
|
-
function createPanelGroupId() {
|
|
26
|
-
id++;
|
|
27
|
-
return id;
|
|
28
|
-
}
|
|
29
|
-
// Convert the initial layouts from the JSON to panel groups and keep track of the order
|
|
24
|
+
// Convert the initial layouts from the JSON
|
|
30
25
|
const panelGroups = {};
|
|
31
26
|
const panelGroupIdOrder = [];
|
|
32
27
|
for (const layout of layouts){
|
|
33
28
|
var ref, ref1, ref2;
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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,
|
|
38
47
|
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
39
|
-
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title
|
|
48
|
+
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
49
|
+
itemLayouts,
|
|
50
|
+
itemPanelKeys
|
|
40
51
|
};
|
|
41
|
-
panelGroupIdOrder.push(
|
|
52
|
+
panelGroupIdOrder.push(panelGroupId);
|
|
42
53
|
}
|
|
43
54
|
// Return the state creator function for Zustand
|
|
44
|
-
return (set
|
|
45
|
-
return {
|
|
55
|
+
return (set)=>({
|
|
46
56
|
panelGroups,
|
|
47
|
-
panelGroupIdOrder,
|
|
48
|
-
|
|
57
|
+
panelGroupOrder: panelGroupIdOrder,
|
|
58
|
+
previousPanelGroupState: {
|
|
49
59
|
panelGroups,
|
|
50
60
|
panelGroupIdOrder
|
|
51
61
|
},
|
|
52
|
-
// TODO: Reorder init logic so this isn't exposed
|
|
53
|
-
createPanelGroupId,
|
|
54
62
|
savePanelGroups () {
|
|
55
63
|
set((state)=>{
|
|
56
|
-
state.
|
|
64
|
+
state.previousPanelGroupState = {
|
|
57
65
|
panelGroups: state.panelGroups,
|
|
58
|
-
panelGroupIdOrder: state.
|
|
66
|
+
panelGroupIdOrder: state.panelGroupOrder
|
|
59
67
|
};
|
|
60
68
|
});
|
|
61
69
|
},
|
|
62
70
|
resetPanelGroups () {
|
|
63
71
|
set((state)=>{
|
|
64
|
-
state.panelGroups = state.
|
|
65
|
-
state.
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
getPanelKey ({ panelGroupId , itemIndex }) {
|
|
69
|
-
const { panelGroups } = get();
|
|
70
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
71
|
-
const item = findItem(group, itemIndex);
|
|
72
|
-
return (0, _core.getPanelKeyFromRef)(item.content);
|
|
73
|
-
},
|
|
74
|
-
addPanelToGroup (panelKey, panelGroupId) {
|
|
75
|
-
const { panelGroups } = get();
|
|
76
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
77
|
-
const gridItem = {
|
|
78
|
-
x: 0,
|
|
79
|
-
y: getYForNewRow(group),
|
|
80
|
-
width: 12,
|
|
81
|
-
height: 6,
|
|
82
|
-
content: (0, _core.createPanelRef)(panelKey)
|
|
83
|
-
};
|
|
84
|
-
set((state)=>{
|
|
85
|
-
var ref;
|
|
86
|
-
(ref = state.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
movePanelToGroup ({ panelGroupId , itemIndex }, newPanelGroupId) {
|
|
90
|
-
const { panelGroups } = get();
|
|
91
|
-
// Find the existing item to make sure it exists
|
|
92
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
93
|
-
const item = findItem(group, itemIndex);
|
|
94
|
-
// Find the new group and figure out where a new row should go
|
|
95
|
-
const newGroup = findGroup(panelGroups, newPanelGroupId);
|
|
96
|
-
const newGroupY = getYForNewRow(newGroup);
|
|
97
|
-
set((state)=>{
|
|
98
|
-
var // Remove the item from its current group
|
|
99
|
-
ref, // Add a new item to the new group
|
|
100
|
-
ref1;
|
|
101
|
-
(ref = state.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
|
|
102
|
-
(ref1 = state.panelGroups[newPanelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
|
|
103
|
-
x: 0,
|
|
104
|
-
y: newGroupY,
|
|
105
|
-
width: item.width,
|
|
106
|
-
height: item.height,
|
|
107
|
-
content: item.content
|
|
108
|
-
});
|
|
72
|
+
state.panelGroups = state.previousPanelGroupState.panelGroups;
|
|
73
|
+
state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
|
|
109
74
|
});
|
|
110
75
|
},
|
|
111
76
|
swapPanelGroups (x, y) {
|
|
112
77
|
set((state)=>{
|
|
113
|
-
if (x < 0 || x >= state.
|
|
78
|
+
if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
|
|
114
79
|
throw new Error('index out of bound');
|
|
115
80
|
}
|
|
116
|
-
const xPanelGroup = state.
|
|
117
|
-
const yPanelGroup = state.
|
|
81
|
+
const xPanelGroup = state.panelGroupOrder[x];
|
|
82
|
+
const yPanelGroup = state.panelGroupOrder[y];
|
|
118
83
|
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
119
84
|
throw new Error('panel group is undefined');
|
|
120
85
|
}
|
|
121
86
|
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
122
|
-
[state.
|
|
87
|
+
[state.panelGroupOrder[x], state.panelGroupOrder[y]] = [
|
|
123
88
|
yPanelGroup,
|
|
124
89
|
xPanelGroup
|
|
125
90
|
];
|
|
126
91
|
});
|
|
127
92
|
},
|
|
128
|
-
|
|
93
|
+
updatePanelGroupLayouts (panelGroupId, itemLayouts) {
|
|
129
94
|
set((state)=>{
|
|
130
95
|
const group = state.panelGroups[panelGroupId];
|
|
131
96
|
if (group === undefined) {
|
|
132
|
-
throw new Error(`
|
|
97
|
+
throw new Error(`Cannot find panel group ${panelGroupId}`);
|
|
133
98
|
}
|
|
134
|
-
|
|
135
|
-
group.items.splice(itemIndex, 1);
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
deletePanelGroup (panelGroupId) {
|
|
139
|
-
const { panelGroups , panelGroupIdOrder: panelGroupOrder , deletePanels } = get();
|
|
140
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
141
|
-
const orderIdx = panelGroupOrder.findIndex((id)=>id === panelGroupId);
|
|
142
|
-
if (orderIdx === -1) {
|
|
143
|
-
throw new Error(`Could not find panel group Id ${panelGroupId} in order array`);
|
|
144
|
-
}
|
|
145
|
-
// remove panels from group first
|
|
146
|
-
const panelsToBeDeleted = [];
|
|
147
|
-
for(let i = 0; i < group.items.length; i++){
|
|
148
|
-
panelsToBeDeleted.push({
|
|
149
|
-
panelGroupId,
|
|
150
|
-
itemIndex: i
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
deletePanels(panelsToBeDeleted);
|
|
154
|
-
// remove group from both panelGroups and panelGroupOrder
|
|
155
|
-
set((state)=>{
|
|
156
|
-
state.panelGroupIdOrder.splice(orderIdx, 1);
|
|
157
|
-
delete state.panelGroups[panelGroupId];
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
// Return an object that maps each panel to the groups it belongs
|
|
161
|
-
mapPanelToPanelGroups () {
|
|
162
|
-
const map = {}; // { panel key: [group ids] }
|
|
163
|
-
Object.values(get().panelGroups).forEach((group)=>{
|
|
164
|
-
// for each panel in a group, add the group id to map[panelKey]
|
|
165
|
-
group.items.forEach((panel)=>{
|
|
166
|
-
const panelKey = (0, _core.getPanelKeyFromRef)(panel.content);
|
|
167
|
-
if (map[panelKey]) {
|
|
168
|
-
var ref;
|
|
169
|
-
(ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
|
|
170
|
-
} else {
|
|
171
|
-
map[panelKey] = [
|
|
172
|
-
group.id
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
});
|
|
99
|
+
group.itemLayouts = itemLayouts;
|
|
176
100
|
});
|
|
177
|
-
return map;
|
|
178
101
|
}
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
// Helper to find a group and throw if not found
|
|
183
|
-
function findGroup(panelGroups, groupId) {
|
|
184
|
-
const group = panelGroups[groupId];
|
|
185
|
-
if (group === undefined) {
|
|
186
|
-
throw new Error(`No panel group found for Id ${groupId}`);
|
|
187
|
-
}
|
|
188
|
-
return group;
|
|
189
|
-
}
|
|
190
|
-
// Helper to get an item in a group and throw if not found
|
|
191
|
-
function findItem(group, itemIndex) {
|
|
192
|
-
const item = group.items[itemIndex];
|
|
193
|
-
if (item === undefined) {
|
|
194
|
-
throw new Error(`No grid item found at position ${itemIndex}`);
|
|
195
|
-
}
|
|
196
|
-
return item;
|
|
197
|
-
}
|
|
198
|
-
// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
|
|
199
|
-
function getYForNewRow(group) {
|
|
200
|
-
let newRowY = 0;
|
|
201
|
-
for (const item of group.items){
|
|
202
|
-
const itemMaxY = item.y + item.height;
|
|
203
|
-
if (itemMaxY > newRowY) {
|
|
204
|
-
newRowY = itemMaxY;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return newRowY;
|
|
102
|
+
});
|
|
208
103
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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, "createPanelSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createPanelSlice
|
|
20
|
+
});
|
|
21
|
+
function createPanelSlice(panels) {
|
|
22
|
+
return (set)=>({
|
|
23
|
+
panels,
|
|
24
|
+
previousPanels: panels,
|
|
25
|
+
resetPanels () {
|
|
26
|
+
set((state)=>{
|
|
27
|
+
state.panels = state.previousPanels;
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
savePanels () {
|
|
31
|
+
set((state)=>{
|
|
32
|
+
state.previousPanels = state.panels;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -18,27 +18,44 @@ Object.defineProperty(exports, "useDashboardSpec", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>useDashboardSpec
|
|
20
20
|
});
|
|
21
|
+
const _core = require("@perses-dev/core");
|
|
21
22
|
const _dashboardProvider = require("./DashboardProvider");
|
|
22
23
|
const _templateVariableProvider = require("./TemplateVariableProvider");
|
|
23
24
|
function useDashboardSpec() {
|
|
24
|
-
const { panels , panelGroups , defaultTimeRange } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , defaultTimeRange })=>({
|
|
25
|
+
const { panels , panelGroups , panelGroupOrder , defaultTimeRange , reset: resetDashboardStore , } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , reset })=>({
|
|
25
26
|
panels,
|
|
26
27
|
panelGroups,
|
|
27
|
-
|
|
28
|
+
panelGroupOrder,
|
|
29
|
+
defaultTimeRange,
|
|
30
|
+
reset
|
|
28
31
|
}));
|
|
32
|
+
const { setVariableDefinitions } = (0, _templateVariableProvider.useTemplateVariableActions)();
|
|
29
33
|
const variables = (0, _templateVariableProvider.useTemplateVariableDefinitions)();
|
|
30
|
-
const layouts = convertPanelGroupsToLayouts(panelGroups);
|
|
31
|
-
|
|
34
|
+
const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
|
|
35
|
+
const spec = {
|
|
32
36
|
panels,
|
|
33
37
|
layouts,
|
|
34
38
|
variables,
|
|
35
39
|
duration: defaultTimeRange.pastDuration
|
|
36
40
|
};
|
|
41
|
+
const resetSpec = (spec)=>{
|
|
42
|
+
setVariableDefinitions(spec.variables);
|
|
43
|
+
// TODO: Should we call reset on the dashboard store with the spec?
|
|
44
|
+
resetDashboardStore();
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
spec,
|
|
48
|
+
resetSpec
|
|
49
|
+
};
|
|
37
50
|
}
|
|
38
|
-
function convertPanelGroupsToLayouts(panelGroups) {
|
|
51
|
+
function convertPanelGroupsToLayouts(panelGroups, panelGroupOrder) {
|
|
39
52
|
const layouts = [];
|
|
40
|
-
|
|
41
|
-
const
|
|
53
|
+
panelGroupOrder.map((groupOrderId)=>{
|
|
54
|
+
const group = panelGroups[groupOrderId];
|
|
55
|
+
if (group === undefined) {
|
|
56
|
+
throw new Error('panel group not found');
|
|
57
|
+
}
|
|
58
|
+
const { title , isCollapsed , itemLayouts , itemPanelKeys } = group;
|
|
42
59
|
let display = undefined;
|
|
43
60
|
if (title) {
|
|
44
61
|
display = {
|
|
@@ -52,7 +69,19 @@ function convertPanelGroupsToLayouts(panelGroups) {
|
|
|
52
69
|
kind: 'Grid',
|
|
53
70
|
spec: {
|
|
54
71
|
display,
|
|
55
|
-
items
|
|
72
|
+
items: itemLayouts.map((layout)=>{
|
|
73
|
+
const panelKey = itemPanelKeys[layout.i];
|
|
74
|
+
if (panelKey === undefined) {
|
|
75
|
+
throw new Error(`Missing panel key of layout ${layout.i}`);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
x: layout.x,
|
|
79
|
+
y: layout.y,
|
|
80
|
+
width: layout.w,
|
|
81
|
+
height: layout.h,
|
|
82
|
+
content: (0, _core.createPanelRef)(panelKey)
|
|
83
|
+
};
|
|
84
|
+
})
|
|
56
85
|
}
|
|
57
86
|
};
|
|
58
87
|
layouts.push(layout);
|
|
@@ -111,15 +111,21 @@ function useSetTimeRangeParams(initialTimeRange, paramsEnabled = true) {
|
|
|
111
111
|
// fallback when app does not want query string as source of truth
|
|
112
112
|
const [timeRangeState, setTimeRangeState] = (0, _react.useState)(initialTimeRange);
|
|
113
113
|
const { start } = query;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
(0, _react.useEffect)(()=>{
|
|
115
|
+
if (paramsEnabled && !start) {
|
|
116
|
+
if ((0, _core.isRelativeTimeRange)(initialTimeRange)) {
|
|
117
|
+
setQuery({
|
|
118
|
+
start: initialTimeRange.pastDuration,
|
|
119
|
+
end: undefined
|
|
120
|
+
});
|
|
121
|
+
}
|
|
121
122
|
}
|
|
122
|
-
}
|
|
123
|
+
}, [
|
|
124
|
+
initialTimeRange,
|
|
125
|
+
paramsEnabled,
|
|
126
|
+
start,
|
|
127
|
+
setQuery
|
|
128
|
+
]);
|
|
123
129
|
const setTimeRange = (0, _react.useCallback)((value)=>{
|
|
124
130
|
if ((0, _core.isRelativeTimeRange)(value)) {
|
|
125
131
|
setQuery({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../src/components/DashboardToolbar.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../src/components/DashboardToolbar.tsx"],"names":[],"mappings":";AAuBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBA6F5D,CAAC"}
|
|
@@ -11,23 +11,30 @@
|
|
|
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';
|
|
14
15
|
import { Typography, Stack, Button, Box, useTheme, useMediaQuery } from '@mui/material';
|
|
15
16
|
import PencilIcon from 'mdi-material-ui/PencilOutline';
|
|
16
17
|
import AddPanelGroupIcon from 'mdi-material-ui/PlusBoxOutline';
|
|
17
18
|
import AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';
|
|
18
19
|
import { ErrorBoundary, ErrorAlert } from '@perses-dev/components';
|
|
19
|
-
import { useDashboardActions, useEditMode } from '../context';
|
|
20
|
+
import { useDashboardActions, useDashboardSpec, useEditMode } from '../context';
|
|
20
21
|
import { TemplateVariableList, TimeRangeControls } from '../components';
|
|
21
22
|
export const DashboardToolbar = (props)=>{
|
|
22
23
|
const { dashboardName } = props;
|
|
23
24
|
const { isEditMode , setEditMode } = useEditMode();
|
|
24
|
-
const { openAddPanelGroup , openAddPanel ,
|
|
25
|
+
const { openAddPanelGroup , openAddPanel , save } = useDashboardActions();
|
|
25
26
|
const isLaptopSize = useMediaQuery(useTheme().breakpoints.up('sm'));
|
|
27
|
+
const [originalSpec, setOriginalSpec] = useState(undefined);
|
|
28
|
+
const { spec , resetSpec } = useDashboardSpec();
|
|
26
29
|
const onEditButtonClick = ()=>{
|
|
30
|
+
setOriginalSpec(spec);
|
|
27
31
|
setEditMode(true);
|
|
28
32
|
};
|
|
29
33
|
const onCancelButtonClick = ()=>{
|
|
30
|
-
|
|
34
|
+
// Reset to the original spec and exit edit mode
|
|
35
|
+
if (originalSpec) {
|
|
36
|
+
resetSpec(originalSpec);
|
|
37
|
+
}
|
|
31
38
|
setEditMode(false);
|
|
32
39
|
};
|
|
33
40
|
const onSave = ()=>{
|