@perses-dev/dashboards 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Dashboard.js +7 -11
- package/dist/cjs/components/DashboardToolbar.js +4 -4
- package/dist/cjs/components/GridLayout/GridItemContent.js +13 -13
- package/dist/cjs/components/GridLayout/GridLayout.js +24 -21
- package/dist/cjs/components/GridLayout/GridTitle.js +27 -5
- package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
- package/dist/cjs/components/Panel/Panel.js +16 -5
- package/dist/cjs/components/Panel/Panel.test.js +12 -4
- package/dist/cjs/components/Panel/PanelContent.js +3 -2
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +13 -12
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +8 -12
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +77 -35
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +12 -19
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +2 -2
- package/dist/cjs/components/Variables/Variable.js +19 -11
- package/dist/cjs/components/Variables/VariableEditor.js +207 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
- package/dist/cjs/components/Variables/VariableList.js +50 -69
- package/dist/cjs/components/Variables/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
- package/dist/cjs/context/DashboardProvider/common.js +18 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
- package/dist/cjs/context/DashboardProvider/index.js +29 -0
- package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
- package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
- package/dist/{context/DashboardAppSlice.js → cjs/context/DashboardProvider/panel-group-slice.js} +18 -25
- package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
- package/dist/cjs/context/TemplateVariableProvider.js +8 -1
- package/dist/cjs/context/index.js +0 -2
- package/dist/cjs/test/testDashboard.js +13 -1
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +6 -7
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
- package/dist/components/Dashboard.d.ts +1 -4
- package/dist/components/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard.js +8 -12
- package/dist/components/Dashboard.js.map +1 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +5 -5
- package/dist/components/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +14 -14
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -3
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +24 -21
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +28 -6
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/Panel/DeletePanelDialog.js +80 -0
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +17 -6
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +7 -4
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/PanelContent.d.ts +4 -1
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +3 -2
- package/dist/components/Panel/PanelContent.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +8 -12
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +78 -36
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelPreview.js +42 -0
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +13 -20
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +3 -3
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/Variable.js +21 -13
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +8 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditor.js +196 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js +15 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +48 -72
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -0
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
- package/dist/context/DashboardProvider/common.d.ts +5 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -0
- package/dist/context/DashboardProvider/common.js +17 -0
- package/dist/context/DashboardProvider/common.js.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +3 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -0
- package/dist/context/DashboardProvider/index.js +16 -0
- package/dist/context/DashboardProvider/index.js.map +1 -0
- package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
- package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/layout-slice.js +196 -0
- package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
- package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +10 -2
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +111 -9
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/TemplateVariableProvider.d.ts +2 -0
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +8 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -2
- package/dist/context/index.js.map +1 -1
- package/dist/test/plugin-registry.d.ts +2 -2
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +13 -1
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +6 -7
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
- package/package.json +4 -4
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
- package/dist/cjs/context/DashboardAppSlice.js +0 -57
- package/dist/cjs/context/DashboardProvider.js +0 -128
- package/dist/cjs/context/LayoutsSlice.js +0 -55
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
- package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
- package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
- package/dist/context/DashboardAppSlice.d.ts +0 -26
- package/dist/context/DashboardAppSlice.d.ts.map +0 -1
- package/dist/context/DashboardAppSlice.js.map +0 -1
- package/dist/context/DashboardProvider.d.ts +0 -36
- package/dist/context/DashboardProvider.d.ts.map +0 -1
- package/dist/context/DashboardProvider.js +0 -107
- package/dist/context/DashboardProvider.js.map +0 -1
- package/dist/context/LayoutsSlice.d.ts +0 -12
- package/dist/context/LayoutsSlice.d.ts.map +0 -1
- package/dist/context/LayoutsSlice.js +0 -43
- package/dist/context/LayoutsSlice.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelDrawer/panel-editor-model.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 { usePlugin } from '@perses-dev/plugin-system';\nimport { useImmer } from 'use-immer';\nimport { useDashboardApp, usePanels } from '../../context';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\n\nexport interface PanelEditorFormValues {\n name: string;\n description: string;\n group: number;\n kind: string;\n spec: unknown;\n}\n\n// Props that vary based on whether the PanelDrawer is in add or edit mode\ninterface PanelDrawerModel {\n drawerTitle: string;\n submitButtonText: string;\n initialValues: PanelEditorFormValues;\n applyChanges: (values: PanelEditorFormValues) => void;\n}\n\n/**\n * Returns props that are different depending on whether the PanelDrawer has been opened in add or edit mode. If the\n * drawer isn't open at all, returns undefined.\n */\nexport function usePanelDrawerModel(): PanelDrawerModel | undefined {\n const { panelDrawer } = useDashboardApp();\n const { panels, updatePanel } = usePanels();\n\n // If we're closed, no model to return\n if (panelDrawer === undefined) {\n return undefined;\n }\n\n // If we don't have a panel key, we're adding a new panel\n const { panelKey, groupIndex } = panelDrawer;\n if (panelKey === undefined) {\n return {\n drawerTitle: 'Add Panel',\n submitButtonText: 'Add',\n initialValues: {\n name: '',\n description: '',\n group: groupIndex ?? 0,\n kind: '',\n spec: {},\n },\n applyChanges: (values) => {\n const { name, description, group, kind, spec } = values;\n const panelKey = removeWhiteSpacesAndSpecialCharacters(name);\n updatePanel(\n panelKey,\n {\n kind: 'Panel',\n spec: {\n display: { name, description },\n plugin: {\n kind,\n spec,\n },\n },\n },\n group\n );\n },\n };\n }\n\n // Otherwise we have a panel key, so we're trying to edit an existing panel\n const existingPanel = panels[panelKey];\n\n // TODO: Can we better express this via the type system on the dashboard store to avoid these states?\n if (existingPanel === undefined) {\n throw new Error(`Cannot find existing panel '${panelKey}' to edit`);\n }\n if (groupIndex === undefined) {\n throw new Error(`Cannot edit existing panel '${panelKey}' without its group index`);\n }\n\n return {\n drawerTitle: 'Edit Panel',\n submitButtonText: 'Apply',\n initialValues: {\n name: existingPanel.spec.display.name,\n description: existingPanel.spec.display.description ?? '',\n group: groupIndex,\n kind: existingPanel.spec.plugin.kind,\n spec: existingPanel.spec.plugin.spec, // TODO: Should we clone to be safe?\n },\n applyChanges: (values) => {\n const { name, description, group, kind, spec } = values;\n updatePanel(panelKey, {\n kind: 'Panel',\n spec: {\n display: { name, description },\n plugin: {\n kind,\n spec,\n },\n },\n });\n\n if (group !== groupIndex) {\n // TO DO: need to move panel if panel group changes\n }\n },\n };\n}\n\n/**\n * Manages panel plugin spec state. The spec will be undefined while a plugin is being loaded.\n */\nexport function usePanelSpecState(panelPluginKind: string, initialState: unknown) {\n // Keeping track of spec values by kind allows users to switch between panel types and come back with their old\n // values intact from before the switch\n const [specByKind, setSpecByKind] = useImmer<Record<string, unknown>>({ [panelPluginKind]: initialState });\n const { data: plugin } = usePlugin('Panel', panelPluginKind, { enabled: panelPluginKind !== '' });\n const pluginInitialSpec = useMemo(() => plugin?.createInitialOptions(), [plugin]);\n\n // Use the value in specByKind or if unset, use the initial values from the plugin (which could still be undefined)\n const spec = specByKind[panelPluginKind] ?? pluginInitialSpec;\n\n // TODO: Do we want to expose more of a immer style API to plugin authors for managing their state, rather than the\n // current \"onChange\" API?\n const onSpecChange = (next: unknown) => {\n setSpecByKind((draft) => {\n draft[panelPluginKind] = next;\n });\n };\n\n return {\n spec,\n onSpecChange,\n };\n}\n"],"names":["useMemo","usePlugin","useImmer","useDashboardApp","usePanels","removeWhiteSpacesAndSpecialCharacters","usePanelDrawerModel","panelDrawer","panels","updatePanel","undefined","panelKey","groupIndex","drawerTitle","submitButtonText","initialValues","name","description","group","kind","spec","applyChanges","values","display","plugin","existingPanel","Error","usePanelSpecState","panelPluginKind","initialState","specByKind","setSpecByKind","data","enabled","pluginInitialSpec","createInitialOptions","onSpecChange","next","draft"],"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,SAAS,QAAQ,2BAA2B,CAAC;AACtD,SAASC,QAAQ,QAAQ,WAAW,CAAC;AACrC,SAASC,eAAe,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAC3D,SAASC,qCAAqC,QAAQ,uBAAuB,CAAC;AAkB9E;;;CAGC,GACD,OAAO,SAASC,mBAAmB,GAAiC;IAClE,MAAM,EAAEC,WAAW,CAAA,EAAE,GAAGJ,eAAe,EAAE,AAAC;IAC1C,MAAM,EAAEK,MAAM,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAGL,SAAS,EAAE,AAAC;IAE5C,sCAAsC;IACtC,IAAIG,WAAW,KAAKG,SAAS,EAAE;QAC7B,OAAOA,SAAS,CAAC;IACnB,CAAC;IAED,yDAAyD;IACzD,MAAM,EAAEC,QAAQ,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGL,WAAW,AAAC;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C,AAAC;IAClG,MAAMM,iBAAiB,GAAGlC,OAAO,CAAC;QAAMwB,OAAAA,MAAM,aAANA,MAAM,WAAsB,GAA5BA,KAAAA,CAA4B,GAA5BA,MAAM,CAAEW,oBAAoB,EAAE,CAAA;KAAA,EAAE;QAACX,MAAM;KAAC,CAAC,AAAC;QAGrEM,gBAA2B;IADxC,mHAAmH;IACnH,MAAMV,IAAI,GAAGU,CAAAA,gBAA2B,GAA3BA,UAAU,CAACF,eAAe,CAAC,cAA3BE,gBAA2B,cAA3BA,gBAA2B,GAAII,iBAAiB,AAAC;IAE9D,mHAAmH;IACnH,0BAA0B;IAC1B,MAAME,YAAY,GAAG,CAACC,IAAa,GAAK;QACtCN,aAAa,CAAC,CAACO,KAAK,GAAK;YACvBA,KAAK,CAACV,eAAe,CAAC,GAAGS,IAAI,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,AAAC;IAEF,OAAO;QACLjB,IAAI;QACJgB,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
interface PanelDrawer {
|
|
2
|
-
groupIndex?: number;
|
|
3
|
-
panelKey?: string;
|
|
4
|
-
}
|
|
5
|
-
interface PanelGroupDialog {
|
|
6
|
-
groupIndex?: number;
|
|
7
|
-
}
|
|
8
|
-
export interface DashboardAppSlice {
|
|
9
|
-
panelDrawer?: PanelDrawer;
|
|
10
|
-
openPanelDrawer: (panelDrawer: PanelDrawer) => void;
|
|
11
|
-
closePanelDrawer: () => void;
|
|
12
|
-
panelGroupDialog?: PanelGroupDialog;
|
|
13
|
-
openPanelGroupDialog: (groupIndex?: number) => void;
|
|
14
|
-
closePanelGroupDialog: () => void;
|
|
15
|
-
}
|
|
16
|
-
export declare const createDashboardAppSlice: import("zustand").StateCreator<DashboardAppSlice, [], [["zustand/immer", never]], DashboardAppSlice>;
|
|
17
|
-
export declare function useDashboardApp(): {
|
|
18
|
-
panelDrawer: PanelDrawer | undefined;
|
|
19
|
-
openPanelDrawer: (panelDrawer: PanelDrawer) => void;
|
|
20
|
-
closePanelDrawer: () => void;
|
|
21
|
-
panelGroupDialog: PanelGroupDialog | undefined;
|
|
22
|
-
openPanelGroupDialog: (groupIndex?: number | undefined) => void;
|
|
23
|
-
closePanelGroupDialog: () => void;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
|
26
|
-
//# sourceMappingURL=DashboardAppSlice.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardAppSlice.d.ts","sourceRoot":"","sources":["../../src/context/DashboardAppSlice.tsx"],"names":[],"mappings":"AAgBA,UAAU,WAAW;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AACD,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;IACpD,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,oBAAoB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,qBAAqB,EAAE,MAAM,IAAI,CAAC;CACnC;AAED,eAAO,MAAM,uBAAuB,sGAoBjC,CAAC;AAEJ,wBAAgB,eAAe;;;;;;;EAkB9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/DashboardAppSlice.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 { immer } from 'zustand/middleware/immer';\nimport { useDashboardStore } from './DashboardProvider';\n\ninterface PanelDrawer {\n groupIndex?: number;\n panelKey?: string;\n}\ninterface PanelGroupDialog {\n groupIndex?: number;\n}\n\nexport interface DashboardAppSlice {\n panelDrawer?: PanelDrawer;\n openPanelDrawer: (panelDrawer: PanelDrawer) => void;\n closePanelDrawer: () => void;\n panelGroupDialog?: PanelGroupDialog;\n openPanelGroupDialog: (groupIndex?: number) => void;\n closePanelGroupDialog: () => void;\n}\n\nexport const createDashboardAppSlice = immer<DashboardAppSlice>((set) => ({\n openPanelDrawer: ({ groupIndex, panelKey }: PanelDrawer) =>\n set((state) => {\n state.panelDrawer = {\n groupIndex,\n panelKey,\n };\n }),\n closePanelDrawer: () =>\n set((state) => {\n state.panelDrawer = undefined;\n }),\n openPanelGroupDialog: (groupIndex?: number) =>\n set((state) => {\n state.panelGroupDialog = { groupIndex };\n }),\n closePanelGroupDialog: () =>\n set((state) => {\n state.panelGroupDialog = undefined;\n }),\n}));\n\nexport function useDashboardApp() {\n return useDashboardStore(\n ({\n panelDrawer,\n openPanelDrawer,\n closePanelDrawer,\n panelGroupDialog,\n openPanelGroupDialog,\n closePanelGroupDialog,\n }) => ({\n panelDrawer,\n openPanelDrawer,\n closePanelDrawer,\n panelGroupDialog,\n openPanelGroupDialog,\n closePanelGroupDialog,\n })\n );\n}\n"],"names":["immer","useDashboardStore","createDashboardAppSlice","set","openPanelDrawer","groupIndex","panelKey","state","panelDrawer","closePanelDrawer","undefined","openPanelGroupDialog","panelGroupDialog","closePanelGroupDialog","useDashboardApp"],"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,KAAK,QAAQ,0BAA0B,CAAC;AACjD,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AAmBxD,OAAO,MAAMC,uBAAuB,GAAGF,KAAK,CAAoB,CAACG,GAAG,GAAM,CAAA;QACxEC,eAAe,EAAE,CAAC,EAAEC,UAAU,CAAA,EAAEC,QAAQ,CAAA,EAAe,GACrDH,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACC,WAAW,GAAG;oBAClBH,UAAU;oBACVC,QAAQ;iBACT,CAAC;YACJ,CAAC,CAAC;QACJG,gBAAgB,EAAE,IAChBN,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACC,WAAW,GAAGE,SAAS,CAAC;YAChC,CAAC,CAAC;QACJC,oBAAoB,EAAE,CAACN,UAAmB,GACxCF,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACK,gBAAgB,GAAG;oBAAEP,UAAU;iBAAE,CAAC;YAC1C,CAAC,CAAC;QACJQ,qBAAqB,EAAE,IACrBV,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACK,gBAAgB,GAAGF,SAAS,CAAC;YACrC,CAAC,CAAC;KACL,CAAA,AAAC,CAAC,CAAC;AAEJ,OAAO,SAASI,eAAe,GAAG;IAChC,OAAOb,iBAAiB,CACtB,CAAC,EACCO,WAAW,CAAA,EACXJ,eAAe,CAAA,EACfK,gBAAgB,CAAA,EAChBG,gBAAgB,CAAA,EAChBD,oBAAoB,CAAA,EACpBE,qBAAqB,CAAA,IACtB,GAAM,CAAA;YACLL,WAAW;YACXJ,eAAe;YACfK,gBAAgB;YAChBG,gBAAgB;YAChBD,oBAAoB;YACpBE,qBAAqB;SACtB,CAAA,AAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { StoreApi } from 'zustand';
|
|
3
|
-
import { DashboardSpec, LayoutDefinition, PanelDefinition } from '@perses-dev/core';
|
|
4
|
-
import { DashboardAppSlice } from './DashboardAppSlice';
|
|
5
|
-
import { LayoutsSlice } from './LayoutsSlice';
|
|
6
|
-
export interface DashboardStoreState extends DashboardAppSlice, LayoutsSlice {
|
|
7
|
-
dashboard: DashboardSpec;
|
|
8
|
-
layouts: LayoutDefinition[];
|
|
9
|
-
panels: Record<string, PanelDefinition>;
|
|
10
|
-
updatePanel: (name: string, panel: PanelDefinition, groupIndex?: number) => void;
|
|
11
|
-
isEditMode: boolean;
|
|
12
|
-
setEditMode: (isEditMode: boolean) => void;
|
|
13
|
-
}
|
|
14
|
-
export interface DashboardStoreProps {
|
|
15
|
-
dashboardSpec: DashboardSpec;
|
|
16
|
-
isEditMode?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface DashboardProviderProps {
|
|
19
|
-
initialState: DashboardStoreProps;
|
|
20
|
-
children?: React.ReactNode;
|
|
21
|
-
}
|
|
22
|
-
export declare function usePanels(): {
|
|
23
|
-
panels: Record<string, PanelDefinition<unknown>>;
|
|
24
|
-
updatePanel: (name: string, panel: PanelDefinition<unknown>, groupIndex?: number | undefined) => void;
|
|
25
|
-
};
|
|
26
|
-
export declare function useEditMode(): {
|
|
27
|
-
isEditMode: boolean;
|
|
28
|
-
setEditMode: (isEditMode: boolean) => void;
|
|
29
|
-
};
|
|
30
|
-
export declare function useDashboard(): {
|
|
31
|
-
dashboard: DashboardSpec;
|
|
32
|
-
};
|
|
33
|
-
export declare const DashboardContext: import("react").Context<StoreApi<DashboardStoreState> | undefined>;
|
|
34
|
-
export declare function useDashboardStore<T>(selector: (state: DashboardStoreState) => T): T;
|
|
35
|
-
export declare function DashboardProvider(props: DashboardProviderProps): JSX.Element;
|
|
36
|
-
//# sourceMappingURL=DashboardProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardProvider.d.ts","sourceRoot":"","sources":["../../src/context/DashboardProvider.tsx"],"names":[],"mappings":";AA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
|
|
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
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { createStore, useStore } from 'zustand';
|
|
15
|
-
import { immer } from 'zustand/middleware/immer';
|
|
16
|
-
import shallow from 'zustand/shallow';
|
|
17
|
-
import { createContext, useContext } from 'react';
|
|
18
|
-
import produce from 'immer';
|
|
19
|
-
import { createDashboardAppSlice } from './DashboardAppSlice';
|
|
20
|
-
import { createLayoutsSlice } from './LayoutsSlice';
|
|
21
|
-
export function usePanels() {
|
|
22
|
-
return useDashboardStore(({ panels , updatePanel })=>({
|
|
23
|
-
panels,
|
|
24
|
-
updatePanel
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
export function useEditMode() {
|
|
28
|
-
return useDashboardStore(({ isEditMode , setEditMode })=>({
|
|
29
|
-
isEditMode,
|
|
30
|
-
setEditMode
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
export function useDashboard() {
|
|
34
|
-
const selectDashboardSpec = (state)=>{
|
|
35
|
-
return produce(state.dashboard, (draftState)=>{
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
draftState.panels = state.panels;
|
|
38
|
-
draftState.layouts = state.layouts;
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const dashboard = useDashboardStore(selectDashboardSpec);
|
|
42
|
-
return {
|
|
43
|
-
dashboard
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export const DashboardContext = /*#__PURE__*/ createContext(undefined);
|
|
47
|
-
export function useDashboardStore(selector) {
|
|
48
|
-
const store = useContext(DashboardContext);
|
|
49
|
-
if (store === undefined) {
|
|
50
|
-
throw new Error('No DashboardContext found. Did you forget a Provider?');
|
|
51
|
-
}
|
|
52
|
-
return useStore(store, selector, shallow);
|
|
53
|
-
}
|
|
54
|
-
export function DashboardProvider(props) {
|
|
55
|
-
const { children , initialState: { dashboardSpec , isEditMode } , } = props;
|
|
56
|
-
const { layouts , panels } = dashboardSpec;
|
|
57
|
-
const dashboardStore = createStore()(immer((set, get, api)=>{
|
|
58
|
-
return {
|
|
59
|
-
...createDashboardAppSlice(set, get, api, []),
|
|
60
|
-
...createLayoutsSlice(set, get, api, []),
|
|
61
|
-
layouts,
|
|
62
|
-
panels,
|
|
63
|
-
dashboard: dashboardSpec,
|
|
64
|
-
updatePanel: (name, panel, groupIndex = 0)=>{
|
|
65
|
-
return set((state)=>{
|
|
66
|
-
// add new panel to layouts if panels[name] is undefined
|
|
67
|
-
if (state.panels[name] === undefined) {
|
|
68
|
-
var ref;
|
|
69
|
-
// find maximum y so new panel is added to the end of the grid
|
|
70
|
-
let maxY = 0;
|
|
71
|
-
(ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.items.forEach((layout)=>{
|
|
72
|
-
if (layout.y > maxY) {
|
|
73
|
-
maxY = layout.y;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
const panelLayout = {
|
|
77
|
-
x: 0,
|
|
78
|
-
y: maxY + 1,
|
|
79
|
-
width: 12,
|
|
80
|
-
height: 6,
|
|
81
|
-
content: {
|
|
82
|
-
$ref: `#/spec/panels/${name}`
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const layouts = state.layouts;
|
|
86
|
-
if (layouts && layouts[groupIndex]) {
|
|
87
|
-
var ref1;
|
|
88
|
-
(ref1 = layouts[groupIndex]) === null || ref1 === void 0 ? void 0 : ref1.spec.items.push(panelLayout);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
-
state.panels[name] = panel;
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
isEditMode: !!isEditMode,
|
|
96
|
-
setEditMode: (isEditMode)=>set({
|
|
97
|
-
isEditMode
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
}));
|
|
101
|
-
return /*#__PURE__*/ _jsx(DashboardContext.Provider, {
|
|
102
|
-
value: dashboardStore,
|
|
103
|
-
children: children
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
//# sourceMappingURL=DashboardProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/DashboardProvider.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 { createStore, useStore } from 'zustand';\nimport type { StoreApi } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport shallow from 'zustand/shallow';\nimport { createContext, useContext } from 'react';\nimport produce from 'immer';\nimport { DashboardSpec, GridItemDefinition, LayoutDefinition, PanelDefinition } from '@perses-dev/core';\nimport { DashboardAppSlice, createDashboardAppSlice } from './DashboardAppSlice';\nimport { LayoutsSlice, createLayoutsSlice } from './LayoutsSlice';\n\nexport interface DashboardStoreState extends DashboardAppSlice, LayoutsSlice {\n dashboard: DashboardSpec;\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n updatePanel: (name: string, panel: PanelDefinition, groupIndex?: number) => void;\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n}\n\nexport interface DashboardStoreProps {\n dashboardSpec: DashboardSpec;\n isEditMode?: boolean;\n}\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: React.ReactNode;\n}\n\nexport function usePanels() {\n return useDashboardStore(({ panels, updatePanel }) => ({ panels, updatePanel }));\n}\n\nexport function useEditMode() {\n return useDashboardStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));\n}\n\nexport function useDashboard() {\n const selectDashboardSpec = (state: DashboardStoreState) => {\n return produce(state.dashboard, (draftState) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n draftState.panels = state.panels as any;\n draftState.layouts = state.layouts;\n });\n };\n const dashboard = useDashboardStore(selectDashboardSpec);\n return { dashboard };\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T) {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStore(store, selector, shallow);\n}\n\nexport function DashboardProvider(props: DashboardProviderProps) {\n const {\n children,\n initialState: { dashboardSpec, isEditMode },\n } = props;\n\n const { layouts, panels } = dashboardSpec;\n\n const dashboardStore = createStore<DashboardStoreState>()(\n immer((set, get, api) => {\n return {\n ...(createDashboardAppSlice(set, get, api, []) as unknown as DashboardAppSlice),\n ...(createLayoutsSlice(set, get, api, []) as unknown as LayoutsSlice),\n layouts,\n panels,\n dashboard: dashboardSpec,\n updatePanel: (name: string, panel: PanelDefinition, groupIndex = 0) =>\n set((state) => {\n // add new panel to layouts if panels[name] is undefined\n if (state.panels[name] === undefined) {\n // find maximum y so new panel is added to the end of the grid\n let maxY = 0;\n state.layouts[groupIndex]?.spec.items.forEach((layout) => {\n if (layout.y > maxY) {\n maxY = layout.y;\n }\n });\n const panelLayout: GridItemDefinition = {\n x: 0,\n y: maxY + 1,\n width: 12,\n height: 6,\n content: { $ref: `#/spec/panels/${name}` },\n };\n const layouts = state.layouts;\n if (layouts && layouts[groupIndex]) {\n layouts[groupIndex]?.spec.items.push(panelLayout);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n state.panels[name] = panel as any;\n }),\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean) => set({ isEditMode }),\n };\n })\n );\n\n return (\n <DashboardContext.Provider value={dashboardStore as StoreApi<DashboardStoreState>}>\n {children}\n </DashboardContext.Provider>\n );\n}\n"],"names":["createStore","useStore","immer","shallow","createContext","useContext","produce","createDashboardAppSlice","createLayoutsSlice","usePanels","useDashboardStore","panels","updatePanel","useEditMode","isEditMode","setEditMode","useDashboard","selectDashboardSpec","state","dashboard","draftState","layouts","DashboardContext","undefined","selector","store","Error","DashboardProvider","props","children","initialState","dashboardSpec","dashboardStore","set","get","api","name","panel","groupIndex","maxY","spec","items","forEach","layout","y","panelLayout","x","width","height","content","$ref","push","Provider","value"],"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;AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,SAAS,CAAC;AAEhD,SAASC,KAAK,QAAQ,0BAA0B,CAAC;AACjD,OAAOC,OAAO,MAAM,iBAAiB,CAAC;AACtC,SAASC,aAAa,EAAEC,UAAU,QAAQ,OAAO,CAAC;AAClD,OAAOC,OAAO,MAAM,OAAO,CAAC;AAE5B,SAA4BC,uBAAuB,QAAQ,qBAAqB,CAAC;AACjF,SAAuBC,kBAAkB,QAAQ,gBAAgB,CAAC;AAoBlE,OAAO,SAASC,SAAS,GAAG;IAC1B,OAAOC,iBAAiB,CAAC,CAAC,EAAEC,MAAM,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAM,CAAA;YAAED,MAAM;YAAEC,WAAW;SAAE,C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F,MAAMf,OAAO,GAAGH,KAAK,CAACG,OAAO,AAAC;wBAC9B,IAAIA,OAAO,IAAIA,OAAO,CAACiB,UAAU,CAAC,EAAE;gCAClCjB,IAAmB;4BAAnBA,CAAAA,IAAmB,GAAnBA,OAAO,CAACiB,UAAU,CAAC,cAAnBjB,IAAmB,WAAM,GAAzBA,KAAAA,CAAyB,GAAzBA,IAAmB,CAAEmB,IAAI,CAACC,KAAK,CAACU,IAAI,CAACN,WAAW,CAAC,CAAC;wBACpD,CAAC;oBACH,CAAC;oBAED,8DAA8D;oBAC9D3B,KAAK,CAACP,MAAM,CAACyB,IAAI,CAAC,GAAGC,KAAK,AAAO,CAAC;gBACpC,CAAC,CAAC,CAAA;aAAA;YACJvB,UAAU,EAAE,CAAC,CAACA,UAAU;YACxBC,WAAW,EAAE,CAACD,UAAmB,GAAKmB,GAAG,CAAC;oBAAEnB,UAAU;iBAAE,CAAC;SAC1D,CAAC;IACJ,CAAC,CAAC,CACH,AAAC;IAEF,qBACE,KAACQ,gBAAgB,CAAC8B,QAAQ;QAACC,KAAK,EAAErB,cAAc;kBAC7CH,QAAQ;MACiB,CAC5B;AACJ,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { LayoutDefinition, GridItemDefinition } from '@perses-dev/core';
|
|
2
|
-
export interface LayoutsSlice {
|
|
3
|
-
updateLayout: (layout: LayoutDefinition, index?: number) => void;
|
|
4
|
-
addItemToLayout: (index: number, item: GridItemDefinition) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const createLayoutsSlice: import("zustand").StateCreator<LayoutsSlice, [], [["zustand/immer", never]], LayoutsSlice>;
|
|
7
|
-
export declare function useLayouts(): {
|
|
8
|
-
layouts: import("@perses-dev/core").GridDefinition[];
|
|
9
|
-
updateLayout: (layout: import("@perses-dev/core").GridDefinition, index?: number | undefined) => void;
|
|
10
|
-
addItemToLayout: (index: number, item: GridItemDefinition) => void;
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=LayoutsSlice.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutsSlice.d.ts","sourceRoot":"","sources":["../../src/context/LayoutsSlice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAIxE,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACpE;AAED,eAAO,MAAM,kBAAkB,4FAgB5B,CAAC;AAEJ,wBAAgB,UAAU;;;;EAMzB"}
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
import { immer } from 'zustand/middleware/immer';
|
|
14
|
-
import { useDashboardStore } from './DashboardProvider';
|
|
15
|
-
export const createLayoutsSlice = immer((set)=>{
|
|
16
|
-
return {
|
|
17
|
-
updateLayout: (layout, index)=>set((state)=>{
|
|
18
|
-
if (index === undefined) {
|
|
19
|
-
state.layouts.unshift(layout);
|
|
20
|
-
} else {
|
|
21
|
-
state.layouts[index] = layout;
|
|
22
|
-
}
|
|
23
|
-
}),
|
|
24
|
-
addItemToLayout: (index, item)=>{
|
|
25
|
-
return set((state)=>{
|
|
26
|
-
const layouts = state.layouts;
|
|
27
|
-
if (layouts && layouts[index]) {
|
|
28
|
-
var ref;
|
|
29
|
-
(ref = layouts[index]) === null || ref === void 0 ? void 0 : ref.spec.items.push(item);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
export function useLayouts() {
|
|
36
|
-
return useDashboardStore(({ layouts , updateLayout , addItemToLayout })=>({
|
|
37
|
-
layouts,
|
|
38
|
-
updateLayout,
|
|
39
|
-
addItemToLayout
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=LayoutsSlice.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/LayoutsSlice.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 { LayoutDefinition, GridItemDefinition } from '@perses-dev/core';\nimport { immer } from 'zustand/middleware/immer';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\n\nexport interface LayoutsSlice {\n updateLayout: (layout: LayoutDefinition, index?: number) => void;\n addItemToLayout: (index: number, item: GridItemDefinition) => void;\n}\n\nexport const createLayoutsSlice = immer<LayoutsSlice>((set) => ({\n updateLayout: (layout: LayoutDefinition, index?: number) =>\n set((state) => {\n if (index === undefined) {\n (state as DashboardStoreState).layouts.unshift(layout);\n } else {\n (state as DashboardStoreState).layouts[index] = layout;\n }\n }),\n addItemToLayout: (index: number, item: GridItemDefinition) =>\n set((state) => {\n const layouts = (state as DashboardStoreState).layouts;\n if (layouts && layouts[index]) {\n layouts[index]?.spec.items.push(item);\n }\n }),\n}));\n\nexport function useLayouts() {\n return useDashboardStore(({ layouts, updateLayout, addItemToLayout }) => ({\n layouts,\n updateLayout,\n addItemToLayout,\n }));\n}\n"],"names":["immer","useDashboardStore","createLayoutsSlice","set","updateLayout","layout","index","state","undefined","layouts","unshift","addItemToLayout","item","spec","items","push","useLayouts"],"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,KAAK,QAAQ,0BAA0B,CAAC;AACjD,SAA8BC,iBAAiB,QAAQ,qBAAqB,CAAC;AAO7E,OAAO,MAAMC,kBAAkB,GAAGF,KAAK,CAAe,CAACG,GAAG;IAAM,OAAA;QAC9DC,YAAY,EAAE,CAACC,MAAwB,EAAEC,KAAc,GACrDH,GAAG,CAAC,CAACI,KAAK,GAAK;gBACb,IAAID,KAAK,KAAKE,SAAS,EAAE;oBACvB,AAACD,KAAK,CAAyBE,OAAO,CAACC,OAAO,CAACL,MAAM,CAAC,CAAC;gBACzD,OAAO;oBACL,AAACE,KAAK,CAAyBE,OAAO,CAACH,KAAK,CAAC,GAAGD,MAAM,CAAC;gBACzD,CAAC;YACH,CAAC,CAAC;QACJM,eAAe,EAAE,CAACL,KAAa,EAAEM,IAAwB;YACvDT,OAAAA,GAAG,CAAC,CAACI,KAAK,GAAK;gBACb,MAAME,OAAO,GAAG,AAACF,KAAK,CAAyBE,OAAO,AAAC;gBACvD,IAAIA,OAAO,IAAIA,OAAO,CAACH,KAAK,CAAC,EAAE;wBAC7BG,GAAc;oBAAdA,CAAAA,GAAc,GAAdA,OAAO,CAACH,KAAK,CAAC,cAAdG,GAAc,WAAM,GAApBA,KAAAA,CAAoB,GA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