@perses-dev/dashboards 0.12.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 -23
- package/dist/cjs/components/DashboardToolbar/index.js +28 -0
- package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +2 -3
- 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/Panel/Panel.js +30 -89
- package/dist/cjs/components/Panel/Panel.test.js +93 -47
- package/dist/cjs/components/Panel/PanelHeader.js +116 -0
- package/dist/cjs/components/Panel/index.js +0 -1
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -15
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
- 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/index.js +4 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +24 -18
- package/dist/cjs/context/DashboardProvider/common.js +3 -3
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +2 -4
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +47 -52
- package/dist/cjs/context/DashboardProvider/panel-slice.js +2 -13
- 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/{useDashboardSpec.js → useDashboard.js} +20 -16
- 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/views/ViewDashboard/DashboardApp.js +40 -10
- 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 -19
- 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 +1 -2
- 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.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +12 -2
- package/dist/components/GridLayout/GridItemContent.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 -91
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +95 -49
- 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/Panel/index.d.ts +0 -1
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +0 -1
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +10 -16
- 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 +1 -1
- 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/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 +4 -4
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +26 -20
- 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 +4 -4
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +2 -4
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +1 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -15
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +38 -49
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +0 -9
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.js +2 -13
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
- 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/{useDashboardSpec.js → useDashboard.js} +19 -15
- 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/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +40 -5
- 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/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 -4
- 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 -11
- package/dist/context/useDashboardSpec.d.ts.map +0 -1
- package/dist/context/useDashboardSpec.js.map +0 -1
|
@@ -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 { 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 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.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","save","store","reset","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;AAC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ED;;CAEC,GACD,OAAO,SAASU,cAAc,GAAG;IAC/B,OAAOrD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACgD,WAAW,CAAC,CAAC;AACzD,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,oBAAoB,GAAG;IACrC,MAAMC,iBAAiB,GAAGxD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACkD,iBAAiB,CAAC,AAAC;IAChF,0FAA0F;IAC1F,MAAMC,WAAW,GAAGzD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACmD,WAAW,CAAC,AAAC;IACpE,MAAMC,sBAAsB,GAAG1D,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACoD,sBAAsB,CAAC,AAAC;IAE1F,OAAO;QACLF,iBAAiB;QACjBC,WAAW;QACXC,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAO3D,iBAAiB,CAAC,CAAC4D,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;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qBAAqB,GAAGnD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAAC6C,qBAAqB,CAAC,AAAC;IACxF,OAAO;QACLD,aAAa,EAAE,IAAMA,aAAa,CAACR,gBAAgB,CAAC;QACpDS,qBAAqB,EAAE,IAAMA,qBAAqB,CAACT,gBAAgB,CAAC;KACrE,CAAC;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,SAASU,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,WAAW,GAAGxD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACkD,WAAW,CAAC,AAAC;IACpE,MAAMC,sBAAsB,GAAGzD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACmD,sBAAsB,CAAC,AAAC;IAE1F,OAAO;QACLF,iBAAiB;QACjBC,WAAW;QACXC,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAO1D,iBAAiB,CAAC,CAAC2D,KAAK,GAAKA,KAAK,CAACC,gBAAgB,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -3,4 +3,5 @@ export * from './DashboardProvider';
|
|
|
3
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
5
|
export type { DeletePanelDialogState } from './delete-panel-slice';
|
|
6
|
+
export type { PanelEditorValues } from './panel-editor-slice';
|
|
6
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,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"}
|
|
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 {\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';\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
|
+
{"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"}
|
|
@@ -14,13 +14,6 @@ export interface PanelGroupSlice {
|
|
|
14
14
|
* An array of panel group IDs, representing their order in the dashboard.
|
|
15
15
|
*/
|
|
16
16
|
panelGroupOrder: PanelGroupId[];
|
|
17
|
-
/**
|
|
18
|
-
* previous state
|
|
19
|
-
*/
|
|
20
|
-
previousPanelGroupState: {
|
|
21
|
-
panelGroups: PanelGroupSlice['panelGroups'];
|
|
22
|
-
panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];
|
|
23
|
-
};
|
|
24
17
|
/**
|
|
25
18
|
* Rearrange the order of panel groups by swapping the positions
|
|
26
19
|
*/
|
|
@@ -29,14 +22,6 @@ export interface PanelGroupSlice {
|
|
|
29
22
|
* Update the item layouts for a panel group when, for example, a panel is moved or resized.
|
|
30
23
|
*/
|
|
31
24
|
updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
|
|
32
|
-
/**
|
|
33
|
-
* save
|
|
34
|
-
*/
|
|
35
|
-
savePanelGroups: () => void;
|
|
36
|
-
/**
|
|
37
|
-
* reset to previous panel group states
|
|
38
|
-
*/
|
|
39
|
-
resetPanelGroups: () => void;
|
|
40
25
|
}
|
|
41
26
|
export declare type PanelGroupId = number;
|
|
42
27
|
export interface PanelGroupDefinition {
|
|
@@ -61,4 +46,5 @@ export interface PanelGroupItemId {
|
|
|
61
46
|
* Curried function for creating a PanelGroupSlice.
|
|
62
47
|
*/
|
|
63
48
|
export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
|
|
49
|
+
export declare function convertLayoutsToPanelGroups(layouts: LayoutDefinition[]): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'>;
|
|
64
50
|
//# sourceMappingURL=panel-group-slice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D"}
|
|
@@ -15,58 +15,11 @@ import { generateId } from './common';
|
|
|
15
15
|
/**
|
|
16
16
|
* Curried function for creating a PanelGroupSlice.
|
|
17
17
|
*/ export function createPanelGroupSlice(layouts) {
|
|
18
|
-
|
|
19
|
-
const panelGroups = {};
|
|
20
|
-
const panelGroupIdOrder = [];
|
|
21
|
-
for (const layout of layouts){
|
|
22
|
-
var ref, ref1, ref2;
|
|
23
|
-
const itemLayouts = [];
|
|
24
|
-
const itemPanelKeys = {};
|
|
25
|
-
// Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
|
|
26
|
-
for (const item of layout.spec.items){
|
|
27
|
-
const panelGroupLayoutId = generateId().toString();
|
|
28
|
-
itemLayouts.push({
|
|
29
|
-
i: panelGroupLayoutId,
|
|
30
|
-
w: item.width,
|
|
31
|
-
h: item.height,
|
|
32
|
-
x: item.x,
|
|
33
|
-
y: item.y
|
|
34
|
-
});
|
|
35
|
-
itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);
|
|
36
|
-
}
|
|
37
|
-
// Create the panel group and keep track of the ID order
|
|
38
|
-
const panelGroupId = generateId();
|
|
39
|
-
panelGroups[panelGroupId] = {
|
|
40
|
-
id: panelGroupId,
|
|
41
|
-
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
42
|
-
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
43
|
-
itemLayouts,
|
|
44
|
-
itemPanelKeys
|
|
45
|
-
};
|
|
46
|
-
panelGroupIdOrder.push(panelGroupId);
|
|
47
|
-
}
|
|
18
|
+
const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
|
|
48
19
|
// Return the state creator function for Zustand
|
|
49
20
|
return (set)=>({
|
|
50
21
|
panelGroups,
|
|
51
|
-
panelGroupOrder
|
|
52
|
-
previousPanelGroupState: {
|
|
53
|
-
panelGroups,
|
|
54
|
-
panelGroupIdOrder
|
|
55
|
-
},
|
|
56
|
-
savePanelGroups () {
|
|
57
|
-
set((state)=>{
|
|
58
|
-
state.previousPanelGroupState = {
|
|
59
|
-
panelGroups: state.panelGroups,
|
|
60
|
-
panelGroupIdOrder: state.panelGroupOrder
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
resetPanelGroups () {
|
|
65
|
-
set((state)=>{
|
|
66
|
-
state.panelGroups = state.previousPanelGroupState.panelGroups;
|
|
67
|
-
state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
|
|
68
|
-
});
|
|
69
|
-
},
|
|
22
|
+
panelGroupOrder,
|
|
70
23
|
swapPanelGroups (x, y) {
|
|
71
24
|
set((state)=>{
|
|
72
25
|
if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
|
|
@@ -95,5 +48,41 @@ import { generateId } from './common';
|
|
|
95
48
|
}
|
|
96
49
|
});
|
|
97
50
|
}
|
|
51
|
+
export function convertLayoutsToPanelGroups(layouts) {
|
|
52
|
+
// Convert the initial layouts from the JSON
|
|
53
|
+
const panelGroups = {};
|
|
54
|
+
const panelGroupIdOrder = [];
|
|
55
|
+
for (const layout of layouts){
|
|
56
|
+
var ref, ref1, ref2;
|
|
57
|
+
const itemLayouts = [];
|
|
58
|
+
const itemPanelKeys = {};
|
|
59
|
+
// Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
|
|
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
|
+
}
|
|
71
|
+
// Create the panel group and keep track of the ID order
|
|
72
|
+
const panelGroupId = generateId();
|
|
73
|
+
panelGroups[panelGroupId] = {
|
|
74
|
+
id: panelGroupId,
|
|
75
|
+
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
76
|
+
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
77
|
+
itemLayouts,
|
|
78
|
+
itemPanelKeys
|
|
79
|
+
};
|
|
80
|
+
panelGroupIdOrder.push(panelGroupId);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
panelGroups,
|
|
84
|
+
panelGroupOrder: panelGroupIdOrder
|
|
85
|
+
};
|
|
86
|
+
}
|
|
98
87
|
|
|
99
88
|
//# sourceMappingURL=panel-group-slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\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 *
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\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\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\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) {\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) {\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 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 // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\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"],"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","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title"],"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,SA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,MAAM,CAACG,IAAI,CAACa,OAAO,cAAnBhB,GAAmB,WAAU,GAA7BA,KAAAA,CAA6B,GAA7BA,QAAAA,GAAmB,CAAEiB,QAAQ,6BAAA,GAA7BjB,KAAAA,CAA6B,QAAEkB,IAAI,AAAN,CAAA,KAAW,KAAK;YAC1DC,KAAK,EAAEnB,CAAAA,IAAmB,GAAnBA,MAAM,CAACG,IAAI,CAACa,OAAO,cAAnBhB,IAAmB,WAAO,GAA1BA,KAAAA,CAA0B,GAA1BA,IAAmB,CAAEmB,KAAK;YACjCtB,WAAW;YACXI,aAAa;SACd,CAAC;QACFF,iBAAiB,CAACQ,IAAI,CAACX,YAAY,CAAC,CAAC;IACvC,CAAC;IACD,OAAO;QACLd,WAAW;QACXC,eAAe,EAAEgB,iBAAiB;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -6,15 +6,6 @@ import { Middleware } from './common';
|
|
|
6
6
|
*/
|
|
7
7
|
export interface PanelSlice {
|
|
8
8
|
panels: Record<string, PanelDefinition>;
|
|
9
|
-
previousPanels: Record<string, PanelDefinition>;
|
|
10
|
-
/**
|
|
11
|
-
* Reset panels to previous state
|
|
12
|
-
*/
|
|
13
|
-
resetPanels: () => void;
|
|
14
|
-
/**
|
|
15
|
-
* Save panels
|
|
16
|
-
*/
|
|
17
|
-
savePanels: () => void;
|
|
18
9
|
}
|
|
19
10
|
/**
|
|
20
11
|
* Curried function for creating the PanelSlice.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,CAAC,CAInH"}
|
|
@@ -13,19 +13,8 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* Curried function for creating the PanelSlice.
|
|
15
15
|
*/ export function createPanelSlice(panels) {
|
|
16
|
-
return (
|
|
17
|
-
panels
|
|
18
|
-
previousPanels: panels,
|
|
19
|
-
resetPanels () {
|
|
20
|
-
set((state)=>{
|
|
21
|
-
state.panels = state.previousPanels;
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
savePanels () {
|
|
25
|
-
set((state)=>{
|
|
26
|
-
state.previousPanels = state.panels;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
16
|
+
return ()=>({
|
|
17
|
+
panels
|
|
29
18
|
});
|
|
30
19
|
}
|
|
31
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/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 { PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/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 { PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n}\n\n/**\n * Curried function for creating the PanelSlice.\n */\nexport function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice> {\n return () => ({\n panels,\n });\n}\n"],"names":["createPanelSlice","panels"],"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;AAajC;;CAEC,GACD,OAAO,SAASA,gBAAgB,CAACC,MAA4B,EAAwD;IACnH,OAAO,IAAO,CAAA;YACZA,MAAM;SACP,CAAA,AAAC,CAAC;AACL,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,cAAc,EAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGnF,aAAK,qBAAqB,GAAG;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,aAAa,EAAE,gBAAgB,CAAC;IAChC,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7E,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IAC5E,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACnE,sBAAsB,EAAE,CAAC,WAAW,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;CACrE,CAAC;AAaF,wBAAgB,yBAAyB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,oBAqBjE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM;;;EAU/C;AAED,wBAAgB,0BAA0B;;;;;EAUzC;AAED,wBAAgB,8BAA8B,yBAG7C;AAED,wBAAgB,wBAAwB,0BAGvC;AA0FD,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,0BAA+B,GAChC,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACnD,eASA"}
|
|
@@ -16,6 +16,7 @@ import { createStore, useStore } from 'zustand';
|
|
|
16
16
|
import { immer } from 'zustand/middleware/immer';
|
|
17
17
|
import { devtools } from 'zustand/middleware';
|
|
18
18
|
import { TemplateVariableContext, DEFAULT_ALL_VALUE as ALL_VALUE } from '@perses-dev/plugin-system';
|
|
19
|
+
import { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';
|
|
19
20
|
const TemplateVariableStoreContext = /*#__PURE__*/ createContext(undefined);
|
|
20
21
|
function useTemplateVariableStoreCtx() {
|
|
21
22
|
const context = useContext(TemplateVariableStoreContext);
|
|
@@ -101,14 +102,15 @@ function PluginProvider({ children }) {
|
|
|
101
102
|
children: children
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
|
-
function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
105
|
+
function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , queryParams }) {
|
|
106
|
+
const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});
|
|
105
107
|
const store = createStore()(devtools(immer((set)=>({
|
|
106
|
-
variableState: hydrateTemplateVariableStates(initialVariableDefinitions),
|
|
108
|
+
variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),
|
|
107
109
|
variableDefinitions: initialVariableDefinitions,
|
|
108
110
|
setVariableDefinitions (definitions) {
|
|
109
111
|
set((state)=>{
|
|
110
112
|
state.variableDefinitions = definitions;
|
|
111
|
-
state.variableState = hydrateTemplateVariableStates(definitions);
|
|
113
|
+
state.variableState = hydrateTemplateVariableStates(definitions, initialParams);
|
|
112
114
|
});
|
|
113
115
|
},
|
|
114
116
|
setVariableOptions (name, options) {
|
|
@@ -143,14 +145,22 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
|
143
145
|
val = val.filter((v)=>v !== ALL_VALUE);
|
|
144
146
|
}
|
|
145
147
|
}
|
|
148
|
+
if (queryParams) {
|
|
149
|
+
const setQueryParams = queryParams[1];
|
|
150
|
+
setQueryParams({
|
|
151
|
+
[getURLQueryParamName(name)]: val
|
|
152
|
+
});
|
|
153
|
+
}
|
|
146
154
|
varState.value = val;
|
|
147
155
|
})
|
|
148
156
|
}))));
|
|
149
157
|
return store;
|
|
150
158
|
}
|
|
151
159
|
export function TemplateVariableProvider({ children , initialVariableDefinitions =[] }) {
|
|
160
|
+
const queryParams = useVariableQueryParams(initialVariableDefinitions);
|
|
152
161
|
const [store] = useState(createTemplateVariableSrvStore({
|
|
153
|
-
initialVariableDefinitions
|
|
162
|
+
initialVariableDefinitions,
|
|
163
|
+
queryParams
|
|
154
164
|
}));
|
|
155
165
|
return /*#__PURE__*/ _jsx(TemplateVariableStoreContext.Provider, {
|
|
156
166
|
value: store,
|
|
@@ -159,23 +169,23 @@ export function TemplateVariableProvider({ children , initialVariableDefinitions
|
|
|
159
169
|
})
|
|
160
170
|
});
|
|
161
171
|
}
|
|
162
|
-
/** Helpers */ function hydrateTemplateVariableState(definition) {
|
|
172
|
+
/** Helpers */ function hydrateTemplateVariableState(definition, initialValue) {
|
|
163
173
|
const v = definition;
|
|
164
|
-
var
|
|
174
|
+
var ref;
|
|
165
175
|
const varState = {
|
|
166
|
-
value: (
|
|
176
|
+
value: (ref = initialValue !== null && initialValue !== void 0 ? initialValue : v.spec.default_value) !== null && ref !== void 0 ? ref : null,
|
|
167
177
|
loading: false
|
|
168
178
|
};
|
|
169
179
|
switch(v.kind){
|
|
170
180
|
case 'TextVariable':
|
|
171
|
-
varState.value = v.spec.value;
|
|
181
|
+
varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : v.spec.value;
|
|
172
182
|
break;
|
|
173
183
|
case 'ListVariable':
|
|
174
184
|
varState.options = [];
|
|
175
185
|
if (varState.options.length > 0 && !varState.value) {
|
|
176
|
-
var ref;
|
|
177
186
|
var ref1;
|
|
178
|
-
|
|
187
|
+
var ref2;
|
|
188
|
+
const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
|
|
179
189
|
if (firstOptionValue !== null) {
|
|
180
190
|
varState.value = v.spec.allow_multiple ? [
|
|
181
191
|
firstOptionValue
|
|
@@ -188,10 +198,13 @@ export function TemplateVariableProvider({ children , initialVariableDefinitions
|
|
|
188
198
|
}
|
|
189
199
|
return varState;
|
|
190
200
|
}
|
|
191
|
-
function hydrateTemplateVariableStates(definitions) {
|
|
201
|
+
function hydrateTemplateVariableStates(definitions, initialValues) {
|
|
192
202
|
const state = {};
|
|
193
203
|
definitions.forEach((v)=>{
|
|
194
|
-
|
|
204
|
+
const name = v.spec.name;
|
|
205
|
+
const param = initialValues[name];
|
|
206
|
+
const initialValue = param ? param : null;
|
|
207
|
+
state[name] = hydrateTemplateVariableState(v, initialValue);
|
|
195
208
|
});
|
|
196
209
|
return state;
|
|
197
210
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\n\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [], queryParams }: TemplateVariableSrvArgs) {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),\n variableDefinitions: initialVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set((state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateTemplateVariableStates(definitions, initialParams);\n });\n },\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n if (queryParams) {\n const setQueryParams = queryParams[1];\n setQueryParams({ [getURLQueryParamName(name)]: val });\n }\n varState.value = val;\n }),\n }))\n )\n );\n\n return store;\n}\n\nexport function TemplateVariableProvider({\n children,\n initialVariableDefinitions = [],\n}: {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}) {\n const queryParams = useVariableQueryParams(initialVariableDefinitions);\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions, queryParams }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n\n/** Helpers */\n\nfunction hydrateTemplateVariableState(definition: VariableDefinition, initialValue?: VariableValue) {\n const v = definition;\n const varState: VariableState = {\n value: initialValue ?? v.spec.default_value ?? null,\n loading: false,\n };\n switch (v.kind) {\n case 'TextVariable':\n varState.value = initialValue ?? v.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = v.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nfunction hydrateTemplateVariableStates(\n definitions: VariableDefinition[],\n initialValues: Record<string, VariableValue>\n): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state[name] = hydrateTemplateVariableState(v, initialValue);\n });\n return state;\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","useVariableQueryParams","getInitalValuesFromQueryParameters","getURLQueryParamName","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","queryParams","initialParams","set","hydrateTemplateVariableStates","definitions","loading","val","Array","isArray","includes","at","filter","setQueryParams","TemplateVariableProvider","hydrateTemplateVariableState","initialValue","default_value","kind","length","firstOptionValue","allow_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A,IAAmB,CAAEuB,KAAK,cAA1BvB,IAA0B,cAA1BA,IAA0B,GAAI,IAAI,AAAC;gBAC5D,IAAIiD,gBAAgB,KAAK,IAAI,EAAE;oBAC7BjD,QAAQ,CAACuB,KAAK,GAAGd,CAAC,CAACC,IAAI,CAACwC,cAAc,GAAG;wBAACD,gBAAgB;qBAAC,GAAGA,gBAAgB,CAAC;gBACjF,CAAC;YACH,CAAC;YACD,MAAM;QACR;YACE,MAAM;KACT;IACD,OAAOjD,QAAQ,CAAC;AAClB,CAAC;AAED,SAASiC,6BAA6B,CACpCC,WAAiC,EACjCiB,aAA4C,EAC1B;IAClB,MAAM5D,KAAK,GAAqB,EAAE,AAAC;IACnC2C,WAAW,CAACpC,OAAO,CAAC,CAACW,CAAC,GAAK;QACzB,MAAMV,IAAI,GAAGU,CAAC,CAACC,IAAI,CAACX,IAAI,AAAC;QACzB,MAAMqD,KAAK,GAAGD,aAAa,CAACpD,IAAI,CAAC,AAAC;QAClC,MAAM8C,YAAY,GAAGO,KAAK,GAAGA,KAAK,GAAG,IAAI,AAAC;QAC1C7D,KAAK,CAACQ,IAAI,CAAC,GAAG6C,4BAA4B,CAACnC,CAAC,EAAEoC,YAAY,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IACH,OAAOtD,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 * from './TemplateVariableProvider';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/TemplateVariableProvider/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 './TemplateVariableProvider';\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,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VariableValue, VariableDefinition } from '@perses-dev/core';
|
|
2
|
+
import { QueryParamConfig } from 'use-query-params';
|
|
3
|
+
export declare function getURLQueryParamName(name: string): string;
|
|
4
|
+
export declare function encodeVariableValue(value: VariableValue): string | null;
|
|
5
|
+
export declare function decodeVariableValue(value: string): VariableValue;
|
|
6
|
+
export declare function useVariableQueryParams(defs: VariableDefinition[]): [import("use-query-params").DecodedValueMap<{
|
|
7
|
+
[x: string]: QueryParamConfig<VariableValue, VariableValue>;
|
|
8
|
+
}>, import("use-query-params").SetQuery<{
|
|
9
|
+
[x: string]: QueryParamConfig<VariableValue, VariableValue>;
|
|
10
|
+
}>];
|
|
11
|
+
export declare function getInitalValuesFromQueryParameters(queryParamValues: Record<string, VariableValue>): Record<string, VariableValue>;
|
|
12
|
+
//# sourceMappingURL=query-params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/query-params.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,kBAAkB,CAAC;AAIpE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAEhD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,iBAKvD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAShE;AAYD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,EAAE;;;;IAOhE;AAED,wBAAgB,kCAAkC,CAChD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAC9C,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAW/B"}
|