@perses-dev/dashboards 0.22.0 → 0.23.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 (126) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -0
  2. package/dist/cjs/components/DeletePanelDialog/DeletePanelDialog.js +8 -30
  3. package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +1 -0
  4. package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -0
  5. package/dist/cjs/components/GridLayout/GridItemContent.js +2 -1
  6. package/dist/cjs/components/GridLayout/GridLayout.js +4 -7
  7. package/dist/cjs/components/Panel/Panel.js +4 -5
  8. package/dist/cjs/components/Panel/Panel.test.js +10 -2
  9. package/dist/cjs/components/Panel/PanelContent.js +2 -1
  10. package/dist/cjs/components/Panel/PanelHeader.js +17 -0
  11. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
  12. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +2 -2
  13. package/dist/cjs/components/Variables/EditVariablesButton.js +1 -0
  14. package/dist/cjs/components/Variables/VariableEditor.js +1 -1
  15. package/dist/cjs/components/Variables/VariableList.js +8 -2
  16. package/dist/cjs/{utils/functions.js → constants/grid-layout-config.js} +13 -5
  17. package/dist/cjs/constants/index.js +1 -0
  18. package/dist/cjs/constants/user-interface-text.js +2 -0
  19. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +27 -2
  20. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +6 -4
  21. package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +62 -0
  22. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +8 -37
  23. package/dist/cjs/context/useDashboard.js +4 -2
  24. package/dist/cjs/utils/index.js +1 -1
  25. package/dist/cjs/utils/panelUtils.js +168 -0
  26. package/dist/cjs/utils/panelUtils.test.js +195 -0
  27. package/dist/cjs/views/ViewDashboard/DashboardApp.js +4 -1
  28. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +4 -2
  29. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  30. package/dist/components/DashboardToolbar/DashboardToolbar.js +3 -0
  31. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  32. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -1
  33. package/dist/components/DeletePanelDialog/DeletePanelDialog.js +7 -24
  34. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -1
  35. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +1 -0
  36. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  37. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -0
  38. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  39. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  40. package/dist/components/GridLayout/GridItemContent.js +2 -1
  41. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  42. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  43. package/dist/components/GridLayout/GridLayout.js +4 -7
  44. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  45. package/dist/components/Panel/Panel.d.ts.map +1 -1
  46. package/dist/components/Panel/Panel.js +5 -6
  47. package/dist/components/Panel/Panel.js.map +1 -1
  48. package/dist/components/Panel/Panel.test.js +10 -2
  49. package/dist/components/Panel/Panel.test.js.map +1 -1
  50. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  51. package/dist/components/Panel/PanelContent.js +2 -1
  52. package/dist/components/Panel/PanelContent.js.map +1 -1
  53. package/dist/components/Panel/PanelHeader.d.ts +1 -0
  54. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  55. package/dist/components/Panel/PanelHeader.js +17 -0
  56. package/dist/components/Panel/PanelHeader.js.map +1 -1
  57. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
  58. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  59. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +2 -2
  60. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  61. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  62. package/dist/components/Variables/EditVariablesButton.js +1 -0
  63. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  64. package/dist/components/Variables/VariableEditor.js +1 -1
  65. package/dist/components/Variables/VariableEditor.js.map +1 -1
  66. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  67. package/dist/components/Variables/VariableList.js +8 -2
  68. package/dist/components/Variables/VariableList.js.map +1 -1
  69. package/dist/constants/grid-layout-config.d.ts +6 -0
  70. package/dist/constants/grid-layout-config.d.ts.map +1 -0
  71. package/dist/{utils/functions.js → constants/grid-layout-config.js} +5 -3
  72. package/dist/constants/grid-layout-config.js.map +1 -0
  73. package/dist/constants/index.d.ts +1 -0
  74. package/dist/constants/index.d.ts.map +1 -1
  75. package/dist/constants/index.js +1 -0
  76. package/dist/constants/index.js.map +1 -1
  77. package/dist/constants/user-interface-text.d.ts +2 -0
  78. package/dist/constants/user-interface-text.d.ts.map +1 -1
  79. package/dist/constants/user-interface-text.js +2 -0
  80. package/dist/constants/user-interface-text.js.map +1 -1
  81. package/dist/context/DashboardProvider/DashboardProvider.d.ts +6 -4
  82. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  83. package/dist/context/DashboardProvider/DashboardProvider.js +28 -3
  84. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  85. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -0
  86. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  87. package/dist/context/DashboardProvider/dashboard-provider-api.js +6 -4
  88. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  89. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +19 -0
  90. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -0
  91. package/dist/context/DashboardProvider/duplicate-panel-slice.js +58 -0
  92. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -0
  93. package/dist/context/DashboardProvider/index.d.ts +1 -1
  94. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  95. package/dist/context/DashboardProvider/index.js.map +1 -1
  96. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +4 -0
  97. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  98. package/dist/context/DashboardProvider/panel-editor-slice.js +6 -35
  99. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  100. package/dist/context/useDashboard.d.ts.map +1 -1
  101. package/dist/context/useDashboard.js +4 -2
  102. package/dist/context/useDashboard.js.map +1 -1
  103. package/dist/utils/index.d.ts +1 -1
  104. package/dist/utils/index.d.ts.map +1 -1
  105. package/dist/utils/index.js +1 -1
  106. package/dist/utils/index.js.map +1 -1
  107. package/dist/utils/panelUtils.d.ts +27 -0
  108. package/dist/utils/panelUtils.d.ts.map +1 -0
  109. package/dist/utils/panelUtils.js +174 -0
  110. package/dist/utils/panelUtils.js.map +1 -0
  111. package/dist/utils/panelUtils.test.d.ts +2 -0
  112. package/dist/utils/panelUtils.test.d.ts.map +1 -0
  113. package/dist/utils/panelUtils.test.js +193 -0
  114. package/dist/utils/panelUtils.test.js.map +1 -0
  115. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  116. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  117. package/dist/views/ViewDashboard/DashboardApp.js +4 -1
  118. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  119. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -0
  120. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  121. package/dist/views/ViewDashboard/ViewDashboard.js +4 -2
  122. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  123. package/package.json +4 -4
  124. package/dist/utils/functions.d.ts +0 -2
  125. package/dist/utils/functions.d.ts.map +0 -1
  126. package/dist/utils/functions.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardResource, GridDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupId, useDashboardStore } from './DashboardProvider';\nimport { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';\n\nexport function useDashboard() {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n metadata,\n setDashboard: setDashboardResource,\n } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, defaultTimeRange, setDashboard, metadata }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n setDashboard,\n metadata,\n }));\n const { setVariableDefinitions } = useTemplateVariableActions();\n const variables = useTemplateVariableDefinitions();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata,\n spec: {\n panels,\n layouts,\n variables,\n duration: defaultTimeRange.pastDuration,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource) => {\n setVariableDefinitions(dashboardResource.spec.variables);\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title) {\n display = {\n title,\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useTemplateVariableActions","useTemplateVariableDefinitions","useDashboard","panels","panelGroups","panelGroupOrder","defaultTimeRange","metadata","setDashboard","setDashboardResource","setVariableDefinitions","variables","layouts","convertPanelGroupsToLayouts","dashboard","kind","spec","duration","pastDuration","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","itemLayouts","itemPanelKeys","display","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"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,cAAc,QAA2C,kBAAkB,CAAC;AACrF,SAA6CC,iBAAiB,QAAQ,qBAAqB,CAAC;AAC5F,SAASC,0BAA0B,EAAEC,8BAA8B,QAAQ,4BAA4B,CAAC;AAExG,OAAO,SAASC,YAAY,GAAG;IAC7B,MAAM,EACJC,MAAM,CAAA,EACNC,WAAW,CAAA,EACXC,eAAe,CAAA,EACfC,gBAAgB,CAAA,EAChBC,QAAQ,CAAA,EACRC,YAAY,EAAEC,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,WAAW,CAAA,EAAEC,WAAW,CAAA,EAAEC,aAAa,CAAA,EAAE,GAAGN,KAAK,AAAC;QACjE,IAAIO,OAAO,GAAGN,SAAS,AAAC;QACxB,IAAIE,KAAK,EAAE;YACTI,OAAO,GAAG;gBACRJ,KAAK;gBACLK,QAAQ,EAAE;oBACRC,IAAI,EAAE,CAACL,WAAW;iBACnB;aACF,CAAC;QACJ,CAAC;QACD,MAAMM,MAAM,GAAmB;YAC7BjB,IAAI,EAAE,MAAM;YACZC,IAAI,EAAE;gBACJa,OAAO;gBACPI,KAAK,EAAEN,WAAW,CAACP,GAAG,CAAC,CAACY,MAAM,GAAK;oBACjC,MAAME,QAAQ,GAAGN,aAAa,CAACI,MAAM,CAACG,CAAC,CAAC,AAAC;oBACzC,IAAID,QAAQ,KAAKX,SAAS,EAAE;wBAC1B,MAAM,IAAIC,KAAK,CAAC,CAAC,4BAA4B,EAAEQ,MAAM,CAACG,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC7D,CAAC;oBACD,OAAO;wBACLC,CAAC,EAAEJ,MAAM,CAACI,CAAC;wBACXC,CAAC,EAAEL,MAAM,CAACK,CAAC;wBACXC,KAAK,EAAEN,MAAM,CAACO,CAAC;wBACfC,MAAM,EAAER,MAAM,CAACS,CAAC;wBAChBC,OAAO,EAAE5C,cAAc,CAACoC,QAAQ,CAAC;qBAClC,CAAC;gBACJ,CAAC,CAAC;aACH;SACF,AAAC;QACFtB,OAAO,CAAC+B,IAAI,CAACX,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAOpB,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardResource, GridDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupId, useDashboardStore } from './DashboardProvider';\nimport { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';\n\nexport function useDashboard() {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n setDashboard: setDashboardResource,\n metadata,\n display,\n } = useDashboardStore(\n ({ panels, panelGroups, panelGroupOrder, defaultTimeRange, setDashboard, metadata, display }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n setDashboard,\n metadata,\n display,\n })\n );\n const { setVariableDefinitions } = useTemplateVariableActions();\n const variables = useTemplateVariableDefinitions();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata,\n spec: {\n display,\n panels,\n layouts,\n variables,\n duration: defaultTimeRange.pastDuration,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource) => {\n setVariableDefinitions(dashboardResource.spec.variables);\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title) {\n display = {\n title,\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useTemplateVariableActions","useTemplateVariableDefinitions","useDashboard","panels","panelGroups","panelGroupOrder","defaultTimeRange","setDashboard","setDashboardResource","metadata","display","setVariableDefinitions","variables","layouts","convertPanelGroupsToLayouts","dashboard","kind","spec","duration","pastDuration","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","itemLayouts","itemPanelKeys","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"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,cAAc,QAA2C,kBAAkB,CAAC;AACrF,SAA6CC,iBAAiB,QAAQ,qBAAqB,CAAC;AAC5F,SAASC,0BAA0B,EAAEC,8BAA8B,QAAQ,4BAA4B,CAAC;AAExG,OAAO,SAASC,YAAY,GAAG;IAC7B,MAAM,EACJC,MAAM,CAAA,EACNC,WAAW,CAAA,EACXC,eAAe,CAAA,EACfC,gBAAgB,CAAA,EAChBC,YAAY,EAAEC,oBAAoB,CAAA,EAClCC,QAAQ,CAAA,EACRC,OAAO,CAAA,IACR,GAAGX,iBAAiB,CACnB,CAAC,EAAEI,MAAM,CAAA,EAAEC,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAEC,gBAAgB,CAAA,EAAEC,YAAY,CAAA,EAAEE,QAAQ,CAAA,EAAEC,OAAO,CAAA,EAAE,GAAM,CAAA;YAChGP,MAAM;YACNC,WAAW;YACXC,eAAe;YACfC,gBAAgB;YAChBC,YAAY;YACZE,QAAQ;YACRC,OAAO;SACR,CAAA,AAAC,CACH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MAAM,GAAmB;YAC7BhB,IAAI,EAAE,MAAM;YACZC,IAAI,EAAE;gBACJP,OAAO;gBACPuB,KAAK,EAAEL,WAAW,CAACP,GAAG,CAAC,CAACW,MAAM,GAAK;oBACjC,MAAME,QAAQ,GAAGL,aAAa,CAACG,MAAM,CAACG,CAAC,CAAC,AAAC;oBACzC,IAAID,QAAQ,KAAKV,SAAS,EAAE;wBAC1B,MAAM,IAAIC,KAAK,CAAC,CAAC,4BAA4B,EAAEO,MAAM,CAACG,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC7D,CAAC;oBACD,OAAO;wBACLC,CAAC,EAAEJ,MAAM,CAACI,CAAC;wBACXC,CAAC,EAAEL,MAAM,CAACK,CAAC;wBACXC,KAAK,EAAEN,MAAM,CAACO,CAAC;wBACfC,MAAM,EAAER,MAAM,CAACS,CAAC;wBAChBC,OAAO,EAAE5C,cAAc,CAACoC,QAAQ,CAAC;qBAClC,CAAC;gBACJ,CAAC,CAAC;aACH;SACF,AAAC;QACFrB,OAAO,CAAC8B,IAAI,CAACX,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAOnB,OAAO,CAAC;AACjB,CAAC"}
@@ -1,2 +1,2 @@
1
- export * from './functions';
1
+ export * from './panelUtils';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC"}
@@ -10,6 +10,6 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export * from './functions';
13
+ export * from './panelUtils';
14
14
 
15
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './functions';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './panelUtils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { PanelDefinition } from '@perses-dev/core';
2
+ import { PanelGroupDefinition, PanelGroupItemLayout } from '../context';
3
+ export declare function getYForNewRow(group: PanelGroupDefinition): number;
4
+ export declare type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' | 'y'>;
5
+ /**
6
+ * Inserts a new panel into the layout with placement determined by a specified
7
+ * reference panel. The new panel is placed:
8
+ * - To the right of the reference panel if there is space available without
9
+ * moving other panels.
10
+ * - Otherwise, directly below the reference panel. If other panels are below
11
+ * this location, they will also shift downward because the grid uses
12
+ * vertical-based compacting.
13
+ *
14
+ * @param newLayout - Layout for new panel to insert into the grid.
15
+ * @param referenceLayout - Layout for reference panel used to determine the
16
+ * placement of the new panel.
17
+ * @param itemLayouts - Full grid layout.
18
+ * @returns - Item layouts modified to insert the new panel.
19
+ */
20
+ export declare function insertPanelInLayout(newLayout: UnpositionedPanelGroupItemLayout, referenceLayout: PanelGroupItemLayout, itemLayouts: PanelGroupItemLayout[]): PanelGroupItemLayout[];
21
+ /**
22
+ * Get a valid panel key, where a valid key:
23
+ * - does not include invalid characters
24
+ * - is unique
25
+ */
26
+ export declare function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string;
27
+ //# sourceMappingURL=panelUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panelUtils.d.ts","sourceRoot":"","sources":["../../src/utils/panelUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,UASxD;AA8BD,oBAAY,gCAAgC,GAAG,IAAI,CAAC,oBAAoB,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gCAAgC,EAC3C,eAAe,EAAE,oBAAoB,EACrC,WAAW,EAAE,oBAAoB,EAAE,GAClC,oBAAoB,EAAE,CAyExB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,MAAM,CASlG"}
@@ -0,0 +1,174 @@
1
+ // Copyright 2023 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 { GRID_LAYOUT_SMALL_BREAKPOINT, GRID_LAYOUT_COLS } from '../constants';
14
+ // Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present
15
+ export function getYForNewRow(group) {
16
+ let newRowY = 0;
17
+ for (const layout of group.itemLayouts){
18
+ const itemMaxY = layout.y + layout.h;
19
+ if (itemMaxY > newRowY) {
20
+ newRowY = itemMaxY;
21
+ }
22
+ }
23
+ return newRowY;
24
+ }
25
+ function getPanelBounds({ x , y , w , h }) {
26
+ return {
27
+ x1: x,
28
+ x2: x + w,
29
+ y1: y,
30
+ y2: y + h
31
+ };
32
+ }
33
+ /**
34
+ * Inserts a new panel into the layout with placement determined by a specified
35
+ * reference panel. The new panel is placed:
36
+ * - To the right of the reference panel if there is space available without
37
+ * moving other panels.
38
+ * - Otherwise, directly below the reference panel. If other panels are below
39
+ * this location, they will also shift downward because the grid uses
40
+ * vertical-based compacting.
41
+ *
42
+ * @param newLayout - Layout for new panel to insert into the grid.
43
+ * @param referenceLayout - Layout for reference panel used to determine the
44
+ * placement of the new panel.
45
+ * @param itemLayouts - Full grid layout.
46
+ * @returns - Item layouts modified to insert the new panel.
47
+ */ export function insertPanelInLayout(newLayout, referenceLayout, itemLayouts) {
48
+ const MAX_LAYOUT_WIDTH = GRID_LAYOUT_COLS[GRID_LAYOUT_SMALL_BREAKPOINT];
49
+ const referenceBounds = getPanelBounds(referenceLayout);
50
+ // Organize layouts based on vertical relation to the item being inserted
51
+ // after.
52
+ const aboveInsertRow = [];
53
+ const insertRow = [];
54
+ const belowInsertRow = [];
55
+ itemLayouts.forEach((itemLayout)=>{
56
+ const itemBounds = getPanelBounds(itemLayout);
57
+ if (itemBounds.y2 <= referenceBounds.y1) {
58
+ aboveInsertRow.push(itemLayout);
59
+ } else if (itemBounds.y1 >= referenceBounds.y2) {
60
+ belowInsertRow.push(itemLayout);
61
+ } else {
62
+ insertRow.push(itemLayout);
63
+ }
64
+ });
65
+ // Cannot safely assume that the order of item layouts array is strictly
66
+ // left to right. Sorting the row by horizontal position to more easily find
67
+ // gaps.
68
+ insertRow.sort((a, b)=>a.x - b.x);
69
+ const insertAfterIndex = insertRow.findIndex((item)=>item.i === referenceLayout.i);
70
+ if (insertAfterIndex === insertRow.length - 1) {
71
+ // Insert to the right when space is available and the reference is the last
72
+ // item in the row.
73
+ if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {
74
+ return [
75
+ ...aboveInsertRow,
76
+ ...insertRow,
77
+ {
78
+ ...newLayout,
79
+ x: referenceBounds.x2,
80
+ y: referenceBounds.y1
81
+ },
82
+ ...belowInsertRow
83
+ ];
84
+ }
85
+ } else if (insertAfterIndex >= 0) {
86
+ const nextItem = insertRow[insertAfterIndex + 1];
87
+ if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {
88
+ // Insert to the right when space is available between the reference and
89
+ // the next item in the row.
90
+ insertRow.splice(insertAfterIndex + 1, 0, {
91
+ ...newLayout,
92
+ x: referenceBounds.x2,
93
+ y: referenceBounds.y1
94
+ });
95
+ return [
96
+ ...aboveInsertRow,
97
+ ...insertRow,
98
+ ...belowInsertRow
99
+ ];
100
+ }
101
+ }
102
+ // Insert the new item below the original and shift the items below the
103
+ // row where the reference is located.
104
+ return [
105
+ ...aboveInsertRow,
106
+ ...insertRow,
107
+ {
108
+ x: referenceBounds.x1,
109
+ y: referenceBounds.y2,
110
+ ...newLayout
111
+ },
112
+ ...belowInsertRow.map((itemLayout)=>{
113
+ // Note: the grid will not necessarily display all of these items shifted
114
+ // all the way down because of vertical compacting, but shifing their
115
+ // y position ensures the new item gets vertical precedence over items
116
+ // below it in that compacting.
117
+ return {
118
+ ...itemLayout,
119
+ y: itemLayout.y + newLayout.h
120
+ };
121
+ })
122
+ ];
123
+ }
124
+ /**
125
+ * Get a valid panel key, where a valid key:
126
+ * - does not include invalid characters
127
+ * - is unique
128
+ */ export function getValidPanelKey(panelKey, panels) {
129
+ const uniquePanelKeys = getUniquePanelKeys(panels);
130
+ let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;
131
+ const matchingKey = uniquePanelKeys[normalizedPanelKey];
132
+ if (typeof matchingKey === 'number') {
133
+ normalizedPanelKey += `-${matchingKey + 1}`;
134
+ }
135
+ return normalizedPanelKey;
136
+ }
137
+ const removeWhiteSpaces = (str)=>{
138
+ return str.replace(/\s+/g, '');
139
+ };
140
+ /**
141
+ * Breaks the specified panel key into the name and the optional `-number` used
142
+ * for deduping panels with the same name.
143
+ */ function getPanelKeyParts(panelKey) {
144
+ const parts = panelKey.match(/(.+)-([0-9]+)/);
145
+ if (parts && parts[1] && parts[2]) {
146
+ return {
147
+ name: parts[1],
148
+ number: parseInt(parts[2], 10)
149
+ };
150
+ }
151
+ return {
152
+ name: panelKey
153
+ };
154
+ }
155
+ // Find all the unique panel keys and the largest number used for each.
156
+ // ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
157
+ function getUniquePanelKeys(panels) {
158
+ const uniquePanelKeys = {};
159
+ Object.keys(panels).forEach((panelKey)=>{
160
+ const { name , number } = getPanelKeyParts(panelKey);
161
+ if (uniquePanelKeys[name] === undefined) {
162
+ uniquePanelKeys[name] = 0;
163
+ }
164
+ const currentValue = uniquePanelKeys[name];
165
+ if (typeof currentValue === 'number' && number) {
166
+ // Check for the maximum value because we cannot rely on a sequential
167
+ // set of numbers when panels are modified.
168
+ uniquePanelKeys[name] = Math.max(currentValue, number);
169
+ }
170
+ });
171
+ return uniquePanelKeys;
172
+ }
173
+
174
+ //# sourceMappingURL=panelUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/panelUtils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupItemLayout } from '../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT, GRID_LAYOUT_COLS } from '../constants';\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nexport function getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n\ntype PanelGroupItemBounds = {\n /**\n * Left horizontal position.\n */\n x1: number;\n /**\n * Right horizontal position.\n */\n x2: number;\n /**\n * Top vertical position.\n */\n y1: number;\n /**\n * Bottom vertical position\n */\n y2: number;\n};\n\nfunction getPanelBounds({ x, y, w, h }: PanelGroupItemLayout): PanelGroupItemBounds {\n return {\n x1: x,\n x2: x + w,\n y1: y,\n y2: y + h,\n };\n}\n\nexport type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' | 'y'>;\n\n/**\n * Inserts a new panel into the layout with placement determined by a specified\n * reference panel. The new panel is placed:\n * - To the right of the reference panel if there is space available without\n * moving other panels.\n * - Otherwise, directly below the reference panel. If other panels are below\n * this location, they will also shift downward because the grid uses\n * vertical-based compacting.\n *\n * @param newLayout - Layout for new panel to insert into the grid.\n * @param referenceLayout - Layout for reference panel used to determine the\n * placement of the new panel.\n * @param itemLayouts - Full grid layout.\n * @returns - Item layouts modified to insert the new panel.\n */\nexport function insertPanelInLayout(\n newLayout: UnpositionedPanelGroupItemLayout,\n referenceLayout: PanelGroupItemLayout,\n itemLayouts: PanelGroupItemLayout[]\n): PanelGroupItemLayout[] {\n const MAX_LAYOUT_WIDTH = GRID_LAYOUT_COLS[GRID_LAYOUT_SMALL_BREAKPOINT];\n\n const referenceBounds = getPanelBounds(referenceLayout);\n\n // Organize layouts based on vertical relation to the item being inserted\n // after.\n const aboveInsertRow: PanelGroupItemLayout[] = [];\n const insertRow: PanelGroupItemLayout[] = [];\n const belowInsertRow: PanelGroupItemLayout[] = [];\n itemLayouts.forEach((itemLayout) => {\n const itemBounds = getPanelBounds(itemLayout);\n\n if (itemBounds.y2 <= referenceBounds.y1) {\n aboveInsertRow.push(itemLayout);\n } else if (itemBounds.y1 >= referenceBounds.y2) {\n belowInsertRow.push(itemLayout);\n } else {\n insertRow.push(itemLayout);\n }\n });\n\n // Cannot safely assume that the order of item layouts array is strictly\n // left to right. Sorting the row by horizontal position to more easily find\n // gaps.\n insertRow.sort((a, b) => a.x - b.x);\n const insertAfterIndex = insertRow.findIndex((item) => item.i === referenceLayout.i);\n\n if (insertAfterIndex === insertRow.length - 1) {\n // Insert to the right when space is available and the reference is the last\n // item in the row.\n if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {\n return [\n ...aboveInsertRow,\n ...insertRow,\n {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n },\n ...belowInsertRow,\n ];\n }\n } else if (insertAfterIndex >= 0) {\n const nextItem = insertRow[insertAfterIndex + 1];\n\n if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {\n // Insert to the right when space is available between the reference and\n // the next item in the row.\n insertRow.splice(insertAfterIndex + 1, 0, {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n });\n\n return [...aboveInsertRow, ...insertRow, ...belowInsertRow];\n }\n }\n\n // Insert the new item below the original and shift the items below the\n // row where the reference is located.\n return [\n ...aboveInsertRow,\n ...insertRow,\n { x: referenceBounds.x1, y: referenceBounds.y2, ...newLayout },\n ...belowInsertRow.map((itemLayout) => {\n // Note: the grid will not necessarily display all of these items shifted\n // all the way down because of vertical compacting, but shifing their\n // y position ensures the new item gets vertical precedence over items\n // below it in that compacting.\n return { ...itemLayout, y: itemLayout.y + newLayout.h };\n }),\n ];\n}\n\n/**\n * Get a valid panel key, where a valid key:\n * - does not include invalid characters\n * - is unique\n */\nexport function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string {\n const uniquePanelKeys = getUniquePanelKeys(panels);\n let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;\n\n const matchingKey = uniquePanelKeys[normalizedPanelKey];\n if (typeof matchingKey === 'number') {\n normalizedPanelKey += `-${matchingKey + 1}`;\n }\n return normalizedPanelKey;\n}\n\ntype PanelKeyParts = {\n name: string;\n number?: number;\n};\n\nconst removeWhiteSpaces = (str: string) => {\n return str.replace(/\\s+/g, '');\n};\n\n/**\n * Breaks the specified panel key into the name and the optional `-number` used\n * for deduping panels with the same name.\n */\nfunction getPanelKeyParts(panelKey: string): PanelKeyParts {\n const parts = panelKey.match(/(.+)-([0-9]+)/);\n if (parts && parts[1] && parts[2]) {\n return {\n name: parts[1],\n number: parseInt(parts[2], 10),\n };\n }\n\n return {\n name: panelKey,\n };\n}\n\n// Find all the unique panel keys and the largest number used for each.\n// ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name\nfunction getUniquePanelKeys(panels: Record<string, PanelDefinition>): Record<string, number> {\n const uniquePanelKeys: Record<string, number> = {};\n Object.keys(panels).forEach((panelKey) => {\n const { name, number } = getPanelKeyParts(panelKey);\n if (uniquePanelKeys[name] === undefined) {\n uniquePanelKeys[name] = 0;\n }\n const currentValue = uniquePanelKeys[name];\n if (typeof currentValue === 'number' && number) {\n // Check for the maximum value because we cannot rely on a sequential\n // set of numbers when panels are modified.\n uniquePanelKeys[name] = Math.max(currentValue, number);\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["GRID_LAYOUT_SMALL_BREAKPOINT","GRID_LAYOUT_COLS","getYForNewRow","group","newRowY","layout","itemLayouts","itemMaxY","y","h","getPanelBounds","x","w","x1","x2","y1","y2","insertPanelInLayout","newLayout","referenceLayout","MAX_LAYOUT_WIDTH","referenceBounds","aboveInsertRow","insertRow","belowInsertRow","forEach","itemLayout","itemBounds","push","sort","a","b","insertAfterIndex","findIndex","item","i","length","nextItem","splice","map","getValidPanelKey","panelKey","panels","uniquePanelKeys","getUniquePanelKeys","normalizedPanelKey","getPanelKeyParts","removeWhiteSpaces","name","matchingKey","str","replace","parts","match","number","parseInt","Object","keys","undefined","currentValue","Math","max"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,4BAA4B,EAAEC,gBAAgB,QAAQ,cAAc,CAAC;AAE9E,yHAAyH;AACzH,OAAO,SAASC,aAAa,CAACC,KAA2B,EAAE;IACzD,IAAIC,OAAO,GAAG,CAAC,AAAC;IAChB,KAAK,MAAMC,MAAM,IAAIF,KAAK,CAACG,WAAW,CAAE;QACtC,MAAMC,QAAQ,GAAGF,MAAM,CAACG,CAAC,GAAGH,MAAM,CAACI,CAAC,AAAC;QACrC,IAAIF,QAAQ,GAAGH,OAAO,EAAE;YACtBA,OAAO,GAAGG,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOH,OAAO,CAAC;AACjB,CAAC;AAq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AAI,EAAEP,QAAQ;KACf,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,0FAA0F;AAC1F,SAASG,kBAAkB,CAACF,MAAuC,EAA0B;IAC3F,MAAMC,eAAe,GAA2B,EAAE,AAAC;IACnDa,MAAM,CAACC,IAAI,CAACf,MAAM,CAAC,CAACjB,OAAO,CAAC,CAACgB,QAAQ,GAAK;QACxC,MAAM,EAAEO,IAAI,CAAA,EAAEM,MAAM,CAAA,EAAE,GAAGR,gBAAgB,CAACL,QAAQ,CAAC,AAAC;QACpD,IAAIE,eAAe,CAACK,IAAI,CAAC,KAAKU,SAAS,EAAE;YACvCf,eAAe,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;QACD,MAAMW,YAAY,GAAGhB,eAAe,CAACK,IAAI,CAAC,AAAC;QAC3C,IAAI,OAAOW,YAAY,KAAK,QAAQ,IAAIL,MAAM,EAAE;YAC9C,qEAAqE;YACrE,2CAA2C;YAC3CX,eAAe,CAACK,IAAI,CAAC,GAAGY,IAAI,CAACC,GAAG,CAACF,YAAY,EAAEL,MAAM,CAAC,CAAC;QACzD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAOX,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=panelUtils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panelUtils.test.d.ts","sourceRoot":"","sources":["../../src/utils/panelUtils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,193 @@
1
+ // Copyright 2023 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 { getValidPanelKey, insertPanelInLayout } from './panelUtils';
14
+ describe('insertPanelInLayout', ()=>{
15
+ describe('inserts the panel to the right when space is available', ()=>{
16
+ test('with a single panel in that row', ()=>{
17
+ const newLayout = {
18
+ i: 'abc',
19
+ w: 10,
20
+ h: 8
21
+ };
22
+ const referenceLayout = {
23
+ i: 'one',
24
+ x: 0,
25
+ y: 0,
26
+ w: 6,
27
+ h: 6
28
+ };
29
+ const layouts = [
30
+ referenceLayout
31
+ ];
32
+ expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([
33
+ referenceLayout,
34
+ {
35
+ x: 6,
36
+ y: 0,
37
+ ...newLayout
38
+ }
39
+ ]);
40
+ });
41
+ test('with multiple panels in that row with space between them', ()=>{
42
+ const newLayout = {
43
+ i: 'abc',
44
+ w: 10,
45
+ h: 8
46
+ };
47
+ const referenceLayout = {
48
+ i: 'one',
49
+ x: 0,
50
+ y: 0,
51
+ w: 3,
52
+ h: 4
53
+ };
54
+ const otherPanelInRow = {
55
+ i: 'two',
56
+ x: 20,
57
+ y: 0,
58
+ w: 4,
59
+ h: 4
60
+ };
61
+ const layouts = [
62
+ referenceLayout,
63
+ otherPanelInRow
64
+ ];
65
+ expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([
66
+ referenceLayout,
67
+ {
68
+ x: 3,
69
+ y: 0,
70
+ ...newLayout
71
+ },
72
+ otherPanelInRow
73
+ ]);
74
+ });
75
+ });
76
+ describe('inserts the panel below when space is not available to the right', ()=>{
77
+ test('with a single panel in the initial layout', ()=>{
78
+ const newLayout = {
79
+ i: 'abc',
80
+ w: 10,
81
+ h: 8
82
+ };
83
+ const referenceLayout = {
84
+ i: 'one',
85
+ x: 1,
86
+ y: 0,
87
+ w: 18,
88
+ h: 4
89
+ };
90
+ const layouts = [
91
+ referenceLayout
92
+ ];
93
+ expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([
94
+ referenceLayout,
95
+ {
96
+ x: 1,
97
+ y: 4,
98
+ ...newLayout
99
+ }
100
+ ]);
101
+ });
102
+ test('with a single panel in the same row and additional panels below', ()=>{
103
+ const newLayout = {
104
+ i: 'abc',
105
+ w: 10,
106
+ h: 8
107
+ };
108
+ const referenceLayout = {
109
+ i: 'one',
110
+ x: 0,
111
+ y: 0,
112
+ w: 18,
113
+ h: 4
114
+ };
115
+ const nextRowItem = {
116
+ i: 'two',
117
+ x: 0,
118
+ y: 4,
119
+ w: 6,
120
+ h: 6
121
+ };
122
+ const layouts = [
123
+ referenceLayout,
124
+ nextRowItem
125
+ ];
126
+ expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([
127
+ referenceLayout,
128
+ {
129
+ x: 0,
130
+ y: 4,
131
+ ...newLayout
132
+ },
133
+ {
134
+ ...nextRowItem,
135
+ y: nextRowItem.y + newLayout.h
136
+ }
137
+ ]);
138
+ });
139
+ });
140
+ });
141
+ describe('getValidPanelKey', ()=>{
142
+ test('removes whitespace', ()=>{
143
+ expect(getValidPanelKey('my panel name', {})).toBe('mypanelname');
144
+ });
145
+ test('does not include a counter if the key is not in use', ()=>{
146
+ const mockPanelDefs = {
147
+ alreadyInUse: {
148
+ kind: 'Panel',
149
+ spec: {}
150
+ }
151
+ };
152
+ expect(getValidPanelKey('newPanelName', mockPanelDefs)).toBe('newPanelName');
153
+ });
154
+ test('includes a counter if the key is already in use', ()=>{
155
+ const mockPanelDefs = {
156
+ alreadyInUse: {
157
+ kind: 'Panel',
158
+ spec: {}
159
+ }
160
+ };
161
+ expect(getValidPanelKey('alreadyInUse', mockPanelDefs)).toBe('alreadyInUse-1');
162
+ });
163
+ test('includes an incremented counter if the key is already in use multiple times', ()=>{
164
+ const mockPanelDefs = {
165
+ popularKey: {
166
+ kind: 'Panel',
167
+ spec: {}
168
+ },
169
+ 'popularKey-1': {
170
+ kind: 'Panel',
171
+ spec: {}
172
+ }
173
+ };
174
+ expect(getValidPanelKey('popularKey', mockPanelDefs)).toBe('popularKey-2');
175
+ expect(getValidPanelKey('popularKey-1', mockPanelDefs)).toBe('popularKey-2');
176
+ });
177
+ test('does not duplicate counters when they are out of order', ()=>{
178
+ const mockPanelDefs = {
179
+ outoforder: {
180
+ kind: 'Panel',
181
+ spec: {}
182
+ },
183
+ 'outoforder-2': {
184
+ kind: 'Panel',
185
+ spec: {}
186
+ }
187
+ };
188
+ expect(getValidPanelKey('outoforder', mockPanelDefs)).toBe('outoforder-3');
189
+ expect(getValidPanelKey('outoforder-2', mockPanelDefs)).toBe('outoforder-3');
190
+ });
191
+ });
192
+
193
+ //# sourceMappingURL=panelUtils.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/panelUtils.test.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition } from '@perses-dev/core';\nimport { PanelGroupItemLayout } from '../context';\nimport { getValidPanelKey, insertPanelInLayout, UnpositionedPanelGroupItemLayout } from './panelUtils';\n\ndescribe('insertPanelInLayout', () => {\n describe('inserts the panel to the right when space is available', () => {\n test('with a single panel in that row', () => {\n const newLayout: UnpositionedPanelGroupItemLayout = { i: 'abc', w: 10, h: 8 };\n const referenceLayout: PanelGroupItemLayout = {\n i: 'one',\n x: 0,\n y: 0,\n w: 6,\n h: 6,\n };\n const layouts: PanelGroupItemLayout[] = [referenceLayout];\n expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([\n referenceLayout,\n {\n x: 6,\n y: 0,\n ...newLayout,\n },\n ]);\n });\n\n test('with multiple panels in that row with space between them', () => {\n const newLayout: UnpositionedPanelGroupItemLayout = { i: 'abc', w: 10, h: 8 };\n const referenceLayout: PanelGroupItemLayout = {\n i: 'one',\n x: 0,\n y: 0,\n w: 3,\n h: 4,\n };\n const otherPanelInRow: PanelGroupItemLayout = {\n i: 'two',\n x: 20,\n y: 0,\n w: 4,\n h: 4,\n };\n const layouts: PanelGroupItemLayout[] = [referenceLayout, otherPanelInRow];\n\n expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([\n referenceLayout,\n {\n x: 3,\n y: 0,\n ...newLayout,\n },\n otherPanelInRow,\n ]);\n });\n });\n\n describe('inserts the panel below when space is not available to the right', () => {\n test('with a single panel in the initial layout', () => {\n const newLayout: UnpositionedPanelGroupItemLayout = { i: 'abc', w: 10, h: 8 };\n const referenceLayout: PanelGroupItemLayout = {\n i: 'one',\n x: 1,\n y: 0,\n w: 18,\n h: 4,\n };\n const layouts: PanelGroupItemLayout[] = [referenceLayout];\n expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([\n referenceLayout,\n {\n x: 1,\n y: 4,\n ...newLayout,\n },\n ]);\n });\n\n test('with a single panel in the same row and additional panels below', () => {\n const newLayout: UnpositionedPanelGroupItemLayout = { i: 'abc', w: 10, h: 8 };\n const referenceLayout: PanelGroupItemLayout = {\n i: 'one',\n x: 0,\n y: 0,\n w: 18,\n h: 4,\n };\n const nextRowItem: PanelGroupItemLayout = {\n i: 'two',\n x: 0,\n y: 4,\n w: 6,\n h: 6,\n };\n const layouts: PanelGroupItemLayout[] = [referenceLayout, nextRowItem];\n\n expect(insertPanelInLayout(newLayout, referenceLayout, layouts)).toEqual([\n referenceLayout,\n {\n x: 0,\n y: 4,\n ...newLayout,\n },\n {\n ...nextRowItem,\n y: nextRowItem.y + newLayout.h,\n },\n ]);\n });\n });\n});\n\ndescribe('getValidPanelKey', () => {\n test('removes whitespace', () => {\n expect(getValidPanelKey('my panel name', {})).toBe('mypanelname');\n });\n\n test('does not include a counter if the key is not in use', () => {\n const mockPanelDefs = {\n alreadyInUse: {\n kind: 'Panel',\n spec: {},\n } as PanelDefinition,\n };\n expect(getValidPanelKey('newPanelName', mockPanelDefs)).toBe('newPanelName');\n });\n\n test('includes a counter if the key is already in use', () => {\n const mockPanelDefs = {\n alreadyInUse: {\n kind: 'Panel',\n spec: {},\n } as PanelDefinition,\n };\n expect(getValidPanelKey('alreadyInUse', mockPanelDefs)).toBe('alreadyInUse-1');\n });\n\n test('includes an incremented counter if the key is already in use multiple times', () => {\n const mockPanelDefs = {\n popularKey: {\n kind: 'Panel',\n spec: {},\n } as PanelDefinition,\n 'popularKey-1': {\n kind: 'Panel',\n spec: {},\n } as PanelDefinition,\n };\n expect(getValidPanelKey('popularKey', mockPanelDefs)).toBe('popularKey-2');\n expect(getValidPanelKey('popularKey-1', mockPanelDefs)).toBe('popularKey-2');\n });\n\n test('does not duplicate counters when they are out of order', () => {\n const mockPanelDefs = {\n outoforder: {\n kind: 'Panel',\n spec: {},\n } as PanelDefinition,\n 'outoforder-2': {\n kind: 'Panel',\n spec: {},\n } as PanelDefinition,\n };\n expect(getValidPanelKey('outoforder', mockPanelDefs)).toBe('outoforder-3');\n expect(getValidPanelKey('outoforder-2', mockPanelDefs)).toBe('outoforder-3');\n });\n});\n"],"names":["getValidPanelKey","insertPanelInLayout","describe","test","newLayout","i","w","h","referenceLayout","x","y","layouts","expect","toEqual","otherPanelInRow","nextRowItem","toBe","mockPanelDefs","alreadyInUse","kind","spec","popularKey","outoforder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,gBAAgB,EAAEC,mBAAmB,QAA0C,cAAc,CAAC;AAEvGC,QAAQ,CAAC,qBAAqB,EAAE,IAAM;IACpCA,QAAQ,CAAC,wDAAwD,EAAE,IAAM;QACv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C,cAAc,EAAEiB,aAAa,CAAC,CAAC,CAACD,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IAEHb,IAAI,CAAC,6EAA6E,EAAE,IAAM;QACxF,MAAMc,aAAa,GAAG;YACpBI,UAAU,EAAE;gBACVF,IAAI,EAAE,OAAO;gBACbC,IAAI,EAAE,EAAE;aACT;YACD,cAAc,EAAE;gBACdD,IAAI,EAAE,OAAO;gBACbC,IAAI,EAAE,EAAE;aACT;SACF,AAAC;QACFR,MAAM,CAACZ,gBAAgB,CAAC,YAAY,EAAEiB,aAAa,CAAC,CAAC,CAACD,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3EJ,MAAM,CAACZ,gBAAgB,CAAC,cAAc,EAAEiB,aAAa,CAAC,CAAC,CAACD,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IAEHb,IAAI,CAAC,wDAAwD,EAAE,IAAM;QACnE,MAAMc,aAAa,GAAG;YACpBK,UAAU,EAAE;gBACVH,IAAI,EAAE,OAAO;gBACbC,IAAI,EAAE,EAAE;aACT;YACD,cAAc,EAAE;gBACdD,IAAI,EAAE,OAAO;gBACbC,IAAI,EAAE,EAAE;aACT;SACF,AAAC;QACFR,MAAM,CAACZ,gBAAgB,CAAC,YAAY,EAAEiB,aAAa,CAAC,CAAC,CAACD,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3EJ,MAAM,CAACZ,gBAAgB,CAAC,cAAc,EAAEiB,aAAa,CAAC,CAAC,CAACD,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -4,6 +4,7 @@ export interface DashboardAppProps {
4
4
  dashboardResource: DashboardResource;
5
5
  dashboardTitleComponent?: JSX.Element;
6
6
  onSave?: (entity: DashboardResource) => Promise<DashboardResource>;
7
+ onDiscard?: (entity: DashboardResource) => void;
7
8
  initialVariableIsSticky?: boolean;
8
9
  isReadonly: boolean;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnE,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,gBAsEpD,CAAC"}
1
+ {"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAChD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,gBAyEpD,CAAC"}
@@ -17,7 +17,7 @@ import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
17
17
  import { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog, DiscardChangesConfirmationDialog, DashboardToolbar, DeletePanelDialog } from '../../components';
18
18
  import { useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';
19
19
  export const DashboardApp = (props)=>{
20
- const { dashboardResource , dashboardTitleComponent , onSave , initialVariableIsSticky , isReadonly } = props;
20
+ const { dashboardResource , dashboardTitleComponent , onSave , onDiscard , initialVariableIsSticky , isReadonly } = props;
21
21
  const { setEditMode } = useEditMode();
22
22
  const { dashboard , setDashboard } = useDashboard();
23
23
  const [originalDashboard, setOriginalDashboard] = useState(undefined);
@@ -29,6 +29,9 @@ export const DashboardApp = (props)=>{
29
29
  }
30
30
  setEditMode(false);
31
31
  closeDiscardChangesConfirmationDialog();
32
+ if (onDiscard) {
33
+ onDiscard(dashboard);
34
+ }
32
35
  };
33
36
  const onEditButtonClick = ()=>{
34
37
  setEditMode(true);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright 2023 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 { useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport {\n PanelDrawer,\n Dashboard,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n} from '../../components';\nimport { useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n dashboardTitleComponent?: JSX.Element;\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n}\n\nexport const DashboardApp = (props: DashboardAppProps) => {\n const { dashboardResource, dashboardTitleComponent, onSave, initialVariableIsSticky, isReadonly } = props;\n const { setEditMode } = useEditMode();\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = () => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n };\n\n const onEditButtonClick = () => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n };\n\n const onCancelButtonClick = () => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={initialVariableIsSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ padding: (theme) => theme.spacing(2) }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard />\n </ErrorBoundary>\n <PanelDrawer />\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DiscardChangesConfirmationDialog />\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ErrorAlert","ErrorBoundary","PanelDrawer","Dashboard","PanelGroupDialog","DeletePanelGroupDialog","DiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","DashboardApp","props","dashboardResource","dashboardTitleComponent","onSave","initialVariableIsSticky","isReadonly","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","onEditButtonClick","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","metadata","name","padding","theme","spacing","FallbackComponent"],"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,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAwB,CAAC;AAEnE,SACEC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,sBAAsB,EACtBC,gCAAgC,EAChCC,gBAAgB,EAChBC,iBAAiB,QACZ,kBAAkB,CAAC;AAC1B,SAASC,YAAY,EAAEC,mCAAmC,EAAEC,WAAW,QAAQ,eAAe,CAAC;AAU/F,OAAO,MAAMC,YAAY,GAAG,CAACC,KAAwB,GAAK;IACxD,MAAM,EAAEC,iBAAiB,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,MAAM,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGL,KAAK,AAAC;IAC1G,MAAM,EAAEM,WAAW,CAAA,EAAE,GAAGR,WAAW,EAAE,AAAC;IACtC,MAAM,EAAES,SAAS,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGZ,YAAY,EAAE,AAAC;IACnD,MAAM,CAACa,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGzB,QAAQ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AAEA,UAAU;gBACtBU,iBAAiB,EAAEA,iBAAiB;gBACpCC,mBAAmB,EAAEA,mBAAmB;cACxC;0BACF,MAAC9B,GAAG;gBAACmC,EAAE,EAAE;oBAAES,OAAO,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC;iBAAE;;kCAC/C,KAAC5C,aAAa;wBAAC6C,iBAAiB,EAAE9C,UAAU;kCAC1C,cAAA,KAACG,SAAS,KAAG;sBACC;kCAChB,KAACD,WAAW,KAAG;kCACf,KAACE,gBAAgB,KAAG;kCACpB,KAACC,sBAAsB,KAAG;kCAC1B,KAACG,iBAAiB,KAAG;kCACrB,KAACF,gCAAgC,KAAG;;cAChC;;MACF,CACN;AACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright 2023 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 { useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport {\n PanelDrawer,\n Dashboard,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n} from '../../components';\nimport { useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n dashboardTitleComponent?: JSX.Element;\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n onDiscard?: (entity: DashboardResource) => void;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n}\n\nexport const DashboardApp = (props: DashboardAppProps) => {\n const { dashboardResource, dashboardTitleComponent, onSave, onDiscard, initialVariableIsSticky, isReadonly } = props;\n const { setEditMode } = useEditMode();\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = () => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard);\n }\n };\n\n const onEditButtonClick = () => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n };\n\n const onCancelButtonClick = () => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={initialVariableIsSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ padding: (theme) => theme.spacing(2) }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard />\n </ErrorBoundary>\n <PanelDrawer />\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DiscardChangesConfirmationDialog />\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ErrorAlert","ErrorBoundary","PanelDrawer","Dashboard","PanelGroupDialog","DeletePanelGroupDialog","DiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","DashboardApp","props","dashboardResource","dashboardTitleComponent","onSave","onDiscard","initialVariableIsSticky","isReadonly","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","onEditButtonClick","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","metadata","name","padding","theme","spacing","FallbackComponent"],"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,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAwB,CAAC;AAEnE,SACEC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,sBAAsB,EACtBC,gCAAgC,EAChCC,gBAAgB,EAChBC,iBAAiB,QACZ,kBAAkB,CAAC;AAC1B,SAASC,YAAY,EAAEC,mCAAmC,EAAEC,WAAW,QAAQ,eAAe,CAAC;AAW/F,OAAO,MAAMC,YAAY,GAAG,CAACC,KAAwB,GAAK;IACxD,MAAM,EAAEC,iBAAiB,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,MAAM,CAAA,EAAEC,SAAS,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGN,KAAK,AAAC;IACrH,MAAM,EAAEO,WAAW,CAAA,EAAE,GAAGT,WAAW,EAAE,AAAC;IACtC,MAAM,EAAEU,SAAS,CAAA,EAAEC,YAAY,CAAA,EAAE,GAA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Aa,EAAE3B,iBAAiB,CAAC4B,QAAQ,CAACC,IAAI;gBAC9C5B,uBAAuB,EAAEA,uBAAuB;gBAChDG,uBAAuB,EAAEA,uBAAuB;gBAChDF,MAAM,EAAEA,MAAM;gBACdG,UAAU,EAAEA,UAAU;gBACtBU,iBAAiB,EAAEA,iBAAiB;gBACpCC,mBAAmB,EAAEA,mBAAmB;cACxC;0BACF,MAAC/B,GAAG;gBAACoC,EAAE,EAAE;oBAAES,OAAO,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC;iBAAE;;kCAC/C,KAAC7C,aAAa;wBAAC8C,iBAAiB,EAAE/C,UAAU;kCAC1C,cAAA,KAACG,SAAS,KAAG;sBACC;kCAChB,KAACD,WAAW,KAAG;kCACf,KAACE,gBAAgB,KAAG;kCACpB,KAACC,sBAAsB,KAAG;kCAC1B,KAACG,iBAAiB,KAAG;kCACrB,KAACF,gCAAgC,KAAG;;cAChC;;MACF,CACN;AACJ,CAAC,CAAC"}
@@ -7,8 +7,10 @@ export interface ViewDashboardProps extends Omit<BoxProps, 'children'> {
7
7
  datasourceApi: DatasourceStoreProviderProps['datasourceApi'];
8
8
  dashboardTitleComponent?: JSX.Element;
9
9
  onSave?: (entity: DashboardResource) => Promise<DashboardResource>;
10
+ onDiscard?: (entity: DashboardResource) => void;
10
11
  initialVariableIsSticky?: boolean;
11
12
  isReadonly: boolean;
13
+ isEditing?: boolean;
12
14
  }
13
15
  /**
14
16
  * The View for displaying a Dashboard, along with the UI for selecting variable values.
@@ -1 +1 @@
1
- {"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAGL,4BAA4B,EAE7B,MAAM,eAAe,CAAC;AAGvB,MAA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