@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
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
export const createPanelGroupEditorSlice = (set, get)=>({
|
|
14
|
+
panelGroupEditor: undefined,
|
|
15
|
+
openAddPanelGroup: ()=>{
|
|
16
|
+
// Create the editor state
|
|
17
|
+
const editor = {
|
|
18
|
+
mode: 'Add',
|
|
19
|
+
initialValues: {
|
|
20
|
+
title: '',
|
|
21
|
+
isCollapsed: false
|
|
22
|
+
},
|
|
23
|
+
applyChanges (next) {
|
|
24
|
+
const newGroup = {
|
|
25
|
+
id: get().createPanelGroupId(),
|
|
26
|
+
items: [],
|
|
27
|
+
...next
|
|
28
|
+
};
|
|
29
|
+
set((draft)=>{
|
|
30
|
+
draft.panelGroups[newGroup.id] = newGroup;
|
|
31
|
+
draft.panelGroupIdOrder.unshift(newGroup.id);
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
close () {
|
|
35
|
+
set((draft)=>{
|
|
36
|
+
draft.panelGroupEditor = undefined;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// Open the editor
|
|
41
|
+
set((draft)=>{
|
|
42
|
+
draft.panelGroupEditor = editor;
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
openEditPanelGroup: (panelGroupId)=>{
|
|
46
|
+
const existingGroup = get().panelGroups[panelGroupId];
|
|
47
|
+
if (existingGroup === undefined) {
|
|
48
|
+
throw new Error(`Panel group with Id ${panelGroupId} does not exist`);
|
|
49
|
+
}
|
|
50
|
+
var _title;
|
|
51
|
+
// Create the editor state
|
|
52
|
+
const editor = {
|
|
53
|
+
mode: 'Edit',
|
|
54
|
+
initialValues: {
|
|
55
|
+
title: (_title = existingGroup.title) !== null && _title !== void 0 ? _title : '',
|
|
56
|
+
isCollapsed: existingGroup.isCollapsed
|
|
57
|
+
},
|
|
58
|
+
applyChanges (next) {
|
|
59
|
+
set((draft)=>{
|
|
60
|
+
const group = draft.panelGroups[panelGroupId];
|
|
61
|
+
if (group === undefined) {
|
|
62
|
+
throw new Error(`Panel group with Id ${panelGroupId} does not exist`);
|
|
63
|
+
}
|
|
64
|
+
group.title = next.title;
|
|
65
|
+
group.isCollapsed = next.isCollapsed;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
close () {
|
|
69
|
+
set((draft)=>{
|
|
70
|
+
draft.panelGroupEditor = undefined;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// Open the editor
|
|
75
|
+
set((draft)=>{
|
|
76
|
+
draft.panelGroupEditor = editor;
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
openDeletePanelGroupDialog: (panelGroupId)=>{
|
|
80
|
+
const panelGroup = get().panelGroups[panelGroupId];
|
|
81
|
+
if (panelGroup === undefined) {
|
|
82
|
+
throw new Error(`Panel group with Id ${panelGroupId} not found`);
|
|
83
|
+
}
|
|
84
|
+
set((state)=>{
|
|
85
|
+
state.deletePanelGroupDialog = {
|
|
86
|
+
panelGroupId,
|
|
87
|
+
panelGroupName: panelGroup.title
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
closeDeletePanelGroupDialog: ()=>set((state)=>{
|
|
92
|
+
state.deletePanelGroupDialog = undefined;
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=panel-group-editor-slice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupDefinition, PanelGroupId } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\nexport interface DeletePanelGroupDialog {\n panelGroupId: PanelGroupId;\n panelGroupName?: string;\n}\n\n/**\n * Slice that handles the visual editor state and actions for Panel Groups (i.e. add, edit, delete).\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n\n deletePanelGroupDialog?: DeletePanelGroupDialog;\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n closeDeletePanelGroupDialog: () => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup: PanelGroupDefinition = {\n id: get().createPanelGroupId(),\n items: [],\n ...next,\n };\n set((draft) => {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupIdOrder.unshift(newGroup.id);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openDeletePanelGroupDialog: (panelGroupId) => {\n const panelGroup = get().panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} not found`);\n }\n set((state) => {\n state.deletePanelGroupDialog = { panelGroupId, panelGroupName: panelGroup.title };\n });\n },\n closeDeletePanelGroupDialog: () =>\n set((state) => {\n state.deletePanelGroupDialog = undefined;\n }),\n});\n"],"names":["createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","id","createPanelGroupId","items","draft","panelGroups","panelGroupIdOrder","unshift","close","openEditPanelGroup","panelGroupId","existingGroup","Error","group","openDeletePanelGroupDialog","panelGroup","state","deletePanelGroupDialog","panelGroupName","closeDeletePanelGroupDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA+CjC,OAAO,MAAMA,2BAA2B,GAKpC,CAACC,GAAG,EAAEC,GAAG,GAAM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K;gBACbA,KAAK,CAACC,sBAAsB,GAAG;oBAAEP,YAAY;oBAAEQ,cAAc,EAAEH,UAAU,CAACnB,KAAK;iBAAE,CAAC;YACpF,CAAC,CAAC,CAAC;QACL,CAAC;QACDuB,2BAA2B,EAAE,IAC3B/B,GAAG,CAAC,CAAC4B,KAAK,GAAK;gBACbA,KAAK,CAACC,sBAAsB,GAAG1B,SAAS,CAAC;YAC3C,CAAC,CAAC;KACL,CAAA,AAAC,CAAC"}
|
|
@@ -1,15 +1,80 @@
|
|
|
1
|
+
import { GridItemDefinition, LayoutDefinition } from '@perses-dev/core';
|
|
1
2
|
import { StateCreator } from 'zustand';
|
|
2
3
|
import { Middleware } from './common';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { PanelEditorSlice } from './panel-editor-slice';
|
|
5
|
+
/**
|
|
6
|
+
* Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.
|
|
7
|
+
*/
|
|
6
8
|
export interface PanelGroupSlice {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Panel groups indexed by their ID.
|
|
11
|
+
*/
|
|
12
|
+
panelGroups: Record<PanelGroupId, PanelGroupDefinition>;
|
|
13
|
+
/**
|
|
14
|
+
* An array of panel group IDs, representing their order in the dashboard.
|
|
15
|
+
*/
|
|
16
|
+
panelGroupIdOrder: PanelGroupId[];
|
|
17
|
+
/**
|
|
18
|
+
* previous state
|
|
19
|
+
*/
|
|
20
|
+
previousPanelGroupStates: {
|
|
21
|
+
panelGroups: PanelGroupSlice['panelGroups'];
|
|
22
|
+
panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'];
|
|
23
|
+
};
|
|
24
|
+
createPanelGroupId: () => PanelGroupId;
|
|
25
|
+
/**
|
|
26
|
+
* Given a LayoutItem location, returns the panel's unique key at that location.
|
|
27
|
+
*/
|
|
28
|
+
getPanelKey: (layoutItem: PanelGroupItemId) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Add a panel with the specified key to an existing group.
|
|
31
|
+
*/
|
|
32
|
+
addPanelToGroup: (panelKey: string, panelGroupId: PanelGroupId) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Move an existing Panel to a new panel group.
|
|
35
|
+
*/
|
|
36
|
+
movePanelToGroup: (layoutItem: PanelGroupItemId, newPanelGroupId: PanelGroupId) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Rearrange the order of panel groups by swapping the positions
|
|
39
|
+
*/
|
|
40
|
+
swapPanelGroups: (xIndex: number, yIndex: number) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Delete panel group and all the panels within the group
|
|
43
|
+
*/
|
|
44
|
+
deletePanelGroup: (panelGroupId: PanelGroupId) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Delete panel in panel group
|
|
47
|
+
*/
|
|
48
|
+
deletePanelInPanelGroup: (layoutItem: PanelGroupItemId) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Map panel to panel groups
|
|
51
|
+
*/
|
|
52
|
+
mapPanelToPanelGroups: () => Record<string, PanelGroupId[]>;
|
|
53
|
+
/**
|
|
54
|
+
* save
|
|
55
|
+
*/
|
|
56
|
+
savePanelGroups: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* reset to previous panel group states
|
|
59
|
+
*/
|
|
60
|
+
resetPanelGroups: () => void;
|
|
61
|
+
}
|
|
62
|
+
export declare type PanelGroupId = number;
|
|
63
|
+
export interface PanelGroupDefinition {
|
|
64
|
+
id: PanelGroupId;
|
|
65
|
+
items: GridItemDefinition[];
|
|
66
|
+
isCollapsed: boolean;
|
|
67
|
+
title?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Uniquely identifies an item in a PanelGroup.
|
|
71
|
+
*/
|
|
72
|
+
export interface PanelGroupItemId {
|
|
73
|
+
panelGroupId: PanelGroupId;
|
|
74
|
+
itemIndex: number;
|
|
13
75
|
}
|
|
14
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Curried function for creating a PanelGroupSlice.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice & PanelEditorSlice, Middleware, [], PanelGroupSlice>;
|
|
15
80
|
//# sourceMappingURL=panel-group-slice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAsC,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,iBAAiB,EAAE,YAAY,EAAE,CAAC;IAElC;;OAEG;IACH,wBAAwB,EAAE;QACxB,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;QAC5C,iBAAiB,EAAE,eAAe,CAAC,mBAAmB,CAAC,CAAC;KACzD,CAAC;IAGF,kBAAkB,EAAE,MAAM,YAAY,CAAC;IAEvC;;OAEG;IACH,WAAW,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,MAAM,CAAC;IAEtD;;OAEG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAExE;;OAEG;IACH,gBAAgB,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,KAAK,IAAI,CAAC;IAExF;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAEvD;;OAEG;IACH,uBAAuB,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAEhE;;OAEG;IACH,qBAAqB,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAE5D;;OAEG;IACH,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,GAAG,gBAAgB,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkKnF"}
|
|
@@ -10,23 +10,195 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
import { createPanelRef, getPanelKeyFromRef } from '@perses-dev/core';
|
|
14
|
+
/**
|
|
15
|
+
* Curried function for creating a PanelGroupSlice.
|
|
16
|
+
*/ export function createPanelGroupSlice(layouts) {
|
|
17
|
+
// Helper function for generating unique IDs for a PanelGroup
|
|
18
|
+
let id = -1;
|
|
19
|
+
function createPanelGroupId() {
|
|
20
|
+
id++;
|
|
21
|
+
return id;
|
|
22
|
+
}
|
|
23
|
+
// Convert the initial layouts from the JSON to panel groups and keep track of the order
|
|
24
|
+
const panelGroups = {};
|
|
25
|
+
const panelGroupIdOrder = [];
|
|
26
|
+
for (const layout of layouts){
|
|
27
|
+
var ref, ref1, ref2;
|
|
28
|
+
const id1 = createPanelGroupId();
|
|
29
|
+
panelGroups[id1] = {
|
|
30
|
+
id: id1,
|
|
31
|
+
items: layout.spec.items,
|
|
32
|
+
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
33
|
+
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title
|
|
34
|
+
};
|
|
35
|
+
panelGroupIdOrder.push(id1);
|
|
36
|
+
}
|
|
37
|
+
// Return the state creator function for Zustand
|
|
38
|
+
return (set, get)=>{
|
|
39
|
+
return {
|
|
40
|
+
panelGroups,
|
|
41
|
+
panelGroupIdOrder,
|
|
42
|
+
previousPanelGroupStates: {
|
|
43
|
+
panelGroups,
|
|
44
|
+
panelGroupIdOrder
|
|
45
|
+
},
|
|
46
|
+
// TODO: Reorder init logic so this isn't exposed
|
|
47
|
+
createPanelGroupId,
|
|
48
|
+
savePanelGroups () {
|
|
49
|
+
set((state)=>{
|
|
50
|
+
state.previousPanelGroupStates = {
|
|
51
|
+
panelGroups: state.panelGroups,
|
|
52
|
+
panelGroupIdOrder: state.panelGroupIdOrder
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
resetPanelGroups () {
|
|
57
|
+
set((state)=>{
|
|
58
|
+
state.panelGroups = state.previousPanelGroupStates.panelGroups;
|
|
59
|
+
state.panelGroupIdOrder = state.previousPanelGroupStates.panelGroupIdOrder;
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
getPanelKey ({ panelGroupId , itemIndex }) {
|
|
63
|
+
const { panelGroups } = get();
|
|
64
|
+
const group = findGroup(panelGroups, panelGroupId);
|
|
65
|
+
const item = findItem(group, itemIndex);
|
|
66
|
+
return getPanelKeyFromRef(item.content);
|
|
67
|
+
},
|
|
68
|
+
addPanelToGroup (panelKey, panelGroupId) {
|
|
69
|
+
const { panelGroups } = get();
|
|
70
|
+
const group = findGroup(panelGroups, panelGroupId);
|
|
71
|
+
const gridItem = {
|
|
72
|
+
x: 0,
|
|
73
|
+
y: getYForNewRow(group),
|
|
74
|
+
width: 12,
|
|
75
|
+
height: 6,
|
|
76
|
+
content: createPanelRef(panelKey)
|
|
17
77
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
78
|
+
set((state)=>{
|
|
79
|
+
var ref;
|
|
80
|
+
(ref = state.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
movePanelToGroup ({ panelGroupId , itemIndex }, newPanelGroupId) {
|
|
84
|
+
const { panelGroups } = get();
|
|
85
|
+
// Find the existing item to make sure it exists
|
|
86
|
+
const group = findGroup(panelGroups, panelGroupId);
|
|
87
|
+
const item = findItem(group, itemIndex);
|
|
88
|
+
// Find the new group and figure out where a new row should go
|
|
89
|
+
const newGroup = findGroup(panelGroups, newPanelGroupId);
|
|
90
|
+
const newGroupY = getYForNewRow(newGroup);
|
|
91
|
+
set((state)=>{
|
|
92
|
+
var // Remove the item from its current group
|
|
93
|
+
ref, // Add a new item to the new group
|
|
94
|
+
ref1;
|
|
95
|
+
(ref = state.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
|
|
96
|
+
(ref1 = state.panelGroups[newPanelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
|
|
97
|
+
x: 0,
|
|
98
|
+
y: newGroupY,
|
|
99
|
+
width: item.width,
|
|
100
|
+
height: item.height,
|
|
101
|
+
content: item.content
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
swapPanelGroups (x, y) {
|
|
106
|
+
set((state)=>{
|
|
107
|
+
if (x < 0 || x >= state.panelGroupIdOrder.length || y < 0 || y >= state.panelGroupIdOrder.length) {
|
|
108
|
+
throw new Error('index out of bound');
|
|
109
|
+
}
|
|
110
|
+
const xPanelGroup = state.panelGroupIdOrder[x];
|
|
111
|
+
const yPanelGroup = state.panelGroupIdOrder[y];
|
|
112
|
+
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
113
|
+
throw new Error('panel group is undefined');
|
|
114
|
+
}
|
|
115
|
+
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
116
|
+
[state.panelGroupIdOrder[x], state.panelGroupIdOrder[y]] = [
|
|
117
|
+
yPanelGroup,
|
|
118
|
+
xPanelGroup
|
|
119
|
+
];
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
deletePanelInPanelGroup ({ panelGroupId , itemIndex }) {
|
|
123
|
+
set((state)=>{
|
|
124
|
+
const group = state.panelGroups[panelGroupId];
|
|
125
|
+
if (group === undefined) {
|
|
126
|
+
throw new Error(`No panel group found: ${panelGroupId}`);
|
|
127
|
+
}
|
|
128
|
+
// remove panel from panel group
|
|
129
|
+
group.items.splice(itemIndex, 1);
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
deletePanelGroup (panelGroupId) {
|
|
133
|
+
const { panelGroups , panelGroupIdOrder: panelGroupOrder , deletePanels } = get();
|
|
134
|
+
const group = findGroup(panelGroups, panelGroupId);
|
|
135
|
+
const orderIdx = panelGroupOrder.findIndex((id)=>id === panelGroupId);
|
|
136
|
+
if (orderIdx === -1) {
|
|
137
|
+
throw new Error(`Could not find panel group Id ${panelGroupId} in order array`);
|
|
138
|
+
}
|
|
139
|
+
// remove panels from group first
|
|
140
|
+
const panelsToBeDeleted = [];
|
|
141
|
+
for(let i = 0; i < group.items.length; i++){
|
|
142
|
+
panelsToBeDeleted.push({
|
|
143
|
+
panelGroupId,
|
|
144
|
+
itemIndex: i
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
deletePanels(panelsToBeDeleted);
|
|
148
|
+
// remove group from both panelGroups and panelGroupOrder
|
|
149
|
+
set((state)=>{
|
|
150
|
+
state.panelGroupIdOrder.splice(orderIdx, 1);
|
|
151
|
+
delete state.panelGroups[panelGroupId];
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
// Return an object that maps each panel to the groups it belongs
|
|
155
|
+
mapPanelToPanelGroups () {
|
|
156
|
+
const map = {}; // { panel key: [group ids] }
|
|
157
|
+
Object.values(get().panelGroups).forEach((group)=>{
|
|
158
|
+
// for each panel in a group, add the group id to map[panelKey]
|
|
159
|
+
group.items.forEach((panel)=>{
|
|
160
|
+
const panelKey = getPanelKeyFromRef(panel.content);
|
|
161
|
+
if (map[panelKey]) {
|
|
162
|
+
var ref;
|
|
163
|
+
(ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
|
|
164
|
+
} else {
|
|
165
|
+
map[panelKey] = [
|
|
166
|
+
group.id
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
return map;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
// Helper to find a group and throw if not found
|
|
177
|
+
function findGroup(panelGroups, groupId) {
|
|
178
|
+
const group = panelGroups[groupId];
|
|
179
|
+
if (group === undefined) {
|
|
180
|
+
throw new Error(`No panel group found for Id ${groupId}`);
|
|
181
|
+
}
|
|
182
|
+
return group;
|
|
183
|
+
}
|
|
184
|
+
// Helper to get an item in a group and throw if not found
|
|
185
|
+
function findItem(group, itemIndex) {
|
|
186
|
+
const item = group.items[itemIndex];
|
|
187
|
+
if (item === undefined) {
|
|
188
|
+
throw new Error(`No grid item found at position ${itemIndex}`);
|
|
189
|
+
}
|
|
190
|
+
return item;
|
|
191
|
+
}
|
|
192
|
+
// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
|
|
193
|
+
function getYForNewRow(group) {
|
|
194
|
+
let newRowY = 0;
|
|
195
|
+
for (const item of group.items){
|
|
196
|
+
const itemMaxY = item.y + item.height;
|
|
197
|
+
if (itemMaxY > newRowY) {
|
|
198
|
+
newRowY = itemMaxY;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return newRowY;
|
|
202
|
+
}
|
|
31
203
|
|
|
32
204
|
//# sourceMappingURL=panel-group-slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface PanelGroupDialog {\n groupIndex?: number;\n}\n\nexport interface PanelGroupSlice {\n panelGroupDialog?: PanelGroupDialog;\n openPanelGroupDialog: (groupIndex?: number) => void;\n closePanelGroupDialog: () => void;\n deletePanelGroupDialog?: PanelGroupDialog;\n openDeletePanelGroupDialog: (groupIndex: number) => void;\n closeDeletePanelGroupDialog: () => void;\n}\n\nexport const createPanelGroupSlice: StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> = (set) => ({\n openPanelGroupDialog: (groupIndex?: number) =>\n set((state) => {\n state.panelGroupDialog = { groupIndex };\n }),\n closePanelGroupDialog: () =>\n set((state) => {\n state.panelGroupDialog = undefined;\n }),\n openDeletePanelGroupDialog: (groupIndex: number) =>\n set((state) => {\n state.deletePanelGroupDialog = { groupIndex };\n }),\n closeDeletePanelGroupDialog: () =>\n set((state) => {\n state.deletePanelGroupDialog = undefined;\n }),\n});\n"],"names":["createPanelGroupSlice","set","openPanelGroupDialog","groupIndex","state","panelGroupDialog","closePanelGroupDialog","undefined","openDeletePanelGroupDialog","deletePanelGroupDialog","closeDeletePanelGroupDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAkBjC,OAAO,MAAMA,qBAAqB,GAAmE,CAACC,GAAG,GAAM,CAAA;QAC7GC,oBAAoB,EAAE,CAACC,UAAmB,GACxCF,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACC,gBAAgB,GAAG;oBAAEF,UAAU;iBAAE,CAAC;YAC1C,CAAC,CAAC;QACJG,qBAAqB,EAAE,IACrBL,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACC,gBAAgB,GAAGE,SAAS,CAAC;YACrC,CAAC,CAAC;QACJC,0BAA0B,EAAE,CAACL,UAAkB,GAC7CF,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACK,sBAAsB,GAAG;oBAAEN,UAAU;iBAAE,CAAC;YAChD,CAAC,CAAC;QACJO,2BAA2B,EAAE,IAC3BT,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACK,sBAAsB,GAAGF,SAAS,CAAC;YAC3C,CAAC,CAAC;KACL,CAAA,AAAC,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, getPanelKeyFromRef, GridItemDefinition, LayoutDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelEditorSlice } from './panel-editor-slice';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupIdOrder: PanelGroupId[];\n\n /**\n * previous state\n */\n previousPanelGroupStates: {\n panelGroups: PanelGroupSlice['panelGroups'];\n panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'];\n };\n\n // TODO: Remove this\n createPanelGroupId: () => PanelGroupId;\n\n /**\n * Given a LayoutItem location, returns the panel's unique key at that location.\n */\n getPanelKey: (layoutItem: PanelGroupItemId) => string;\n\n /**\n * Add a panel with the specified key to an existing group.\n */\n addPanelToGroup: (panelKey: string, panelGroupId: PanelGroupId) => void;\n\n /**\n * Move an existing Panel to a new panel group.\n */\n movePanelToGroup: (layoutItem: PanelGroupItemId, newPanelGroupId: PanelGroupId) => void;\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Delete panel group and all the panels within the group\n */\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n\n /**\n * Delete panel in panel group\n */\n deletePanelInPanelGroup: (layoutItem: PanelGroupItemId) => void;\n\n /**\n * Map panel to panel groups\n */\n mapPanelToPanelGroups: () => Record<string, PanelGroupId[]>;\n\n /**\n * save\n */\n savePanelGroups: () => void;\n\n /**\n * reset to previous panel group states\n */\n resetPanelGroups: () => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n items: GridItemDefinition[];\n isCollapsed: boolean;\n title?: string;\n}\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n itemIndex: number;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice & PanelEditorSlice, Middleware, [], PanelGroupSlice> {\n // Helper function for generating unique IDs for a PanelGroup\n let id: PanelGroupId = -1;\n function createPanelGroupId(): PanelGroupId {\n id++;\n return id;\n }\n\n // Convert the initial layouts from the JSON to panel groups and keep track of the order\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'] = [];\n for (const layout of layouts) {\n const id = createPanelGroupId();\n panelGroups[id] = {\n id,\n items: layout.spec.items,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n };\n panelGroupIdOrder.push(id);\n }\n\n // Return the state creator function for Zustand\n return (set, get) => ({\n panelGroups,\n panelGroupIdOrder,\n\n previousPanelGroupStates: { panelGroups, panelGroupIdOrder },\n\n // TODO: Reorder init logic so this isn't exposed\n createPanelGroupId,\n\n savePanelGroups() {\n set((state) => {\n state.previousPanelGroupStates = {\n panelGroups: state.panelGroups,\n panelGroupIdOrder: state.panelGroupIdOrder,\n };\n });\n },\n\n resetPanelGroups() {\n set((state) => {\n state.panelGroups = state.previousPanelGroupStates.panelGroups;\n state.panelGroupIdOrder = state.previousPanelGroupStates.panelGroupIdOrder;\n });\n },\n\n getPanelKey({ panelGroupId, itemIndex }) {\n const { panelGroups } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const item = findItem(group, itemIndex);\n return getPanelKeyFromRef(item.content);\n },\n\n addPanelToGroup(panelKey, panelGroupId) {\n const { panelGroups } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const gridItem: GridItemDefinition = {\n x: 0,\n y: getYForNewRow(group),\n width: 12,\n height: 6,\n content: createPanelRef(panelKey),\n };\n set((state) => {\n state.panelGroups[panelGroupId]?.items.push(gridItem);\n });\n },\n\n movePanelToGroup({ panelGroupId, itemIndex }, newPanelGroupId) {\n const { panelGroups } = get();\n\n // Find the existing item to make sure it exists\n const group = findGroup(panelGroups, panelGroupId);\n const item = findItem(group, itemIndex);\n\n // Find the new group and figure out where a new row should go\n const newGroup = findGroup(panelGroups, newPanelGroupId);\n const newGroupY = getYForNewRow(newGroup);\n\n set((state) => {\n // Remove the item from its current group\n state.panelGroups[panelGroupId]?.items.splice(itemIndex, 1);\n\n // Add a new item to the new group\n state.panelGroups[newPanelGroupId]?.items.push({\n x: 0,\n y: newGroupY,\n width: item.width,\n height: item.height,\n content: item.content,\n });\n });\n },\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupIdOrder.length || y < 0 || y >= state.panelGroupIdOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupIdOrder[x];\n const yPanelGroup = state.panelGroupIdOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupIdOrder[x], state.panelGroupIdOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n deletePanelInPanelGroup({ panelGroupId, itemIndex }) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`No panel group found: ${panelGroupId}`);\n }\n // remove panel from panel group\n group.items.splice(itemIndex, 1);\n });\n },\n\n deletePanelGroup(panelGroupId) {\n const { panelGroups, panelGroupIdOrder: panelGroupOrder, deletePanels } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const orderIdx = panelGroupOrder.findIndex((id) => id === panelGroupId);\n if (orderIdx === -1) {\n throw new Error(`Could not find panel group Id ${panelGroupId} in order array`);\n }\n\n // remove panels from group first\n const panelsToBeDeleted: PanelGroupItemId[] = [];\n for (let i = 0; i < group.items.length; i++) {\n panelsToBeDeleted.push({ panelGroupId, itemIndex: i });\n }\n deletePanels(panelsToBeDeleted);\n\n // remove group from both panelGroups and panelGroupOrder\n set((state) => {\n state.panelGroupIdOrder.splice(orderIdx, 1);\n delete state.panelGroups[panelGroupId];\n });\n },\n\n // Return an object that maps each panel to the groups it belongs\n mapPanelToPanelGroups() {\n const map: Record<string, Array<PanelGroupDefinition['id']>> = {}; // { panel key: [group ids] }\n Object.values(get().panelGroups).forEach((group) => {\n // for each panel in a group, add the group id to map[panelKey]\n group.items.forEach((panel) => {\n const panelKey = getPanelKeyFromRef(panel.content);\n if (map[panelKey]) {\n map[panelKey]?.push(group.id);\n } else {\n map[panelKey] = [group.id];\n }\n });\n });\n return map;\n },\n });\n}\n\n// Helper to find a group and throw if not found\nfunction findGroup(panelGroups: PanelGroupSlice['panelGroups'], groupId: PanelGroupId) {\n const group = panelGroups[groupId];\n if (group === undefined) {\n throw new Error(`No panel group found for Id ${groupId}`);\n }\n return group;\n}\n\n// Helper to get an item in a group and throw if not found\nfunction findItem(group: PanelGroupDefinition, itemIndex: number) {\n const item = group.items[itemIndex];\n if (item === undefined) {\n throw new Error(`No grid item found at position ${itemIndex}`);\n }\n return item;\n}\n\n// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const item of group.items) {\n const itemMaxY = item.y + item.height;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["createPanelRef","getPanelKeyFromRef","createPanelGroupSlice","layouts","id","createPanelGroupId","panelGroups","panelGroupIdOrder","layout","items","spec","isCollapsed","display","collapse","open","title","push","set","get","previousPanelGroupStates","savePanelGroups","state","resetPanelGroups","getPanelKey","panelGroupId","itemIndex","group","findGroup","item","findItem","content","addPanelToGroup","panelKey","gridItem","x","y","getYForNewRow","width","height","movePanelToGroup","newPanelGroupId","newGroup","newGroupY","splice","swapPanelGroups","length","Error","xPanelGroup","yPanelGroup","undefined","deletePanelInPanelGroup","deletePanelGroup","panelGroupOrder","deletePanels","orderIdx","findIndex","panelsToBeDeleted","i","mapPanelToPanelGroups","map","Object","values","forEach","panel","groupId","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,EAAEC,kBAAkB,QAA8C,kBAAkB,CAAC;AA6F5G;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACwD;IACnF,6DAA6D;IAC7D,IAAIC,EAAE,GAAiB,CAAC,CAAC,AAAC;IAC1B,SAASC,kBAAkB,GAAiB;QAC1CD,EAAE,EAAE,CAAC;QACL,OAAOA,EAAE,CAAC;IACZ,CAAC;IAED,wFAAwF;IACxF,MAAME,WAAW,GAAmC,EAAE,AAAC;IACvD,MAAMC,iBAAiB,GAAyC,EAAE,AAAC;IACnE,KAAK,MAAMC,MAAM,IAAIL,OAAO,CAAE;YAKbK,GAAmB,QACzBA,IAAmB;QAL5B,MAAMJ,GAAE,GAAGC,kBAAkB,EAAE,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,IAAI4B,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TimeRangeValue } from '@perses-dev/core';
|
|
3
3
|
export interface TimeRangeProviderProps {
|
|
4
|
-
|
|
4
|
+
timeRange: TimeRangeValue;
|
|
5
|
+
setTimeRange?: (value: TimeRangeValue) => void;
|
|
5
6
|
children?: React.ReactNode;
|
|
6
|
-
onTimeRangeChange?: (e: TimeRangeValue) => void;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Provider implementation that supplies the time range state at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export declare function TimeRangeProvider(props: TimeRangeProviderProps): JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* Internal version of time range hook to get all supported values
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDashboardTimeRange(): {
|
|
16
|
+
timeRange: TimeRangeValue;
|
|
17
|
+
setTimeRange: (value: TimeRangeValue) => void;
|
|
18
|
+
};
|
|
12
19
|
//# sourceMappingURL=TimeRangeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAiB9D;AAED;;GAEG;AACH,wBAAgB,qBAAqB;;;EAGpC"}
|
|
@@ -11,54 +11,17 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import React, {
|
|
15
|
-
import {
|
|
16
|
-
import { toAbsoluteTimeRange, isRelativeTimeRange } from '@perses-dev/core';
|
|
17
|
-
import { TimeRangeContext, useQueryString } from '@perses-dev/plugin-system';
|
|
14
|
+
import React, { useMemo } from 'react';
|
|
15
|
+
import { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';
|
|
18
16
|
/**
|
|
19
17
|
* Provider implementation that supplies the time range state at runtime.
|
|
20
18
|
*/ export function TimeRangeProvider(props) {
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
const defaultTimeRange = isRelativeTimeRange(initialTimeRange) ? toAbsoluteTimeRange(initialTimeRange) : initialTimeRange;
|
|
24
|
-
const [timeRange, setActiveTimeRange] = useState(defaultTimeRange);
|
|
25
|
-
const setTimeRange = useCallback((value)=>{
|
|
26
|
-
if (onTimeRangeChange !== undefined) {
|
|
27
|
-
// optional callback to override default behavior
|
|
28
|
-
onTimeRangeChange(value);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (isRelativeTimeRange(value)) {
|
|
32
|
-
if (setQueryString) {
|
|
33
|
-
queryString.set('start', value.pastDuration);
|
|
34
|
-
// end not required for relative time but may have been set by AbsoluteTimePicker or zoom
|
|
35
|
-
queryString.delete('end');
|
|
36
|
-
setQueryString(queryString);
|
|
37
|
-
} else {
|
|
38
|
-
setActiveTimeRange(toAbsoluteTimeRange(value));
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// allows app to specify whether query params should be source of truth for active time range
|
|
43
|
-
if (setQueryString) {
|
|
44
|
-
// Absolute URL example) ?start=1663707045000&end=1663713330000
|
|
45
|
-
// currently set from ViewDashboard initial queryString, AbsoluteTimePicker, or LineChart panel onDataZoom
|
|
46
|
-
const startUnixMs = getUnixTime(value.start) * 1000;
|
|
47
|
-
const endUnixMs = getUnixTime(value.end) * 1000;
|
|
48
|
-
queryString.set('start', startUnixMs.toString());
|
|
49
|
-
queryString.set('end', endUnixMs.toString());
|
|
50
|
-
setQueryString(queryString);
|
|
51
|
-
} else {
|
|
52
|
-
setActiveTimeRange(value);
|
|
53
|
-
}
|
|
54
|
-
}, [
|
|
55
|
-
queryString,
|
|
56
|
-
setQueryString,
|
|
57
|
-
onTimeRangeChange
|
|
58
|
-
]);
|
|
19
|
+
const { timeRange , children , setTimeRange } = props;
|
|
20
|
+
// TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround
|
|
59
21
|
const ctx = useMemo(()=>({
|
|
60
22
|
timeRange,
|
|
61
|
-
setTimeRange
|
|
23
|
+
setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : ()=>{
|
|
24
|
+
/* no-op */ }
|
|
62
25
|
}), [
|
|
63
26
|
timeRange,
|
|
64
27
|
setTimeRange
|
|
@@ -68,5 +31,14 @@ import { TimeRangeContext, useQueryString } from '@perses-dev/plugin-system';
|
|
|
68
31
|
children: children
|
|
69
32
|
});
|
|
70
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Internal version of time range hook to get all supported values
|
|
36
|
+
*/ export function useDashboardTimeRange() {
|
|
37
|
+
const { timeRange , setTimeRange } = useTimeRangeContext();
|
|
38
|
+
return {
|
|
39
|
+
timeRange,
|
|
40
|
+
setTimeRange
|
|
41
|
+
};
|
|
42
|
+
}
|
|
71
43
|
|
|
72
44
|
//# sourceMappingURL=TimeRangeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, {
|
|
1
|
+
{"version":3,"sources":["../../src/context/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useMemo } from 'react';\nimport { TimeRangeValue } from '@perses-dev/core';\nimport { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n setTimeRange?: (value: TimeRangeValue) => void;\n children?: React.ReactNode;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { timeRange, children, setTimeRange } = props;\n\n // TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround\n const ctx = useMemo(\n () => ({\n timeRange,\n setTimeRange:\n setTimeRange ??\n (() => {\n /* no-op */\n }),\n }),\n [timeRange, setTimeRange]\n );\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n\n/**\n * Internal version of time range hook to get all supported values\n */\nexport function useDashboardTimeRange() {\n const { timeRange, setTimeRange } = useTimeRangeContext();\n return { timeRange, setTimeRange };\n}\n"],"names":["React","useMemo","TimeRangeContext","useTimeRangeContext","TimeRangeProvider","props","timeRange","children","setTimeRange","ctx","Provider","value","useDashboardTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO,CAAC;AAEvC,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,2BAA2B,CAAC;AAQlF;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAACC,KAA6B,EAAE;IAC/D,MAAM,EAAEC,SAAS,CAAA,EAAEC,QAAQ,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGH,KAAK,AAAC;IAEpD,sFAAsF;IACtF,MAAMI,GAAG,GAAGR,OAAO,CACjB,IAAO,CAAA;YACLK,SAAS;YACTE,YAAY,EACVA,YAAY,aAAZA,YAAY,cAAZA,YAAY,GACX,IAAM;YACL,SAAS,GACX,CAAC,AAAC;SACL,CAAA,AAAC,EACF;QAACF,SAAS;QAAEE,YAAY;KAAC,CAC1B,AAAC;IAEF,qBAAO,KAACN,gBAAgB,CAACQ,QAAQ;QAACC,KAAK,EAAEF,GAAG;kBAAGF,QAAQ;MAA6B,CAAC;AACvF,CAAC;AAED;;CAEC,GACD,OAAO,SAASK,qBAAqB,GAAG;IACtC,MAAM,EAAEN,SAAS,CAAA,EAAEE,YAAY,CAAA,EAAE,GAAGL,mBAAmB,EAAE,AAAC;IAC1D,OAAO;QAAEG,SAAS;QAAEE,YAAY;KAAE,CAAC;AACrC,CAAC"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './DashboardProvider';
|
|
2
2
|
export * from './DatasourceStoreProvider';
|
|
3
|
-
export * from './QueryStringProvider';
|
|
4
3
|
export * from './TemplateVariableProvider';
|
|
5
4
|
export * from './TimeRangeProvider';
|
|
5
|
+
export * from './useDashboardSpec';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
package/dist/context/index.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './DashboardProvider';
|
|
14
14
|
export * from './DatasourceStoreProvider';
|
|
15
|
-
export * from './QueryStringProvider';
|
|
16
15
|
export * from './TemplateVariableProvider';
|
|
17
16
|
export * from './TimeRangeProvider';
|
|
17
|
+
export * from './useDashboardSpec';
|
|
18
18
|
|
|
19
19
|
//# sourceMappingURL=index.js.map
|