@perses-dev/dashboards 0.8.1 → 0.10.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 +25 -14
- package/dist/cjs/components/DashboardToolbar.js +148 -20
- package/dist/cjs/components/GridLayout/GridItemContent.js +25 -19
- package/dist/cjs/components/GridLayout/GridLayout.js +92 -27
- package/dist/cjs/components/GridLayout/GridTitle.js +91 -31
- package/dist/cjs/components/GridLayout/index.js +18 -19
- package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
- package/dist/cjs/components/Panel/Panel.js +156 -55
- package/dist/cjs/components/Panel/Panel.test.js +58 -41
- package/dist/cjs/components/Panel/PanelContent.js +41 -12
- package/dist/cjs/components/Panel/index.js +16 -17
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +84 -108
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +87 -92
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +194 -0
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
- package/dist/cjs/components/PanelDrawer/index.js +28 -0
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +121 -39
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +74 -88
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
- package/dist/cjs/components/TimeRangeControls/index.js +16 -17
- package/dist/cjs/components/Variables/Variable.js +195 -36
- package/dist/cjs/components/Variables/VariableEditor.js +207 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
- package/dist/cjs/components/Variables/VariableList.js +81 -13
- package/dist/cjs/components/Variables/index.js +18 -18
- package/dist/cjs/components/index.js +21 -21
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
- package/dist/cjs/context/DashboardProvider/common.js +18 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
- package/dist/cjs/context/DashboardProvider/index.js +29 -0
- package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
- package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +38 -0
- package/dist/cjs/context/DatasourceStoreProvider.js +170 -0
- package/dist/cjs/context/QueryStringProvider.js +69 -15
- package/dist/cjs/context/TemplateVariableProvider.js +135 -136
- package/dist/cjs/context/TimeRangeProvider.js +79 -30
- package/dist/cjs/context/index.js +20 -22
- package/dist/cjs/css/styles.js +43 -39
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/test/dashboard-provider.js +51 -0
- package/dist/cjs/test/index.js +18 -18
- package/dist/cjs/test/plugin-registry.js +52 -25
- package/dist/cjs/test/render.js +25 -22
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/cjs/test/testDashboard.js +203 -107
- package/dist/cjs/utils/functions.js +9 -5
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +49 -23
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +62 -31
- package/dist/cjs/views/ViewDashboard/index.js +16 -17
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
- package/dist/cjs/views/index.js +16 -17
- package/dist/components/Dashboard.d.ts +1 -4
- package/dist/components/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard.js +34 -1
- package/dist/components/Dashboard.js.map +1 -0
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +154 -1
- package/dist/components/DashboardToolbar.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +35 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -0
- 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 +102 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -0
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +99 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -0
- package/dist/components/GridLayout/index.js +16 -1
- package/dist/components/GridLayout/index.js.map +1 -0
- package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/Panel/DeletePanelDialog.js +80 -0
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +181 -1
- package/dist/components/Panel/Panel.js.map +1 -0
- package/dist/components/Panel/Panel.test.js +74 -1
- package/dist/components/Panel/Panel.test.js.map +1 -0
- package/dist/components/Panel/PanelContent.d.ts +5 -4
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +41 -1
- package/dist/components/Panel/PanelContent.js.map +1 -0
- package/dist/components/Panel/index.js +15 -1
- package/dist/components/Panel/index.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +96 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +99 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js +184 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
- package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelPreview.js +42 -0
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
- package/dist/components/PanelDrawer/index.d.ts +2 -0
- package/dist/components/PanelDrawer/index.d.ts.map +1 -0
- package/dist/components/PanelDrawer/index.js +15 -0
- package/dist/components/PanelDrawer/index.js.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +131 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +74 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
- package/dist/components/TimeRangeControls/index.js +15 -1
- package/dist/components/TimeRangeControls/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +210 -1
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableEditor.d.ts +8 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditor.js +196 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js +15 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +84 -1
- package/dist/components/Variables/VariableList.js.map +1 -0
- package/dist/components/Variables/index.d.ts +1 -0
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +17 -1
- package/dist/components/Variables/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +20 -1
- package/dist/components/index.js.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
- package/dist/context/DashboardProvider/common.d.ts +5 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -0
- package/dist/context/DashboardProvider/common.js +17 -0
- package/dist/context/DashboardProvider/common.js.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +3 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -0
- package/dist/context/DashboardProvider/index.js +16 -0
- package/dist/context/DashboardProvider/index.js.map +1 -0
- package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
- package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/layout-slice.js +196 -0
- package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
- package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +24 -0
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
- package/dist/context/DatasourceStoreProvider.js +166 -0
- package/dist/context/DatasourceStoreProvider.js.map +1 -0
- package/dist/context/QueryStringProvider.js +40 -1
- package/dist/context/QueryStringProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +8 -3
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +199 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TimeRangeProvider.js +72 -1
- package/dist/context/TimeRangeProvider.js.map +1 -0
- package/dist/context/index.d.ts +3 -4
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +19 -1
- package/dist/context/index.js.map +1 -0
- package/dist/css/styles.js +186 -1
- package/dist/css/styles.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/test/dashboard-provider.d.ts +19 -0
- package/dist/test/dashboard-provider.d.ts.map +1 -0
- package/dist/test/dashboard-provider.js +40 -0
- package/dist/test/dashboard-provider.js.map +1 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +17 -1
- package/dist/test/index.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +3 -4
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +74 -1
- package/dist/test/plugin-registry.js.map +1 -0
- package/dist/test/render.d.ts +1 -2
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +34 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.js +18 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +286 -1
- package/dist/test/testDashboard.js.map +1 -0
- package/dist/utils/functions.js +17 -1
- package/dist/utils/functions.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +55 -1
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -0
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +79 -1
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
- package/dist/views/ViewDashboard/index.js +15 -1
- package/dist/views/ViewDashboard/index.js.map +1 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
- package/dist/views/index.js +15 -1
- package/dist/views/index.js.map +1 -0
- package/package.json +13 -7
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
- package/dist/cjs/context/DashboardAppSlice.js +0 -45
- package/dist/cjs/context/DashboardProvider.js +0 -98
- package/dist/cjs/context/LayoutsSlice.js +0 -42
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
- package/dist/context/DashboardAppSlice.d.ts +0 -26
- package/dist/context/DashboardAppSlice.d.ts.map +0 -1
- package/dist/context/DashboardAppSlice.js +0 -1
- package/dist/context/DashboardProvider.d.ts +0 -34
- package/dist/context/DashboardProvider.d.ts.map +0 -1
- package/dist/context/DashboardProvider.js +0 -1
- package/dist/context/LayoutsSlice.d.ts +0 -12
- package/dist/context/LayoutsSlice.d.ts.map +0 -1
- package/dist/context/LayoutsSlice.js +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
useEditMode: ()=>useEditMode,
|
|
25
|
+
useLayouts: ()=>useLayouts,
|
|
26
|
+
usePanelGroupDialog: ()=>usePanelGroupDialog,
|
|
27
|
+
usePanels: ()=>usePanels,
|
|
28
|
+
useDefaultTimeRange: ()=>useDefaultTimeRange
|
|
29
|
+
});
|
|
30
|
+
const _dashboardProvider = require("./DashboardProvider");
|
|
31
|
+
function useEditMode() {
|
|
32
|
+
return (0, _dashboardProvider.useDashboardStore)(({ isEditMode , setEditMode })=>({
|
|
33
|
+
isEditMode,
|
|
34
|
+
setEditMode
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
function useLayouts() {
|
|
38
|
+
return (0, _dashboardProvider.useDashboardStore)(({ layouts , addPanelToGroup , movePanelToGroup , updatePanelGroup , swapPanelGroups , deletePanelGroup })=>({
|
|
39
|
+
layouts,
|
|
40
|
+
addPanelToGroup,
|
|
41
|
+
movePanelToGroup,
|
|
42
|
+
updatePanelGroup,
|
|
43
|
+
swapPanelGroups,
|
|
44
|
+
deletePanelGroup
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
function usePanelGroupDialog() {
|
|
48
|
+
return (0, _dashboardProvider.useDashboardStore)(({ panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , })=>({
|
|
49
|
+
panelGroupDialog,
|
|
50
|
+
openPanelGroupDialog,
|
|
51
|
+
closePanelGroupDialog,
|
|
52
|
+
deletePanelGroupDialog,
|
|
53
|
+
openDeletePanelGroupDialog,
|
|
54
|
+
closeDeletePanelGroupDialog
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
function usePanels() {
|
|
58
|
+
return (0, _dashboardProvider.useDashboardStore)(({ panels , panelEditor , addPanel , editPanel , deletePanelDialog , deletePanels , openDeletePanelDialog , closeDeletePanelDialog , })=>({
|
|
59
|
+
panels,
|
|
60
|
+
panelEditor,
|
|
61
|
+
addPanel,
|
|
62
|
+
editPanel,
|
|
63
|
+
deletePanels,
|
|
64
|
+
deletePanelDialog,
|
|
65
|
+
openDeletePanelDialog,
|
|
66
|
+
closeDeletePanelDialog
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
function useDefaultTimeRange() {
|
|
70
|
+
return (0, _dashboardProvider.useDashboardStore)((state)=>state.defaultTimeRange);
|
|
71
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./dashboard-provider-api"), exports);
|
|
18
|
+
_exportStar(require("./DashboardProvider"), exports);
|
|
19
|
+
function _exportStar(from, to) {
|
|
20
|
+
Object.keys(from).forEach(function(k) {
|
|
21
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return from[k];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return from;
|
|
29
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
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, "createLayoutSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createLayoutSlice
|
|
20
|
+
});
|
|
21
|
+
const _core = require("@perses-dev/core");
|
|
22
|
+
function createLayoutSlice(layouts) {
|
|
23
|
+
// Return the state creator function for Zustand that uses the layouts provided as initial state
|
|
24
|
+
let id = -1;
|
|
25
|
+
function createPanelGroupId() {
|
|
26
|
+
id++;
|
|
27
|
+
return id;
|
|
28
|
+
}
|
|
29
|
+
var ref;
|
|
30
|
+
return (set, get)=>{
|
|
31
|
+
return {
|
|
32
|
+
layouts: layouts.map((layout)=>{
|
|
33
|
+
var ref1, ref2, ref3;
|
|
34
|
+
return {
|
|
35
|
+
...layout,
|
|
36
|
+
id: createPanelGroupId(),
|
|
37
|
+
title: (ref1 = layout.spec.display) === null || ref1 === void 0 ? void 0 : ref1.title,
|
|
38
|
+
isCollapsed: (ref = !((ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.collapse) === null || ref3 === void 0 ? void 0 : ref3.open)) !== null && ref !== void 0 ? ref : false,
|
|
39
|
+
items: layout.spec.items
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
getPanelKey ({ groupIndex , itemIndex }) {
|
|
43
|
+
const { layouts } = get();
|
|
44
|
+
const group = findGroup(layouts, groupIndex);
|
|
45
|
+
const item = findItem(group, itemIndex);
|
|
46
|
+
return (0, _core.getPanelKeyFromRef)(item.content);
|
|
47
|
+
},
|
|
48
|
+
addPanelToGroup (panelKey, groupIndex) {
|
|
49
|
+
const { layouts } = get();
|
|
50
|
+
const group = findGroup(layouts, groupIndex);
|
|
51
|
+
const gridItem = {
|
|
52
|
+
x: 0,
|
|
53
|
+
y: getYForNewRow(group),
|
|
54
|
+
width: 12,
|
|
55
|
+
height: 6,
|
|
56
|
+
content: (0, _core.createPanelRef)(panelKey)
|
|
57
|
+
};
|
|
58
|
+
set((state)=>{
|
|
59
|
+
var ref;
|
|
60
|
+
(ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
movePanelToGroup ({ groupIndex , itemIndex }, newGroupIndex) {
|
|
64
|
+
const { layouts } = get();
|
|
65
|
+
// Find the existing item to make sure it exists
|
|
66
|
+
const group = findGroup(layouts, groupIndex);
|
|
67
|
+
const item = findItem(group, itemIndex);
|
|
68
|
+
// Find the new group and figure out where a new row should go
|
|
69
|
+
const newGroup = findGroup(layouts, newGroupIndex);
|
|
70
|
+
const newGroupY = getYForNewRow(newGroup);
|
|
71
|
+
set((state)=>{
|
|
72
|
+
var // Remove the item from its current group
|
|
73
|
+
ref, // Add a new item to the new group
|
|
74
|
+
ref1;
|
|
75
|
+
(ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
|
|
76
|
+
(ref1 = state.layouts[newGroupIndex]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
|
|
77
|
+
x: 0,
|
|
78
|
+
y: newGroupY,
|
|
79
|
+
width: item.width,
|
|
80
|
+
height: item.height,
|
|
81
|
+
content: item.content
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
// TODO: Maybe combine this into some kind of groupEditor state
|
|
86
|
+
updatePanelGroup (next, groupIndex) {
|
|
87
|
+
set((state)=>{
|
|
88
|
+
if (groupIndex === undefined) {
|
|
89
|
+
state.layouts.unshift({
|
|
90
|
+
...next,
|
|
91
|
+
id: createPanelGroupId()
|
|
92
|
+
});
|
|
93
|
+
} else {
|
|
94
|
+
const layout = state.layouts[groupIndex];
|
|
95
|
+
if (layout === undefined) {
|
|
96
|
+
throw new Error(`No layout at index ${groupIndex}`);
|
|
97
|
+
}
|
|
98
|
+
state.layouts[groupIndex] = {
|
|
99
|
+
...next,
|
|
100
|
+
id: layout.id
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
swapPanelGroups (x, y) {
|
|
106
|
+
set((state)=>{
|
|
107
|
+
if (x < 0 || x >= state.layouts.length || y < 0 || y >= state.layouts.length) {
|
|
108
|
+
throw new Error('index out of bound');
|
|
109
|
+
}
|
|
110
|
+
const xPanelGroup = state.layouts[x];
|
|
111
|
+
const yPanelGroup = state.layouts[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.layouts[x], state.layouts[y]] = [
|
|
117
|
+
yPanelGroup,
|
|
118
|
+
xPanelGroup
|
|
119
|
+
];
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
deletePanelInPanelGroup ({ groupIndex , itemIndex }) {
|
|
123
|
+
set((state)=>{
|
|
124
|
+
const group = state.layouts[groupIndex];
|
|
125
|
+
if (group === undefined) {
|
|
126
|
+
throw new Error(`No panel group found: ${groupIndex}`);
|
|
127
|
+
}
|
|
128
|
+
// remove panel from panel group
|
|
129
|
+
group.items.splice(itemIndex, 1);
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
deletePanelGroup (groupIndex) {
|
|
133
|
+
const { layouts , deletePanels } = get();
|
|
134
|
+
const group = layouts[groupIndex];
|
|
135
|
+
if (group === undefined) {
|
|
136
|
+
throw new Error(`No panel group found: ${groupIndex}`);
|
|
137
|
+
}
|
|
138
|
+
// remove panels from group first
|
|
139
|
+
const panelsToBeDeleted = [];
|
|
140
|
+
for(let i = 0; i < group.items.length; i++){
|
|
141
|
+
panelsToBeDeleted.push({
|
|
142
|
+
groupIndex,
|
|
143
|
+
itemIndex: i
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
deletePanels(panelsToBeDeleted);
|
|
147
|
+
// remove group from state.layouts
|
|
148
|
+
set((state)=>{
|
|
149
|
+
state.layouts.splice(groupIndex, 1);
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
// Return an object that maps each panel to the groups it belongs
|
|
153
|
+
mapPanelToPanelGroups () {
|
|
154
|
+
const map = {}; // { panel key: [group ids] }
|
|
155
|
+
get().layouts.forEach((group)=>{
|
|
156
|
+
// for each panel in a group, add the group id to map[panelKey]
|
|
157
|
+
group.items.forEach((panel)=>{
|
|
158
|
+
const panelKey = (0, _core.getPanelKeyFromRef)(panel.content);
|
|
159
|
+
if (map[panelKey]) {
|
|
160
|
+
var ref;
|
|
161
|
+
(ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
|
|
162
|
+
} else {
|
|
163
|
+
map[panelKey] = [
|
|
164
|
+
group.id
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
return map;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// Helper to find a group and throw if not found
|
|
175
|
+
function findGroup(layouts, groupIndex) {
|
|
176
|
+
const group = layouts[groupIndex];
|
|
177
|
+
if (group === undefined) {
|
|
178
|
+
throw new Error(`No layout at index ${groupIndex}`);
|
|
179
|
+
}
|
|
180
|
+
return group;
|
|
181
|
+
}
|
|
182
|
+
// Helper to get an item in a group and throw if not found
|
|
183
|
+
function findItem(group, itemIndex) {
|
|
184
|
+
const item = group.items[itemIndex];
|
|
185
|
+
if (item === undefined) {
|
|
186
|
+
throw new Error(`No grid item found at position ${itemIndex}`);
|
|
187
|
+
}
|
|
188
|
+
return item;
|
|
189
|
+
}
|
|
190
|
+
// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
|
|
191
|
+
function getYForNewRow(group) {
|
|
192
|
+
let newRowY = 0;
|
|
193
|
+
for (const item of group.items){
|
|
194
|
+
const itemMaxY = item.y + item.height;
|
|
195
|
+
if (itemMaxY > newRowY) {
|
|
196
|
+
newRowY = itemMaxY;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return newRowY;
|
|
200
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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, "createPanelEditorSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createPanelEditorSlice
|
|
20
|
+
});
|
|
21
|
+
const _functions = require("../../utils/functions");
|
|
22
|
+
function createPanelEditorSlice(panels) {
|
|
23
|
+
// Return the state creator function for Zustand that uses the panels provided as intitial state
|
|
24
|
+
return (set, get)=>{
|
|
25
|
+
return {
|
|
26
|
+
panels,
|
|
27
|
+
panelEditor: undefined,
|
|
28
|
+
editPanel (item) {
|
|
29
|
+
const { panels , getPanelKey } = get();
|
|
30
|
+
// Ask the layout store for the panel key at that location
|
|
31
|
+
const panelKey = getPanelKey(item);
|
|
32
|
+
// Find the panel to edit
|
|
33
|
+
const panelToEdit = panels[panelKey];
|
|
34
|
+
if (panelToEdit === undefined) {
|
|
35
|
+
throw new Error(`Cannot find Panel with key '${panelKey}'`);
|
|
36
|
+
}
|
|
37
|
+
var _description;
|
|
38
|
+
const editorState = {
|
|
39
|
+
mode: 'Edit',
|
|
40
|
+
initialValues: {
|
|
41
|
+
name: panelToEdit.spec.display.name,
|
|
42
|
+
description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
43
|
+
groupIndex: item.groupIndex,
|
|
44
|
+
kind: panelToEdit.spec.plugin.kind,
|
|
45
|
+
spec: panelToEdit.spec.plugin.spec
|
|
46
|
+
},
|
|
47
|
+
applyChanges: (next)=>{
|
|
48
|
+
const panelDefinititon = createPanelDefinitionFromEditorValues(next);
|
|
49
|
+
set((state)=>{
|
|
50
|
+
state.panels[panelKey] = panelDefinititon;
|
|
51
|
+
});
|
|
52
|
+
// Move the panel to another group if it changed
|
|
53
|
+
if (next.groupIndex !== item.groupIndex) {
|
|
54
|
+
get().movePanelToGroup(item, next.groupIndex);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
close: ()=>{
|
|
58
|
+
set((state)=>{
|
|
59
|
+
state.panelEditor = undefined;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Open the editor with the new state
|
|
64
|
+
set((state)=>{
|
|
65
|
+
state.panelEditor = editorState;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
addPanel (initialGroup) {
|
|
69
|
+
const editorState = {
|
|
70
|
+
mode: 'Add',
|
|
71
|
+
initialValues: {
|
|
72
|
+
name: '',
|
|
73
|
+
description: '',
|
|
74
|
+
groupIndex: initialGroup,
|
|
75
|
+
// TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to
|
|
76
|
+
// set a smarter default here?
|
|
77
|
+
kind: '',
|
|
78
|
+
spec: {}
|
|
79
|
+
},
|
|
80
|
+
applyChanges: (next)=>{
|
|
81
|
+
const panelDef = createPanelDefinitionFromEditorValues(next);
|
|
82
|
+
const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
|
|
83
|
+
set((state)=>{
|
|
84
|
+
state.panels[panelKey] = panelDef;
|
|
85
|
+
});
|
|
86
|
+
get().addPanelToGroup(panelKey, next.groupIndex);
|
|
87
|
+
},
|
|
88
|
+
close: ()=>{
|
|
89
|
+
set((state)=>{
|
|
90
|
+
state.panelEditor = undefined;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// Open the editor with the new state
|
|
95
|
+
set((state)=>{
|
|
96
|
+
state.panelEditor = editorState;
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
deletePanels (items) {
|
|
100
|
+
const { mapPanelToPanelGroups , deletePanelInPanelGroup , getPanelKey } = get();
|
|
101
|
+
const map = mapPanelToPanelGroups();
|
|
102
|
+
// get panel key first before deleting panel from panel group since getPanelKey relies on index
|
|
103
|
+
const panels = items.map((panel)=>{
|
|
104
|
+
return {
|
|
105
|
+
...panel,
|
|
106
|
+
panelKey: getPanelKey(panel)
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
panels.forEach(({ panelKey , ...panel })=>{
|
|
110
|
+
var ref;
|
|
111
|
+
deletePanelInPanelGroup(panel);
|
|
112
|
+
// make sure panel is only referenced in one panel group before deleting it from state.panels
|
|
113
|
+
if (map[panelKey] && ((ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.length) === 1) {
|
|
114
|
+
set((state)=>{
|
|
115
|
+
delete state.panels[panelKey];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
openDeletePanelDialog (item) {
|
|
121
|
+
set((state)=>{
|
|
122
|
+
var ref;
|
|
123
|
+
const { panels , getPanelKey } = get();
|
|
124
|
+
const panelKey = getPanelKey(item);
|
|
125
|
+
var _name;
|
|
126
|
+
state.deletePanelDialog = {
|
|
127
|
+
panelKey,
|
|
128
|
+
panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
|
|
129
|
+
layoutItem: item
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
closeDeletePanelDialog () {
|
|
134
|
+
set((state)=>{
|
|
135
|
+
state.deletePanelDialog = undefined;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// Helper to create PanelDefinitions when saving
|
|
142
|
+
function createPanelDefinitionFromEditorValues(editorValues) {
|
|
143
|
+
return {
|
|
144
|
+
kind: 'Panel',
|
|
145
|
+
spec: {
|
|
146
|
+
display: {
|
|
147
|
+
name: editorValues.name,
|
|
148
|
+
description: editorValues.description !== '' ? editorValues.description : undefined
|
|
149
|
+
},
|
|
150
|
+
plugin: {
|
|
151
|
+
kind: editorValues.kind,
|
|
152
|
+
spec: editorValues.spec
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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, "createPanelGroupSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createPanelGroupSlice
|
|
20
|
+
});
|
|
21
|
+
const createPanelGroupSlice = (set)=>({
|
|
22
|
+
openPanelGroupDialog: (groupIndex)=>set((state)=>{
|
|
23
|
+
state.panelGroupDialog = {
|
|
24
|
+
groupIndex
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
closePanelGroupDialog: ()=>set((state)=>{
|
|
28
|
+
state.panelGroupDialog = undefined;
|
|
29
|
+
}),
|
|
30
|
+
openDeletePanelGroupDialog: (groupIndex)=>set((state)=>{
|
|
31
|
+
state.deletePanelGroupDialog = {
|
|
32
|
+
groupIndex
|
|
33
|
+
};
|
|
34
|
+
}),
|
|
35
|
+
closeDeletePanelGroupDialog: ()=>set((state)=>{
|
|
36
|
+
state.deletePanelGroupDialog = undefined;
|
|
37
|
+
})
|
|
38
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
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, "DatasourceStoreProvider", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>DatasourceStoreProvider
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _core = require("@perses-dev/core");
|
|
24
|
+
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
|
+
function DatasourceStoreProvider(props) {
|
|
26
|
+
const { dashboardResource , datasourceApi , children } = props;
|
|
27
|
+
const { project } = dashboardResource.metadata;
|
|
28
|
+
const { getPlugin , listPluginMetadata } = (0, _pluginSystem.usePluginRegistry)();
|
|
29
|
+
const findDatasource = (0, _core.useEvent)(async (selector)=>{
|
|
30
|
+
// Try to find it in dashboard spec
|
|
31
|
+
const { datasources } = dashboardResource.spec;
|
|
32
|
+
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
33
|
+
if (dashboardDatasource !== undefined) {
|
|
34
|
+
return {
|
|
35
|
+
spec: dashboardDatasource,
|
|
36
|
+
proxyUrl: undefined
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Try to find it at the project level as a Datasource resource
|
|
40
|
+
const datasource = await datasourceApi.getDatasource(project, selector);
|
|
41
|
+
if (datasource !== undefined) {
|
|
42
|
+
return {
|
|
43
|
+
spec: datasource.resource.spec,
|
|
44
|
+
proxyUrl: datasource.proxyUrl
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Try to find it at the global level as a GlobalDatasource resource
|
|
48
|
+
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
49
|
+
if (globalDatasource !== undefined) {
|
|
50
|
+
return {
|
|
51
|
+
spec: globalDatasource.resource.spec,
|
|
52
|
+
proxyUrl: globalDatasource.proxyUrl
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
|
|
56
|
+
});
|
|
57
|
+
// Gets a datasource spec for a given selector
|
|
58
|
+
const getDatasource = (0, _react.useCallback)(async (selector)=>{
|
|
59
|
+
const { spec } = await findDatasource(selector);
|
|
60
|
+
return spec;
|
|
61
|
+
}, [
|
|
62
|
+
findDatasource
|
|
63
|
+
]);
|
|
64
|
+
// Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client
|
|
65
|
+
const getDatasourceClient = (0, _react.useCallback)(async function getClient(selector) {
|
|
66
|
+
const { kind } = selector;
|
|
67
|
+
const [{ spec , proxyUrl }, plugin] = await Promise.all([
|
|
68
|
+
findDatasource(selector),
|
|
69
|
+
getPlugin('Datasource', kind)
|
|
70
|
+
]);
|
|
71
|
+
return plugin.createClient(spec.plugin.spec, {
|
|
72
|
+
proxyUrl
|
|
73
|
+
});
|
|
74
|
+
}, [
|
|
75
|
+
findDatasource,
|
|
76
|
+
getPlugin
|
|
77
|
+
]);
|
|
78
|
+
const listDatasourceMetadata = (0, _core.useEvent)(async (datasourcePluginKind)=>{
|
|
79
|
+
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
80
|
+
listPluginMetadata('Datasource'),
|
|
81
|
+
datasourceApi.listDatasources(project, datasourcePluginKind),
|
|
82
|
+
datasourceApi.listGlobalDatasources(datasourcePluginKind)
|
|
83
|
+
]);
|
|
84
|
+
// Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
|
|
85
|
+
const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.kind === datasourcePluginKind);
|
|
86
|
+
if (datasourcePluginMetadata === undefined) {
|
|
87
|
+
throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);
|
|
88
|
+
}
|
|
89
|
+
// Get helper for de-duping results properly
|
|
90
|
+
const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
|
|
91
|
+
// Start with dashboard datasources that have highest precedence
|
|
92
|
+
if (dashboardResource.spec.datasources !== undefined) {
|
|
93
|
+
for(const selectorName in dashboardResource.spec.datasources){
|
|
94
|
+
const spec = dashboardResource.spec.datasources[selectorName];
|
|
95
|
+
if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
|
|
96
|
+
addResult(spec, selectorName);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Now look at project-level datasources
|
|
100
|
+
for (const datasource of datasources){
|
|
101
|
+
const selectorName1 = datasource.metadata.name;
|
|
102
|
+
addResult(datasource.spec, selectorName1);
|
|
103
|
+
}
|
|
104
|
+
// And finally global datasources
|
|
105
|
+
for (const globalDatasource of globalDatasources){
|
|
106
|
+
const selectorName2 = globalDatasource.metadata.name;
|
|
107
|
+
addResult(globalDatasource.spec, selectorName2);
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
});
|
|
111
|
+
const ctxValue = (0, _react.useMemo)(()=>({
|
|
112
|
+
getDatasource,
|
|
113
|
+
getDatasourceClient,
|
|
114
|
+
listDatasourceMetadata
|
|
115
|
+
}), [
|
|
116
|
+
getDatasource,
|
|
117
|
+
getDatasourceClient,
|
|
118
|
+
listDatasourceMetadata
|
|
119
|
+
]);
|
|
120
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceStoreContext.Provider, {
|
|
121
|
+
value: ctxValue,
|
|
122
|
+
children: children
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// Helper to find a datasource in the list embedded in a dashboard spec
|
|
126
|
+
function findDashboardDatasource(dashboardDatasources, selector) {
|
|
127
|
+
if (dashboardDatasources === undefined) return undefined;
|
|
128
|
+
// If using a name in the selector...
|
|
129
|
+
if (selector.name !== undefined) {
|
|
130
|
+
const named = dashboardDatasources[selector.name];
|
|
131
|
+
if (named === undefined) return undefined;
|
|
132
|
+
return named.plugin.kind === selector.kind ? named : undefined;
|
|
133
|
+
}
|
|
134
|
+
// If only using a kind, try to find one with that kind that is the default
|
|
135
|
+
return Object.values(dashboardDatasources).find((ds)=>ds.plugin.kind === selector.kind && ds.default === true);
|
|
136
|
+
}
|
|
137
|
+
// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors
|
|
138
|
+
function buildListDatasourceMetadataResults(pluginDisplayName) {
|
|
139
|
+
const results = [];
|
|
140
|
+
const usedNames = new Set();
|
|
141
|
+
let defaultAdded = false;
|
|
142
|
+
const addResult = (spec, selectorName)=>{
|
|
143
|
+
var ref;
|
|
144
|
+
// If we haven't added a default yet and this is a default, add default option to the beginning of the results
|
|
145
|
+
if (spec.default && defaultAdded === false) {
|
|
146
|
+
results.unshift({
|
|
147
|
+
name: `Default ${pluginDisplayName}`,
|
|
148
|
+
selector: {
|
|
149
|
+
kind: spec.plugin.kind
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
defaultAdded = true;
|
|
153
|
+
}
|
|
154
|
+
// If we already have a datasource with this selector name, ignore it, otherwise add to end of list
|
|
155
|
+
if (usedNames.has(selectorName)) return;
|
|
156
|
+
var ref1;
|
|
157
|
+
results.push({
|
|
158
|
+
name: (ref1 = (ref = spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : selectorName,
|
|
159
|
+
selector: {
|
|
160
|
+
kind: spec.plugin.kind,
|
|
161
|
+
name: selectorName
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
usedNames.add(selectorName);
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
results,
|
|
168
|
+
addResult
|
|
169
|
+
};
|
|
170
|
+
}
|