@perses-dev/dashboards 0.11.0 → 0.13.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} +9 -16
- package/dist/cjs/components/DashboardToolbar/index.js +28 -0
- package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +4 -7
- 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/GridLayout/GridLayout.js +14 -16
- package/dist/cjs/components/Panel/Panel.js +30 -90
- package/dist/cjs/components/Panel/Panel.test.js +93 -46
- package/dist/cjs/components/Panel/PanelHeader.js +116 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +21 -19
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +16 -16
- 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/Variables/VariableEditor.js +7 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +32 -20
- package/dist/cjs/context/DashboardProvider/common.js +10 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +14 -16
- 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 +54 -164
- package/dist/cjs/context/DashboardProvider/panel-slice.js +25 -0
- 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/useDashboard.js +94 -0
- package/dist/cjs/test/plugin-registry.js +14 -54
- package/dist/cjs/test/render.js +6 -1
- package/dist/cjs/utils/component-ids.js +31 -0
- package/dist/cjs/utils/time-range-params.js +14 -8
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -11
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +1 -1
- 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} +2 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
- package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +5 -12
- 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 +3 -6
- 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 +2 -2
- 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/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/Panel.d.ts +3 -3
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +32 -92
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +95 -48
- 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/PanelDrawer/PanelDrawer.test.js +22 -20
- package/dist/components/PanelDrawer/PanelDrawer.test.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 +16 -16
- 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/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/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 +8 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +34 -22
- 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 +6 -6
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +14 -16
- 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 +3 -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 +14 -44
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +46 -162
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +14 -0
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-slice.js +21 -0
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
- 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/useDashboard.js +88 -0
- 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 -1
- 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/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 +40 -6
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
- 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 +4 -4
- package/dist/cjs/context/useDashboardSpec.js +0 -61
- 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 -5
- 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 -3
- package/dist/context/useDashboardSpec.d.ts.map +0 -1
- package/dist/context/useDashboardSpec.js +0 -55
- package/dist/context/useDashboardSpec.js.map +0 -1
|
@@ -14,195 +14,85 @@
|
|
|
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");
|
|
28
|
+
const _common = require("./common");
|
|
22
29
|
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
|
|
30
|
-
const panelGroups = {};
|
|
31
|
-
const panelGroupIdOrder = [];
|
|
32
|
-
for (const layout of layouts){
|
|
33
|
-
var ref, ref1, ref2;
|
|
34
|
-
const id1 = createPanelGroupId();
|
|
35
|
-
panelGroups[id1] = {
|
|
36
|
-
id: id1,
|
|
37
|
-
items: layout.spec.items,
|
|
38
|
-
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
|
|
40
|
-
};
|
|
41
|
-
panelGroupIdOrder.push(id1);
|
|
42
|
-
}
|
|
30
|
+
const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
|
|
43
31
|
// Return the state creator function for Zustand
|
|
44
|
-
return (set
|
|
45
|
-
return {
|
|
32
|
+
return (set)=>({
|
|
46
33
|
panelGroups,
|
|
47
|
-
|
|
48
|
-
previousPanelGroupStates: {
|
|
49
|
-
panelGroups,
|
|
50
|
-
panelGroupIdOrder
|
|
51
|
-
},
|
|
52
|
-
// TODO: Reorder init logic so this isn't exposed
|
|
53
|
-
createPanelGroupId,
|
|
54
|
-
savePanelGroups () {
|
|
55
|
-
set((state)=>{
|
|
56
|
-
state.previousPanelGroupStates = {
|
|
57
|
-
panelGroups: state.panelGroups,
|
|
58
|
-
panelGroupIdOrder: state.panelGroupIdOrder
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
resetPanelGroups () {
|
|
63
|
-
set((state)=>{
|
|
64
|
-
state.panelGroups = state.previousPanelGroupStates.panelGroups;
|
|
65
|
-
state.panelGroupIdOrder = state.previousPanelGroupStates.panelGroupIdOrder;
|
|
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
|
-
});
|
|
109
|
-
});
|
|
110
|
-
},
|
|
34
|
+
panelGroupOrder,
|
|
111
35
|
swapPanelGroups (x, y) {
|
|
112
36
|
set((state)=>{
|
|
113
|
-
if (x < 0 || x >= state.
|
|
37
|
+
if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
|
|
114
38
|
throw new Error('index out of bound');
|
|
115
39
|
}
|
|
116
|
-
const xPanelGroup = state.
|
|
117
|
-
const yPanelGroup = state.
|
|
40
|
+
const xPanelGroup = state.panelGroupOrder[x];
|
|
41
|
+
const yPanelGroup = state.panelGroupOrder[y];
|
|
118
42
|
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
119
43
|
throw new Error('panel group is undefined');
|
|
120
44
|
}
|
|
121
45
|
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
122
|
-
[state.
|
|
46
|
+
[state.panelGroupOrder[x], state.panelGroupOrder[y]] = [
|
|
123
47
|
yPanelGroup,
|
|
124
48
|
xPanelGroup
|
|
125
49
|
];
|
|
126
50
|
});
|
|
127
51
|
},
|
|
128
|
-
|
|
52
|
+
updatePanelGroupLayouts (panelGroupId, itemLayouts) {
|
|
129
53
|
set((state)=>{
|
|
130
54
|
const group = state.panelGroups[panelGroupId];
|
|
131
55
|
if (group === undefined) {
|
|
132
|
-
throw new Error(`
|
|
56
|
+
throw new Error(`Cannot find panel group ${panelGroupId}`);
|
|
133
57
|
}
|
|
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];
|
|
58
|
+
group.itemLayouts = itemLayouts;
|
|
158
59
|
});
|
|
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
|
-
});
|
|
176
|
-
});
|
|
177
|
-
return map;
|
|
178
60
|
}
|
|
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;
|
|
61
|
+
});
|
|
197
62
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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);
|
|
205
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);
|
|
206
93
|
}
|
|
207
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
panelGroups,
|
|
96
|
+
panelGroupOrder: panelGroupIdOrder
|
|
97
|
+
};
|
|
208
98
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 ()=>({
|
|
23
|
+
panels
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -34,6 +34,7 @@ const _zustand = require("zustand");
|
|
|
34
34
|
const _immer = require("zustand/middleware/immer");
|
|
35
35
|
const _middleware = require("zustand/middleware");
|
|
36
36
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
37
|
+
const _queryParams = require("./query-params");
|
|
37
38
|
const TemplateVariableStoreContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
|
|
38
39
|
function useTemplateVariableStoreCtx() {
|
|
39
40
|
const context = (0, _react.useContext)(TemplateVariableStoreContext);
|
|
@@ -119,14 +120,15 @@ function PluginProvider({ children }) {
|
|
|
119
120
|
children: children
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
|
-
function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
123
|
+
function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , queryParams }) {
|
|
124
|
+
const initialParams = (0, _queryParams.getInitalValuesFromQueryParameters)(queryParams ? queryParams[0] : {});
|
|
123
125
|
const store = (0, _zustand.createStore)()((0, _middleware.devtools)((0, _immer.immer)((set)=>({
|
|
124
|
-
variableState: hydrateTemplateVariableStates(initialVariableDefinitions),
|
|
126
|
+
variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),
|
|
125
127
|
variableDefinitions: initialVariableDefinitions,
|
|
126
128
|
setVariableDefinitions (definitions) {
|
|
127
129
|
set((state)=>{
|
|
128
130
|
state.variableDefinitions = definitions;
|
|
129
|
-
state.variableState = hydrateTemplateVariableStates(definitions);
|
|
131
|
+
state.variableState = hydrateTemplateVariableStates(definitions, initialParams);
|
|
130
132
|
});
|
|
131
133
|
},
|
|
132
134
|
setVariableOptions (name, options) {
|
|
@@ -161,14 +163,22 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
|
161
163
|
val = val.filter((v)=>v !== _pluginSystem.DEFAULT_ALL_VALUE);
|
|
162
164
|
}
|
|
163
165
|
}
|
|
166
|
+
if (queryParams) {
|
|
167
|
+
const setQueryParams = queryParams[1];
|
|
168
|
+
setQueryParams({
|
|
169
|
+
[(0, _queryParams.getURLQueryParamName)(name)]: val
|
|
170
|
+
});
|
|
171
|
+
}
|
|
164
172
|
varState.value = val;
|
|
165
173
|
})
|
|
166
174
|
}))));
|
|
167
175
|
return store;
|
|
168
176
|
}
|
|
169
177
|
function TemplateVariableProvider({ children , initialVariableDefinitions =[] }) {
|
|
178
|
+
const queryParams = (0, _queryParams.useVariableQueryParams)(initialVariableDefinitions);
|
|
170
179
|
const [store] = (0, _react.useState)(createTemplateVariableSrvStore({
|
|
171
|
-
initialVariableDefinitions
|
|
180
|
+
initialVariableDefinitions,
|
|
181
|
+
queryParams
|
|
172
182
|
}));
|
|
173
183
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(TemplateVariableStoreContext.Provider, {
|
|
174
184
|
value: store,
|
|
@@ -177,23 +187,23 @@ function TemplateVariableProvider({ children , initialVariableDefinitions =[] }
|
|
|
177
187
|
})
|
|
178
188
|
});
|
|
179
189
|
}
|
|
180
|
-
/** Helpers */ function hydrateTemplateVariableState(definition) {
|
|
190
|
+
/** Helpers */ function hydrateTemplateVariableState(definition, initialValue) {
|
|
181
191
|
const v = definition;
|
|
182
|
-
var
|
|
192
|
+
var ref;
|
|
183
193
|
const varState = {
|
|
184
|
-
value: (
|
|
194
|
+
value: (ref = initialValue !== null && initialValue !== void 0 ? initialValue : v.spec.default_value) !== null && ref !== void 0 ? ref : null,
|
|
185
195
|
loading: false
|
|
186
196
|
};
|
|
187
197
|
switch(v.kind){
|
|
188
198
|
case 'TextVariable':
|
|
189
|
-
varState.value = v.spec.value;
|
|
199
|
+
varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : v.spec.value;
|
|
190
200
|
break;
|
|
191
201
|
case 'ListVariable':
|
|
192
202
|
varState.options = [];
|
|
193
203
|
if (varState.options.length > 0 && !varState.value) {
|
|
194
|
-
var ref;
|
|
195
204
|
var ref1;
|
|
196
|
-
|
|
205
|
+
var ref2;
|
|
206
|
+
const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
|
|
197
207
|
if (firstOptionValue !== null) {
|
|
198
208
|
varState.value = v.spec.allow_multiple ? [
|
|
199
209
|
firstOptionValue
|
|
@@ -206,10 +216,13 @@ function TemplateVariableProvider({ children , initialVariableDefinitions =[] }
|
|
|
206
216
|
}
|
|
207
217
|
return varState;
|
|
208
218
|
}
|
|
209
|
-
function hydrateTemplateVariableStates(definitions) {
|
|
219
|
+
function hydrateTemplateVariableStates(definitions, initialValues) {
|
|
210
220
|
const state = {};
|
|
211
221
|
definitions.forEach((v)=>{
|
|
212
|
-
|
|
222
|
+
const name = v.spec.name;
|
|
223
|
+
const param = initialValues[name];
|
|
224
|
+
const initialValue = param ? param : null;
|
|
225
|
+
state[name] = hydrateTemplateVariableState(v, initialValue);
|
|
213
226
|
});
|
|
214
227
|
return state;
|
|
215
228
|
}
|
|
@@ -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("./TemplateVariableProvider"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
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
|
+
getURLQueryParamName: ()=>getURLQueryParamName,
|
|
25
|
+
encodeVariableValue: ()=>encodeVariableValue,
|
|
26
|
+
decodeVariableValue: ()=>decodeVariableValue,
|
|
27
|
+
useVariableQueryParams: ()=>useVariableQueryParams,
|
|
28
|
+
getInitalValuesFromQueryParameters: ()=>getInitalValuesFromQueryParameters
|
|
29
|
+
});
|
|
30
|
+
const _useQueryParams = require("use-query-params");
|
|
31
|
+
const variableQueryParameterPrefix = 'var-';
|
|
32
|
+
function getURLQueryParamName(name) {
|
|
33
|
+
return `${variableQueryParameterPrefix}${name}`;
|
|
34
|
+
}
|
|
35
|
+
function encodeVariableValue(value) {
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return value.join(',');
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function decodeVariableValue(value) {
|
|
42
|
+
if (!value) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const values = value.split(',');
|
|
46
|
+
if (values.length === 1) {
|
|
47
|
+
return values[0];
|
|
48
|
+
}
|
|
49
|
+
return values;
|
|
50
|
+
}
|
|
51
|
+
const VariableValueParam = {
|
|
52
|
+
encode: encodeVariableValue,
|
|
53
|
+
decode: (v)=>{
|
|
54
|
+
if (typeof v === 'string') {
|
|
55
|
+
return decodeVariableValue(v);
|
|
56
|
+
}
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
function useVariableQueryParams(defs) {
|
|
61
|
+
const config = {};
|
|
62
|
+
defs.forEach((def)=>{
|
|
63
|
+
const name = getURLQueryParamName(def.spec.name);
|
|
64
|
+
config[name] = VariableValueParam;
|
|
65
|
+
});
|
|
66
|
+
return (0, _useQueryParams.useQueryParams)(config);
|
|
67
|
+
}
|
|
68
|
+
function getInitalValuesFromQueryParameters(queryParamValues) {
|
|
69
|
+
const values = {};
|
|
70
|
+
Object.keys(queryParamValues).forEach((key)=>{
|
|
71
|
+
const value = queryParamValues[key];
|
|
72
|
+
if (!value) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const name = key.replace(variableQueryParameterPrefix, '');
|
|
76
|
+
values[name] = value;
|
|
77
|
+
});
|
|
78
|
+
return values;
|
|
79
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
const _queryParams = require("./query-params");
|
|
18
|
+
describe('getInitalValuesFromQueryParameters', ()=>{
|
|
19
|
+
test('base case', ()=>{
|
|
20
|
+
expect((0, _queryParams.getInitalValuesFromQueryParameters)({
|
|
21
|
+
'var-foo': 'bar',
|
|
22
|
+
'var-baz': [
|
|
23
|
+
'qux',
|
|
24
|
+
'quux'
|
|
25
|
+
]
|
|
26
|
+
})).toEqual({
|
|
27
|
+
foo: 'bar',
|
|
28
|
+
baz: [
|
|
29
|
+
'qux',
|
|
30
|
+
'quux'
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('encodeVariableValue', ()=>{
|
|
36
|
+
const testCases = [
|
|
37
|
+
{
|
|
38
|
+
input: 'foo',
|
|
39
|
+
expected: 'foo'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
input: [
|
|
43
|
+
'foo',
|
|
44
|
+
'bar'
|
|
45
|
+
],
|
|
46
|
+
expected: 'foo,bar'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
input: '$__all',
|
|
50
|
+
expected: '$__all'
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
testCases.forEach(({ input , expected })=>{
|
|
54
|
+
test(`encodes ${input} as ${expected}`, ()=>{
|
|
55
|
+
expect((0, _queryParams.encodeVariableValue)(input)).toEqual(expected);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('decodeVariableValue', ()=>{
|
|
60
|
+
const testCases = [
|
|
61
|
+
{
|
|
62
|
+
input: 'foo',
|
|
63
|
+
expected: 'foo'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
input: 'foo,bar',
|
|
67
|
+
expected: [
|
|
68
|
+
'foo',
|
|
69
|
+
'bar'
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
input: '$__all',
|
|
74
|
+
expected: '$__all'
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
testCases.forEach(({ input , expected })=>{
|
|
78
|
+
test(`encodes ${input} as ${expected}`, ()=>{
|
|
79
|
+
expect((0, _queryParams.decodeVariableValue)(input)).toEqual(expected);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -18,7 +18,7 @@ _exportStar(require("./DashboardProvider"), exports);
|
|
|
18
18
|
_exportStar(require("./DatasourceStoreProvider"), exports);
|
|
19
19
|
_exportStar(require("./TemplateVariableProvider"), exports);
|
|
20
20
|
_exportStar(require("./TimeRangeProvider"), exports);
|
|
21
|
-
_exportStar(require("./
|
|
21
|
+
_exportStar(require("./useDashboard"), exports);
|
|
22
22
|
function _exportStar(from, to) {
|
|
23
23
|
Object.keys(from).forEach(function(k) {
|
|
24
24
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -0,0 +1,94 @@
|
|
|
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, "useDashboard", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>useDashboard
|
|
20
|
+
});
|
|
21
|
+
const _core = require("@perses-dev/core");
|
|
22
|
+
const _dashboardProvider = require("./DashboardProvider");
|
|
23
|
+
const _templateVariableProvider = require("./TemplateVariableProvider");
|
|
24
|
+
function useDashboard() {
|
|
25
|
+
const { panels , panelGroups , panelGroupOrder , defaultTimeRange , metadata , setDashboard: setDashboardResource , } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard , metadata })=>({
|
|
26
|
+
panels,
|
|
27
|
+
panelGroups,
|
|
28
|
+
panelGroupOrder,
|
|
29
|
+
defaultTimeRange,
|
|
30
|
+
setDashboard,
|
|
31
|
+
metadata
|
|
32
|
+
}));
|
|
33
|
+
const { setVariableDefinitions } = (0, _templateVariableProvider.useTemplateVariableActions)();
|
|
34
|
+
const variables = (0, _templateVariableProvider.useTemplateVariableDefinitions)();
|
|
35
|
+
const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
|
|
36
|
+
const dashboard = {
|
|
37
|
+
kind: 'Dashboard',
|
|
38
|
+
metadata,
|
|
39
|
+
spec: {
|
|
40
|
+
panels,
|
|
41
|
+
layouts,
|
|
42
|
+
variables,
|
|
43
|
+
duration: defaultTimeRange.pastDuration
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const setDashboard = (dashboardResource)=>{
|
|
47
|
+
setVariableDefinitions(dashboardResource.spec.variables);
|
|
48
|
+
setDashboardResource(dashboardResource);
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
dashboard,
|
|
52
|
+
setDashboard
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function convertPanelGroupsToLayouts(panelGroups, panelGroupOrder) {
|
|
56
|
+
const layouts = [];
|
|
57
|
+
panelGroupOrder.map((groupOrderId)=>{
|
|
58
|
+
const group = panelGroups[groupOrderId];
|
|
59
|
+
if (group === undefined) {
|
|
60
|
+
throw new Error('panel group not found');
|
|
61
|
+
}
|
|
62
|
+
const { title , isCollapsed , itemLayouts , itemPanelKeys } = group;
|
|
63
|
+
let display = undefined;
|
|
64
|
+
if (title) {
|
|
65
|
+
display = {
|
|
66
|
+
title,
|
|
67
|
+
collapse: {
|
|
68
|
+
open: !isCollapsed
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const layout = {
|
|
73
|
+
kind: 'Grid',
|
|
74
|
+
spec: {
|
|
75
|
+
display,
|
|
76
|
+
items: itemLayouts.map((layout)=>{
|
|
77
|
+
const panelKey = itemPanelKeys[layout.i];
|
|
78
|
+
if (panelKey === undefined) {
|
|
79
|
+
throw new Error(`Missing panel key of layout ${layout.i}`);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
x: layout.x,
|
|
83
|
+
y: layout.y,
|
|
84
|
+
width: layout.w,
|
|
85
|
+
height: layout.h,
|
|
86
|
+
content: (0, _core.createPanelRef)(panelKey)
|
|
87
|
+
};
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
layouts.push(layout);
|
|
92
|
+
});
|
|
93
|
+
return layouts;
|
|
94
|
+
}
|