@perses-dev/dashboards 0.54.0-beta.0 → 0.54.0-beta.10
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/Annotations/AnnotationsEditor.js +302 -0
- package/dist/cjs/components/Annotations/EditAnnotationsButton.js +83 -0
- package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +4 -2
- package/dist/cjs/components/GridLayout/GridItemContent.js +4 -11
- package/dist/cjs/components/Panel/Panel.js +4 -1
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +2 -2
- package/dist/cjs/components/PanelDrawer/PanelQueriesSharedControls.js +3 -16
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +20 -3
- package/dist/cjs/components/Variables/VariableEditor.js +52 -18
- package/dist/cjs/constants/defaults.js +32 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/constants/user-interface-text.js +1 -0
- package/dist/cjs/context/AnnotationProvider/AnnotationHydrationWrapper.js +50 -0
- package/dist/cjs/context/AnnotationProvider/AnnotationProvider.js +145 -0
- package/dist/cjs/context/AnnotationProvider/index.js +30 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +11 -4
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +14 -11
- package/dist/cjs/context/DashboardProvider/use-save-dashboard.js +12 -4
- package/dist/cjs/context/DatasourceStoreProvider.js +38 -5
- package/dist/cjs/context/VariableProvider/VariableProvider.js +11 -6
- package/dist/cjs/context/index.js +1 -0
- package/dist/cjs/context/useDashboard.js +11 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/keyboard-shortcuts/index.js +3 -0
- package/dist/cjs/keyboard-shortcuts/utils.js +11 -0
- package/dist/cjs/model/PanelGroupDefinition.js +25 -0
- package/dist/cjs/model/index.js +2 -1
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +9 -1
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +33 -28
- package/dist/components/AddGroupButton/AddGroupButton.js +1 -1
- package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
- package/dist/components/AddPanelButton/AddPanelButton.js +1 -1
- package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
- package/dist/components/Annotations/AnnotationsEditor.d.ts +8 -0
- package/dist/components/Annotations/AnnotationsEditor.d.ts.map +1 -0
- package/dist/components/Annotations/AnnotationsEditor.js +289 -0
- package/dist/components/Annotations/AnnotationsEditor.js.map +1 -0
- package/dist/components/Annotations/EditAnnotationsButton.d.ts +18 -0
- package/dist/components/Annotations/EditAnnotationsButton.d.ts.map +1 -0
- package/dist/components/Annotations/EditAnnotationsButton.js +70 -0
- package/dist/components/Annotations/EditAnnotationsButton.js.map +1 -0
- package/dist/components/Dashboard/Dashboard.js +1 -1
- package/dist/components/Dashboard/Dashboard.js.map +1 -1
- package/dist/components/DashboardLinks/DashboardLinksEditor.js +1 -1
- package/dist/components/DashboardLinks/DashboardLinksEditor.js.map +1 -1
- package/dist/components/DashboardLinks/EditDashboardLinksButton.js +1 -1
- package/dist/components/DashboardLinks/EditDashboardLinksButton.js.map +1 -1
- package/dist/components/DashboardShortcuts/useDashboardShortcuts.js.map +1 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +1 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +5 -3
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.js +1 -1
- package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
- package/dist/components/Datasources/EditDatasourcesButton.js +1 -1
- package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/components/DownloadButton/DownloadButton.js +1 -1
- package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
- package/dist/components/DownloadButton/serializeDashboard.d.ts +1 -1
- package/dist/components/DownloadButton/serializeDashboard.d.ts.map +1 -1
- package/dist/components/DownloadButton/serializeDashboard.js.map +1 -1
- package/dist/components/EditButton/EditButton.js +1 -1
- package/dist/components/EditButton/EditButton.js.map +1 -1
- package/dist/components/EditJsonButton/EditJsonButton.js +1 -1
- package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
- package/dist/components/EditJsonDialog/EditJsonDialog.js +1 -1
- package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
- package/dist/components/GridLayout/GridContainer.js +1 -1
- package/dist/components/GridLayout/GridContainer.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +4 -11
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +1 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/GridLayout/Row.d.ts +1 -1
- package/dist/components/GridLayout/Row.d.ts.map +1 -1
- package/dist/components/GridLayout/Row.js +1 -1
- package/dist/components/GridLayout/Row.js.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.js +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
- package/dist/components/LinksDisplay/LinksDisplay.js +1 -1
- package/dist/components/LinksDisplay/LinksDisplay.js.map +1 -1
- 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 +5 -2
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelActions.js +1 -1
- package/dist/components/Panel/PanelActions.js.map +1 -1
- package/dist/components/Panel/PanelContent.js +1 -1
- package/dist/components/Panel/PanelContent.js.map +1 -1
- package/dist/components/Panel/PanelHeader.js +1 -1
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/Panel/PanelPluginLoader.js +1 -1
- package/dist/components/Panel/PanelPluginLoader.js.map +1 -1
- package/dist/components/Panel/useSelectionItemActions.js +1 -1
- package/dist/components/Panel/useSelectionItemActions.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.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 +3 -3
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +5 -18
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
- package/dist/components/QuerySummaryTable/QuerySummaryTable.js +1 -1
- package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
- package/dist/components/QueryViewerDialog/QueryViewerDialog.js +1 -1
- package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +22 -5
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js +1 -1
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/ListVariableListBox.js +1 -1
- package/dist/components/Variables/ListVariableListBox.js.map +1 -1
- package/dist/components/Variables/Variable.js +2 -2
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +57 -23
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +1 -1
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/constants/defaults.d.ts +4 -0
- package/dist/constants/defaults.d.ts.map +1 -0
- package/dist/{model/DashboardResource.js → constants/defaults.js} +3 -5
- package/dist/constants/defaults.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/user-interface-text.d.ts +1 -0
- package/dist/constants/user-interface-text.d.ts.map +1 -1
- package/dist/constants/user-interface-text.js +1 -0
- package/dist/constants/user-interface-text.js.map +1 -1
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts +7 -0
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts.map +1 -0
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js +48 -0
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js.map +1 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.d.ts +40 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.d.ts.map +1 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.js +114 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.js.map +1 -0
- package/dist/context/AnnotationProvider/index.d.ts +2 -0
- package/dist/context/AnnotationProvider/index.d.ts.map +1 -0
- package/dist/context/AnnotationProvider/index.js +15 -0
- package/dist/context/AnnotationProvider/index.js.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -2
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +11 -4
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +1 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -2
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +14 -11
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +8 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/use-save-dashboard.d.ts.map +1 -1
- package/dist/context/DashboardProvider/use-save-dashboard.js +13 -5
- package/dist/context/DashboardProvider/use-save-dashboard.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +1 -2
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +40 -7
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js +1 -1
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.d.ts +3 -2
- package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.js +13 -8
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -1
- package/dist/context/VariableProvider/hydrationUtils.js.map +1 -1
- package/dist/context/VariableProvider/utils.d.ts +1 -1
- package/dist/context/VariableProvider/utils.d.ts.map +1 -1
- package/dist/context/VariableProvider/utils.js.map +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts +2 -3
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +11 -1
- package/dist/context/useDashboard.js.map +1 -1
- 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/keyboard-shortcuts/PanelFocusProvider.js +1 -1
- package/dist/keyboard-shortcuts/PanelFocusProvider.js.map +1 -1
- package/dist/keyboard-shortcuts/index.d.ts +1 -1
- package/dist/keyboard-shortcuts/index.d.ts.map +1 -1
- package/dist/keyboard-shortcuts/index.js +1 -1
- package/dist/keyboard-shortcuts/index.js.map +1 -1
- package/dist/keyboard-shortcuts/utils.d.ts +8 -0
- package/dist/keyboard-shortcuts/utils.d.ts.map +1 -1
- package/dist/keyboard-shortcuts/utils.js +13 -0
- package/dist/keyboard-shortcuts/utils.js.map +1 -1
- package/dist/model/PanelGroupDefinition.d.ts +59 -0
- package/dist/model/PanelGroupDefinition.d.ts.map +1 -0
- package/dist/model/PanelGroupDefinition.js +19 -0
- package/dist/model/PanelGroupDefinition.js.map +1 -0
- package/dist/model/VariableDefinition.d.ts +50 -0
- package/dist/model/VariableDefinition.d.ts.map +1 -0
- package/dist/model/VariableDefinition.js +20 -0
- package/dist/model/VariableDefinition.js.map +1 -0
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +2 -1
- package/dist/model/index.js.map +1 -1
- package/dist/test/dashboard-provider.d.ts +1 -1
- package/dist/test/dashboard-provider.d.ts.map +1 -1
- package/dist/test/dashboard-provider.js.map +1 -1
- package/dist/test/datasource-provider.d.ts +1 -1
- package/dist/test/datasource-provider.d.ts.map +1 -1
- package/dist/test/datasource-provider.js.map +1 -1
- package/dist/test/render.js +1 -1
- package/dist/test/render.js.map +1 -1
- package/dist/test/testDashboard.d.ts +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/panelUtils.d.ts +1 -1
- package/dist/utils/panelUtils.d.ts.map +1 -1
- package/dist/utils/panelUtils.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +3 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +11 -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 +33 -28
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +9 -10
- package/dist/model/DashboardResource.d.ts +0 -15
- package/dist/model/DashboardResource.d.ts.map +0 -1
- package/dist/model/DashboardResource.js.map +0 -1
- /package/dist/cjs/model/{DashboardResource.js → VariableDefinition.js} +0 -0
|
@@ -56,23 +56,26 @@ export function convertLayoutsToPanelGroups(layouts) {
|
|
|
56
56
|
const itemLayouts = [];
|
|
57
57
|
const itemPanelKeys = {};
|
|
58
58
|
// Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
if ('items' in layout.spec) {
|
|
60
|
+
for (const item of layout.spec.items){
|
|
61
|
+
const panelGroupLayoutId = generateId().toString();
|
|
62
|
+
itemLayouts.push({
|
|
63
|
+
i: panelGroupLayoutId,
|
|
64
|
+
w: item.width,
|
|
65
|
+
h: item.height,
|
|
66
|
+
x: item.x,
|
|
67
|
+
y: item.y
|
|
68
|
+
});
|
|
69
|
+
itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);
|
|
70
|
+
}
|
|
69
71
|
}
|
|
70
72
|
// Create the panel group and keep track of the ID order
|
|
73
|
+
const repeatVariable = 'repeatVariable' in layout.spec ? layout.spec.repeatVariable : undefined;
|
|
71
74
|
const panelGroupId = generateId();
|
|
72
75
|
panelGroups[panelGroupId] = {
|
|
73
76
|
id: panelGroupId,
|
|
74
77
|
isCollapsed: layout.spec.display?.collapse?.open === false,
|
|
75
|
-
repeatVariable
|
|
78
|
+
repeatVariable,
|
|
76
79
|
title: layout.spec.display?.title,
|
|
77
80
|
itemLayouts,
|
|
78
81
|
itemPanelKeys
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 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 { getPanelKeyFromRef, LayoutDefinition, PanelGroupId } from '@perses-dev/spec';\nimport { StateCreator } from 'zustand';\nimport { WritableDraft } from 'immer';\nimport { PanelGroupDefinition } from '../../model';\nimport { generateId, Middleware } from './common';\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 panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y): void {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[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.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts): void {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n if ('items' in layout.spec) {\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n }\n\n // Create the panel group and keep track of the ID order\n const repeatVariable = 'repeatVariable' in layout.spec ? layout.spec.repeatVariable : undefined;\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n repeatVariable,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","spec","item","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","repeatVariable","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup","draft","newGroup","unshift"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2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D,CAAC;QAE9D,6GAA6G;QAC7G,IAAI,WAAWD,OAAOE,IAAI,EAAE;YAC1B,KAAK,MAAMC,QAAQH,OAAOE,IAAI,CAACE,KAAK,CAAE;gBACpC,MAAMC,qBAAqB1B,aAAa2B,QAAQ;gBAChDT,YAAYU,IAAI,CAAC;oBACfC,GAAGH;oBACHI,GAAGN,KAAKO,KAAK;oBACbC,GAAGR,KAAKS,MAAM;oBACdzB,GAAGgB,KAAKhB,CAAC;oBACTC,GAAGe,KAAKf,CAAC;gBACX;gBACAa,aAAa,CAACI,mBAAmB,GAAG3B,mBAAmByB,KAAKU,OAAO;YACrE;QACF;QAEA,wDAAwD;QACxD,MAAMC,iBAAiB,oBAAoBd,OAAOE,IAAI,GAAGF,OAAOE,IAAI,CAACY,cAAc,GAAGpB;QACtF,MAAME,eAAejB;QACrBG,WAAW,CAACc,aAAa,GAAG;YAC1BmB,IAAInB;YACJoB,aAAahB,OAAOE,IAAI,CAACe,OAAO,EAAEC,UAAUC,SAAS;YACrDL;YACAM,OAAOpB,OAAOE,IAAI,CAACe,OAAO,EAAEG;YAC5BvB;YACAI;QACF;QACAF,kBAAkBQ,IAAI,CAACX;IACzB;IACA,OAAO;QACLd;QACAC,iBAAiBgB;IACnB;AACF;AAEA;;CAEC,GACD,OAAO,SAASsB;IACd,OAAO;QACLN,IAAIpC;QACJyC,OAAO1B;QACPsB,aAAa;QACbnB,aAAa,EAAE;QACfI,eAAe,CAAC;IAClB;AACF;AAEA;;CAEC,GACD,OAAO,SAASqB,cAAcC,KAAqC,EAAEC,QAA8B;IACjGD,MAAMzC,WAAW,CAAC0C,SAAST,EAAE,CAAC,GAAGS;IACjCD,MAAMxC,eAAe,CAAC0C,OAAO,CAACD,SAAST,EAAE;AAC3C"}
|
|
@@ -5,12 +5,19 @@ export interface SaveChangesConfirmationDialogSlice {
|
|
|
5
5
|
openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;
|
|
6
6
|
closeSaveChangesConfirmationDialog: () => void;
|
|
7
7
|
}
|
|
8
|
+
export type SaveChangesConfirmationDialogOptions = {
|
|
9
|
+
saveDefaultTimeRange: boolean;
|
|
10
|
+
saveDefaultRefreshInterval: boolean;
|
|
11
|
+
saveDefaultVariables: boolean;
|
|
12
|
+
saveDefaultTimeZone: boolean;
|
|
13
|
+
};
|
|
8
14
|
export interface SaveChangesConfirmationDialogState {
|
|
9
|
-
onSaveChanges: (
|
|
15
|
+
onSaveChanges: (options: SaveChangesConfirmationDialogOptions) => void;
|
|
10
16
|
onCancel: () => void;
|
|
11
17
|
isSavedDurationModified: boolean;
|
|
12
18
|
isSavedRefreshIntervalModified: boolean;
|
|
13
19
|
isSavedVariableModified: boolean;
|
|
20
|
+
isTimeZoneModified: boolean;
|
|
14
21
|
description?: string;
|
|
15
22
|
}
|
|
16
23
|
export declare const createSaveChangesDialogSlice: StateCreator<SaveChangesConfirmationDialogSlice, Middleware, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-changes-dialog-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,kCAAkC;IACjD,6BAA6B,CAAC,EAAE,kCAAkC,CAAC;IACnE,iCAAiC,EAAE,CAAC,6BAA6B,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAC/G,kCAAkC,EAAE,MAAM,IAAI,CAAC;CAChD;AAED,MAAM,
|
|
1
|
+
{"version":3,"file":"save-changes-dialog-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,kCAAkC;IACjD,6BAA6B,CAAC,EAAE,kCAAkC,CAAC;IACnE,iCAAiC,EAAE,CAAC,6BAA6B,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAC/G,kCAAkC,EAAE,MAAM,IAAI,CAAC;CAChD;AAED,MAAM,MAAM,oCAAoC,GAAG;IACjD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,0BAA0B,EAAE,OAAO,CAAC;IACpC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AACF,MAAM,WAAW,kCAAkC;IACjD,aAAa,EAAE,CAAC,OAAO,EAAE,oCAAoC,KAAK,IAAI,CAAC;IACvE,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,uBAAuB,EAAE,OAAO,CAAC;IACjC,8BAA8B,EAAE,OAAO,CAAC;IACxC,uBAAuB,EAAE,OAAO,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,4BAA4B,EAAE,YAAY,CACrD,kCAAkC,EAClC,UAAU,EACV;CAAE,EACF,kCAAkC,CAuBlC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"sourcesContent":["// Copyright 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 SaveChangesConfirmationDialogSlice {\n saveChangesConfirmationDialog?: SaveChangesConfirmationDialogState;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n closeSaveChangesConfirmationDialog: () => void;\n}\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"sourcesContent":["// Copyright 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 SaveChangesConfirmationDialogSlice {\n saveChangesConfirmationDialog?: SaveChangesConfirmationDialogState;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n closeSaveChangesConfirmationDialog: () => void;\n}\n\nexport type SaveChangesConfirmationDialogOptions = {\n saveDefaultTimeRange: boolean;\n saveDefaultRefreshInterval: boolean;\n saveDefaultVariables: boolean;\n saveDefaultTimeZone: boolean;\n};\nexport interface SaveChangesConfirmationDialogState {\n onSaveChanges: (options: SaveChangesConfirmationDialogOptions) => void;\n onCancel: () => void;\n isSavedDurationModified: boolean;\n isSavedRefreshIntervalModified: boolean;\n isSavedVariableModified: boolean;\n isTimeZoneModified: boolean;\n description?: string;\n}\n\nexport const createSaveChangesDialogSlice: StateCreator<\n SaveChangesConfirmationDialogSlice,\n Middleware,\n [],\n SaveChangesConfirmationDialogSlice\n> = (set) => ({\n isOpen: false,\n\n openSaveChangesConfirmationDialog(dialog): void {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = dialog;\n },\n false,\n 'openSaveChangesConfirmationDialog'\n );\n },\n\n closeSaveChangesConfirmationDialog(): void {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = undefined;\n },\n false,\n 'closeSaveChangesConfirmationDialog'\n );\n },\n});\n"],"names":["createSaveChangesDialogSlice","set","isOpen","openSaveChangesConfirmationDialog","dialog","state","saveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","undefined"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA2BjC,OAAO,MAAMA,+BAKT,CAACC,MAAS,CAAA;QACZC,QAAQ;QAERC,mCAAkCC,MAAM;YACtCH,IACE,CAACI;gBACCA,MAAMC,6BAA6B,GAAGF;YACxC,GACA,OACA;QAEJ;QAEAG;YACEN,IACE,CAACI;gBACCA,MAAMC,6BAA6B,GAAGE;YACxC,GACA,OACA;QAEJ;IACF,CAAA,EAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-save-dashboard.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"use-save-dashboard.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,aAAa,EAAE,MAAM,IAAI,CAAC;IAE1B;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,mBAAmB,CAmF9E"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useCallback, useState } from 'react';
|
|
14
14
|
import { isRelativeTimeRange } from '@perses-dev/spec';
|
|
15
|
-
import { useTimeRange } from '@perses-dev/plugin-system';
|
|
15
|
+
import { useTimeRange, useTimeZoneParams } from '@perses-dev/plugin-system';
|
|
16
16
|
import { useVariableDefinitionActions } from '../VariableProvider/VariableProvider';
|
|
17
17
|
import { useDashboard } from '../useDashboard';
|
|
18
18
|
import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provider-api';
|
|
@@ -30,6 +30,7 @@ import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provi
|
|
|
30
30
|
const { dashboard, setDashboard } = useDashboard();
|
|
31
31
|
const { setEditMode } = useEditMode();
|
|
32
32
|
const { timeRange, refreshInterval } = useTimeRange();
|
|
33
|
+
const { timeZone } = useTimeZoneParams();
|
|
33
34
|
const { getSavedVariablesStatus, setVariableDefaultValues } = useVariableDefinitionActions();
|
|
34
35
|
const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();
|
|
35
36
|
const performSave = useCallback(async ()=>{
|
|
@@ -58,12 +59,17 @@ import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provi
|
|
|
58
59
|
const { isSavedVariableModified } = getSavedVariablesStatus();
|
|
59
60
|
const isSavedDurationModified = isRelativeTimeRange(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;
|
|
60
61
|
const isSavedRefreshIntervalModified = dashboard.spec.refreshInterval !== refreshInterval;
|
|
61
|
-
|
|
62
|
+
const isTimeZoneModified = timeZone === 'local' && !dashboard.spec.timezone ? false : dashboard.spec.timezone !== timeZone;
|
|
63
|
+
if (isSavedDurationModified || isSavedVariableModified || isSavedRefreshIntervalModified || isTimeZoneModified) {
|
|
62
64
|
openSaveChangesConfirmationDialog({
|
|
63
|
-
onSaveChanges: (
|
|
65
|
+
onSaveChanges: (options)=>{
|
|
66
|
+
const { saveDefaultRefreshInterval, saveDefaultTimeRange, saveDefaultTimeZone, saveDefaultVariables } = options;
|
|
64
67
|
if (isRelativeTimeRange(timeRange) && saveDefaultTimeRange) {
|
|
65
68
|
dashboard.spec.duration = timeRange.pastDuration;
|
|
66
69
|
}
|
|
70
|
+
if (saveDefaultTimeZone) {
|
|
71
|
+
dashboard.spec.timezone = timeZone;
|
|
72
|
+
}
|
|
67
73
|
if (saveDefaultVariables) {
|
|
68
74
|
const variables = setVariableDefaultValues();
|
|
69
75
|
dashboard.spec.variables = variables;
|
|
@@ -79,17 +85,19 @@ import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provi
|
|
|
79
85
|
},
|
|
80
86
|
isSavedDurationModified,
|
|
81
87
|
isSavedVariableModified,
|
|
82
|
-
isSavedRefreshIntervalModified
|
|
88
|
+
isSavedRefreshIntervalModified,
|
|
89
|
+
isTimeZoneModified
|
|
83
90
|
});
|
|
84
91
|
} else {
|
|
85
92
|
performSave();
|
|
86
93
|
}
|
|
87
94
|
}, [
|
|
88
95
|
isSaving,
|
|
89
|
-
getSavedVariablesStatus,
|
|
90
96
|
timeRange,
|
|
91
97
|
dashboard,
|
|
92
98
|
refreshInterval,
|
|
99
|
+
timeZone,
|
|
100
|
+
getSavedVariablesStatus,
|
|
93
101
|
openSaveChangesConfirmationDialog,
|
|
94
102
|
setVariableDefaultValues,
|
|
95
103
|
setDashboard,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"sourcesContent":["// Copyright 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 { useCallback, useState } from 'react';\nimport { isRelativeTimeRange } from '@perses-dev/spec';\nimport { useTimeRange } from '@perses-dev/plugin-system';\nimport { useVariableDefinitionActions } from '../VariableProvider/VariableProvider';\nimport { useDashboard } from '../useDashboard';\nimport { OnSaveDashboard } from './common';\nimport { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provider-api';\n\nexport interface SaveDashboardResult {\n /**\n * Triggers the save flow. If time range, refresh interval, or variable defaults have been\n * modified, opens the SaveChangesConfirmationDialog before saving. Otherwise saves directly.\n * Includes a concurrent-save guard to prevent duplicate saves.\n */\n saveDashboard: () => void;\n\n /**\n * Whether a save operation is currently in progress.\n */\n isSaving: boolean;\n}\n\n/**\n * Hook that encapsulates the full save-dashboard flow, including:\n * - Checking for modified defaults (time range, refresh interval, variables)\n * - Opening the SaveChangesConfirmationDialog when defaults have changed\n * - Saving directly when no confirmation is needed\n * - Preventing concurrent saves via an `isSaving` guard\n * - Exiting edit mode after a successful save\n *\n * Used by both SaveDashboardButton and DashboardShortcuts to ensure consistent save behavior.\n */\nexport function useSaveDashboard(onSave?: OnSaveDashboard): SaveDashboardResult {\n const [isSaving, setSaving] = useState(false);\n const { dashboard, setDashboard } = useDashboard();\n const { setEditMode } = useEditMode();\n const { timeRange, refreshInterval } = useTimeRange();\n const { getSavedVariablesStatus, setVariableDefaultValues } = useVariableDefinitionActions();\n const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();\n
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"sourcesContent":["// Copyright 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 { useCallback, useState } from 'react';\nimport { isRelativeTimeRange } from '@perses-dev/spec';\nimport { useTimeRange, useTimeZoneParams } from '@perses-dev/plugin-system';\nimport { useVariableDefinitionActions } from '../VariableProvider/VariableProvider';\nimport { useDashboard } from '../useDashboard';\nimport { OnSaveDashboard } from './common';\nimport { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provider-api';\nimport { SaveChangesConfirmationDialogOptions } from './save-changes-dialog-slice';\n\nexport interface SaveDashboardResult {\n /**\n * Triggers the save flow. If time range, refresh interval, or variable defaults have been\n * modified, opens the SaveChangesConfirmationDialog before saving. Otherwise saves directly.\n * Includes a concurrent-save guard to prevent duplicate saves.\n */\n saveDashboard: () => void;\n\n /**\n * Whether a save operation is currently in progress.\n */\n isSaving: boolean;\n}\n\n/**\n * Hook that encapsulates the full save-dashboard flow, including:\n * - Checking for modified defaults (time range, refresh interval, variables)\n * - Opening the SaveChangesConfirmationDialog when defaults have changed\n * - Saving directly when no confirmation is needed\n * - Preventing concurrent saves via an `isSaving` guard\n * - Exiting edit mode after a successful save\n *\n * Used by both SaveDashboardButton and DashboardShortcuts to ensure consistent save behavior.\n */\nexport function useSaveDashboard(onSave?: OnSaveDashboard): SaveDashboardResult {\n const [isSaving, setSaving] = useState(false);\n const { dashboard, setDashboard } = useDashboard();\n const { setEditMode } = useEditMode();\n const { timeRange, refreshInterval } = useTimeRange();\n const { timeZone } = useTimeZoneParams();\n const { getSavedVariablesStatus, setVariableDefaultValues } = useVariableDefinitionActions();\n const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();\n const performSave = useCallback(async (): Promise<void> => {\n if (!onSave) {\n setEditMode(false);\n return;\n }\n\n try {\n setSaving(true);\n await onSave(dashboard);\n closeSaveChangesConfirmationDialog();\n setEditMode(false);\n } finally {\n setSaving(false);\n }\n }, [closeSaveChangesConfirmationDialog, dashboard, onSave, setEditMode]);\n\n const saveDashboard = useCallback((): void => {\n if (isSaving) {\n return;\n }\n\n const { isSavedVariableModified } = getSavedVariablesStatus();\n const isSavedDurationModified =\n isRelativeTimeRange(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;\n const isSavedRefreshIntervalModified = dashboard.spec.refreshInterval !== refreshInterval;\n const isTimeZoneModified =\n timeZone === 'local' && !dashboard.spec.timezone ? false : dashboard.spec.timezone !== timeZone;\n\n if (isSavedDurationModified || isSavedVariableModified || isSavedRefreshIntervalModified || isTimeZoneModified) {\n openSaveChangesConfirmationDialog({\n onSaveChanges: (options: SaveChangesConfirmationDialogOptions) => {\n const { saveDefaultRefreshInterval, saveDefaultTimeRange, saveDefaultTimeZone, saveDefaultVariables } =\n options;\n if (isRelativeTimeRange(timeRange) && saveDefaultTimeRange) {\n dashboard.spec.duration = timeRange.pastDuration;\n }\n if (saveDefaultTimeZone) {\n dashboard.spec.timezone = timeZone;\n }\n if (saveDefaultVariables) {\n const variables = setVariableDefaultValues();\n dashboard.spec.variables = variables;\n }\n if (saveDefaultRefreshInterval && isSavedRefreshIntervalModified) {\n dashboard.spec.refreshInterval = refreshInterval;\n }\n setDashboard(dashboard);\n performSave();\n },\n onCancel: () => {\n closeSaveChangesConfirmationDialog();\n },\n isSavedDurationModified,\n isSavedVariableModified,\n isSavedRefreshIntervalModified,\n isTimeZoneModified,\n });\n } else {\n performSave();\n }\n }, [\n isSaving,\n timeRange,\n dashboard,\n refreshInterval,\n timeZone,\n getSavedVariablesStatus,\n openSaveChangesConfirmationDialog,\n setVariableDefaultValues,\n setDashboard,\n performSave,\n closeSaveChangesConfirmationDialog,\n ]);\n\n return { saveDashboard, isSaving };\n}\n"],"names":["useCallback","useState","isRelativeTimeRange","useTimeRange","useTimeZoneParams","useVariableDefinitionActions","useDashboard","useEditMode","useSaveChangesConfirmationDialog","useSaveDashboard","onSave","isSaving","setSaving","dashboard","setDashboard","setEditMode","timeRange","refreshInterval","timeZone","getSavedVariablesStatus","setVariableDefaultValues","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","performSave","saveDashboard","isSavedVariableModified","isSavedDurationModified","spec","duration","pastDuration","isSavedRefreshIntervalModified","isTimeZoneModified","timezone","onSaveChanges","options","saveDefaultRefreshInterval","saveDefaultTimeRange","saveDefaultTimeZone","saveDefaultVariables","variables","onCancel"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAC9C,SAASC,mBAAmB,QAAQ,mBAAmB;AACvD,SAASC,YAAY,EAAEC,iBAAiB,QAAQ,4BAA4B;AAC5E,SAASC,4BAA4B,QAAQ,uCAAuC;AACpF,SAASC,YAAY,QAAQ,kBAAkB;AAE/C,SAASC,WAAW,EAAEC,gCAAgC,QAAQ,2BAA2B;AAiBzF;;;;;;;;;CASC,GACD,OAAO,SAASC,iBAAiBC,MAAwB;IACvD,MAAM,CAACC,UAAUC,UAAU,GAAGX,SAAS;IACvC,MAAM,EAAEY,SAAS,EAAEC,YAAY,EAAE,GAAGR;IACpC,MAAM,EAAES,WAAW,EAAE,GAAGR;IACxB,MAAM,EAAES,SAAS,EAAEC,eAAe,EAAE,GAAGd;IACvC,MAAM,EAAEe,QAAQ,EAAE,GAAGd;IACrB,MAAM,EAAEe,uBAAuB,EAAEC,wBAAwB,EAAE,GAAGf;IAC9D,MAAM,EAAEgB,iCAAiC,EAAEC,kCAAkC,EAAE,GAAGd;IAClF,MAAMe,cAAcvB,YAAY;QAC9B,IAAI,CAACU,QAAQ;YACXK,YAAY;YACZ;QACF;QAEA,IAAI;YACFH,UAAU;YACV,MAAMF,OAAOG;YACbS;YACAP,YAAY;QACd,SAAU;YACRH,UAAU;QACZ;IACF,GAAG;QAACU;QAAoCT;QAAWH;QAAQK;KAAY;IAEvE,MAAMS,gBAAgBxB,YAAY;QAChC,IAAIW,UAAU;YACZ;QACF;QAEA,MAAM,EAAEc,uBAAuB,EAAE,GAAGN;QACpC,MAAMO,0BACJxB,oBAAoBc,cAAcH,UAAUc,IAAI,CAACC,QAAQ,KAAKZ,UAAUa,YAAY;QACtF,MAAMC,iCAAiCjB,UAAUc,IAAI,CAACV,eAAe,KAAKA;QAC1E,MAAMc,qBACJb,aAAa,WAAW,CAACL,UAAUc,IAAI,CAACK,QAAQ,GAAG,QAAQnB,UAAUc,IAAI,CAACK,QAAQ,KAAKd;QAEzF,IAAIQ,2BAA2BD,2BAA2BK,kCAAkCC,oBAAoB;YAC9GV,kCAAkC;gBAChCY,eAAe,CAACC;oBACd,MAAM,EAAEC,0BAA0B,EAAEC,oBAAoB,EAAEC,mBAAmB,EAAEC,oBAAoB,EAAE,GACnGJ;oBACF,IAAIhC,oBAAoBc,cAAcoB,sBAAsB;wBAC1DvB,UAAUc,IAAI,CAACC,QAAQ,GAAGZ,UAAUa,YAAY;oBAClD;oBACA,IAAIQ,qBAAqB;wBACvBxB,UAAUc,IAAI,CAACK,QAAQ,GAAGd;oBAC5B;oBACA,IAAIoB,sBAAsB;wBACxB,MAAMC,YAAYnB;wBAClBP,UAAUc,IAAI,CAACY,SAAS,GAAGA;oBAC7B;oBACA,IAAIJ,8BAA8BL,gCAAgC;wBAChEjB,UAAUc,IAAI,CAACV,eAAe,GAAGA;oBACnC;oBACAH,aAAaD;oBACbU;gBACF;gBACAiB,UAAU;oBACRlB;gBACF;gBACAI;gBACAD;gBACAK;gBACAC;YACF;QACF,OAAO;YACLR;QACF;IACF,GAAG;QACDZ;QACAK;QACAH;QACAI;QACAC;QACAC;QACAE;QACAD;QACAN;QACAS;QACAD;KACD;IAED,OAAO;QAAEE;QAAeb;IAAS;AACnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateCreator } from 'zustand';
|
|
2
|
-
import { PanelGroupItemId } from '
|
|
2
|
+
import { PanelGroupItemId } from '../../model';
|
|
3
3
|
import { Middleware } from './common';
|
|
4
4
|
import { PanelGroupSlice } from './panel-group-slice';
|
|
5
5
|
export interface VirtualPanelRef {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"view-panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAwB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKtD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,EAAE,MAAM,gBAAgB,GAAG,SAAS,CAAC;IACjD,YAAY,EAAE,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,cAAc;IAE7B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,CAAC,EAAE,eAAe,EAC9B,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,KAAK,IAAI,GAC3D,YAAY,CAAC,cAAc,GAAG,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,cAAc,CAAC,CAwBhF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"sourcesContent":["// Copyright 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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"sourcesContent":["// Copyright 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 { PanelGroupId } from '@perses-dev/spec';\nimport { PanelGroupDefinition, PanelGroupItemId } from '../../model';\nimport { Middleware } from './common';\nimport { PanelGroupSlice } from './panel-group-slice';\n\n/*\n * A reference to a Panel that can be repeated in a PanelGroup.\n */\nexport interface VirtualPanelRef {\n ref: string;\n repeatVariable?: [string, string];\n}\n\n/**\n * Slice that handles viewing Panels in max size (\"full screen\").\n */\nexport interface ViewPanelSlice {\n viewPanel: ViewPanelState;\n getViewPanel: () => PanelGroupItemId | undefined;\n setViewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n}\n\nexport interface ViewPanelState {\n // Do not use directly, use `getViewPanel()` instead for getting the current viewed PanelGroupItemId!\n panelGroupItemId?: PanelGroupItemId;\n panelRef?: VirtualPanelRef;\n}\n\n/**\n * Curried function for viewing panel in max size (\"full screen\").\n */\nexport function createViewPanelSlice(\n viewPanelRef?: VirtualPanelRef,\n setViewPanelRef?: (ref: VirtualPanelRef | undefined) => void\n): StateCreator<ViewPanelSlice & PanelGroupSlice, Middleware, [], ViewPanelSlice> {\n return (set, get) => ({\n viewPanel: {\n panelGroupItemId: undefined,\n panelRef: viewPanelRef,\n },\n\n getViewPanel(): PanelGroupItemId | undefined {\n return getViewPanelGroupId(get().panelGroups, get().viewPanel.panelGroupItemId, get().viewPanel.panelRef);\n },\n\n setViewPanel(panelGroupItemId?: PanelGroupItemId): void {\n set((state) => {\n state.viewPanel = {\n panelRef: undefined,\n panelGroupItemId: panelGroupItemId,\n };\n const panelRef = findPanelRefOfPanelGroupItemId(get().panelGroups, panelGroupItemId);\n if (setViewPanelRef) {\n setViewPanelRef(panelRef);\n }\n });\n },\n });\n}\n\nfunction getViewPanelGroupId(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelGroupItemId?: PanelGroupItemId,\n panelRef?: VirtualPanelRef\n): PanelGroupItemId | undefined {\n if (panelGroupItemId) {\n return panelGroupItemId;\n }\n\n if (panelRef) {\n return findPanelGroupItemIdOfPanelRef(panelGroups, panelRef);\n }\n\n return undefined;\n}\n\n// Find the PanelGroupItemId of a Panel from a PanelRef\nfunction findPanelGroupItemIdOfPanelRef(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelRef: VirtualPanelRef\n): PanelGroupItemId | undefined {\n for (const panelGroup of Object.values(panelGroups)) {\n const itemPanel = Object.entries(panelGroup.itemPanelKeys ?? []).find(([_, value]) => value === panelRef.ref);\n if (itemPanel) {\n const [key] = itemPanel;\n return {\n panelGroupId: panelGroup.id,\n panelGroupItemLayoutId: key,\n repeatVariable: panelRef.repeatVariable,\n };\n }\n }\n return undefined;\n}\n\n// Find the PanelRef from a PanelGroupItemId\nfunction findPanelRefOfPanelGroupItemId(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelGroupItemId?: PanelGroupItemId\n): VirtualPanelRef | undefined {\n if (!panelGroupItemId) {\n return undefined;\n }\n const panelGroup = panelGroups[panelGroupItemId.panelGroupId];\n if (panelGroup) {\n const panelRef = panelGroup.itemPanelKeys[panelGroupItemId.panelGroupItemLayoutId];\n if (panelRef) {\n return { ref: panelRef, repeatVariable: panelGroupItemId.repeatVariable };\n }\n }\n return undefined;\n}\n"],"names":["createViewPanelSlice","viewPanelRef","setViewPanelRef","set","get","viewPanel","panelGroupItemId","undefined","panelRef","getViewPanel","getViewPanelGroupId","panelGroups","setViewPanel","state","findPanelRefOfPanelGroupItemId","findPanelGroupItemIdOfPanelRef","panelGroup","Object","values","itemPanel","entries","itemPanelKeys","find","_","value","ref","key","panelGroupId","id","panelGroupItemLayoutId","repeatVariable"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA+BjC;;CAEC,GACD,OAAO,SAASA,qBACdC,YAA8B,EAC9BC,eAA4D;IAE5D,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,WAAW;gBACTC,kBAAkBC;gBAClBC,UAAUP;YACZ;YAEAQ;gBACE,OAAOC,oBAAoBN,MAAMO,WAAW,EAAEP,MAAMC,SAAS,CAACC,gBAAgB,EAAEF,MAAMC,SAAS,CAACG,QAAQ;YAC1G;YAEAI,cAAaN,gBAAmC;gBAC9CH,IAAI,CAACU;oBACHA,MAAMR,SAAS,GAAG;wBAChBG,UAAUD;wBACVD,kBAAkBA;oBACpB;oBACA,MAAME,WAAWM,+BAA+BV,MAAMO,WAAW,EAAEL;oBACnE,IAAIJ,iBAAiB;wBACnBA,gBAAgBM;oBAClB;gBACF;YACF;QACF,CAAA;AACF;AAEA,SAASE,oBACPC,WAAuD,EACvDL,gBAAmC,EACnCE,QAA0B;IAE1B,IAAIF,kBAAkB;QACpB,OAAOA;IACT;IAEA,IAAIE,UAAU;QACZ,OAAOO,+BAA+BJ,aAAaH;IACrD;IAEA,OAAOD;AACT;AAEA,uDAAuD;AACvD,SAASQ,+BACPJ,WAAuD,EACvDH,QAAyB;IAEzB,KAAK,MAAMQ,cAAcC,OAAOC,MAAM,CAACP,aAAc;QACnD,MAAMQ,YAAYF,OAAOG,OAAO,CAACJ,WAAWK,aAAa,IAAI,EAAE,EAAEC,IAAI,CAAC,CAAC,CAACC,GAAGC,MAAM,GAAKA,UAAUhB,SAASiB,GAAG;QAC5G,IAAIN,WAAW;YACb,MAAM,CAACO,IAAI,GAAGP;YACd,OAAO;gBACLQ,cAAcX,WAAWY,EAAE;gBAC3BC,wBAAwBH;gBACxBI,gBAAgBtB,SAASsB,cAAc;YACzC;QACF;IACF;IACA,OAAOvB;AACT;AAEA,4CAA4C;AAC5C,SAASO,+BACPH,WAAuD,EACvDL,gBAAmC;IAEnC,IAAI,CAACA,kBAAkB;QACrB,OAAOC;IACT;IACA,MAAMS,aAAaL,WAAW,CAACL,iBAAiBqB,YAAY,CAAC;IAC7D,IAAIX,YAAY;QACd,MAAMR,WAAWQ,WAAWK,aAAa,CAACf,iBAAiBuB,sBAAsB,CAAC;QAClF,IAAIrB,UAAU;YACZ,OAAO;gBAAEiB,KAAKjB;gBAAUsB,gBAAgBxB,iBAAiBwB,cAAc;YAAC;QAC1E;IACF;IACA,OAAOvB;AACT"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from 'react';
|
|
2
|
-
import { DatasourceApi } from '@perses-dev/core';
|
|
3
2
|
import { DatasourceSpec } from '@perses-dev/spec';
|
|
4
3
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
5
|
-
import { DashboardResource } from '
|
|
4
|
+
import { DashboardResource, DatasourceApi } from '@perses-dev/client';
|
|
6
5
|
export interface DatasourceStoreProviderProps {
|
|
7
6
|
dashboardResource?: DashboardResource;
|
|
8
7
|
projectName?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAA0C,MAAM,OAAO,CAAC;AACxF,OAAO,EAAqC,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAML,gBAAgB,EAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,iBAAiB,EACjB,aAAa,EAEd,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CAC3D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,GAAG,YAAY,CAoNzF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,8 +11,7 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import {
|
|
14
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
14
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
15
15
|
import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev/plugin-system';
|
|
16
16
|
/**
|
|
17
17
|
* A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
|
|
@@ -19,15 +19,24 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
|
|
|
19
19
|
const { projectName, datasourceApi, onCreate, children } = props;
|
|
20
20
|
const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);
|
|
21
21
|
const [savedDatasources, setSavedDatasources] = useState(props.savedDatasources ?? {});
|
|
22
|
+
// Cache for synchronous datasource spec access
|
|
23
|
+
const datasourceSpecCache = useRef(new Map());
|
|
22
24
|
const project = projectName ?? dashboardResource?.metadata.project;
|
|
23
25
|
const { getPlugin, listPluginMetadata } = usePluginRegistry();
|
|
26
|
+
// Helper to create cache key from DatasourceSelector
|
|
27
|
+
const createCacheKey = useCallback((selector)=>{
|
|
28
|
+
const name = selector.name === undefined ? '__undefined__' : selector.name;
|
|
29
|
+
return `${selector.kind}:${name}:${project ?? 'global'}`;
|
|
30
|
+
}, [
|
|
31
|
+
project
|
|
32
|
+
]);
|
|
24
33
|
const findDatasource = useEvent(async (selector)=>{
|
|
25
34
|
// Try to find it in dashboard spec
|
|
26
35
|
if (dashboardResource) {
|
|
27
36
|
const { datasources } = dashboardResource.spec;
|
|
28
37
|
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
29
38
|
if (dashboardDatasource !== undefined) {
|
|
30
|
-
|
|
39
|
+
const result = {
|
|
31
40
|
spec: dashboardDatasource.spec,
|
|
32
41
|
proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
|
|
33
42
|
project: dashboardResource.metadata.project,
|
|
@@ -35,30 +44,42 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
|
|
|
35
44
|
name: dashboardDatasource.name
|
|
36
45
|
})
|
|
37
46
|
};
|
|
47
|
+
// Cache the spec for synchronous access
|
|
48
|
+
const cacheKey = createCacheKey(selector);
|
|
49
|
+
datasourceSpecCache.current.set(cacheKey, result.spec);
|
|
50
|
+
return result;
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
if (project) {
|
|
41
54
|
// Try to find it at the project level as a Datasource resource
|
|
42
55
|
const datasource = await datasourceApi.getDatasource(String(project), selector);
|
|
43
56
|
if (datasource !== undefined) {
|
|
44
|
-
|
|
57
|
+
const result = {
|
|
45
58
|
spec: datasource.spec,
|
|
46
59
|
proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
|
|
47
60
|
project: datasource.metadata.project,
|
|
48
61
|
name: datasource.metadata.name
|
|
49
62
|
})
|
|
50
63
|
};
|
|
64
|
+
// Cache the spec for synchronous access
|
|
65
|
+
const cacheKey = createCacheKey(selector);
|
|
66
|
+
datasourceSpecCache.current.set(cacheKey, result.spec);
|
|
67
|
+
return result;
|
|
51
68
|
}
|
|
52
69
|
}
|
|
53
70
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
54
71
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
55
72
|
if (globalDatasource !== undefined) {
|
|
56
|
-
|
|
73
|
+
const result = {
|
|
57
74
|
spec: globalDatasource.spec,
|
|
58
75
|
proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
|
|
59
76
|
name: globalDatasource.metadata.name
|
|
60
77
|
})
|
|
61
78
|
};
|
|
79
|
+
// Cache the spec for synchronous access
|
|
80
|
+
const cacheKey = createCacheKey(selector);
|
|
81
|
+
datasourceSpecCache.current.set(cacheKey, result.spec);
|
|
82
|
+
return result;
|
|
62
83
|
}
|
|
63
84
|
throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
|
|
64
85
|
});
|
|
@@ -74,7 +95,10 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
|
|
|
74
95
|
const { kind } = selector;
|
|
75
96
|
const [{ spec, proxyUrl }, plugin] = await Promise.all([
|
|
76
97
|
findDatasource(selector),
|
|
77
|
-
getPlugin(
|
|
98
|
+
getPlugin({
|
|
99
|
+
kind: 'Datasource',
|
|
100
|
+
name: kind
|
|
101
|
+
})
|
|
78
102
|
]);
|
|
79
103
|
// allows extending client
|
|
80
104
|
const client = plugin.createClient(spec.plugin.spec, {
|
|
@@ -150,6 +174,13 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
|
|
|
150
174
|
}, [
|
|
151
175
|
savedDatasources
|
|
152
176
|
]);
|
|
177
|
+
// Gets a cached datasource spec synchronously if available
|
|
178
|
+
const getDatasourceSpecSync = useCallback((selector)=>{
|
|
179
|
+
const cacheKey = createCacheKey(selector);
|
|
180
|
+
return datasourceSpecCache.current.get(cacheKey);
|
|
181
|
+
}, [
|
|
182
|
+
createCacheKey
|
|
183
|
+
]);
|
|
153
184
|
const setLocalDatasources = useCallback((datasources)=>{
|
|
154
185
|
if (dashboardResource) {
|
|
155
186
|
setDashboardResource({
|
|
@@ -166,6 +197,7 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
|
|
|
166
197
|
const ctxValue = useMemo(()=>({
|
|
167
198
|
getDatasource,
|
|
168
199
|
getDatasourceClient,
|
|
200
|
+
getDatasourceSpecSync,
|
|
169
201
|
getLocalDatasources,
|
|
170
202
|
setLocalDatasources,
|
|
171
203
|
setSavedDatasources,
|
|
@@ -174,6 +206,7 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
|
|
|
174
206
|
}), [
|
|
175
207
|
getDatasource,
|
|
176
208
|
getDatasourceClient,
|
|
209
|
+
getDatasourceSpecSync,
|
|
177
210
|
getLocalDatasources,
|
|
178
211
|
setLocalDatasources,
|
|
179
212
|
listDatasourceSelectItems,
|
|
@@ -255,7 +288,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
255
288
|
});
|
|
256
289
|
usedNames.add(selectorName);
|
|
257
290
|
const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;
|
|
258
|
-
if (results[0] &&
|
|
291
|
+
if (results[0] && isExplicitDefault) {
|
|
259
292
|
// If we haven't added a default yet and this is a default, add default option to the beginning of the results
|
|
260
293
|
results[0].items = [
|
|
261
294
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 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 { ReactElement, ReactNode, useCallback, useMemo, useState } from 'react';\nimport { DatasourceDefinition, BuildDatasourceProxyUrlParams, DatasourceApi } from '@perses-dev/core'; // TODO\nimport { DashboardSpec, DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n useEvent,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\nimport { DashboardResource } from '../model/DashboardResource';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(String(project), selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(String(project), datasourcePluginName) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginName),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.spec.name === datasourcePluginName);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n });\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({\n spec,\n selectorName,\n selectorGroup: group,\n editLink,\n saved,\n }: AddDatasouceSelectItemParams): void => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","DatasourceStoreContext","usePluginRegistry","useEvent","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","String","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginName","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAkCA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAGhF,SACEC,sBAAsB,EAGtBC,iBAAiB,EACjBC,QAAQ,QAGH,4BAA4B;AAYnC;;CAEC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;IACzE,MAAM,EAAEC,WAAW,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGJ;IAC3D,MAAM,CAACK,mBAAmBC,qBAAqB,GAAGX,SAASK,MAAMK,iBAAiB;IAClF,MAAM,CAACE,kBAAkBC,oBAAoB,GAAGb,SAC9CK,MAAMO,gBAAgB,IAAI,CAAC;IAE7B,MAAME,UAAUR,eAAeI,mBAAmBK,SAASD;IAE3D,MAAM,EAAEE,SAAS,EAAEC,kBAAkB,EAAE,GAAGf;IAE1C,MAAMgB,iBAAiBf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S,IAAI,KAAK2B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
|
|
1
|
+
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 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 { ReactElement, ReactNode, useCallback, useMemo, useRef, useState } from 'react';\nimport { DashboardSpec, DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n useEvent,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\nimport {\n BuildDatasourceProxyUrlParams,\n DashboardResource,\n DatasourceApi,\n DatasourceDefinition,\n} from '@perses-dev/client';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n // Cache for synchronous datasource spec access\n const datasourceSpecCache = useRef<Map<string, DatasourceSpec>>(new Map());\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n // Helper to create cache key from DatasourceSelector\n const createCacheKey = useCallback(\n (selector: DatasourceSelector): string => {\n const name = selector.name === undefined ? '__undefined__' : selector.name;\n return `${selector.kind}:${name}:${project ?? 'global'}`;\n },\n [project]\n );\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n const result = {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n // Cache the spec for synchronous access\n const cacheKey = createCacheKey(selector);\n datasourceSpecCache.current.set(cacheKey, result.spec);\n return result;\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(String(project), selector);\n if (datasource !== undefined) {\n const result = {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n // Cache the spec for synchronous access\n const cacheKey = createCacheKey(selector);\n datasourceSpecCache.current.set(cacheKey, result.spec);\n return result;\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n const result = {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n // Cache the spec for synchronous access\n const cacheKey = createCacheKey(selector);\n datasourceSpecCache.current.set(cacheKey, result.spec);\n return result;\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([\n findDatasource(selector),\n getPlugin({ kind: 'Datasource', name: kind }),\n ]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(String(project), datasourcePluginName) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginName),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.spec.name === datasourcePluginName);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n // Gets a cached datasource spec synchronously if available\n const getDatasourceSpecSync = useCallback(\n (selector: DatasourceSelector): DatasourceSpec | undefined => {\n const cacheKey = createCacheKey(selector);\n return datasourceSpecCache.current.get(cacheKey);\n },\n [createCacheKey]\n );\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n });\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getDatasourceSpecSync,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getDatasourceSpecSync,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({\n spec,\n selectorName,\n selectorGroup: group,\n editLink,\n saved,\n }: AddDatasouceSelectItemParams): void => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && isExplicitDefault) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useRef","useState","DatasourceStoreContext","usePluginRegistry","useEvent","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","datasourceSpecCache","Map","project","metadata","getPlugin","listPluginMetadata","createCacheKey","selector","name","undefined","kind","findDatasource","datasources","spec","dashboardDatasource","findDashboardDatasource","result","proxyUrl","buildDatasourceProxyUrl","dashboard","cacheKey","current","set","datasource","getDatasource","String","globalDatasource","getGlobalDatasource","Error","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginName","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","getDatasourceSpecSync","get","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":";AAAA,+BA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AM,CAACrB,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD+D,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;gBACpEzC,CAAAA,OAAO,CAACyC,EAAE,EAAEP,SAAS,EAAE,AAAD,EACpBQ,MAAM,CAAC,CAACC,OAA+BA,KAAKhF,QAAQ,CAACC,IAAI,KAAKwC,cAC9DwC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE5B;QAASC;IAAQ;AAC5B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { createContext, useMemo, useState } from 'react';
|
|
15
15
|
export const PanelEditorContext = /*#__PURE__*/ createContext(undefined);
|
|
16
16
|
export const PanelEditorProvider = ({ children })=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/PanelEditorProvider/PanelEditorProvider.tsx"],"sourcesContent":["// Copyright 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 { createContext, ReactElement, ReactNode, useMemo, useState } from 'react';\n\nexport interface PanelEditor {\n preview: {\n previewPanelWidth?: number;\n setPreviewPanelWidth: (width: number) => void;\n };\n}\n\nexport interface PanelEditorProviderProps {\n children: ReactNode;\n}\n\nexport const PanelEditorContext = createContext<PanelEditor | undefined>(undefined);\n\nexport const PanelEditorProvider = ({ children }: PanelEditorProviderProps): ReactElement => {\n const [previewPanelWidth, setPreviewPanelWidth] = useState<number | undefined>(undefined);\n\n const ctx = useMemo(\n (): PanelEditor => ({\n preview: {\n previewPanelWidth,\n setPreviewPanelWidth,\n },\n }),\n [previewPanelWidth]\n );\n\n return <PanelEditorContext.Provider value={ctx}>{children}</PanelEditorContext.Provider>;\n};\n"],"names":["createContext","useMemo","useState","PanelEditorContext","undefined","PanelEditorProvider","children","previewPanelWidth","setPreviewPanelWidth","ctx","preview","Provider","value"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC
|
|
1
|
+
{"version":3,"sources":["../../../src/context/PanelEditorProvider/PanelEditorProvider.tsx"],"sourcesContent":["// Copyright 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 { createContext, ReactElement, ReactNode, useMemo, useState } from 'react';\n\nexport interface PanelEditor {\n preview: {\n previewPanelWidth?: number;\n setPreviewPanelWidth: (width: number) => void;\n };\n}\n\nexport interface PanelEditorProviderProps {\n children: ReactNode;\n}\n\nexport const PanelEditorContext = createContext<PanelEditor | undefined>(undefined);\n\nexport const PanelEditorProvider = ({ children }: PanelEditorProviderProps): ReactElement => {\n const [previewPanelWidth, setPreviewPanelWidth] = useState<number | undefined>(undefined);\n\n const ctx = useMemo(\n (): PanelEditor => ({\n preview: {\n previewPanelWidth,\n setPreviewPanelWidth,\n },\n }),\n [previewPanelWidth]\n );\n\n return <PanelEditorContext.Provider value={ctx}>{children}</PanelEditorContext.Provider>;\n};\n"],"names":["createContext","useMemo","useState","PanelEditorContext","undefined","PanelEditorProvider","children","previewPanelWidth","setPreviewPanelWidth","ctx","preview","Provider","value"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAA2BC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAalF,OAAO,MAAMC,mCAAqBH,cAAuCI,WAAW;AAEpF,OAAO,MAAMC,sBAAsB,CAAC,EAAEC,QAAQ,EAA4B;IACxE,MAAM,CAACC,mBAAmBC,qBAAqB,GAAGN,SAA6BE;IAE/E,MAAMK,MAAMR,QACV,IAAoB,CAAA;YAClBS,SAAS;gBACPH;gBACAC;YACF;QACF,CAAA,GACA;QAACD;KAAkB;IAGrB,qBAAO,KAACJ,mBAAmBQ,QAAQ;QAACC,OAAOH;kBAAMH;;AACnD,EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import { StoreApi } from 'zustand';
|
|
3
3
|
import { VariableStateMap, VariableState, VariableStoreStateMap, VariableOption } from '@perses-dev/plugin-system';
|
|
4
|
-
import { ExternalVariableDefinition } from '@perses-dev/core';
|
|
5
4
|
import { VariableName, VariableValue, VariableDefinition, BuiltinVariableDefinition, TextVariableDefinition, ListVariableDefinition } from '@perses-dev/spec';
|
|
5
|
+
import { ExternalVariableDefinition } from '../../model/VariableDefinition';
|
|
6
6
|
/**
|
|
7
7
|
* This store is used to manipulate and read the definition of the variables and their state.
|
|
8
8
|
* - being local or external variables.
|
|
@@ -104,8 +104,9 @@ export interface VariableProviderProps {
|
|
|
104
104
|
initialVariableDefinitions?: VariableDefinition[];
|
|
105
105
|
externalVariableDefinitions?: ExternalVariableDefinition[];
|
|
106
106
|
builtinVariableDefinitions?: BuiltinVariableDefinition[];
|
|
107
|
+
initialVariableValues?: Record<string, VariableValue>;
|
|
107
108
|
}
|
|
108
|
-
export declare function VariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, }: VariableProviderProps): ReactElement;
|
|
109
|
+
export declare function VariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, initialVariableValues, }: VariableProviderProps): ReactElement;
|
|
109
110
|
export declare function VariableProviderWithQueryParams({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions: builtinVariables, }: VariableProviderProps): ReactElement;
|
|
110
111
|
export {};
|
|
111
112
|
//# sourceMappingURL=VariableProvider.d.ts.map
|