@perses-dev/dashboards 0.10.0 → 0.11.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 +4 -5
- package/dist/cjs/components/DashboardToolbar.js +11 -5
- package/dist/cjs/components/GridLayout/GridItemContent.js +3 -11
- package/dist/cjs/components/GridLayout/GridLayout.js +8 -6
- package/dist/cjs/components/GridLayout/GridTitle.js +9 -11
- package/dist/cjs/components/Panel/DeletePanelDialog.js +12 -8
- package/dist/cjs/components/Panel/Panel.js +4 -13
- package/dist/cjs/components/Panel/Panel.test.js +4 -3
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -1
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +3 -3
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +21 -15
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +9 -3
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +70 -111
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +22 -16
- package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +92 -0
- package/dist/cjs/components/PanelGroupDialog/index.js +29 -0
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +8 -11
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +20 -13
- package/dist/cjs/components/Variables/Variable.js +1 -0
- package/dist/cjs/components/Variables/VariableEditor.js +33 -0
- package/dist/cjs/components/Variables/VariableList.js +0 -1
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +20 -8
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +122 -29
- package/dist/cjs/context/DashboardProvider/{panel-editing-slice.js → panel-editor-slice.js} +32 -13
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +102 -0
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +187 -17
- package/dist/cjs/context/TimeRangeProvider.js +20 -44
- package/dist/cjs/context/index.js +1 -1
- package/dist/cjs/context/useDashboardSpec.js +61 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/test/render.js +25 -5
- package/dist/cjs/test/setup-tests.js +4 -1
- package/dist/cjs/test/testDashboard.js +11 -10
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/utils/time-range-params.js +145 -0
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -4
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +42 -93
- package/dist/components/Dashboard.js +5 -6
- package/dist/components/Dashboard.js.map +1 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +13 -7
- package/dist/components/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -4
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +4 -12
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -3
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +9 -7
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +2 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +10 -12
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.js +13 -9
- 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 +5 -14
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.d.ts +1 -1
- package/dist/components/Panel/Panel.test.d.ts.map +1 -1
- package/dist/components/Panel/Panel.test.js +4 -3
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +2 -2
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +3 -3
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +22 -16
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +9 -3
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +1 -2
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -2
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +73 -112
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +21 -15
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +12 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +82 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -0
- package/dist/components/PanelGroupDialog/index.d.ts +3 -0
- package/dist/components/PanelGroupDialog/index.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/index.js +16 -0
- package/dist/components/PanelGroupDialog/index.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +11 -14
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +21 -14
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/Variables/Variable.js +1 -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 +33 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.js +0 -1
- 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/DashboardProvider.d.ts +7 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +19 -7
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +64 -22
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +133 -26
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +2 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/{panel-editing-slice.d.ts → panel-editor-slice.d.ts} +28 -13
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/{panel-editing-slice.js → panel-editor-slice.js} +33 -14
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +40 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +96 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +75 -10
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +189 -17
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/TimeRangeProvider.d.ts +9 -2
- package/dist/context/TimeRangeProvider.d.ts.map +1 -1
- package/dist/context/TimeRangeProvider.js +15 -43
- package/dist/context/TimeRangeProvider.js.map +1 -1
- 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/useDashboardSpec.d.ts +3 -0
- package/dist/context/useDashboardSpec.d.ts.map +1 -0
- package/dist/context/useDashboardSpec.js +55 -0
- package/dist/context/useDashboardSpec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/test/render.d.ts +2 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +25 -5
- package/dist/test/render.js.map +1 -1
- package/dist/test/setup-tests.d.ts.map +1 -1
- package/dist/test/setup-tests.js +4 -0
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +11 -10
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/time-range-params.d.ts +25 -0
- package/dist/utils/time-range-params.d.ts.map +1 -0
- package/dist/utils/time-range-params.js +137 -0
- package/dist/utils/time-range-params.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +1 -3
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +45 -96
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +5 -4
- package/dist/cjs/context/DashboardProvider/layout-slice.js +0 -200
- package/dist/cjs/context/QueryStringProvider.js +0 -89
- package/dist/context/DashboardProvider/layout-slice.d.ts +0 -57
- package/dist/context/DashboardProvider/layout-slice.d.ts.map +0 -1
- package/dist/context/DashboardProvider/layout-slice.js +0 -196
- package/dist/context/DashboardProvider/layout-slice.js.map +0 -1
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +0 -1
- package/dist/context/DashboardProvider/panel-editing-slice.js.map +0 -1
- package/dist/context/QueryStringProvider.d.ts +0 -13
- package/dist/context/QueryStringProvider.d.ts.map +0 -1
- package/dist/context/QueryStringProvider.js +0 -40
- package/dist/context/QueryStringProvider.js.map +0 -1
|
@@ -22,11 +22,21 @@ function _export(target, all) {
|
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
24
|
useEditMode: ()=>useEditMode,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
useDashboardActions: ()=>useDashboardActions,
|
|
26
|
+
usePanelGroupIds: ()=>usePanelGroupIds,
|
|
27
|
+
useListPanelGroups: ()=>useListPanelGroups,
|
|
28
|
+
usePanelGroup: ()=>usePanelGroup,
|
|
29
|
+
usePanelGroupActions: ()=>usePanelGroupActions,
|
|
30
|
+
usePanelGroupEditor: ()=>usePanelGroupEditor,
|
|
31
|
+
useDeletePanelGroupDialog: ()=>useDeletePanelGroupDialog,
|
|
32
|
+
usePanel: ()=>usePanel,
|
|
33
|
+
usePanelActions: ()=>usePanelActions,
|
|
34
|
+
usePanelEditor: ()=>usePanelEditor,
|
|
35
|
+
useDeletePanelDialog: ()=>useDeletePanelDialog,
|
|
28
36
|
useDefaultTimeRange: ()=>useDefaultTimeRange
|
|
29
37
|
});
|
|
38
|
+
const _core = require("@perses-dev/core");
|
|
39
|
+
const _react = require("react");
|
|
30
40
|
const _dashboardProvider = require("./DashboardProvider");
|
|
31
41
|
function useEditMode() {
|
|
32
42
|
return (0, _dashboardProvider.useDashboardStore)(({ isEditMode , setEditMode })=>({
|
|
@@ -34,37 +44,120 @@ function useEditMode() {
|
|
|
34
44
|
setEditMode
|
|
35
45
|
}));
|
|
36
46
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
function useDashboardActions() {
|
|
48
|
+
const save = (0, _dashboardProvider.useDashboardStore)((store)=>store.save);
|
|
49
|
+
const reset = (0, _dashboardProvider.useDashboardStore)((store)=>store.reset);
|
|
50
|
+
const openAddPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanelGroup);
|
|
51
|
+
const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
|
|
52
|
+
return {
|
|
53
|
+
save,
|
|
54
|
+
reset,
|
|
55
|
+
openAddPanelGroup,
|
|
56
|
+
openAddPanel: ()=>openAddPanel(undefined)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function usePanelGroupIds() {
|
|
60
|
+
return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder);
|
|
61
|
+
}
|
|
62
|
+
function useListPanelGroups() {
|
|
63
|
+
const panelGroupIds = usePanelGroupIds();
|
|
64
|
+
const panelGroups = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroups);
|
|
65
|
+
return (0, _react.useMemo)(()=>{
|
|
66
|
+
return panelGroupIds.map((id)=>{
|
|
67
|
+
const group = panelGroups[id];
|
|
68
|
+
if (group === undefined) {
|
|
69
|
+
throw new Error(`Invalid panel group Id found ${id}`);
|
|
70
|
+
}
|
|
71
|
+
return group;
|
|
72
|
+
});
|
|
73
|
+
}, [
|
|
74
|
+
panelGroupIds,
|
|
75
|
+
panelGroups
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
function usePanelGroup(panelGroupId) {
|
|
79
|
+
const panelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroups[panelGroupId]);
|
|
80
|
+
if (panelGroup === undefined) {
|
|
81
|
+
throw new Error(`Panel group with Id ${panelGroupId} was not found`);
|
|
82
|
+
}
|
|
83
|
+
return panelGroup;
|
|
84
|
+
}
|
|
85
|
+
function usePanelGroupActions(panelGroupId) {
|
|
86
|
+
const { moveUp , moveDown } = useMovePanelGroup(panelGroupId);
|
|
87
|
+
const openEditPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openEditPanelGroup);
|
|
88
|
+
const deletePanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openDeletePanelGroupDialog);
|
|
89
|
+
const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
|
|
90
|
+
return {
|
|
91
|
+
openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
|
|
92
|
+
deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
|
|
93
|
+
openAddPanel: ()=>openAddPanel(panelGroupId),
|
|
94
|
+
moveUp,
|
|
95
|
+
moveDown
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
|
|
100
|
+
* moved in that direction.
|
|
101
|
+
*/ function useMovePanelGroup(panelGroupId) {
|
|
102
|
+
const currentIndex = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder.findIndex((id)=>id === panelGroupId));
|
|
103
|
+
const panelGroupsLength = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder.length);
|
|
104
|
+
const swapPanelGroups = (0, _dashboardProvider.useDashboardStore)((store)=>store.swapPanelGroups);
|
|
105
|
+
if (currentIndex < 0) {
|
|
106
|
+
throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
|
|
107
|
+
}
|
|
108
|
+
const moveUp = ()=>swapPanelGroups(currentIndex, currentIndex - 1);
|
|
109
|
+
const moveDown = ()=>swapPanelGroups(currentIndex, currentIndex + 1);
|
|
110
|
+
return {
|
|
111
|
+
moveUp: currentIndex > 0 ? moveUp : undefined,
|
|
112
|
+
moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined
|
|
113
|
+
};
|
|
46
114
|
}
|
|
47
|
-
function
|
|
48
|
-
return (0, _dashboardProvider.useDashboardStore)((
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
115
|
+
function usePanelGroupEditor() {
|
|
116
|
+
return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupEditor);
|
|
117
|
+
}
|
|
118
|
+
function useDeletePanelGroupDialog() {
|
|
119
|
+
return (0, _dashboardProvider.useDashboardStore)(({ deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup })=>({
|
|
52
120
|
deletePanelGroupDialog,
|
|
53
121
|
openDeletePanelGroupDialog,
|
|
54
|
-
closeDeletePanelGroupDialog
|
|
122
|
+
closeDeletePanelGroupDialog,
|
|
123
|
+
deletePanelGroup
|
|
55
124
|
}));
|
|
56
125
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})
|
|
126
|
+
function usePanel(panelGroupItemId) {
|
|
127
|
+
const { panelGroupId , itemIndex } = panelGroupItemId;
|
|
128
|
+
const panel = (0, _dashboardProvider.useDashboardStore)((store)=>{
|
|
129
|
+
var ref, ref1;
|
|
130
|
+
const panelRef = (ref1 = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items[itemIndex]) === null || ref1 === void 0 ? void 0 : ref1.content;
|
|
131
|
+
if (panelRef === undefined) return;
|
|
132
|
+
const panelKey = (0, _core.getPanelKeyFromRef)(panelRef);
|
|
133
|
+
return store.panels[panelKey];
|
|
134
|
+
});
|
|
135
|
+
if (panel === undefined) {
|
|
136
|
+
throw new Error(`Could not find panel for Id ${panelGroupItemId}`);
|
|
137
|
+
}
|
|
138
|
+
return panel;
|
|
139
|
+
}
|
|
140
|
+
function usePanelActions(panelGroupItemId) {
|
|
141
|
+
const openEditPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openEditPanel);
|
|
142
|
+
const openDeletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.openDeletePanelDialog);
|
|
143
|
+
return {
|
|
144
|
+
openEditPanel: ()=>openEditPanel(panelGroupItemId),
|
|
145
|
+
openDeletePanelDialog: ()=>openDeletePanelDialog(panelGroupItemId)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function usePanelEditor() {
|
|
149
|
+
return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelEditor);
|
|
150
|
+
}
|
|
151
|
+
function useDeletePanelDialog() {
|
|
152
|
+
const deletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanelDialog);
|
|
153
|
+
// TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
|
|
154
|
+
const deletePanels = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanels);
|
|
155
|
+
const closeDeletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.closeDeletePanelDialog);
|
|
156
|
+
return {
|
|
157
|
+
deletePanelDialog,
|
|
158
|
+
deletePanels,
|
|
159
|
+
closeDeletePanelDialog
|
|
160
|
+
};
|
|
68
161
|
}
|
|
69
162
|
function useDefaultTimeRange() {
|
|
70
163
|
return (0, _dashboardProvider.useDashboardStore)((state)=>state.defaultTimeRange);
|
|
@@ -23,9 +23,20 @@ function createPanelEditorSlice(panels) {
|
|
|
23
23
|
// Return the state creator function for Zustand that uses the panels provided as intitial state
|
|
24
24
|
return (set, get)=>{
|
|
25
25
|
return {
|
|
26
|
+
previousPanels: panels,
|
|
26
27
|
panels,
|
|
27
28
|
panelEditor: undefined,
|
|
28
|
-
|
|
29
|
+
savePanels () {
|
|
30
|
+
set((state)=>{
|
|
31
|
+
state.previousPanels = state.panels;
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
resetPanels () {
|
|
35
|
+
set((state)=>{
|
|
36
|
+
state.panels = state.previousPanels;
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
openEditPanel (item) {
|
|
29
40
|
const { panels , getPanelKey } = get();
|
|
30
41
|
// Ask the layout store for the panel key at that location
|
|
31
42
|
const panelKey = getPanelKey(item);
|
|
@@ -40,7 +51,7 @@ function createPanelEditorSlice(panels) {
|
|
|
40
51
|
initialValues: {
|
|
41
52
|
name: panelToEdit.spec.display.name,
|
|
42
53
|
description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
43
|
-
|
|
54
|
+
groupId: item.panelGroupId,
|
|
44
55
|
kind: panelToEdit.spec.plugin.kind,
|
|
45
56
|
spec: panelToEdit.spec.plugin.spec
|
|
46
57
|
},
|
|
@@ -50,8 +61,8 @@ function createPanelEditorSlice(panels) {
|
|
|
50
61
|
state.panels[panelKey] = panelDefinititon;
|
|
51
62
|
});
|
|
52
63
|
// Move the panel to another group if it changed
|
|
53
|
-
if (next.
|
|
54
|
-
get().movePanelToGroup(item, next.
|
|
64
|
+
if (next.groupId !== item.panelGroupId) {
|
|
65
|
+
get().movePanelToGroup(item, next.groupId);
|
|
55
66
|
}
|
|
56
67
|
},
|
|
57
68
|
close: ()=>{
|
|
@@ -65,13 +76,21 @@ function createPanelEditorSlice(panels) {
|
|
|
65
76
|
state.panelEditor = editorState;
|
|
66
77
|
});
|
|
67
78
|
},
|
|
68
|
-
|
|
79
|
+
openAddPanel (panelGroupId) {
|
|
80
|
+
// If a panel group isn't supplied, add to the first group
|
|
81
|
+
if (panelGroupId === undefined) {
|
|
82
|
+
const firstGroupId = get().panelGroupIdOrder[0];
|
|
83
|
+
if (firstGroupId === undefined) {
|
|
84
|
+
throw new Error('No panel groups to add a panel to');
|
|
85
|
+
}
|
|
86
|
+
panelGroupId = firstGroupId;
|
|
87
|
+
}
|
|
69
88
|
const editorState = {
|
|
70
89
|
mode: 'Add',
|
|
71
90
|
initialValues: {
|
|
72
91
|
name: '',
|
|
73
92
|
description: '',
|
|
74
|
-
|
|
93
|
+
groupId: panelGroupId,
|
|
75
94
|
// TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to
|
|
76
95
|
// set a smarter default here?
|
|
77
96
|
kind: '',
|
|
@@ -83,7 +102,7 @@ function createPanelEditorSlice(panels) {
|
|
|
83
102
|
set((state)=>{
|
|
84
103
|
state.panels[panelKey] = panelDef;
|
|
85
104
|
});
|
|
86
|
-
get().addPanelToGroup(panelKey, next.
|
|
105
|
+
get().addPanelToGroup(panelKey, next.groupId);
|
|
87
106
|
},
|
|
88
107
|
close: ()=>{
|
|
89
108
|
set((state)=>{
|
|
@@ -118,15 +137,15 @@ function createPanelEditorSlice(panels) {
|
|
|
118
137
|
});
|
|
119
138
|
},
|
|
120
139
|
openDeletePanelDialog (item) {
|
|
140
|
+
const { panels , getPanelKey , panelGroups } = get();
|
|
141
|
+
const panelKey = getPanelKey(item);
|
|
121
142
|
set((state)=>{
|
|
122
|
-
var ref;
|
|
123
|
-
|
|
124
|
-
const panelKey = getPanelKey(item);
|
|
125
|
-
var _name;
|
|
143
|
+
var ref, ref1;
|
|
144
|
+
var _name, ref2;
|
|
126
145
|
state.deletePanelDialog = {
|
|
127
|
-
|
|
146
|
+
panelGroupItemId: item,
|
|
128
147
|
panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
|
|
129
|
-
|
|
148
|
+
panelGroupName: (ref2 = (ref1 = panelGroups[item.panelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref2 !== void 0 ? ref2 : ''
|
|
130
149
|
};
|
|
131
150
|
});
|
|
132
151
|
},
|
|
@@ -0,0 +1,102 @@
|
|
|
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, "createPanelGroupEditorSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createPanelGroupEditorSlice
|
|
20
|
+
});
|
|
21
|
+
const createPanelGroupEditorSlice = (set, get)=>({
|
|
22
|
+
panelGroupEditor: undefined,
|
|
23
|
+
openAddPanelGroup: ()=>{
|
|
24
|
+
// Create the editor state
|
|
25
|
+
const editor = {
|
|
26
|
+
mode: 'Add',
|
|
27
|
+
initialValues: {
|
|
28
|
+
title: '',
|
|
29
|
+
isCollapsed: false
|
|
30
|
+
},
|
|
31
|
+
applyChanges (next) {
|
|
32
|
+
const newGroup = {
|
|
33
|
+
id: get().createPanelGroupId(),
|
|
34
|
+
items: [],
|
|
35
|
+
...next
|
|
36
|
+
};
|
|
37
|
+
set((draft)=>{
|
|
38
|
+
draft.panelGroups[newGroup.id] = newGroup;
|
|
39
|
+
draft.panelGroupIdOrder.unshift(newGroup.id);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
close () {
|
|
43
|
+
set((draft)=>{
|
|
44
|
+
draft.panelGroupEditor = undefined;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// Open the editor
|
|
49
|
+
set((draft)=>{
|
|
50
|
+
draft.panelGroupEditor = editor;
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
openEditPanelGroup: (panelGroupId)=>{
|
|
54
|
+
const existingGroup = get().panelGroups[panelGroupId];
|
|
55
|
+
if (existingGroup === undefined) {
|
|
56
|
+
throw new Error(`Panel group with Id ${panelGroupId} does not exist`);
|
|
57
|
+
}
|
|
58
|
+
var _title;
|
|
59
|
+
// Create the editor state
|
|
60
|
+
const editor = {
|
|
61
|
+
mode: 'Edit',
|
|
62
|
+
initialValues: {
|
|
63
|
+
title: (_title = existingGroup.title) !== null && _title !== void 0 ? _title : '',
|
|
64
|
+
isCollapsed: existingGroup.isCollapsed
|
|
65
|
+
},
|
|
66
|
+
applyChanges (next) {
|
|
67
|
+
set((draft)=>{
|
|
68
|
+
const group = draft.panelGroups[panelGroupId];
|
|
69
|
+
if (group === undefined) {
|
|
70
|
+
throw new Error(`Panel group with Id ${panelGroupId} does not exist`);
|
|
71
|
+
}
|
|
72
|
+
group.title = next.title;
|
|
73
|
+
group.isCollapsed = next.isCollapsed;
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
close () {
|
|
77
|
+
set((draft)=>{
|
|
78
|
+
draft.panelGroupEditor = undefined;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
// Open the editor
|
|
83
|
+
set((draft)=>{
|
|
84
|
+
draft.panelGroupEditor = editor;
|
|
85
|
+
});
|
|
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
|
+
})
|
|
102
|
+
});
|
|
@@ -18,21 +18,191 @@ Object.defineProperty(exports, "createPanelGroupSlice", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>createPanelGroupSlice
|
|
20
20
|
});
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const _core = require("@perses-dev/core");
|
|
22
|
+
function createPanelGroupSlice(layouts) {
|
|
23
|
+
// Helper function for generating unique IDs for a PanelGroup
|
|
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
|
+
}
|
|
43
|
+
// Return the state creator function for Zustand
|
|
44
|
+
return (set, get)=>{
|
|
45
|
+
return {
|
|
46
|
+
panelGroups,
|
|
47
|
+
panelGroupIdOrder,
|
|
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)
|
|
25
83
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
},
|
|
111
|
+
swapPanelGroups (x, y) {
|
|
112
|
+
set((state)=>{
|
|
113
|
+
if (x < 0 || x >= state.panelGroupIdOrder.length || y < 0 || y >= state.panelGroupIdOrder.length) {
|
|
114
|
+
throw new Error('index out of bound');
|
|
115
|
+
}
|
|
116
|
+
const xPanelGroup = state.panelGroupIdOrder[x];
|
|
117
|
+
const yPanelGroup = state.panelGroupIdOrder[y];
|
|
118
|
+
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
119
|
+
throw new Error('panel group is undefined');
|
|
120
|
+
}
|
|
121
|
+
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
122
|
+
[state.panelGroupIdOrder[x], state.panelGroupIdOrder[y]] = [
|
|
123
|
+
yPanelGroup,
|
|
124
|
+
xPanelGroup
|
|
125
|
+
];
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
deletePanelInPanelGroup ({ panelGroupId , itemIndex }) {
|
|
129
|
+
set((state)=>{
|
|
130
|
+
const group = state.panelGroups[panelGroupId];
|
|
131
|
+
if (group === undefined) {
|
|
132
|
+
throw new Error(`No panel group found: ${panelGroupId}`);
|
|
133
|
+
}
|
|
134
|
+
// remove panel from panel group
|
|
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
|
+
});
|
|
176
|
+
});
|
|
177
|
+
return map;
|
|
178
|
+
}
|
|
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;
|
|
208
|
+
}
|
|
@@ -14,14 +14,18 @@
|
|
|
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
|
+
TimeRangeProvider: ()=>TimeRangeProvider,
|
|
25
|
+
useDashboardTimeRange: ()=>useDashboardTimeRange
|
|
20
26
|
});
|
|
21
27
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
28
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
23
|
-
const _dateFns = require("date-fns");
|
|
24
|
-
const _core = require("@perses-dev/core");
|
|
25
29
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
26
30
|
function _getRequireWildcardCache(nodeInterop) {
|
|
27
31
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -63,47 +67,12 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
63
67
|
return newObj;
|
|
64
68
|
}
|
|
65
69
|
function TimeRangeProvider(props) {
|
|
66
|
-
const {
|
|
67
|
-
|
|
68
|
-
const defaultTimeRange = (0, _core.isRelativeTimeRange)(initialTimeRange) ? (0, _core.toAbsoluteTimeRange)(initialTimeRange) : initialTimeRange;
|
|
69
|
-
const [timeRange, setActiveTimeRange] = (0, _react.useState)(defaultTimeRange);
|
|
70
|
-
const setTimeRange = (0, _react.useCallback)((value)=>{
|
|
71
|
-
if (onTimeRangeChange !== undefined) {
|
|
72
|
-
// optional callback to override default behavior
|
|
73
|
-
onTimeRangeChange(value);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if ((0, _core.isRelativeTimeRange)(value)) {
|
|
77
|
-
if (setQueryString) {
|
|
78
|
-
queryString.set('start', value.pastDuration);
|
|
79
|
-
// end not required for relative time but may have been set by AbsoluteTimePicker or zoom
|
|
80
|
-
queryString.delete('end');
|
|
81
|
-
setQueryString(queryString);
|
|
82
|
-
} else {
|
|
83
|
-
setActiveTimeRange((0, _core.toAbsoluteTimeRange)(value));
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
// allows app to specify whether query params should be source of truth for active time range
|
|
88
|
-
if (setQueryString) {
|
|
89
|
-
// Absolute URL example) ?start=1663707045000&end=1663713330000
|
|
90
|
-
// currently set from ViewDashboard initial queryString, AbsoluteTimePicker, or LineChart panel onDataZoom
|
|
91
|
-
const startUnixMs = (0, _dateFns.getUnixTime)(value.start) * 1000;
|
|
92
|
-
const endUnixMs = (0, _dateFns.getUnixTime)(value.end) * 1000;
|
|
93
|
-
queryString.set('start', startUnixMs.toString());
|
|
94
|
-
queryString.set('end', endUnixMs.toString());
|
|
95
|
-
setQueryString(queryString);
|
|
96
|
-
} else {
|
|
97
|
-
setActiveTimeRange(value);
|
|
98
|
-
}
|
|
99
|
-
}, [
|
|
100
|
-
queryString,
|
|
101
|
-
setQueryString,
|
|
102
|
-
onTimeRangeChange
|
|
103
|
-
]);
|
|
70
|
+
const { timeRange , children , setTimeRange } = props;
|
|
71
|
+
// TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround
|
|
104
72
|
const ctx = (0, _react.useMemo)(()=>({
|
|
105
73
|
timeRange,
|
|
106
|
-
setTimeRange
|
|
74
|
+
setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : ()=>{
|
|
75
|
+
/* no-op */ }
|
|
107
76
|
}), [
|
|
108
77
|
timeRange,
|
|
109
78
|
setTimeRange
|
|
@@ -113,3 +82,10 @@ function TimeRangeProvider(props) {
|
|
|
113
82
|
children: children
|
|
114
83
|
});
|
|
115
84
|
}
|
|
85
|
+
function useDashboardTimeRange() {
|
|
86
|
+
const { timeRange , setTimeRange } = (0, _pluginSystem.useTimeRangeContext)();
|
|
87
|
+
return {
|
|
88
|
+
timeRange,
|
|
89
|
+
setTimeRange
|
|
90
|
+
};
|
|
91
|
+
}
|