@perses-dev/dashboards 0.15.0 → 0.17.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.
Files changed (86) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -12
  2. package/dist/cjs/components/DownloadButton/DownloadButton.js +109 -0
  3. package/dist/cjs/{utils/component-ids.js → components/DownloadButton/index.js} +11 -14
  4. package/dist/cjs/components/GridLayout/GridLayout.js +13 -2
  5. package/dist/cjs/components/GridLayout/GridTitle.js +11 -17
  6. package/dist/cjs/components/Panel/Panel.js +4 -2
  7. package/dist/cjs/components/Panel/PanelHeader.js +54 -50
  8. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -3
  9. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +23 -0
  10. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +3 -1
  11. package/dist/cjs/components/Variables/Variable.js +7 -46
  12. package/dist/cjs/components/Variables/VariableEditor.js +157 -126
  13. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +353 -161
  14. package/dist/cjs/components/Variables/VariableList.js +15 -8
  15. package/dist/cjs/components/Variables/variable-model.js +74 -0
  16. package/dist/cjs/components/index.js +1 -0
  17. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +40 -15
  18. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  19. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -1
  20. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  21. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  22. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  23. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  24. package/dist/components/DownloadButton/DownloadButton.d.ts +3 -0
  25. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -0
  26. package/dist/components/DownloadButton/DownloadButton.js +60 -0
  27. package/dist/components/DownloadButton/DownloadButton.js.map +1 -0
  28. package/dist/components/DownloadButton/index.d.ts +2 -0
  29. package/dist/components/DownloadButton/index.d.ts.map +1 -0
  30. package/dist/{utils/component-ids.js → components/DownloadButton/index.js} +2 -14
  31. package/dist/components/DownloadButton/index.js.map +1 -0
  32. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  33. package/dist/components/GridLayout/GridLayout.js +13 -2
  34. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  35. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  36. package/dist/components/GridLayout/GridTitle.js +11 -17
  37. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  38. package/dist/components/Panel/Panel.d.ts.map +1 -1
  39. package/dist/components/Panel/Panel.js +4 -2
  40. package/dist/components/Panel/Panel.js.map +1 -1
  41. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  42. package/dist/components/Panel/PanelHeader.js +54 -50
  43. package/dist/components/Panel/PanelHeader.js.map +1 -1
  44. package/dist/components/PanelDrawer/PanelDrawer.js +1 -3
  45. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  46. package/dist/components/PanelDrawer/PanelDrawer.test.js +23 -0
  47. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  48. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +4 -2
  49. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  50. package/dist/components/Variables/Variable.d.ts.map +1 -1
  51. package/dist/components/Variables/Variable.js +8 -47
  52. package/dist/components/Variables/Variable.js.map +1 -1
  53. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditor.js +159 -128
  55. package/dist/components/Variables/VariableEditor.js.map +1 -1
  56. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  57. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +315 -162
  58. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  59. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  60. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  61. package/dist/components/Variables/VariableList.js +15 -8
  62. package/dist/components/Variables/VariableList.js.map +1 -1
  63. package/dist/components/Variables/variable-model.d.ts +8 -0
  64. package/dist/components/Variables/variable-model.d.ts.map +1 -0
  65. package/dist/components/Variables/variable-model.js +64 -0
  66. package/dist/components/Variables/variable-model.js.map +1 -0
  67. package/dist/components/index.d.ts +1 -0
  68. package/dist/components/index.d.ts.map +1 -1
  69. package/dist/components/index.js +1 -0
  70. package/dist/components/index.js.map +1 -1
  71. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  72. package/dist/context/DashboardProvider/panel-editor-slice.js +40 -15
  73. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  74. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  75. package/dist/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  76. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  77. package/dist/context/DashboardProvider/panel-group-slice.d.ts +9 -0
  78. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  79. package/dist/context/DashboardProvider/panel-group-slice.js +17 -0
  80. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  81. package/dist/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  82. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  83. package/package.json +4 -4
  84. package/dist/utils/component-ids.d.ts +0 -8
  85. package/dist/utils/component-ids.d.ts.map +0 -1
  86. package/dist/utils/component-ids.js.map +0 -1
@@ -1 +1 @@
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,UAAU,CAAC;AAmClD,OAAO,MAAMC,2BAA2B,GAMpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAAEC,SAAS;QAE3BC,iBAAiB,EAAE,IAAM;YACvB,0BAA0B;YAC1B,MAAMC,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,KAAK;gBACXC,aAAa,EAAE;oBACbC,KAAK,EAAE,EAAE;oBACTC,WAAW,EAAE,KAAK;iBACnB;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjB,MAAMC,QAAQ,GAAyB;wBACrCC,EAAE,EAAEf,UAAU,EAAE;wBAChBgB,WAAW,EAAE,EAAE;w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,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
+ {"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 { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupId, addPanelGroup, createEmptyPanelGroup } 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 = createEmptyPanelGroup();\n newGroup.title = next.title;\n newGroup.isCollapsed = next.isCollapsed;\n set((draft) => {\n addPanelGroup(draft, newGroup);\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":["addPanelGroup","createEmptyPanelGroup","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","draft","close","openEditPanelGroup","panelGroupId","existingGroup","panelGroups","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;AAIjC,SAAwCA,aAAa,EAAEC,qBAAqB,QAAQ,qBAAqB,CAAC;AAkC1G,OAAO,MAAMC,2BAA2B,GAMpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAAEC,SAAS;QAE3BC,iBAAiB,EAAE,IAAM;YACvB,0BAA0B;YAC1B,MAAMC,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,KAAK;gBACXC,aAAa,EAAE;oBACbC,KAAK,EAAE,EAAE;oBACTC,WAAW,EAAE,KAAK;iBACnB;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjB,MAAMC,QAAQ,GAAGd,qBAAqB,EAAE,AAAC;oBACzCc,QAAQ,CAACJ,KAAK,GAAGG,IAAI,CAACH,KAAK,CAAC;oBAC5BI,QAAQ,CAACH,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACxCT,GAAG,CAAC,CAACa,KAAK,GAAK;wBACbhB,aAAa,CAACgB,KAAK,EAAED,QAAQ,CAAC,CAAC;oBACjC,CAAC,CAAC,CAAC;gBACL,CAAC;gBACDE,KAAK,IAAG;oBACNd,GAAG,CAAC,CAACa,KAAK,GAAK;wBACbA,KAAK,CAACX,gBAAgB,GAAGC,SAAS,CAAC;oBACrC,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,AAAC;YAEF,kBAAkB;YAClBH,GAAG,CAAC,CAACa,KAAK,GAAK;gBACbA,KAAK,CAACX,gBAAgB,GAAGG,MAAM,CAAC;YAClC,CAA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YAClC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAA,AAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { LayoutDefinition } from '@perses-dev/core';
2
+ import { WritableDraft } from 'immer/dist/internal';
2
3
  import { Layout } from 'react-grid-layout';
3
4
  import { StateCreator } from 'zustand';
4
5
  import { Middleware } from './common';
@@ -47,4 +48,12 @@ export interface PanelGroupItemId {
47
48
  */
48
49
  export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
49
50
  export declare function convertLayoutsToPanelGroups(layouts: LayoutDefinition[]): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'>;
51
+ /**
52
+ * Private helper function for creating an empty panel group.
53
+ */
54
+ export declare function createEmptyPanelGroup(): PanelGroupDefinition;
55
+ /**
56
+ * Private helper function that modifies panel group state to add a new panel
57
+ */
58
+ export declare function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void;
50
59
  //# sourceMappingURL=panel-group-slice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D"}
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,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAA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AC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,QAGlG"}
@@ -84,5 +84,22 @@ export function convertLayoutsToPanelGroups(layouts) {
84
84
  panelGroupOrder: panelGroupIdOrder
85
85
  };
86
86
  }
87
+ /**
88
+ * Private helper function for creating an empty panel group.
89
+ */ export function createEmptyPanelGroup() {
90
+ return {
91
+ id: generateId(),
92
+ title: undefined,
93
+ isCollapsed: false,
94
+ itemLayouts: [],
95
+ itemPanelKeys: {}
96
+ };
97
+ }
98
+ /**
99
+ * Private helper function that modifies panel group state to add a new panel
100
+ */ export function addPanelGroup(draft, newGroup) {
101
+ draft.panelGroups[newGroup.id] = newGroup;
102
+ draft.panelGroupOrder.unshift(newGroup.id);
103
+ }
87
104
 
88
105
  //# sourceMappingURL=panel-group-slice.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,QAA0B,kBAAkB,CAAC;AAGxE,SAASC,UAAU,QAAoB,UAAU,CAAC;AA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B,GAA7BA,QAAAA,GAAmB,CAAEiB,QAAQ,6BAAA,GAA7BjB,KAAAA,CAA6B,QAAEkB,IAAI,AAAN,CAAA,KAAW,KAAK;YAC1DC,KAAK,EAAEnB,CAAAA,IAAmB,GAAnBA,MAAM,CAACG,IAAI,CAACa,OAAO,cAAnBhB,IAAmB,WAAO,GAA1BA,KAAAA,CAA0B,GAA1BA,IAAmB,CAAEmB,KAAK;YACjCtB,WAAW;YACXI,aAAa;SACd,CAAC;QACFF,iBAAiB,CAACQ,IAAI,CAACX,YAAY,CAAC,CAAC;IACvC,CAAC;IACD,OAAO;QACLd,WAAW;QACXC,eAAe,EAAEgB,iBAAiB;KACnC,CAAC;AACJ,CAAC"}
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 { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition) {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelG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
38
  it('should delete panel', ()=>{
39
39
  renderDashboard();
40
- const panel = screen.getByText('CPU');
41
- userEvent.hover(panel);
42
- const deletePanelButton = screen.getByLabelText('delete panel');
40
+ const panelTitle = 'CPU';
41
+ const deletePanelButton = screen.getByLabelText(`delete panel ${panelTitle}`);
43
42
  userEvent.click(deletePanelButton);
44
43
  screen.getByText('Delete Panel');
45
44
  const deleteButton = screen.getByText('Delete');
46
45
  userEvent.click(deleteButton);
47
46
  // The panel should disappear
48
- const deletedPanel = screen.queryByText('CPU');
47
+ const deletedPanel = screen.queryByText(panelTitle);
49
48
  expect(deletedPanel).not.toBeInTheDocument();
50
49
  });
51
50
  it('should only delete panel from panel group if panel is not referenced more than once', ()=>{
52
51
  renderDashboard();
53
- const panels = screen.getAllByText('Disk I/O Utilization');
52
+ const panelTitle = 'Disk I/O Utilization';
53
+ const panels = screen.getAllByText(panelTitle);
54
54
  expect(panels).toHaveLength(2);
55
- const panel = panels[0];
56
- if (panel === undefined) throw new Error('Missing panel');
57
- userEvent.hover(panel);
58
- const deletePanelButton = screen.getByLabelText('delete panel');
55
+ const deletePanelButton = screen.getAllByLabelText(`delete panel ${panelTitle}`)[0];
56
+ if (deletePanelButton === undefined) throw new Error('Missing delete button');
59
57
  userEvent.click(deletePanelButton);
60
58
  screen.getByText('Delete Panel');
61
59
  const deleteButton = screen.getByText('Delete');
62
60
  userEvent.click(deleteButton);
63
61
  // The deleted panel should still be on screen in the other group
64
- const deletedPanel = screen.queryByText('Disk I/O Utilization');
62
+ const deletedPanel = screen.queryByText(panelTitle);
65
63
  expect(deletedPanel).toBeInTheDocument();
66
64
  });
67
65
  it('should swap panels', ()=>{
68
66
  renderDashboard();
69
67
  // should move panel down
70
- const group1 = screen.getByText('CPU Stats');
71
- userEvent.hover(group1);
72
- const moveGroupDownBtn = screen.getByLabelText('move group down');
68
+ const groupTitle1 = 'CPU Stats';
69
+ const moveGroupDownBtn = screen.getByLabelText(`move group ${groupTitle1} down`);
73
70
  userEvent.click(moveGroupDownBtn);
74
- userEvent.unhover(moveGroupDownBtn);
75
71
  // should move panel up
76
- const group2 = screen.getByText('Disk Stats');
77
- userEvent.hover(group2);
78
- const moveGroupUpBtn = screen.getByLabelText('move group up');
72
+ const groupTitle2 = 'Disk Stats';
73
+ const moveGroupUpBtn = screen.getByLabelText(`move group ${groupTitle2} up`);
79
74
  userEvent.click(moveGroupUpBtn);
80
75
  /* TODO: Figure out how to test this visually without coupling to the store
81
76
  const layouts = storeApi.getState().layouts;
@@ -85,15 +80,14 @@ describe('Panel Groups', ()=>{
85
80
  */ });
86
81
  it('should delete a panel group', ()=>{
87
82
  renderDashboard();
88
- const group = screen.getByText('CPU Stats');
89
- userEvent.hover(group);
90
- const deleteGroupIcon = screen.getByLabelText('delete group');
83
+ const groupTitle = 'CPU Stats';
84
+ const deleteGroupIcon = screen.getByLabelText(`delete group ${groupTitle}`);
91
85
  userEvent.click(deleteGroupIcon);
92
86
  screen.getByText('Delete Panel Group');
93
87
  const deleteButton = screen.getByText('Delete');
94
88
  userEvent.click(deleteButton);
95
89
  // should remove group
96
- const deletedGroup = screen.queryByText('CPU Stats');
90
+ const deletedGroup = screen.queryByText(groupTitle);
97
91
  expect(deletedGroup).not.toBeInTheDocument();
98
92
  // CPU panel should be completely gone since it wasn't in any other group
99
93
  let panel = screen.queryByText('CPU');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/views/ViewDashboard/tests/panelGroups.test.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 { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { DashboardProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';\nimport { getTestDashboard, renderWithContext } from '../../../test';\nimport { DashboardApp } from '../DashboardApp';\n\ndescribe('Panel Groups', () => {\n const renderDashboard = () => {\n renderWithContext(\n <TimeRangeProvider initialTimeRange={{ pastDuration: '30m' }}>\n <TemplateVariableProvider>\n <DashboardProvider initialState={{ dashboardResource: getTestDashboard(), isEditMode: true }}>\n <DashboardApp dashboardResource={getTestDashboard()} />\n </DashboardProvider>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n );\n };\n it('should delete panel', () => {\n renderDashboard();\n const panel = screen.getByText('CPU');\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The panel should disappear\n const deletedPanel = screen.queryByText('CPU');\n expect(deletedPanel).not.toBeInTheDocument();\n });\n\n it('should only delete panel from panel group if panel is not referenced more than once', () => {\n renderDashboard();\n\n const panels = screen.getAllByText('Disk I/O Utilization');\n expect(panels).toHaveLength(2);\n\n const panel = panels[0];\n if (panel === undefined) throw new Error('Missing panel');\n\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The deleted panel should still be on screen in the other group\n const deletedPanel = screen.queryByText('Disk I/O Utilization');\n expect(deletedPanel).toBeInTheDocument();\n });\n\n it('should swap panels', () => {\n renderDashboard();\n\n // should move panel down\n const group1 = screen.getByText('CPU Stats');\n userEvent.hover(group1);\n const moveGroupDownBtn = screen.getByLabelText('move group down');\n userEvent.click(moveGroupDownBtn);\n userEvent.unhover(moveGroupDownBtn);\n\n // should move panel up\n const group2 = screen.getByText('Disk Stats');\n userEvent.hover(group2);\n const moveGroupUpBtn = screen.getByLabelText('move group up');\n userEvent.click(moveGroupUpBtn);\n\n /* TODO: Figure out how to test this visually without coupling to the store\n const layouts = storeApi.getState().layouts;\n expect(layouts[0]?.title).toBe(undefined);\n expect(layouts[1]?.title).toBe('Disk Stats');\n expect(layouts[2]?.title).toBe('CPU Stats');\n */\n });\n\n it('should delete a panel group', () => {\n renderDashboard();\n const group = screen.getByText('CPU Stats');\n userEvent.hover(group);\n const deleteGroupIcon = screen.getByLabelText('delete group');\n userEvent.click(deleteGroupIcon);\n screen.getByText('Delete Panel Group');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // should remove group\n const deletedGroup = screen.queryByText('CPU Stats');\n expect(deletedGroup).not.toBeInTheDocument();\n\n // CPU panel should be completely gone since it wasn't in any other group\n let panel = screen.queryByText('CPU');\n expect(panel).not.toBeInTheDocument();\n\n // A DiskIO panel should still be present in the other group that wasn't deleted\n panel = screen.queryByText('Disk I/O Utilization');\n expect(panel).toBeInTheDocument();\n });\n});\n"],"names":["screen","userEvent","DashboardProvider","TemplateVariableProvider","TimeRangeProvider","getTestDashboard","renderWithContext","DashboardApp","describe","renderDashboard","initialTimeRange","pastDuration","initialState","dashboardResource","isEditMode","it","panel","getByText","hover","deletePanelButton","getByLabelText","click","deleteButton","deletedPanel","queryByText","expect","not","toBeInTheDocument","panels","getAllByText","toHaveLength","undefined","Error","group1","moveGroupDownBtn","unhover","group2","moveGroupUpBtn","group","deleteGroupIcon","deletedGroup"],"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,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,iBAAiB,EAAEC,wBAAwB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AAClG,SAASC,g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EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../../src/views/ViewDashboard/tests/panelGroups.test.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 { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { DashboardProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';\nimport { getTestDashboard, renderWithContext } from '../../../test';\nimport { DashboardApp } from '../DashboardApp';\n\ndescribe('Panel Groups', () => {\n const renderDashboard = () => {\n renderWithContext(\n <TimeRangeProvider initialTimeRange={{ pastDuration: '30m' }}>\n <TemplateVariableProvider>\n <DashboardProvider initialState={{ dashboardResource: getTestDashboard(), isEditMode: true }}>\n <DashboardApp dashboardResource={getTestDashboard()} />\n </DashboardProvider>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n );\n };\n it('should delete panel', () => {\n renderDashboard();\n const panelTitle = 'CPU';\n const deletePanelButton = screen.getByLabelText(`delete panel ${panelTitle}`);\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The panel should disappear\n const deletedPanel = screen.queryByText(panelTitle);\n expect(deletedPanel).not.toBeInTheDocument();\n });\n\n it('should only delete panel from panel group if panel is not referenced more than once', () => {\n renderDashboard();\n\n const panelTitle = 'Disk I/O Utilization';\n const panels = screen.getAllByText(panelTitle);\n expect(panels).toHaveLength(2);\n\n const deletePanelButton = screen.getAllByLabelText(`delete panel ${panelTitle}`)[0];\n if (deletePanelButton === undefined) throw new Error('Missing delete button');\n\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The deleted panel should still be on screen in the other group\n const deletedPanel = screen.queryByText(panelTitle);\n expect(deletedPanel).toBeInTheDocument();\n });\n\n it('should swap panels', () => {\n renderDashboard();\n\n // should move panel down\n const groupTitle1 = 'CPU Stats';\n const moveGroupDownBtn = screen.getByLabelText(`move group ${groupTitle1} down`);\n userEvent.click(moveGroupDownBtn);\n\n // should move panel up\n const groupTitle2 = 'Disk Stats';\n const moveGroupUpBtn = screen.getByLabelText(`move group ${groupTitle2} up`);\n userEvent.click(moveGroupUpBtn);\n\n /* TODO: Figure out how to test this visually without coupling to the store\n const layouts = storeApi.getState().layouts;\n expect(layouts[0]?.title).toBe(undefined);\n expect(layouts[1]?.title).toBe('Disk Stats');\n expect(layouts[2]?.title).toBe('CPU Stats');\n */\n });\n\n it('should delete a panel group', () => {\n renderDashboard();\n const groupTitle = 'CPU Stats';\n const deleteGroupIcon = screen.getByLabelText(`delete group ${groupTitle}`);\n userEvent.click(deleteGroupIcon);\n screen.getByText('Delete Panel Group');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // should remove group\n const deletedGroup = screen.queryByText(groupTitle);\n expect(deletedGroup).not.toBeInTheDocument();\n\n // CPU panel should be completely gone since it wasn't in any other group\n let panel = screen.queryByText('CPU');\n expect(panel).not.toBeInTheDocument();\n\n // A DiskIO panel should still be present in the other group that wasn't deleted\n panel = screen.queryByText('Disk I/O Utilization');\n expect(panel).toBeInTheDocument();\n });\n});\n"],"names":["screen","userEvent","DashboardProvider","TemplateVariableProvider","TimeRangeProvider","getTestDashboard","renderWithContext","DashboardApp","describe","renderDashboard","initialTimeRange","pastDuration","initialState","dashboardResource","isEditMode","it","panelTitle","deletePanelButton","getByLabelText","click","getByText","deleteButton","deletedPanel","queryByText","expect","not","toBeInTheDocument","panels","getAllByText","toHaveLength","getAllByLabelText","undefined","Error","groupTitle1","moveGroupDownBtn","groupTitle2","moveGroupUpBtn","groupTitle","deleteGroupIcon","deletedGroup","panel"],"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,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,iBAAiB,EAAEC,wBAAwB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AAClG,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,eAAe,CAAC;AACpE,SAASC,YAAY,QAAQ,iBAAiB,CAAC;AAE/CC,QAAQ,CAAC,cAAc,EAAE,IAAM;IAC7B,MAAMC,eAAe,GAAG,IAAM;QAC5BH,iBAAiB,eACf,KAACF,iBAAiB;YAACM,gBAAgB,EAAE;gBAAEC,YAAY,EAAE,KAAK;aAAE;sBAC1D,cAAA,KAACR,wBAAwB;0BACvB,cAAA,KAACD,iBAAiB;oBAACU,YAAY,EAAE;wBAAEC,iBAAiB,EAAER,gBAAgB,EAAE;wBAAES,UAAU,EAAE,IAAI;qBAAE;8BAC1F,cAAA,KAACP,YAAY;wBAACM,iBAAiB,EAAER,gBAAgB,EAAE;sBAAI;kBACrC;cACK;UACT,CACrB,CAAC;IACJ,CAAC,AAAC;IACFU,EAAE,CAAC,qBAAqB,EAAE,IAAM;QAC9BN,eAAe,EAAE,CAAC;QAClB,MAAMO,UAAU,GAAG,KAAK,AAAC;QACzB,MAAMC,iBAAiB,GAAGjB,MAAM,CAACkB,cAAc,CAAC,CAAC,aAAa,EAAEF,UAAU,CAAC,CAAC,CAAC,AAAC;QAC9Ef,SAAS,CAACkB,KAAK,CAACF,iBAAiB,CAAC,CAAC;QACnCjB,MAAM,CAACo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C,CAACf,GAAG,CAACC,iBAAiB,EAAE,CAAC;QAEtC,gFAAgF;QAChFc,KAAK,GAAGxC,MAAM,CAACuB,WAAW,CAAC,sBAAsB,CAAC,CAAC;QACnDC,MAAM,CAACgB,KAAK,CAAC,CAACd,iBAAiB,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/dashboards",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "The dashboards feature in Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -28,9 +28,9 @@
28
28
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
29
29
  },
30
30
  "dependencies": {
31
- "@perses-dev/components": "^0.15.0",
32
- "@perses-dev/core": "^0.15.0",
33
- "@perses-dev/plugin-system": "^0.15.0",
31
+ "@perses-dev/components": "^0.17.0",
32
+ "@perses-dev/core": "^0.17.0",
33
+ "@perses-dev/plugin-system": "^0.17.0",
34
34
  "@types/react-grid-layout": "^1.3.2",
35
35
  "date-fns": "^2.28.0",
36
36
  "immer": "^9.0.15",
@@ -1,8 +0,0 @@
1
- declare global {
2
- var useIdValue: number;
3
- }
4
- /**
5
- * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
6
- */
7
- export declare function useId(prefix: string): string;
8
- //# sourceMappingURL=component-ids.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"component-ids.d.ts","sourceRoot":"","sources":["../../src/utils/component-ids.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,UAAU,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,UAUnC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/component-ids.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 { useRef } from 'react';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var useIdValue: number;\n}\n\n/**\n * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.\n */\nexport function useId(prefix: string) {\n if (globalThis.useIdValue === undefined) {\n globalThis.useIdValue = 0;\n }\n\n const id = useRef<string | undefined>(undefined);\n if (id.current === undefined) {\n id.current = `${prefix}-${globalThis.useIdValue++}`;\n }\n return id.current;\n}\n"],"names":["useRef","useId","prefix","globalThis","useIdValue","undefined","id","current"],"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,MAAM,QAAQ,OAAO,CAAC;AAO/B;;CAEC,GACD,OAAO,SAASC,KAAK,CAACC,MAAc,EAAE;IACpC,IAAIC,UAAU,CAACC,UAAU,KAAKC,SAAS,EAAE;QACvCF,UAAU,CAACC,UAAU,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,MAAME,EAAE,GAAGN,MAAM,CAAqBK,SAAS,CAAC,AAAC;IACjD,IAAIC,EAAE,CAACC,OAAO,KAAKF,SAAS,EAAE;QAC5BC,EAAE,CAACC,OAAO,GAAG,CAAC,EAAEL,MAAM,CAAC,CAAC,EAAEC,UAAU,CAACC,UAAU,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,OAAOE,EAAE,CAACC,OAAO,CAAC;AACpB,CAAC"}