@perses-dev/dashboards 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
- package/dist/cjs/components/Dashboard/index.js +28 -0
- package/dist/cjs/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +9 -16
- package/dist/cjs/components/DashboardToolbar/index.js +28 -0
- package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +4 -7
- package/dist/cjs/components/DeletePanelDialog/index.js +28 -0
- package/dist/cjs/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
- package/dist/cjs/components/DeletePanelGroupDialog/index.js +28 -0
- package/dist/cjs/components/GridLayout/GridItemContent.js +11 -1
- package/dist/cjs/components/GridLayout/GridLayout.js +14 -16
- package/dist/cjs/components/Panel/Panel.js +30 -90
- package/dist/cjs/components/Panel/Panel.test.js +93 -46
- package/dist/cjs/components/Panel/PanelHeader.js +116 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +21 -19
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +16 -16
- package/dist/cjs/components/PanelGroupDialog/index.js +0 -1
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
- package/dist/cjs/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +67 -0
- package/dist/cjs/components/UnsavedChangesConfirmationDialog/index.js +28 -0
- package/dist/cjs/components/Variables/Variable.js +18 -11
- package/dist/cjs/components/Variables/VariableEditor.js +7 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +32 -20
- package/dist/cjs/context/DashboardProvider/common.js +10 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +14 -16
- package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +70 -0
- package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +85 -0
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +74 -67
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -19
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +54 -164
- package/dist/cjs/context/DashboardProvider/panel-slice.js +25 -0
- package/dist/cjs/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
- package/dist/cjs/context/TemplateVariableProvider/index.js +28 -0
- package/dist/cjs/context/TemplateVariableProvider/query-params.js +79 -0
- package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +82 -0
- package/dist/cjs/context/index.js +1 -1
- package/dist/cjs/context/useDashboard.js +94 -0
- package/dist/cjs/test/plugin-registry.js +14 -54
- package/dist/cjs/test/render.js +6 -1
- package/dist/cjs/utils/component-ids.js +31 -0
- package/dist/cjs/utils/time-range-params.js +14 -8
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -11
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +1 -1
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/components/{Dashboard.d.ts → Dashboard/Dashboard.d.ts} +0 -0
- package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
- package/dist/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
- package/dist/components/Dashboard/Dashboard.js.map +1 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/index.d.ts.map +1 -0
- package/dist/components/Dashboard/index.js +15 -0
- package/dist/components/Dashboard/index.js.map +1 -0
- package/dist/components/{DashboardToolbar.d.ts → DashboardToolbar/DashboardToolbar.d.ts} +2 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
- package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +5 -12
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -0
- package/dist/components/DashboardToolbar/index.d.ts +2 -0
- package/dist/components/DashboardToolbar/index.d.ts.map +1 -0
- package/dist/components/DashboardToolbar/index.js +15 -0
- package/dist/components/DashboardToolbar/index.js.map +1 -0
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +3 -0
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +3 -6
- package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -0
- package/dist/components/DeletePanelDialog/index.d.ts +2 -0
- package/dist/components/DeletePanelDialog/index.d.ts.map +1 -0
- package/dist/components/DeletePanelDialog/index.js +15 -0
- package/dist/components/DeletePanelDialog/index.js.map +1 -0
- package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.d.ts +0 -0
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- package/dist/components/DeletePanelGroupDialog/index.d.ts +2 -0
- package/dist/components/DeletePanelGroupDialog/index.d.ts.map +1 -0
- package/dist/components/DeletePanelGroupDialog/index.js +15 -0
- package/dist/components/DeletePanelGroupDialog/index.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -2
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +12 -2
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +16 -18
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +3 -3
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +32 -92
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +95 -48
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts +16 -0
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -0
- package/dist/components/Panel/PanelHeader.js +105 -0
- package/dist/components/Panel/PanelHeader.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +22 -20
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +16 -16
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/PanelGroupDialog/index.d.ts +0 -1
- package/dist/components/PanelGroupDialog/index.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/index.js +0 -1
- package/dist/components/PanelGroupDialog/index.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts +8 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +56 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts +2 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.js +15 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +19 -12
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +7 -6
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +8 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +34 -22
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +7 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +8 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +6 -6
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +14 -16
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +23 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.js +64 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts +36 -0
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-slice.js +81 -0
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +3 -1
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +6 -35
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +74 -67
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -8
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -19
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +14 -44
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +46 -162
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +14 -0
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-slice.js +21 -0
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
- package/dist/context/{TemplateVariableProvider.d.ts → TemplateVariableProvider/TemplateVariableProvider.d.ts} +0 -0
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider/index.d.ts +2 -0
- package/dist/context/TemplateVariableProvider/index.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/index.js +15 -0
- package/dist/context/TemplateVariableProvider/index.js.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.d.ts +12 -0
- package/dist/context/TemplateVariableProvider/query-params.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.js +64 -0
- package/dist/context/TemplateVariableProvider/query-params.js.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts +2 -0
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.test.js +80 -0
- package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts +6 -0
- package/dist/context/useDashboard.d.ts.map +1 -0
- package/dist/context/useDashboard.js +88 -0
- package/dist/context/useDashboard.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -11
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +12 -49
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +6 -1
- package/dist/test/render.js.map +1 -1
- package/dist/utils/component-ids.d.ts +8 -0
- package/dist/utils/component-ids.d.ts.map +1 -0
- package/dist/utils/component-ids.js +27 -0
- package/dist/utils/component-ids.js.map +1 -0
- package/dist/utils/time-range-params.d.ts.map +1 -1
- package/dist/utils/time-range-params.js +15 -9
- package/dist/utils/time-range-params.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +40 -6
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/context/useDashboardSpec.js +0 -61
- package/dist/components/Dashboard.d.ts.map +0 -1
- package/dist/components/Dashboard.js.map +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +0 -1
- package/dist/components/DashboardToolbar.js.map +0 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +0 -5
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +0 -1
- package/dist/components/Panel/DeletePanelDialog.js.map +0 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +0 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +0 -1
- package/dist/context/TemplateVariableProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider.js.map +0 -1
- package/dist/context/useDashboardSpec.d.ts +0 -3
- package/dist/context/useDashboardSpec.d.ts.map +0 -1
- package/dist/context/useDashboardSpec.js +0 -55
- package/dist/context/useDashboardSpec.js.map +0 -1
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
/**
|
|
14
14
|
* The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).
|
|
15
|
-
*/
|
|
15
|
+
*/ if (globalThis.dashboardStoreId === undefined) {
|
|
16
|
+
globalThis.dashboardStoreId = 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Helper function to generate unique IDs for things in the dashboard store that don't have a "natural" ID.
|
|
20
|
+
*/ export function generateId() {
|
|
21
|
+
return globalThis.dashboardStoreId++;
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/common.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).\n */\nexport type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/common.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).\n */\nexport type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];\n\ndeclare global {\n // eslint-disable-next-line no-var\n var dashboardStoreId: number;\n}\n\nif (globalThis.dashboardStoreId === undefined) {\n globalThis.dashboardStoreId = 0;\n}\n\n/**\n * Helper function to generate unique IDs for things in the dashboard store that don't have a \"natural\" ID.\n */\nexport function generateId() {\n return globalThis.dashboardStoreId++;\n}\n"],"names":["globalThis","dashboardStoreId","undefined","generateId"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,AAOA,IAAIA,UAAU,CAACC,gBAAgB,KAAKC,SAAS,EAAE;IAC7CF,UAAU,CAACC,gBAAgB,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,UAAU,GAAG;IAC3B,OAAOH,UAAU,CAACC,gBAAgB,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PanelGroupItemId, PanelGroupId } from './panel-group-slice';
|
|
1
|
+
import { PanelGroupItemId, PanelGroupId, PanelGroupItemLayout } from './panel-group-slice';
|
|
2
2
|
export declare function useEditMode(): {
|
|
3
3
|
isEditMode: boolean;
|
|
4
4
|
setEditMode: (isEditMode: boolean) => void;
|
|
@@ -7,8 +7,7 @@ export declare function useEditMode(): {
|
|
|
7
7
|
* Returns actions that can be performed on the current dashboard.
|
|
8
8
|
*/
|
|
9
9
|
export declare function useDashboardActions(): {
|
|
10
|
-
|
|
11
|
-
reset: () => void;
|
|
10
|
+
setDashboard: (dashboard: import("@perses-dev/core").DashboardResource) => void;
|
|
12
11
|
openAddPanelGroup: () => void;
|
|
13
12
|
openAddPanel: () => void;
|
|
14
13
|
};
|
|
@@ -33,6 +32,7 @@ export declare function usePanelGroupActions(panelGroupId: PanelGroupId): {
|
|
|
33
32
|
openAddPanel: () => void;
|
|
34
33
|
moveUp: (() => void) | undefined;
|
|
35
34
|
moveDown: (() => void) | undefined;
|
|
35
|
+
updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) => void;
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
38
|
* Gets the Panel Group editor state.
|
|
@@ -42,7 +42,7 @@ export declare function usePanelGroupEditor(): import("./panel-group-editor-slic
|
|
|
42
42
|
* Gets the Delete Panel Group dialog state.
|
|
43
43
|
*/
|
|
44
44
|
export declare function useDeletePanelGroupDialog(): {
|
|
45
|
-
deletePanelGroupDialog: import("./panel-group-
|
|
45
|
+
deletePanelGroupDialog: import("./delete-panel-group-slice").DeletePanelGroupDialogState | undefined;
|
|
46
46
|
openDeletePanelGroupDialog: (panelGroupId: number) => void;
|
|
47
47
|
closeDeletePanelGroupDialog: () => void;
|
|
48
48
|
deletePanelGroup: (panelGroupId: number) => void;
|
|
@@ -66,8 +66,8 @@ export declare function usePanelEditor(): import("./panel-editor-slice").PanelEd
|
|
|
66
66
|
* Gets the state for the Delete Panel dialog.
|
|
67
67
|
*/
|
|
68
68
|
export declare function useDeletePanelDialog(): {
|
|
69
|
-
deletePanelDialog: import("./panel-
|
|
70
|
-
|
|
69
|
+
deletePanelDialog: import("./delete-panel-slice").DeletePanelDialogState | undefined;
|
|
70
|
+
deletePanel: (panelGroupItemId: PanelGroupItemId) => void;
|
|
71
71
|
closeDeletePanelDialog: () => void;
|
|
72
72
|
};
|
|
73
73
|
export declare function useDefaultTimeRange(): import("@perses-dev/core").RelativeTimeRange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3F,wBAAgB,WAAW;;;EAE1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;EAUlC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,aAE/B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,yDAYjC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,YAAY,sDAMvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY;;;;;;2CAapB,oBAAoB,EAAE;EAGhE;AAuBD;;GAEG;AACH,wBAAgB,mBAAmB,sEAElC;AAED;;GAEG;AACH,wBAAgB,yBAAyB;;;;;EASxC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,sFAa1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB;;;EAOjE;AAED;;GAEG;AACH,wBAAgB,cAAc,gEAE7B;AAED;;GAEG;AACH,wBAAgB,oBAAoB;;;;EAWnC;AAED,wBAAgB,mBAAmB,iDAElC"}
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { getPanelKeyFromRef } from '@perses-dev/core';
|
|
14
13
|
import { useMemo } from 'react';
|
|
15
14
|
import { useDashboardStore } from './DashboardProvider';
|
|
16
15
|
export function useEditMode() {
|
|
@@ -22,13 +21,11 @@ export function useEditMode() {
|
|
|
22
21
|
/**
|
|
23
22
|
* Returns actions that can be performed on the current dashboard.
|
|
24
23
|
*/ export function useDashboardActions() {
|
|
25
|
-
const
|
|
26
|
-
const reset = useDashboardStore((store)=>store.reset);
|
|
24
|
+
const setDashboard = useDashboardStore((store)=>store.setDashboard);
|
|
27
25
|
const openAddPanelGroup = useDashboardStore((store)=>store.openAddPanelGroup);
|
|
28
26
|
const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
|
|
29
27
|
return {
|
|
30
|
-
|
|
31
|
-
reset,
|
|
28
|
+
setDashboard,
|
|
32
29
|
openAddPanelGroup,
|
|
33
30
|
openAddPanel: ()=>openAddPanel(undefined)
|
|
34
31
|
};
|
|
@@ -36,7 +33,7 @@ export function useEditMode() {
|
|
|
36
33
|
/**
|
|
37
34
|
* Returns an array of PanelGroupIds in the order they appear in the dashboard.
|
|
38
35
|
*/ export function usePanelGroupIds() {
|
|
39
|
-
return useDashboardStore((store)=>store.
|
|
36
|
+
return useDashboardStore((store)=>store.panelGroupOrder);
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
42
39
|
* Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.
|
|
@@ -72,20 +69,22 @@ export function useEditMode() {
|
|
|
72
69
|
const openEditPanelGroup = useDashboardStore((store)=>store.openEditPanelGroup);
|
|
73
70
|
const deletePanelGroup = useDashboardStore((store)=>store.openDeletePanelGroupDialog);
|
|
74
71
|
const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
|
|
72
|
+
const updatePanelGroupLayouts = useDashboardStore((store)=>store.updatePanelGroupLayouts);
|
|
75
73
|
return {
|
|
76
74
|
openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
|
|
77
75
|
deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
|
|
78
76
|
openAddPanel: ()=>openAddPanel(panelGroupId),
|
|
79
77
|
moveUp,
|
|
80
|
-
moveDown
|
|
78
|
+
moveDown,
|
|
79
|
+
updatePanelGroupLayouts: (itemLayouts)=>updatePanelGroupLayouts(panelGroupId, itemLayouts)
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
/**
|
|
84
83
|
* Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
|
|
85
84
|
* moved in that direction.
|
|
86
85
|
*/ function useMovePanelGroup(panelGroupId) {
|
|
87
|
-
const currentIndex = useDashboardStore((store)=>store.
|
|
88
|
-
const panelGroupsLength = useDashboardStore((store)=>store.
|
|
86
|
+
const currentIndex = useDashboardStore((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId));
|
|
87
|
+
const panelGroupsLength = useDashboardStore((store)=>store.panelGroupOrder.length);
|
|
89
88
|
const swapPanelGroups = useDashboardStore((store)=>store.swapPanelGroups);
|
|
90
89
|
if (currentIndex < 0) {
|
|
91
90
|
throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
|
|
@@ -115,12 +114,11 @@ export function useEditMode() {
|
|
|
115
114
|
/**
|
|
116
115
|
* Gets an individual panel in the store. Throws if the panel can't be found.
|
|
117
116
|
*/ export function usePanel(panelGroupItemId) {
|
|
118
|
-
const { panelGroupId ,
|
|
117
|
+
const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
|
|
119
118
|
const panel = useDashboardStore((store)=>{
|
|
120
|
-
var ref
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
const panelKey = getPanelKeyFromRef(panelRef);
|
|
119
|
+
var ref;
|
|
120
|
+
const panelKey = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
|
|
121
|
+
if (panelKey === undefined) return;
|
|
124
122
|
return store.panels[panelKey];
|
|
125
123
|
});
|
|
126
124
|
if (panel === undefined) {
|
|
@@ -148,11 +146,11 @@ export function useEditMode() {
|
|
|
148
146
|
*/ export function useDeletePanelDialog() {
|
|
149
147
|
const deletePanelDialog = useDashboardStore((store)=>store.deletePanelDialog);
|
|
150
148
|
// TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
|
|
151
|
-
const
|
|
149
|
+
const deletePanel = useDashboardStore((store)=>store.deletePanel);
|
|
152
150
|
const closeDeletePanelDialog = useDashboardStore((store)=>store.closeDeletePanelDialog);
|
|
153
151
|
return {
|
|
154
152
|
deletePanelDialog,
|
|
155
|
-
|
|
153
|
+
deletePanel,
|
|
156
154
|
closeDeletePanelDialog
|
|
157
155
|
};
|
|
158
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef } from '@perses-dev/core';\nimport { useMemo } from 'react';\nimport { useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupId } from './panel-group-slice';\n\nexport function useEditMode() {\n return useDashboardStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));\n}\n\n/**\n * Returns actions that can be performed on the current dashboard.\n */\nexport function useDashboardActions() {\n const save = useDashboardStore((store) => store.save);\n const reset = useDashboardStore((store) => store.reset);\n const openAddPanelGroup = useDashboardStore((store) => store.openAddPanelGroup);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n\n return {\n save,\n reset,\n openAddPanelGroup,\n openAddPanel: () => openAddPanel(undefined),\n };\n}\n\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds() {\n return useDashboardStore((store) => store.panelGroupIdOrder);\n}\n\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups() {\n const panelGroupIds = usePanelGroupIds();\n const panelGroups = useDashboardStore((store) => store.panelGroups);\n return useMemo(() => {\n return panelGroupIds.map((id) => {\n const group = panelGroups[id];\n if (group === undefined) {\n throw new Error(`Invalid panel group Id found ${id}`);\n }\n return group;\n });\n }, [panelGroupIds, panelGroups]);\n}\n\n/**\n * Gets a specific panel group by its id. Throws if the panel group does not exist.\n */\nexport function usePanelGroup(panelGroupId: PanelGroupId) {\n const panelGroup = useDashboardStore((store) => store.panelGroups[panelGroupId]);\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} was not found`);\n }\n return panelGroup;\n}\n\n/**\n * Returns actions that can be performed on the given panel group.\n */\nexport function usePanelGroupActions(panelGroupId: PanelGroupId) {\n const { moveUp, moveDown } = useMovePanelGroup(panelGroupId);\n const openEditPanelGroup = useDashboardStore((store) => store.openEditPanelGroup);\n const deletePanelGroup = useDashboardStore((store) => store.openDeletePanelGroupDialog);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\n };\n}\n\n/**\n * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be\n * moved in that direction.\n */\nfunction useMovePanelGroup(panelGroupId: PanelGroupId) {\n const currentIndex = useDashboardStore((store) => store.panelGroupIdOrder.findIndex((id) => id === panelGroupId));\n const panelGroupsLength = useDashboardStore((store) => store.panelGroupIdOrder.length);\n const swapPanelGroups = useDashboardStore((store) => store.swapPanelGroups);\n\n if (currentIndex < 0) {\n throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);\n }\n\n const moveUp = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown = () => swapPanelGroups(currentIndex, currentIndex + 1);\n return {\n moveUp: currentIndex > 0 ? moveUp : undefined,\n moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined,\n };\n}\n\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor() {\n return useDashboardStore((store) => store.panelGroupEditor);\n}\n\n/**\n * Gets the Delete Panel Group dialog state.\n */\nexport function useDeletePanelGroupDialog() {\n return useDashboardStore(\n ({ deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup }) => ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n })\n );\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId) {\n const { panelGroupId, itemIndex } = panelGroupItemId;\n\n const panel = useDashboardStore((store) => {\n const panelRef = store.panelGroups[panelGroupId]?.items[itemIndex]?.content;\n if (panelRef === undefined) return;\n const panelKey = getPanelKeyFromRef(panelRef);\n return store.panels[panelKey];\n });\n\n if (panel === undefined) {\n throw new Error(`Could not find panel for Id ${panelGroupItemId}`);\n }\n return panel;\n}\n\n/**\n * Returns actions that can be performed on the given Panel.\n */\nexport function usePanelActions(panelGroupItemId: PanelGroupItemId) {\n const openEditPanel = useDashboardStore((store) => store.openEditPanel);\n const openDeletePanelDialog = useDashboardStore((store) => store.openDeletePanelDialog);\n return {\n openEditPanel: () => openEditPanel(panelGroupItemId),\n openDeletePanelDialog: () => openDeletePanelDialog(panelGroupItemId),\n };\n}\n\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor() {\n return useDashboardStore((store) => store.panelEditor);\n}\n\n/**\n * Gets the state for the Delete Panel dialog.\n */\nexport function useDeletePanelDialog() {\n const deletePanelDialog = useDashboardStore((store) => store.deletePanelDialog);\n // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself\n const deletePanels = useDashboardStore((store) => store.deletePanels);\n const closeDeletePanelDialog = useDashboardStore((store) => store.closeDeletePanelDialog);\n\n return {\n deletePanelDialog,\n deletePanels,\n closeDeletePanelDialog,\n };\n}\n\nexport function useDefaultTimeRange() {\n return useDashboardStore((state) => state.defaultTimeRange);\n}\n"],"names":["getPanelKeyFromRef","useMemo","useDashboardStore","useEditMode","isEditMode","setEditMode","useDashboardActions","save","store","reset","openAddPanelGroup","openAddPanel","undefined","usePanelGroupIds","panelGroupIdOrder","useListPanelGroups","panelGroupIds","panelGroups","map","id","group","Error","usePanelGroup","panelGroupId","panelGroup","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","openEditPanelGroup","deletePanelGroup","openDeletePanelGroupDialog","currentIndex","findIndex","panelGroupsLength","length","swapPanelGroups","usePanelGroupEditor","panelGroupEditor","useDeletePanelGroupDialog","deletePanelGroupDialog","closeDeletePanelGroupDialog","usePanel","panelGroupItemId","itemIndex","panel","panelRef","items","content","panelKey","panels","usePanelActions","openEditPanel","openDeletePanelDialog","usePanelEditor","panelEditor","useDeletePanelDialog","deletePanelDialog","deletePanels","closeDeletePanelDialog","useDefaultTimeRange","state","defaultTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;A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ACM,KAAK,GAAKA,KAAK,CAAC4C,aAAa,CAAC,AAAC;IACxE,MAAMC,qBAAqB,GAAGnD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAAC6C,qBAAqB,CAAC,AAAC;IACxF,OAAO;QACLD,aAAa,EAAE,IAAMA,aAAa,CAACT,gBAAgB,CAAC;QACpDU,qBAAqB,EAAE,IAAMA,qBAAqB,CAACV,gBAAgB,CAAC;KACrE,CAAC;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,SAASW,cAAc,GAAG;IAC/B,OAAOpD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAAC+C,WAAW,CAAC,CAAC;AACzD,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,oBAAoB,GAAG;IACrC,MAAMC,iBAAiB,GAAGvD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACiD,iBAAiB,CAAC,AAAC;IAChF,0FAA0F;IAC1F,MAAMC,YAAY,GAAGxD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACkD,YAAY,CAAC,AAAC;IACtE,MAAMC,sBAAsB,GAAGzD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACmD,sBAAsB,CAAC,AAAC;IAE1F,OAAO;QACLF,iBAAiB;QACjBC,YAAY;QACZC,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAO1D,iBAAiB,CAAC,CAAC2D,KAAK,GAAKA,KAAK,CAACC,gBAAgB,CAAC,CAAC;AAC9D,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useMemo } from 'react';\nimport { useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupId, PanelGroupItemLayout } from './panel-group-slice';\n\nexport function useEditMode() {\n return useDashboardStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));\n}\n\n/**\n * Returns actions that can be performed on the current dashboard.\n */\nexport function useDashboardActions() {\n const setDashboard = useDashboardStore((store) => store.setDashboard);\n const openAddPanelGroup = useDashboardStore((store) => store.openAddPanelGroup);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n\n return {\n setDashboard,\n openAddPanelGroup,\n openAddPanel: () => openAddPanel(undefined),\n };\n}\n\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds() {\n return useDashboardStore((store) => store.panelGroupOrder);\n}\n\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups() {\n const panelGroupIds = usePanelGroupIds();\n const panelGroups = useDashboardStore((store) => store.panelGroups);\n return useMemo(() => {\n return panelGroupIds.map((id) => {\n const group = panelGroups[id];\n if (group === undefined) {\n throw new Error(`Invalid panel group Id found ${id}`);\n }\n return group;\n });\n }, [panelGroupIds, panelGroups]);\n}\n\n/**\n * Gets a specific panel group by its id. Throws if the panel group does not exist.\n */\nexport function usePanelGroup(panelGroupId: PanelGroupId) {\n const panelGroup = useDashboardStore((store) => store.panelGroups[panelGroupId]);\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} was not found`);\n }\n return panelGroup;\n}\n\n/**\n * Returns actions that can be performed on the given panel group.\n */\nexport function usePanelGroupActions(panelGroupId: PanelGroupId) {\n const { moveUp, moveDown } = useMovePanelGroup(panelGroupId);\n const openEditPanelGroup = useDashboardStore((store) => store.openEditPanelGroup);\n const deletePanelGroup = useDashboardStore((store) => store.openDeletePanelGroupDialog);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n const updatePanelGroupLayouts = useDashboardStore((store) => store.updatePanelGroupLayouts);\n\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) =>\n updatePanelGroupLayouts(panelGroupId, itemLayouts),\n };\n}\n\n/**\n * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be\n * moved in that direction.\n */\nfunction useMovePanelGroup(panelGroupId: PanelGroupId) {\n const currentIndex = useDashboardStore((store) => store.panelGroupOrder.findIndex((id) => id === panelGroupId));\n const panelGroupsLength = useDashboardStore((store) => store.panelGroupOrder.length);\n const swapPanelGroups = useDashboardStore((store) => store.swapPanelGroups);\n\n if (currentIndex < 0) {\n throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);\n }\n\n const moveUp = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown = () => swapPanelGroups(currentIndex, currentIndex + 1);\n return {\n moveUp: currentIndex > 0 ? moveUp : undefined,\n moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined,\n };\n}\n\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor() {\n return useDashboardStore((store) => store.panelGroupEditor);\n}\n\n/**\n * Gets the Delete Panel Group dialog state.\n */\nexport function useDeletePanelGroupDialog() {\n return useDashboardStore(\n ({ deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup }) => ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n })\n );\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId) {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n\n const panel = useDashboardStore((store) => {\n const panelKey = store.panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) return;\n return store.panels[panelKey];\n });\n\n if (panel === undefined) {\n throw new Error(`Could not find panel for Id ${panelGroupItemId}`);\n }\n return panel;\n}\n\n/**\n * Returns actions that can be performed on the given Panel.\n */\nexport function usePanelActions(panelGroupItemId: PanelGroupItemId) {\n const openEditPanel = useDashboardStore((store) => store.openEditPanel);\n const openDeletePanelDialog = useDashboardStore((store) => store.openDeletePanelDialog);\n return {\n openEditPanel: () => openEditPanel(panelGroupItemId),\n openDeletePanelDialog: () => openDeletePanelDialog(panelGroupItemId),\n };\n}\n\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor() {\n return useDashboardStore((store) => store.panelEditor);\n}\n\n/**\n * Gets the state for the Delete Panel dialog.\n */\nexport function useDeletePanelDialog() {\n const deletePanelDialog = useDashboardStore((store) => store.deletePanelDialog);\n // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself\n const deletePanel = useDashboardStore((store) => store.deletePanel);\n const closeDeletePanelDialog = useDashboardStore((store) => store.closeDeletePanelDialog);\n\n return {\n deletePanelDialog,\n deletePanel,\n closeDeletePanelDialog,\n };\n}\n\nexport function useDefaultTimeRange() {\n return useDashboardStore((state) => state.defaultTimeRange);\n}\n"],"names":["useMemo","useDashboardStore","useEditMode","isEditMode","setEditMode","useDashboardActions","setDashboard","store","openAddPanelGroup","openAddPanel","undefined","usePanelGroupIds","panelGroupOrder","useListPanelGroups","panelGroupIds","panelGroups","map","id","group","Error","usePanelGroup","panelGroupId","panelGroup","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","openEditPanelGroup","deletePanelGroup","openDeletePanelGroupDialog","updatePanelGroupLayouts","itemLayouts","currentIndex","findIndex","panelGroupsLength","length","swapPanelGroups","usePanelGroupEditor","panelGroupEditor","useDeletePanelGroupDialog","deletePanelGroupDialog","closeDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","usePanelActions","openEditPanel","openDeletePanelDialog","usePanelEditor","panelEditor","useDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDefaultTimeRange","state","defaultTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AAGxD,OAAO,SAASC,WAAW,GAAG;IAC5B,OAAOD,iBAAiB,CAAC,CAAC,EAAEE,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAM,CAAA;YAAED,UAAU;YAAEC,WAAW;SAAE,CAAA,AAAC,CAAC,CAAC;AAC3F,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,mBAAmB,GAAG;IACpC,MAAMC,YAAY,GAAGL,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACD,YAAY,CAAC,AAAC;IACtE,MAAME,iBAAiB,GAAGP,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACC,iBAAiB,CAAC,AAAC;IAChF,MAAMC,YAAY,GAAGR,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACE,YAAY,CAAC,AAAC;IAEtE,OAAO;QACLH,YAAY;QACZE,iBAAiB;QACjBC,YAAY,EAAE,IAAMA,YAAY,CAACC,SAAS,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,gBAAgB,GAAG;IACjC,OAAOV,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACK,eAAe,CAAC,CAAC;AAC7D,CAAC;AAED;;CAEC,GACD,OAAO,S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 +1,23 @@
|
|
|
1
|
+
import { StateCreator } from 'zustand';
|
|
2
|
+
import { Middleware } from './common';
|
|
3
|
+
import { PanelGroupId, PanelGroupSlice } from './panel-group-slice';
|
|
4
|
+
import { PanelSlice } from './panel-slice';
|
|
5
|
+
/**
|
|
6
|
+
* Slice that handles the visual editor state and related actions for deleting a Panel Group.
|
|
7
|
+
*/
|
|
8
|
+
export interface DeletePanelGroupSlice {
|
|
9
|
+
deletePanelGroupDialog?: DeletePanelGroupDialogState;
|
|
10
|
+
/**
|
|
11
|
+
* Delete panel group and all the panels within the group
|
|
12
|
+
*/
|
|
13
|
+
deletePanelGroup: (panelGroupId: PanelGroupId) => void;
|
|
14
|
+
openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;
|
|
15
|
+
closeDeletePanelGroupDialog: () => void;
|
|
16
|
+
}
|
|
17
|
+
export interface DeletePanelGroupDialogState {
|
|
18
|
+
panelGroupId: PanelGroupId;
|
|
19
|
+
panelGroupName?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const createDeletePanelGroupSlice: StateCreator<DeletePanelGroupSlice & PanelGroupSlice & PanelSlice, Middleware, [
|
|
22
|
+
], DeletePanelGroupSlice>;
|
|
23
|
+
//# sourceMappingURL=delete-panel-group-slice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/delete-panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,sBAAsB,CAAC,EAAE,2BAA2B,CAAC;IAErD;;OAEG;IACH,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAEvD,0BAA0B,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IACjE,2BAA2B,EAAE,MAAM,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,GAAG,UAAU,EACpD,UAAU,EACV;CAAE,EACF,qBAAqB,CA6CrB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export const createDeletePanelGroupSlice = (set, get)=>({
|
|
14
|
+
deletePanelGroup (panelGroupId) {
|
|
15
|
+
const { panelGroups , panelGroupOrder } = get();
|
|
16
|
+
const group = panelGroups[panelGroupId];
|
|
17
|
+
const idIndex = panelGroupOrder.findIndex((id)=>id === panelGroupId);
|
|
18
|
+
if (group === undefined || idIndex === -1) {
|
|
19
|
+
throw new Error(`Panel group ${panelGroupId} not found`);
|
|
20
|
+
}
|
|
21
|
+
// Get the panel keys for all the panel items in the group we're going to delete
|
|
22
|
+
const panelKeys = Object.values(group.itemPanelKeys);
|
|
23
|
+
set((draft)=>{
|
|
24
|
+
// Delete the panel group which also deletes all its items
|
|
25
|
+
delete draft.panelGroups[panelGroupId];
|
|
26
|
+
draft.panelGroupOrder.splice(idIndex, 1);
|
|
27
|
+
// Get all remaining panel keys in use
|
|
28
|
+
const usedPanelKeys = getUsedPanelKeys(draft.panelGroups);
|
|
29
|
+
// For the panel keys of the items that were just deleted, see if they're still used and if not, also delete the
|
|
30
|
+
// panel definition
|
|
31
|
+
for (const panelKey of panelKeys){
|
|
32
|
+
if (usedPanelKeys.has(panelKey)) continue;
|
|
33
|
+
delete draft.panels[panelKey];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
openDeletePanelGroupDialog: (panelGroupId)=>{
|
|
38
|
+
const panelGroup = get().panelGroups[panelGroupId];
|
|
39
|
+
if (panelGroup === undefined) {
|
|
40
|
+
throw new Error(`Panel group with Id ${panelGroupId} not found`);
|
|
41
|
+
}
|
|
42
|
+
set((state)=>{
|
|
43
|
+
state.deletePanelGroupDialog = {
|
|
44
|
+
panelGroupId,
|
|
45
|
+
panelGroupName: panelGroup.title
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
closeDeletePanelGroupDialog: ()=>set((state)=>{
|
|
50
|
+
state.deletePanelGroupDialog = undefined;
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
// Helper to get the panel keys of all groups, returning a set to eliminate duplicates
|
|
54
|
+
function getUsedPanelKeys(panelGroups) {
|
|
55
|
+
const usedPanelKeys = new Set();
|
|
56
|
+
for (const group of Object.values(panelGroups)){
|
|
57
|
+
for (const panelKey of Object.values(group.itemPanelKeys)){
|
|
58
|
+
usedPanelKeys.add(panelKey);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return usedPanelKeys;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=delete-panel-group-slice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/delete-panel-group-slice.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupId, PanelGroupSlice } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and related actions for deleting a Panel Group.\n */\nexport interface DeletePanelGroupSlice {\n deletePanelGroupDialog?: DeletePanelGroupDialogState;\n\n /**\n * Delete panel group and all the panels within the group\n */\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n closeDeletePanelGroupDialog: () => void;\n}\n\nexport interface DeletePanelGroupDialogState {\n panelGroupId: PanelGroupId;\n panelGroupName?: string;\n}\n\nexport const createDeletePanelGroupSlice: StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DeletePanelGroupSlice & PanelGroupSlice & PanelSlice,\n Middleware,\n [],\n DeletePanelGroupSlice\n> = (set, get) => ({\n deletePanelGroup(panelGroupId) {\n const { panelGroups, panelGroupOrder } = get();\n const group = panelGroups[panelGroupId];\n const idIndex = panelGroupOrder.findIndex((id) => id === panelGroupId);\n if (group === undefined || idIndex === -1) {\n throw new Error(`Panel group ${panelGroupId} not found`);\n }\n\n // Get the panel keys for all the panel items in the group we're going to delete\n const panelKeys = Object.values(group.itemPanelKeys);\n\n set((draft) => {\n // Delete the panel group which also deletes all its items\n delete draft.panelGroups[panelGroupId];\n draft.panelGroupOrder.splice(idIndex, 1);\n\n // Get all remaining panel keys in use\n const usedPanelKeys = getUsedPanelKeys(draft.panelGroups);\n\n // For the panel keys of the items that were just deleted, see if they're still used and if not, also delete the\n // panel definition\n for (const panelKey of panelKeys) {\n if (usedPanelKeys.has(panelKey)) continue;\n\n delete draft.panels[panelKey];\n }\n });\n },\n\n openDeletePanelGroupDialog: (panelGroupId) => {\n const panelGroup = get().panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} not found`);\n }\n set((state) => {\n state.deletePanelGroupDialog = { panelGroupId, panelGroupName: panelGroup.title };\n });\n },\n\n closeDeletePanelGroupDialog: () =>\n set((state) => {\n state.deletePanelGroupDialog = undefined;\n }),\n});\n\n// Helper to get the panel keys of all groups, returning a set to eliminate duplicates\nfunction getUsedPanelKeys(panelGroups: PanelGroupSlice['panelGroups']): Set<string> {\n const usedPanelKeys = new Set<string>();\n for (const group of Object.values(panelGroups)) {\n for (const panelKey of Object.values(group.itemPanelKeys)) {\n usedPanelKeys.add(panelKey);\n }\n }\n return usedPanelKeys;\n}\n"],"names":["createDeletePanelGroupSlice","set","get","deletePanelGroup","panelGroupId","panelGroups","panelGroupOrder","group","idIndex","findIndex","id","undefined","Error","panelKeys","Object","values","itemPanelKeys","draft","splice","usedPanelKeys","getUsedPanelKeys","panelKey","has","panels","openDeletePanelGroupDialog","panelGroup","state","deletePanelGroupDialog","panelGroupName","title","closeDeletePanelGroupDialog","Set","add"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA2BjC,OAAO,MAAMA,2BAA2B,GAMpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAACC,YAAY,EAAE;YAC7B,MAAM,EAAEC,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAE,GAAGJ,GAAG,EAAE,AAAC;YAC/C,MAAMK,KAAK,GAAG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AK,CAACC,sBAAsB,GAAG;oBAAEvB,YAAY;oBAAEwB,cAAc,EAAEH,UAAU,CAACI,KAAK;iBAAE,CAAC;YACpF,CAAC,CAAC,CAAC;QACL,CAAC;QAEDC,2BAA2B,EAAE,IAC3B7B,GAAG,CAAC,CAACyB,KAAK,GAAK;gBACbA,KAAK,CAACC,sBAAsB,GAAGhB,SAAS,CAAC;YAC3C,CAAC,CAAC;KACL,CAAA,AAAC,CAAC;AAEH,sFAAsF;AACtF,SAASS,gBAAgB,CAACf,WAA2C,EAAe;IAClF,MAAMc,aAAa,GAAG,IAAIY,GAAG,EAAU,AAAC;IACxC,KAAK,MAAMxB,KAAK,IAAIO,MAAM,CAACC,MAAM,CAACV,WAAW,CAAC,CAAE;QAC9C,KAAK,MAAMgB,QAAQ,IAAIP,MAAM,CAACC,MAAM,CAACR,KAAK,CAACS,aAAa,CAAC,CAAE;YACzDG,aAAa,CAACa,GAAG,CAACX,QAAQ,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAOF,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StateCreator } from 'zustand';
|
|
2
|
+
import { Middleware } from './common';
|
|
3
|
+
import { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';
|
|
4
|
+
import { PanelSlice } from './panel-slice';
|
|
5
|
+
/**
|
|
6
|
+
* Slice that handles the visual editor state and actions for deleting Panels.
|
|
7
|
+
*/
|
|
8
|
+
export interface DeletePanelSlice {
|
|
9
|
+
/**
|
|
10
|
+
* Delete panels
|
|
11
|
+
*/
|
|
12
|
+
deletePanel: (panelGroupItemId: PanelGroupItemId) => void;
|
|
13
|
+
/**
|
|
14
|
+
* State for the delete panel dialog when it's open, otherwise undefined when it's closed.
|
|
15
|
+
*/
|
|
16
|
+
deletePanelDialog?: DeletePanelDialogState;
|
|
17
|
+
/**
|
|
18
|
+
* Open delete panel dialog
|
|
19
|
+
*/
|
|
20
|
+
openDeletePanelDialog: (panelGroupItemId: PanelGroupItemId) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Close delete panel dialog
|
|
23
|
+
*/
|
|
24
|
+
closeDeletePanelDialog: () => void;
|
|
25
|
+
}
|
|
26
|
+
export interface DeletePanelDialogState {
|
|
27
|
+
panelGroupItemId: PanelGroupItemId;
|
|
28
|
+
panelName: string;
|
|
29
|
+
panelGroupName: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Curried function for creating the PanelDeleteSlice.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createDeletePanelSlice(): StateCreator<DeletePanelSlice & PanelSlice & PanelGroupSlice, Middleware, [
|
|
35
|
+
], DeletePanelSlice>;
|
|
36
|
+
//# sourceMappingURL=delete-panel-slice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/delete-panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;IAE3C;;OAEG;IACH,qBAAqB,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAEpE;;OAEG;IACH,sBAAsB,EAAE,MAAM,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA6DA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Curried function for creating the PanelDeleteSlice.
|
|
15
|
+
*/ export function createDeletePanelSlice() {
|
|
16
|
+
// Return the state creator function for Zustand that uses the panels provided as intitial state
|
|
17
|
+
return (set, get)=>({
|
|
18
|
+
deletePanel (panelGroupItemId) {
|
|
19
|
+
set((draft)=>{
|
|
20
|
+
const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
|
|
21
|
+
const existingGroup = draft.panelGroups[panelGroupId];
|
|
22
|
+
if (existingGroup === undefined) {
|
|
23
|
+
throw new Error(`Missing panel group ${panelGroupId}`);
|
|
24
|
+
}
|
|
25
|
+
const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout)=>layout.i === panelGroupLayoutId);
|
|
26
|
+
const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];
|
|
27
|
+
if (existingLayoutIdx === -1 || existingPanelKey === undefined) {
|
|
28
|
+
throw new Error(`Missing panel group item ${panelGroupLayoutId}`);
|
|
29
|
+
}
|
|
30
|
+
// remove panel from panel group
|
|
31
|
+
existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
|
|
32
|
+
delete existingGroup.itemPanelKeys[panelGroupLayoutId];
|
|
33
|
+
// See if panel key is still used and if not, delete it
|
|
34
|
+
if (isPanelKeyStillUsed(draft.panelGroups, existingPanelKey) === false) {
|
|
35
|
+
delete draft.panels[existingPanelKey];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
openDeletePanelDialog (panelGroupItemId) {
|
|
40
|
+
const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
|
|
41
|
+
const { panels , panelGroups } = get();
|
|
42
|
+
const panelGroup = panelGroups[panelGroupId];
|
|
43
|
+
if (panelGroup === undefined) {
|
|
44
|
+
throw new Error(`Panel group not found ${panelGroupId}`);
|
|
45
|
+
}
|
|
46
|
+
const panelKey = panelGroup.itemPanelKeys[panelGroupLayoutId];
|
|
47
|
+
if (panelKey === undefined) {
|
|
48
|
+
throw new Error(`Could not find Panel Group item ${panelGroupLayoutId}`);
|
|
49
|
+
}
|
|
50
|
+
const panel = panels[panelKey];
|
|
51
|
+
if (panel === undefined) {
|
|
52
|
+
throw new Error(`Could not find panel ${panelKey}`);
|
|
53
|
+
}
|
|
54
|
+
set((state)=>{
|
|
55
|
+
var _title;
|
|
56
|
+
state.deletePanelDialog = {
|
|
57
|
+
panelGroupItemId: panelGroupItemId,
|
|
58
|
+
panelName: panel.spec.display.name,
|
|
59
|
+
panelGroupName: (_title = panelGroup.title) !== null && _title !== void 0 ? _title : ''
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
closeDeletePanelDialog () {
|
|
64
|
+
set((state)=>{
|
|
65
|
+
state.deletePanelDialog = undefined;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Helper function to determine if a panel key is still being used somewhere in Panel Groups
|
|
71
|
+
function isPanelKeyStillUsed(panelGroups, panelKey) {
|
|
72
|
+
for (const group of Object.values(panelGroups)){
|
|
73
|
+
const found = Object.values(group.itemPanelKeys).find((key)=>key === panelKey);
|
|
74
|
+
if (found !== undefined) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=delete-panel-slice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/delete-panel-slice.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for deleting Panels.\n */\nexport interface DeletePanelSlice {\n /**\n * Delete panels\n */\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * State for the delete panel dialog when it's open, otherwise undefined when it's closed.\n */\n deletePanelDialog?: DeletePanelDialogState;\n\n /**\n * Open delete panel dialog\n */\n openDeletePanelDialog: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Close delete panel dialog\n */\n closeDeletePanelDialog: () => void;\n}\n\nexport interface DeletePanelDialogState {\n panelGroupItemId: PanelGroupItemId;\n panelName: string;\n panelGroupName: string;\n}\n\n/**\n * Curried function for creating the PanelDeleteSlice.\n */\nexport function createDeletePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DeletePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DeletePanelSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n deletePanel(panelGroupItemId: PanelGroupItemId) {\n set((draft) => {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const existingGroup = draft.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // remove panel from panel group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // See if panel key is still used and if not, delete it\n if (isPanelKeyStillUsed(draft.panelGroups, existingPanelKey) === false) {\n delete draft.panels[existingPanelKey];\n }\n });\n },\n\n openDeletePanelDialog(panelGroupItemId: PanelGroupItemId) {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n\n const { panels, panelGroups } = get();\n const panelGroup = panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group not found ${panelGroupId}`);\n }\n\n const panelKey = panelGroup.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupLayoutId}`);\n }\n\n const panel = panels[panelKey];\n if (panel === undefined) {\n throw new Error(`Could not find panel ${panelKey}`);\n }\n\n set((state) => {\n state.deletePanelDialog = {\n panelGroupItemId: panelGroupItemId,\n panelName: panel.spec.display.name,\n panelGroupName: panelGroup.title ?? '',\n };\n });\n },\n\n closeDeletePanelDialog() {\n set((state) => {\n state.deletePanelDialog = undefined;\n });\n },\n });\n}\n\n// Helper function to determine if a panel key is still being used somewhere in Panel Groups\nfunction isPanelKeyStillUsed(panelGroups: PanelGroupSlice['panelGroups'], panelKey: string) {\n for (const group of Object.values(panelGroups)) {\n const found = Object.values(group.itemPanelKeys).find((key) => key === panelKey);\n if (found !== undefined) {\n return true;\n }\n }\n return false;\n}\n"],"names":["createDeletePanelSlice","set","get","deletePanel","panelGroupItemId","draft","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","existingGroup","panelGroups","undefined","Error","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingPanelKey","itemPanelKeys","splice","isPanelKeyStillUsed","panels","openDeletePanelDialog","panelGroup","panelKey","panel","state","deletePanelDialog","panelName","spec","display","name","panelGroupName","title","closeDeletePanelDialog","group","Object","values","found","find","key"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAsCjC;;CAEC,GACD,OAAO,SAASA,sBAAsB,GAMpC;IACA,gGAAgG;IAChG,OAAO,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;YACpBC,WAAW,EAACC,gBAAkC,EAAE;gBAC9CH,GAAG,CAAC,CAACI,KAAK,GAAK;oBACb,MAAM,EAAEC,YAAY,CAAA,EAAEC,sBAAsB,EAAEC,kBAAkB,CAAA,EAAE,GAAGJ,gBAAgB,AAAC;oBACtF,MAAMK,aAAa,GAAGJ,KAAK,CAACK,WAAW,CAACJ,YAAY,CAAC,AAAC;oBACtD,IAAIG,aAAa,KAAKE,SAAS,EAAE;wBAC/B,MAAM,IAAIC,KAAK,CAAC,CAAC,oBAAoB,EAAEN,YAAY,CAAC,CAAC,CAAC,CAAC;oBACzD,CAAC;oBACD,MAAMO,iBAAiB,GAAGJ,aAAa,CAACK,WAAW,CAACC,SAAS,CAAC,CAACC,MAAM,GAAKA,MAAM,CAACC,CAAC,KAAKT,kBAAkB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export * from './dashboard-provider-api';
|
|
2
2
|
export * from './DashboardProvider';
|
|
3
|
-
export type { PanelGroupId, PanelGroupDefinition, PanelGroupItemId as
|
|
3
|
+
export type { PanelGroupId, PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayoutId as PanelGroupLayoutId, } from './panel-group-slice';
|
|
4
4
|
export type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';
|
|
5
|
+
export type { DeletePanelDialogState } from './delete-panel-slice';
|
|
6
|
+
export type { PanelEditorValues } from './panel-editor-slice';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,IAAI,kBAAkB,GAC7C,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-provider-api';\nexport * from './DashboardProvider';\nexport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-provider-api';\nexport * from './DashboardProvider';\nexport type {\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemId,\n PanelGroupItemLayoutId as PanelGroupLayoutId,\n} from './panel-group-slice';\nexport type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';\nexport type { DeletePanelDialogState } from './delete-panel-slice';\nexport type { PanelEditorValues } from './panel-editor-slice';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnknownSpec } from '@perses-dev/core';
|
|
2
2
|
import { StateCreator } from 'zustand';
|
|
3
3
|
import { Middleware } from './common';
|
|
4
4
|
import { PanelGroupSlice, PanelGroupItemId, PanelGroupId } from './panel-group-slice';
|
|
5
|
+
import { PanelSlice } from './panel-slice';
|
|
5
6
|
/**
|
|
6
|
-
* Slice that handles the visual editor state and actions for
|
|
7
|
+
* Slice that handles the visual editor state and actions for adding or editing Panels.
|
|
7
8
|
*/
|
|
8
9
|
export interface PanelEditorSlice {
|
|
9
|
-
panels: Record<string, PanelDefinition>;
|
|
10
|
-
previousPanels: Record<string, PanelDefinition>;
|
|
11
10
|
/**
|
|
12
11
|
* State for the panel editor when its open, otherwise undefined when it's closed.
|
|
13
12
|
*/
|
|
@@ -15,40 +14,11 @@ export interface PanelEditorSlice {
|
|
|
15
14
|
/**
|
|
16
15
|
* Opens the editor for editing an existing panel by providing its layout coordinates.
|
|
17
16
|
*/
|
|
18
|
-
openEditPanel: (
|
|
17
|
+
openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;
|
|
19
18
|
/**
|
|
20
19
|
* Opens the editor for adding a new Panel to a panel group.
|
|
21
20
|
*/
|
|
22
21
|
openAddPanel: (panelGroupId?: PanelGroupId) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Delete panels
|
|
25
|
-
*/
|
|
26
|
-
deletePanels: (panels: PanelGroupItemId[]) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Reset panels to previous state
|
|
29
|
-
*/
|
|
30
|
-
resetPanels: () => void;
|
|
31
|
-
/**
|
|
32
|
-
* Save panels
|
|
33
|
-
*/
|
|
34
|
-
savePanels: () => void;
|
|
35
|
-
/**
|
|
36
|
-
* State for the delete panel dialog when it's open, otherwise undefined when it's closed.
|
|
37
|
-
*/
|
|
38
|
-
deletePanelDialog?: DeletePanelDialog;
|
|
39
|
-
/**
|
|
40
|
-
* Open delete panel dialog
|
|
41
|
-
*/
|
|
42
|
-
openDeletePanelDialog: (item: PanelGroupItemId) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Close delete panel dialog
|
|
45
|
-
*/
|
|
46
|
-
closeDeletePanelDialog: () => void;
|
|
47
|
-
}
|
|
48
|
-
export interface DeletePanelDialog {
|
|
49
|
-
panelGroupItemId: PanelGroupItemId;
|
|
50
|
-
panelName: string;
|
|
51
|
-
panelGroupName: string;
|
|
52
22
|
}
|
|
53
23
|
export interface PanelEditorState {
|
|
54
24
|
/**
|
|
@@ -81,5 +51,6 @@ export interface PanelEditorValues {
|
|
|
81
51
|
/**
|
|
82
52
|
* Curried function for creating the PanelEditorSlice.
|
|
83
53
|
*/
|
|
84
|
-
export declare function createPanelEditorSlice(
|
|
54
|
+
export declare function createPanelEditorSlice(): StateCreator<PanelEditorSlice & PanelSlice & PanelGroupSlice, Middleware, [
|
|
55
|
+
], PanelEditorSlice>;
|
|
85
56
|
//# sourceMappingURL=panel-editor-slice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.
|
|
1
|
+
{"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA+IA"}
|