@perses-dev/dashboards 0.11.0 → 0.12.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/DashboardToolbar.js +9 -2
- package/dist/cjs/components/GridLayout/GridLayout.js +14 -16
- package/dist/cjs/components/Panel/DeletePanelDialog.js +2 -4
- package/dist/cjs/components/Panel/Panel.js +8 -9
- package/dist/cjs/components/Panel/Panel.test.js +2 -1
- package/dist/cjs/components/Panel/index.js +1 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +12 -4
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +2 -2
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +15 -15
- package/dist/cjs/components/Variables/VariableEditor.js +7 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +8 -2
- package/dist/cjs/context/DashboardProvider/common.js +10 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +12 -12
- 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 +39 -144
- package/dist/cjs/context/DashboardProvider/panel-slice.js +36 -0
- package/dist/cjs/context/useDashboardSpec.js +37 -8
- package/dist/cjs/utils/time-range-params.js +14 -8
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +10 -3
- package/dist/components/DashboardToolbar.js.map +1 -1
- 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.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/DeletePanelDialog.d.ts +0 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.js +2 -4
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +2 -2
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +7 -8
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +2 -1
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/index.d.ts +1 -0
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +1 -0
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +12 -4
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +2 -2
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +15 -15
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.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/context/DashboardProvider/DashboardProvider.d.ts +4 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +8 -2
- 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 +5 -4
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +12 -12
- 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 +2 -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 +15 -31
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +40 -145
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +23 -0
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-slice.js +32 -0
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
- package/dist/context/useDashboardSpec.d.ts +10 -2
- package/dist/context/useDashboardSpec.d.ts.map +1 -1
- package/dist/context/useDashboardSpec.js +38 -9
- package/dist/context/useDashboardSpec.js.map +1 -1
- 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 +0 -1
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId, PanelGroupId } from './panel-group-slice';\n\n/**\n * Slice that handles the visual editor state and actions for Panels (i.e. add, edit, delete).\n */\nexport interface PanelEditorSlice {\n // TODO: Move panels state to its own slice so that other slices can depend on it (and modify the state)\n panels: Record<string, PanelDefinition>;\n previousPanels: Record<string, PanelDefinition>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (item: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n\n /**\n * Delete panels\n */\n deletePanels: (panels: PanelGroupItemId[]) => void;\n\n /**\n * Reset panels to previous state\n */\n resetPanels: () => void;\n\n /**\n * Save panels\n */\n savePanels: () => void;\n\n /**\n * State for the delete panel dialog when it's open, otherwise undefined when it's closed.\n */\n deletePanelDialog?: DeletePanelDialog;\n\n /**\n * Open delete panel dialog\n */\n openDeletePanelDialog: (item: PanelGroupItemId) => void;\n\n /**\n * Close delete panel dialog\n */\n closeDeletePanelDialog: () => void;\n}\n\nexport interface DeletePanelDialog {\n panelGroupItemId: PanelGroupItemId;\n panelName: string;\n panelGroupName: string;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n name: string;\n description: string;\n groupId: PanelGroupId;\n kind: string;\n spec: UnknownSpec;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(\n panels: PanelEditorSlice['panels']\n): StateCreator<PanelEditorSlice & PanelGroupSlice, Middleware, [], PanelEditorSlice> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n previousPanels: panels,\n panels,\n\n panelEditor: undefined,\n\n savePanels() {\n set((state) => {\n state.previousPanels = state.panels;\n });\n },\n\n resetPanels() {\n set((state) => {\n state.panels = state.previousPanels;\n });\n },\n\n openEditPanel(item) {\n const { panels, getPanelKey } = get();\n\n // Ask the layout store for the panel key at that location\n const panelKey = getPanelKey(item);\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n name: panelToEdit.spec.display.name,\n description: panelToEdit.spec.display.description ?? '',\n groupId: item.panelGroupId,\n kind: panelToEdit.spec.plugin.kind,\n spec: panelToEdit.spec.plugin.spec,\n },\n applyChanges: (next) => {\n const panelDefinititon = createPanelDefinitionFromEditorValues(next);\n set((state) => {\n state.panels[panelKey] = panelDefinititon;\n });\n\n // Move the panel to another group if it changed\n if (next.groupId !== item.panelGroupId) {\n get().movePanelToGroup(item, next.groupId);\n }\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group\n if (panelGroupId === undefined) {\n const firstGroupId = get().panelGroupIdOrder[0];\n if (firstGroupId === undefined) {\n throw new Error('No panel groups to add a panel to');\n }\n panelGroupId = firstGroupId;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupId: panelGroupId,\n // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n set((state) => {\n state.panels[panelKey] = panelDef;\n });\n get().addPanelToGroup(panelKey, next.groupId);\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n deletePanels(items: PanelGroupItemId[]) {\n const { mapPanelToPanelGroups, deletePanelInPanelGroup, getPanelKey } = get();\n const map = mapPanelToPanelGroups();\n // get panel key first before deleting panel from panel group since getPanelKey relies on index\n const panels = items.map((panel) => {\n return { ...panel, panelKey: getPanelKey(panel) };\n });\n panels.forEach(({ panelKey, ...panel }) => {\n deletePanelInPanelGroup(panel);\n // make sure panel is only referenced in one panel group before deleting it from state.panels\n if (map[panelKey] && map[panelKey]?.length === 1) {\n set((state) => {\n delete state.panels[panelKey];\n });\n }\n });\n },\n\n openDeletePanelDialog(item: PanelGroupItemId) {\n const { panels, getPanelKey, panelGroups } = get();\n const panelKey = getPanelKey(item);\n set((state) => {\n state.deletePanelDialog = {\n panelGroupItemId: item,\n panelName: panels[panelKey]?.spec.display.name ?? '',\n panelGroupName: panelGroups[item.panelGroupId]?.title ?? '',\n };\n });\n },\n\n closeDeletePanelDialog() {\n set((state) => {\n state.deletePanelDialog = undefined;\n });\n },\n });\n}\n\n// Helper to create PanelDefinitions when saving\nfunction createPanelDefinitionFromEditorValues(editorValues: PanelEditorValues): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: editorValues.name,\n description: editorValues.description !== '' ? editorValues.description : undefined,\n },\n plugin: {\n kind: editorValues.kind,\n spec: editorValues.spec,\n },\n },\n };\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","createPanelEditorSlice","panels","set","get","previousPanels","panelEditor","undefined","savePanels","state","resetPanels","openEditPanel","item","getPanelKey","panelKey","panelToEdit","Error","editorState","mode","initialValues","name","spec","display","description","groupId","panelGroupId","kind","plugin","applyChanges","next","panelDefinititon","createPanelDefinitionFromEditorValues","movePanelToGroup","close","openAddPanel","firstGroupId","panelGroupIdOrder","panelDef","addPanelToGroup","deletePanels","items","mapPanelToPanelGroups","deletePanelInPanelGroup","map","panel","forEach","length","openDeletePanelDialog","panelGroups","deletePanelDialog","panelGroupItemId","panelName","panelGroupName","title","closeDeletePanelDialog","editorValues"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAA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M,GAAtBA,KAAAA,CAAsB,GAAtBA,GAAgB,CAAEmB,IAAI,CAACC,OAAO,CAACF,IAAI,cAAnClB,KAAmC,cAAnCA,KAAmC,GAAI,EAAE;wBACpDkD,cAAc,EAAEJ,CAAAA,IAAqC,GAArCA,CAAAA,IAA8B,GAA9BA,WAAW,CAACpC,IAAI,CAACa,YAAY,CAAC,cAA9BuB,IAA8B,WAAO,GAArCA,KAAAA,CAAqC,GAArCA,IAA8B,CAAEK,KAAK,cAArCL,IAAqC,cAArCA,IAAqC,GAAI,EAAE;qBAC5D,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC;YAEDM,sBAAsB,IAAG;gBACvBnD,GAAG,CAAC,CAACM,KAAK,GAAK;oBACbA,KAAK,CAACwC,iBAAiB,GAAG1C,SAAS,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA;KAAC,CAAC;AACL,CAAC;AAED,gDAAgD;AAChD,SAASwB,qCAAqC,CAACwB,YAA+B,EAAmB;IAC/F,OAAO;QACL7B,IAAI,EAAE,OAAO;QACbL,IAAI,EAAE;YACJC,OAAO,EAAE;gBACPF,IAAI,EAAEmC,YAAY,CAACnC,IAAI;gBACvBG,WAAW,EAAEgC,YAAY,CAAChC,WAAW,KAAK,EAAE,GAAGgC,YAAY,CAAChC,WAAW,GAAGhB,SAAS;aACpF;YACDoB,MAAM,EAAE;gBACND,IAAI,EAAE6B,YAAY,CAAC7B,IAAI;gBACvBL,IAAI,EAAEkC,YAAY,CAAClC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-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, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\nimport { generateId, Middleware } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n name: string;\n description: string;\n groupId: PanelGroupId;\n kind: string;\n spec: UnknownSpec;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n name: panelToEdit.spec.display.name,\n description: panelToEdit.spec.display.description ?? '',\n groupId: panelGroupItemId.panelGroupId,\n kind: panelToEdit.spec.plugin.kind,\n spec: panelToEdit.spec.plugin.spec,\n },\n applyChanges: (next) => {\n const panelDefinititon = createPanelDefinitionFromEditorValues(next);\n set((draft) => {\n draft.panels[panelKey] = panelDefinititon;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = draft.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = draft.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group\n if (panelGroupId === undefined) {\n const firstGroupId = get().panelGroupOrder[0];\n if (firstGroupId === undefined) {\n throw new Error('No panel groups to add a panel to');\n }\n panelGroupId = firstGroupId;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupId: panelGroupId,\n // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n set((draft) => {\n // Add a panel\n draft.panels[panelKey] = panelDef;\n\n // Also add a panel group item referencing the panel\n const group = draft.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n });\n}\n\n// Helper to create PanelDefinitions when saving\nfunction createPanelDefinitionFromEditorValues(editorValues: PanelEditorValues): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: editorValues.name,\n description: editorValues.description !== '' ? editorValues.description : undefined,\n },\n plugin: {\n kind: editorValues.kind,\n spec: editorValues.spec,\n },\n },\n };\n}\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","generateId","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","name","spec","display","description","groupId","kind","plugin","applyChanges","next","panelDefinititon","createPanelDefinitionFromEditorValues","draft","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","getYForNewRow","w","h","close","state","openAddPanel","firstGroupId","panelGroupOrder","panelDef","group","toString","editorValues","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,qCAAqC,QAAQ,uBAAuB,CAAC;AAC9E,SAASC,UAAU,QAAoB,UAAU,CAAC;AA+DlD;;CAEC,GACD,OAAO,SAASC,sBAAsB,GAMpC;IACA,gGAAgG;IAChG,OAAO,CAACC,GAAG,EAAEC,GAAG;QAAM,OAAA;YACpBC,WAAW,EAAEC,SAAS;YAEtBC,aAAa,EAACC,gBAAgB,EAAE;oBAKbC,GAAyB;gBAJ1C,MAAM,EAAEC,MAAM,CAAA,EAAED,WAAW,CAAA,EAAE,GAAGL,GAAG,EAAE,AAAC;gBAEtC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,CAAA,EAAEC,sBAAsB,EAAEC,kBAAkB,CAAA,EAAE,GAAGL,gBAAgB,AAAC;gBACtF,MAAMM,QAAQ,GAAGL,CAAAA,GAAyB,GAAzBA,WAAW,CAACE,YAAY,CAAC,cAAzBF,GAAyB,WAAe,GA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+B,EAAmB;IAC/F,OAAO;QACL/B,IAAI,EAAE,OAAO;QACbJ,IAAI,EAAE;YACJC,OAAO,EAAE;gBACPF,IAAI,EAAEoC,YAAY,CAACpC,IAAI;gBACvBG,WAAW,EAAEiC,YAAY,CAACjC,WAAW,KAAK,EAAE,GAAGiC,YAAY,CAACjC,WAAW,GAAGlB,SAAS;aACpF;YACDqB,MAAM,EAAE;gBACND,IAAI,EAAE+B,YAAY,CAAC/B,IAAI;gBACvBJ,IAAI,EAAEmC,YAAY,CAACnC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC;AAED,yHAAyH;AACzH,SAASwB,aAAa,CAACS,KAA2B,EAAE;IAClD,IAAIG,OAAO,GAAG,CAAC,AAAC;IAChB,KAAK,MAAMrB,MAAM,IAAIkB,KAAK,CAACpB,WAAW,CAAE;QACtC,MAAMwB,QAAQ,GAAGtB,MAAM,CAACQ,CAAC,GAAGR,MAAM,CAACW,CAAC,AAAC;QACrC,IAAIW,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -11,12 +11,8 @@ export interface PanelGroupEditorValues {
|
|
|
11
11
|
title: string;
|
|
12
12
|
isCollapsed: boolean;
|
|
13
13
|
}
|
|
14
|
-
export interface DeletePanelGroupDialog {
|
|
15
|
-
panelGroupId: PanelGroupId;
|
|
16
|
-
panelGroupName?: string;
|
|
17
|
-
}
|
|
18
14
|
/**
|
|
19
|
-
* Slice that handles the visual editor state and actions for
|
|
15
|
+
* Slice that handles the visual editor state and related actions for adding or editing Panel Groups.
|
|
20
16
|
*/
|
|
21
17
|
export interface PanelGroupEditorSlice {
|
|
22
18
|
/**
|
|
@@ -31,9 +27,6 @@ export interface PanelGroupEditorSlice {
|
|
|
31
27
|
* Opens the panel group editor to edit an existing panel group.
|
|
32
28
|
*/
|
|
33
29
|
openEditPanelGroup: (panelGroupId: PanelGroupId) => void;
|
|
34
|
-
deletePanelGroupDialog?: DeletePanelGroupDialog;
|
|
35
|
-
openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;
|
|
36
|
-
closeDeletePanelGroupDialog: () => void;
|
|
37
30
|
}
|
|
38
31
|
export declare const createPanelGroupEditorSlice: StateCreator<PanelGroupEditorSlice & PanelGroupSlice, Middleware, [
|
|
39
32
|
], PanelGroupEditorSlice>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.
|
|
1
|
+
{"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,eAAe,EAAwB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE1F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAwErB,CAAC"}
|
|
@@ -10,6 +10,7 @@
|
|
|
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 { generateId } from './common';
|
|
13
14
|
export const createPanelGroupEditorSlice = (set, get)=>({
|
|
14
15
|
panelGroupEditor: undefined,
|
|
15
16
|
openAddPanelGroup: ()=>{
|
|
@@ -22,13 +23,14 @@ export const createPanelGroupEditorSlice = (set, get)=>({
|
|
|
22
23
|
},
|
|
23
24
|
applyChanges (next) {
|
|
24
25
|
const newGroup = {
|
|
25
|
-
id:
|
|
26
|
-
|
|
26
|
+
id: generateId(),
|
|
27
|
+
itemLayouts: [],
|
|
28
|
+
itemPanelKeys: {},
|
|
27
29
|
...next
|
|
28
30
|
};
|
|
29
31
|
set((draft)=>{
|
|
30
32
|
draft.panelGroups[newGroup.id] = newGroup;
|
|
31
|
-
draft.
|
|
33
|
+
draft.panelGroupOrder.unshift(newGroup.id);
|
|
32
34
|
});
|
|
33
35
|
},
|
|
34
36
|
close () {
|
|
@@ -75,22 +77,7 @@ export const createPanelGroupEditorSlice = (set, get)=>({
|
|
|
75
77
|
set((draft)=>{
|
|
76
78
|
draft.panelGroupEditor = editor;
|
|
77
79
|
});
|
|
78
|
-
}
|
|
79
|
-
openDeletePanelGroupDialog: (panelGroupId)=>{
|
|
80
|
-
const panelGroup = get().panelGroups[panelGroupId];
|
|
81
|
-
if (panelGroup === undefined) {
|
|
82
|
-
throw new Error(`Panel group with Id ${panelGroupId} not found`);
|
|
83
|
-
}
|
|
84
|
-
set((state)=>{
|
|
85
|
-
state.deletePanelGroupDialog = {
|
|
86
|
-
panelGroupId,
|
|
87
|
-
panelGroupName: panelGroup.title
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
closeDeletePanelGroupDialog: ()=>set((state)=>{
|
|
92
|
-
state.deletePanelGroupDialog = undefined;
|
|
93
|
-
})
|
|
80
|
+
}
|
|
94
81
|
});
|
|
95
82
|
|
|
96
83
|
//# sourceMappingURL=panel-group-editor-slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-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 { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupDefinition, PanelGroupId } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup: PanelGroupDefinition = {\n id: generateId(),\n itemLayouts: [],\n itemPanelKeys: {},\n ...next,\n };\n set((draft) => {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["generateId","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","id","itemLayouts","itemPanelKeys","draft","panelGroups","panelGroupOrder","unshift","close","openEditPanelGroup","panelGroupId","existingGroup","Error","group"],"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;AAGjC,SAASA,UAAU,QAAoB,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C,CAAC;YACxE,CAAC;gBAMUC,MAAmB;YAJ9B,0BAA0B;YAC1B,MAAMlB,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,MAAM;gBACZC,aAAa,EAAE;oBACbC,KAAK,EAAEe,CAAAA,MAAmB,GAAnBA,aAAa,CAACf,KAAK,cAAnBe,MAAmB,cAAnBA,MAAmB,GAAI,EAAE;oBAChCd,WAAW,EAAEc,aAAa,CAACd,WAAW;iBACvC;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjBX,GAAG,CAAC,CAACgB,KAAK,GAAK;wBACb,MAAMS,KAAK,GAAGT,KAAK,CAACC,WAAW,CAACK,YAAY,CAAC,AAAC;wBAC9C,IAAIG,KAAK,KAAKtB,SAAS,EAAE;4BACvB,MAAM,IAAIqB,KAAK,CAAC,CAAC,oBAAoB,EAAEF,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;wBACxE,CAAC;wBACDG,KAAK,CAACjB,KAAK,GAAGG,IAAI,CAACH,KAAK,CAAC;wBACzBiB,KAAK,CAAChB,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACvC,CAAC,CAAC,CAAC;gBACL,CAAC;gBACDW,KAAK,IAAG;oBACNpB,GAAG,CAAC,CAACgB,KAAK,GAAK;wBACbA,KAAK,CAACd,gBAAgB,GAAGC,SAAS,CAAC;oBACrC,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,AAAC;YAEF,kBAAkB;YAClBH,GAAG,CAAC,CAACgB,KAAK,GAAK;gBACbA,KAAK,CAACd,gBAAgB,GAAGG,MAAM,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAA,AAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LayoutDefinition } from '@perses-dev/core';
|
|
2
|
+
import { Layout } from 'react-grid-layout';
|
|
2
3
|
import { StateCreator } from 'zustand';
|
|
3
4
|
import { Middleware } from './common';
|
|
4
|
-
import { PanelEditorSlice } from './panel-editor-slice';
|
|
5
5
|
/**
|
|
6
6
|
* Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.
|
|
7
7
|
*/
|
|
@@ -13,43 +13,22 @@ export interface PanelGroupSlice {
|
|
|
13
13
|
/**
|
|
14
14
|
* An array of panel group IDs, representing their order in the dashboard.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
panelGroupOrder: PanelGroupId[];
|
|
17
17
|
/**
|
|
18
18
|
* previous state
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
previousPanelGroupState: {
|
|
21
21
|
panelGroups: PanelGroupSlice['panelGroups'];
|
|
22
|
-
panelGroupIdOrder: PanelGroupSlice['
|
|
22
|
+
panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];
|
|
23
23
|
};
|
|
24
|
-
createPanelGroupId: () => PanelGroupId;
|
|
25
|
-
/**
|
|
26
|
-
* Given a LayoutItem location, returns the panel's unique key at that location.
|
|
27
|
-
*/
|
|
28
|
-
getPanelKey: (layoutItem: PanelGroupItemId) => string;
|
|
29
|
-
/**
|
|
30
|
-
* Add a panel with the specified key to an existing group.
|
|
31
|
-
*/
|
|
32
|
-
addPanelToGroup: (panelKey: string, panelGroupId: PanelGroupId) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Move an existing Panel to a new panel group.
|
|
35
|
-
*/
|
|
36
|
-
movePanelToGroup: (layoutItem: PanelGroupItemId, newPanelGroupId: PanelGroupId) => void;
|
|
37
24
|
/**
|
|
38
25
|
* Rearrange the order of panel groups by swapping the positions
|
|
39
26
|
*/
|
|
40
27
|
swapPanelGroups: (xIndex: number, yIndex: number) => void;
|
|
41
28
|
/**
|
|
42
|
-
*
|
|
29
|
+
* Update the item layouts for a panel group when, for example, a panel is moved or resized.
|
|
43
30
|
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Delete panel in panel group
|
|
47
|
-
*/
|
|
48
|
-
deletePanelInPanelGroup: (layoutItem: PanelGroupItemId) => void;
|
|
49
|
-
/**
|
|
50
|
-
* Map panel to panel groups
|
|
51
|
-
*/
|
|
52
|
-
mapPanelToPanelGroups: () => Record<string, PanelGroupId[]>;
|
|
31
|
+
updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
|
|
53
32
|
/**
|
|
54
33
|
* save
|
|
55
34
|
*/
|
|
@@ -62,19 +41,24 @@ export interface PanelGroupSlice {
|
|
|
62
41
|
export declare type PanelGroupId = number;
|
|
63
42
|
export interface PanelGroupDefinition {
|
|
64
43
|
id: PanelGroupId;
|
|
65
|
-
items: GridItemDefinition[];
|
|
66
44
|
isCollapsed: boolean;
|
|
67
45
|
title?: string;
|
|
46
|
+
itemLayouts: PanelGroupItemLayout[];
|
|
47
|
+
itemPanelKeys: Record<PanelGroupItemLayoutId, string>;
|
|
48
|
+
}
|
|
49
|
+
export interface PanelGroupItemLayout extends Layout {
|
|
50
|
+
i: PanelGroupItemLayoutId;
|
|
68
51
|
}
|
|
52
|
+
export declare type PanelGroupItemLayoutId = string;
|
|
69
53
|
/**
|
|
70
54
|
* Uniquely identifies an item in a PanelGroup.
|
|
71
55
|
*/
|
|
72
56
|
export interface PanelGroupItemId {
|
|
73
57
|
panelGroupId: PanelGroupId;
|
|
74
|
-
|
|
58
|
+
panelGroupItemLayoutId: PanelGroupItemLayoutId;
|
|
75
59
|
}
|
|
76
60
|
/**
|
|
77
61
|
* Curried function for creating a PanelGroupSlice.
|
|
78
62
|
*/
|
|
79
|
-
export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice
|
|
63
|
+
export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
|
|
80
64
|
//# 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.
|
|
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,uBAAuB,EAAE;QACvB,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;QAC5C,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC;KACvD,CAAC;IAEF;;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;IAEhH;;OAEG;IACH,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,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,CAkFhE"}
|
|
@@ -10,195 +10,90 @@
|
|
|
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 {
|
|
13
|
+
import { getPanelKeyFromRef } from '@perses-dev/core';
|
|
14
|
+
import { generateId } from './common';
|
|
14
15
|
/**
|
|
15
16
|
* Curried function for creating a PanelGroupSlice.
|
|
16
17
|
*/ export function createPanelGroupSlice(layouts) {
|
|
17
|
-
//
|
|
18
|
-
let id = -1;
|
|
19
|
-
function createPanelGroupId() {
|
|
20
|
-
id++;
|
|
21
|
-
return id;
|
|
22
|
-
}
|
|
23
|
-
// Convert the initial layouts from the JSON to panel groups and keep track of the order
|
|
18
|
+
// Convert the initial layouts from the JSON
|
|
24
19
|
const panelGroups = {};
|
|
25
20
|
const panelGroupIdOrder = [];
|
|
26
21
|
for (const layout of layouts){
|
|
27
22
|
var ref, ref1, ref2;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,
|
|
32
41
|
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
33
|
-
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title
|
|
42
|
+
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
43
|
+
itemLayouts,
|
|
44
|
+
itemPanelKeys
|
|
34
45
|
};
|
|
35
|
-
panelGroupIdOrder.push(
|
|
46
|
+
panelGroupIdOrder.push(panelGroupId);
|
|
36
47
|
}
|
|
37
48
|
// Return the state creator function for Zustand
|
|
38
|
-
return (set
|
|
39
|
-
return {
|
|
49
|
+
return (set)=>({
|
|
40
50
|
panelGroups,
|
|
41
|
-
panelGroupIdOrder,
|
|
42
|
-
|
|
51
|
+
panelGroupOrder: panelGroupIdOrder,
|
|
52
|
+
previousPanelGroupState: {
|
|
43
53
|
panelGroups,
|
|
44
54
|
panelGroupIdOrder
|
|
45
55
|
},
|
|
46
|
-
// TODO: Reorder init logic so this isn't exposed
|
|
47
|
-
createPanelGroupId,
|
|
48
56
|
savePanelGroups () {
|
|
49
57
|
set((state)=>{
|
|
50
|
-
state.
|
|
58
|
+
state.previousPanelGroupState = {
|
|
51
59
|
panelGroups: state.panelGroups,
|
|
52
|
-
panelGroupIdOrder: state.
|
|
60
|
+
panelGroupIdOrder: state.panelGroupOrder
|
|
53
61
|
};
|
|
54
62
|
});
|
|
55
63
|
},
|
|
56
64
|
resetPanelGroups () {
|
|
57
65
|
set((state)=>{
|
|
58
|
-
state.panelGroups = state.
|
|
59
|
-
state.
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
getPanelKey ({ panelGroupId , itemIndex }) {
|
|
63
|
-
const { panelGroups } = get();
|
|
64
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
65
|
-
const item = findItem(group, itemIndex);
|
|
66
|
-
return getPanelKeyFromRef(item.content);
|
|
67
|
-
},
|
|
68
|
-
addPanelToGroup (panelKey, panelGroupId) {
|
|
69
|
-
const { panelGroups } = get();
|
|
70
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
71
|
-
const gridItem = {
|
|
72
|
-
x: 0,
|
|
73
|
-
y: getYForNewRow(group),
|
|
74
|
-
width: 12,
|
|
75
|
-
height: 6,
|
|
76
|
-
content: createPanelRef(panelKey)
|
|
77
|
-
};
|
|
78
|
-
set((state)=>{
|
|
79
|
-
var ref;
|
|
80
|
-
(ref = state.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
movePanelToGroup ({ panelGroupId , itemIndex }, newPanelGroupId) {
|
|
84
|
-
const { panelGroups } = get();
|
|
85
|
-
// Find the existing item to make sure it exists
|
|
86
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
87
|
-
const item = findItem(group, itemIndex);
|
|
88
|
-
// Find the new group and figure out where a new row should go
|
|
89
|
-
const newGroup = findGroup(panelGroups, newPanelGroupId);
|
|
90
|
-
const newGroupY = getYForNewRow(newGroup);
|
|
91
|
-
set((state)=>{
|
|
92
|
-
var // Remove the item from its current group
|
|
93
|
-
ref, // Add a new item to the new group
|
|
94
|
-
ref1;
|
|
95
|
-
(ref = state.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
|
|
96
|
-
(ref1 = state.panelGroups[newPanelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
|
|
97
|
-
x: 0,
|
|
98
|
-
y: newGroupY,
|
|
99
|
-
width: item.width,
|
|
100
|
-
height: item.height,
|
|
101
|
-
content: item.content
|
|
102
|
-
});
|
|
66
|
+
state.panelGroups = state.previousPanelGroupState.panelGroups;
|
|
67
|
+
state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
|
|
103
68
|
});
|
|
104
69
|
},
|
|
105
70
|
swapPanelGroups (x, y) {
|
|
106
71
|
set((state)=>{
|
|
107
|
-
if (x < 0 || x >= state.
|
|
72
|
+
if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
|
|
108
73
|
throw new Error('index out of bound');
|
|
109
74
|
}
|
|
110
|
-
const xPanelGroup = state.
|
|
111
|
-
const yPanelGroup = state.
|
|
75
|
+
const xPanelGroup = state.panelGroupOrder[x];
|
|
76
|
+
const yPanelGroup = state.panelGroupOrder[y];
|
|
112
77
|
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
113
78
|
throw new Error('panel group is undefined');
|
|
114
79
|
}
|
|
115
80
|
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
116
|
-
[state.
|
|
81
|
+
[state.panelGroupOrder[x], state.panelGroupOrder[y]] = [
|
|
117
82
|
yPanelGroup,
|
|
118
83
|
xPanelGroup
|
|
119
84
|
];
|
|
120
85
|
});
|
|
121
86
|
},
|
|
122
|
-
|
|
87
|
+
updatePanelGroupLayouts (panelGroupId, itemLayouts) {
|
|
123
88
|
set((state)=>{
|
|
124
89
|
const group = state.panelGroups[panelGroupId];
|
|
125
90
|
if (group === undefined) {
|
|
126
|
-
throw new Error(`
|
|
91
|
+
throw new Error(`Cannot find panel group ${panelGroupId}`);
|
|
127
92
|
}
|
|
128
|
-
|
|
129
|
-
group.items.splice(itemIndex, 1);
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
deletePanelGroup (panelGroupId) {
|
|
133
|
-
const { panelGroups , panelGroupIdOrder: panelGroupOrder , deletePanels } = get();
|
|
134
|
-
const group = findGroup(panelGroups, panelGroupId);
|
|
135
|
-
const orderIdx = panelGroupOrder.findIndex((id)=>id === panelGroupId);
|
|
136
|
-
if (orderIdx === -1) {
|
|
137
|
-
throw new Error(`Could not find panel group Id ${panelGroupId} in order array`);
|
|
138
|
-
}
|
|
139
|
-
// remove panels from group first
|
|
140
|
-
const panelsToBeDeleted = [];
|
|
141
|
-
for(let i = 0; i < group.items.length; i++){
|
|
142
|
-
panelsToBeDeleted.push({
|
|
143
|
-
panelGroupId,
|
|
144
|
-
itemIndex: i
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
deletePanels(panelsToBeDeleted);
|
|
148
|
-
// remove group from both panelGroups and panelGroupOrder
|
|
149
|
-
set((state)=>{
|
|
150
|
-
state.panelGroupIdOrder.splice(orderIdx, 1);
|
|
151
|
-
delete state.panelGroups[panelGroupId];
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
// Return an object that maps each panel to the groups it belongs
|
|
155
|
-
mapPanelToPanelGroups () {
|
|
156
|
-
const map = {}; // { panel key: [group ids] }
|
|
157
|
-
Object.values(get().panelGroups).forEach((group)=>{
|
|
158
|
-
// for each panel in a group, add the group id to map[panelKey]
|
|
159
|
-
group.items.forEach((panel)=>{
|
|
160
|
-
const panelKey = getPanelKeyFromRef(panel.content);
|
|
161
|
-
if (map[panelKey]) {
|
|
162
|
-
var ref;
|
|
163
|
-
(ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
|
|
164
|
-
} else {
|
|
165
|
-
map[panelKey] = [
|
|
166
|
-
group.id
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
93
|
+
group.itemLayouts = itemLayouts;
|
|
170
94
|
});
|
|
171
|
-
return map;
|
|
172
95
|
}
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
// Helper to find a group and throw if not found
|
|
177
|
-
function findGroup(panelGroups, groupId) {
|
|
178
|
-
const group = panelGroups[groupId];
|
|
179
|
-
if (group === undefined) {
|
|
180
|
-
throw new Error(`No panel group found for Id ${groupId}`);
|
|
181
|
-
}
|
|
182
|
-
return group;
|
|
183
|
-
}
|
|
184
|
-
// Helper to get an item in a group and throw if not found
|
|
185
|
-
function findItem(group, itemIndex) {
|
|
186
|
-
const item = group.items[itemIndex];
|
|
187
|
-
if (item === undefined) {
|
|
188
|
-
throw new Error(`No grid item found at position ${itemIndex}`);
|
|
189
|
-
}
|
|
190
|
-
return item;
|
|
191
|
-
}
|
|
192
|
-
// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
|
|
193
|
-
function getYForNewRow(group) {
|
|
194
|
-
let newRowY = 0;
|
|
195
|
-
for (const item of group.items){
|
|
196
|
-
const itemMaxY = item.y + item.height;
|
|
197
|
-
if (itemMaxY > newRowY) {
|
|
198
|
-
newRowY = itemMaxY;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return newRowY;
|
|
96
|
+
});
|
|
202
97
|
}
|
|
203
98
|
|
|
204
99
|
//# sourceMappingURL=panel-group-slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, getPanelKeyFromRef, GridItemDefinition, LayoutDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelEditorSlice } from './panel-editor-slice';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupIdOrder: PanelGroupId[];\n\n /**\n * previous state\n */\n previousPanelGroupStates: {\n panelGroups: PanelGroupSlice['panelGroups'];\n panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'];\n };\n\n // TODO: Remove this\n createPanelGroupId: () => PanelGroupId;\n\n /**\n * Given a LayoutItem location, returns the panel's unique key at that location.\n */\n getPanelKey: (layoutItem: PanelGroupItemId) => string;\n\n /**\n * Add a panel with the specified key to an existing group.\n */\n addPanelToGroup: (panelKey: string, panelGroupId: PanelGroupId) => void;\n\n /**\n * Move an existing Panel to a new panel group.\n */\n movePanelToGroup: (layoutItem: PanelGroupItemId, newPanelGroupId: PanelGroupId) => void;\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Delete panel group and all the panels within the group\n */\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n\n /**\n * Delete panel in panel group\n */\n deletePanelInPanelGroup: (layoutItem: PanelGroupItemId) => void;\n\n /**\n * Map panel to panel groups\n */\n mapPanelToPanelGroups: () => Record<string, PanelGroupId[]>;\n\n /**\n * save\n */\n savePanelGroups: () => void;\n\n /**\n * reset to previous panel group states\n */\n resetPanelGroups: () => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n items: GridItemDefinition[];\n isCollapsed: boolean;\n title?: string;\n}\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n itemIndex: number;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice & PanelEditorSlice, Middleware, [], PanelGroupSlice> {\n // Helper function for generating unique IDs for a PanelGroup\n let id: PanelGroupId = -1;\n function createPanelGroupId(): PanelGroupId {\n id++;\n return id;\n }\n\n // Convert the initial layouts from the JSON to panel groups and keep track of the order\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'] = [];\n for (const layout of layouts) {\n const id = createPanelGroupId();\n panelGroups[id] = {\n id,\n items: layout.spec.items,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n };\n panelGroupIdOrder.push(id);\n }\n\n // Return the state creator function for Zustand\n return (set, get) => ({\n panelGroups,\n panelGroupIdOrder,\n\n previousPanelGroupStates: { panelGroups, panelGroupIdOrder },\n\n // TODO: Reorder init logic so this isn't exposed\n createPanelGroupId,\n\n savePanelGroups() {\n set((state) => {\n state.previousPanelGroupStates = {\n panelGroups: state.panelGroups,\n panelGroupIdOrder: state.panelGroupIdOrder,\n };\n });\n },\n\n resetPanelGroups() {\n set((state) => {\n state.panelGroups = state.previousPanelGroupStates.panelGroups;\n state.panelGroupIdOrder = state.previousPanelGroupStates.panelGroupIdOrder;\n });\n },\n\n getPanelKey({ panelGroupId, itemIndex }) {\n const { panelGroups } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const item = findItem(group, itemIndex);\n return getPanelKeyFromRef(item.content);\n },\n\n addPanelToGroup(panelKey, panelGroupId) {\n const { panelGroups } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const gridItem: GridItemDefinition = {\n x: 0,\n y: getYForNewRow(group),\n width: 12,\n height: 6,\n content: createPanelRef(panelKey),\n };\n set((state) => {\n state.panelGroups[panelGroupId]?.items.push(gridItem);\n });\n },\n\n movePanelToGroup({ panelGroupId, itemIndex }, newPanelGroupId) {\n const { panelGroups } = get();\n\n // Find the existing item to make sure it exists\n const group = findGroup(panelGroups, panelGroupId);\n const item = findItem(group, itemIndex);\n\n // Find the new group and figure out where a new row should go\n const newGroup = findGroup(panelGroups, newPanelGroupId);\n const newGroupY = getYForNewRow(newGroup);\n\n set((state) => {\n // Remove the item from its current group\n state.panelGroups[panelGroupId]?.items.splice(itemIndex, 1);\n\n // Add a new item to the new group\n state.panelGroups[newPanelGroupId]?.items.push({\n x: 0,\n y: newGroupY,\n width: item.width,\n height: item.height,\n content: item.content,\n });\n });\n },\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupIdOrder.length || y < 0 || y >= state.panelGroupIdOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupIdOrder[x];\n const yPanelGroup = state.panelGroupIdOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupIdOrder[x], state.panelGroupIdOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n deletePanelInPanelGroup({ panelGroupId, itemIndex }) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`No panel group found: ${panelGroupId}`);\n }\n // remove panel from panel group\n group.items.splice(itemIndex, 1);\n });\n },\n\n deletePanelGroup(panelGroupId) {\n const { panelGroups, panelGroupIdOrder: panelGroupOrder, deletePanels } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const orderIdx = panelGroupOrder.findIndex((id) => id === panelGroupId);\n if (orderIdx === -1) {\n throw new Error(`Could not find panel group Id ${panelGroupId} in order array`);\n }\n\n // remove panels from group first\n const panelsToBeDeleted: PanelGroupItemId[] = [];\n for (let i = 0; i < group.items.length; i++) {\n panelsToBeDeleted.push({ panelGroupId, itemIndex: i });\n }\n deletePanels(panelsToBeDeleted);\n\n // remove group from both panelGroups and panelGroupOrder\n set((state) => {\n state.panelGroupIdOrder.splice(orderIdx, 1);\n delete state.panelGroups[panelGroupId];\n });\n },\n\n // Return an object that maps each panel to the groups it belongs\n mapPanelToPanelGroups() {\n const map: Record<string, Array<PanelGroupDefinition['id']>> = {}; // { panel key: [group ids] }\n Object.values(get().panelGroups).forEach((group) => {\n // for each panel in a group, add the group id to map[panelKey]\n group.items.forEach((panel) => {\n const panelKey = getPanelKeyFromRef(panel.content);\n if (map[panelKey]) {\n map[panelKey]?.push(group.id);\n } else {\n map[panelKey] = [group.id];\n }\n });\n });\n return map;\n },\n });\n}\n\n// Helper to find a group and throw if not found\nfunction findGroup(panelGroups: PanelGroupSlice['panelGroups'], groupId: PanelGroupId) {\n const group = panelGroups[groupId];\n if (group === undefined) {\n throw new Error(`No panel group found for Id ${groupId}`);\n }\n return group;\n}\n\n// Helper to get an item in a group and throw if not found\nfunction findItem(group: PanelGroupDefinition, itemIndex: number) {\n const item = group.items[itemIndex];\n if (item === undefined) {\n throw new Error(`No grid item found at position ${itemIndex}`);\n }\n return item;\n}\n\n// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const item of group.items) {\n const itemMaxY = item.y + item.height;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["createPanelRef","getPanelKeyFromRef","createPanelGroupSlice","layouts","id","createPanelGroupId","panelGroups","panelGroupIdOrder","layout","items","spec","isCollapsed","display","collapse","open","title","push","set","get","previousPanelGroupStates","savePanelGroups","state","resetPanelGroups","getPanelKey","panelGroupId","itemIndex","group","findGroup","item","findItem","content","addPanelToGroup","panelKey","gridItem","x","y","getYForNewRow","width","height","movePanelToGroup","newPanelGroupId","newGroup","newGroupY","splice","swapPanelGroups","length","Error","xPanelGroup","yPanelGroup","undefined","deletePanelInPanelGroup","deletePanelGroup","panelGroupOrder","deletePanels","orderIdx","findIndex","panelsToBeDeleted","i","mapPanelToPanelGroups","map","Object","values","forEach","panel","groupId","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,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AAOtC,KAAK,CAAC;AACf,CAAC;AAED,0DAA0D;AAC1D,SAASG,QAAQ,CAACH,KAA2B,EAAED,SAAiB,EAAE;IAChE,MAAMG,IAAI,GAAGF,KAAK,CAACjB,KAAK,CAACgB,SAAS,CAAC,AAAC;IACpC,IAAIG,IAAI,KAAKqB,SAAS,EAAE;QACtB,MAAM,IAAIH,KAAK,CAAC,CAAC,+BAA+B,EAAErB,SAAS,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IACD,OAAOG,IAAI,CAAC;AACd,CAAC;AAED,mHAAmH;AACnH,SAASQ,aAAa,CAACV,KAA2B,EAAE;IAClD,IAAIuC,OAAO,GAAG,CAAC,AAAC;IAChB,KAAK,MAAMrC,IAAI,IAAIF,KAAK,CAACjB,KAAK,CAAE;QAC9B,MAAMyD,QAAQ,GAAGtC,IAAI,CAACO,CAAC,GAAGP,IAAI,CAACU,MAAM,AAAC;QACtC,IAAI4B,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC"}
|
|
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 * previous state\n */\n previousPanelGroupState: {\n panelGroups: PanelGroupSlice['panelGroups'];\n panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];\n };\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n\n /**\n * save\n */\n savePanelGroups: () => void;\n\n /**\n * reset to previous panel group states\n */\n resetPanelGroups: () => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n 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 // 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\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n\n previousPanelGroupState: { panelGroups, panelGroupIdOrder },\n\n savePanelGroups() {\n set((state) => {\n state.previousPanelGroupState = {\n panelGroups: state.panelGroups,\n panelGroupIdOrder: state.panelGroupOrder,\n };\n });\n },\n\n resetPanelGroups() {\n set((state) => {\n state.panelGroups = state.previousPanelGroupState.panelGroups;\n state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;\n });\n },\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"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupIdOrder","layout","itemLayouts","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","x","y","content","panelGroupId","id","isCollapsed","display","collapse","open","title","set","panelGroupOrder","previousPanelGroupState","savePanelGroups","state","resetPanelGroups","swapPanelGroups","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","group"],"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,kBAAkB,QAA0B,kBAAkB,CAAC;AAGxE,SAASC,UAAU,QAAoB,UAAU,CAAC;AAqElD;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACqC;IAChE,4CAA4C;IAC5C,MAAMC,WAAW,GAAmC,EAAE,AAAC;IACvD,MAAMC,iBAAiB,GAAuC,EAAE,AAAC;IACjE,KAAK,MAAMC,MAAM,IAAIH,OAAO,CAAE;YAqBbG,GAAmB,QACzBA,IAAmB;QArB5B,MAAMC,WAAW,GAAwC,EAAE,AAAC;QAC5D,MAAMC,aAAa,GAA0C,EAAE,AAAC;QAEhE,6GAA6G;QAC7G,KAAK,MAAMC,IAAI,IAAIH,MAAM,CAACI,IAAI,CAACC,KAAK,CAAE;YACpC,MAAMC,kBAAkB,GAAGX,UAAU,EAAE,CAACY,QAAQ,EAAE,AAAC;YACnDN,WAAW,CAACO,IAAI,CAAC;gBACfC,CAAC,EAAEH,kBAAkB;gBACrBI,CAAC,EAAEP,IAAI,CAACQ,KAAK;gBACbC,CAAC,EAAET,IAAI,CAACU,MAAM;gBACdC,CAAC,EAAEX,IAAI,CAACW,CAAC;gBACTC,CAAC,EAAEZ,IAAI,CAACY,CAAC;aACV,CAAC,CAAC;YACHb,aAAa,CAACI,kBAAkB,CAAC,GAAGZ,kBAAkB,CAACS,IAAI,CAACa,OAAO,CAAC,CAAC;QAC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ACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PanelDefinition } from '@perses-dev/core';
|
|
2
|
+
import { StateCreator } from 'zustand';
|
|
3
|
+
import { Middleware } from './common';
|
|
4
|
+
/**
|
|
5
|
+
* Slice with the state of Panels, along with any actions that modify only the Panels state.
|
|
6
|
+
*/
|
|
7
|
+
export interface PanelSlice {
|
|
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
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Curried function for creating the PanelSlice.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice>;
|
|
23
|
+
//# sourceMappingURL=panel-slice.d.ts.map
|
|
@@ -0,0 +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;IACxC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAEhD;;OAEG;IACH,WAAW,EAAE,MAAM,IAAI,CAAC;IAExB;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,CAAC,CAiBnH"}
|