@perses-dev/dashboards 0.53.0 → 0.54.0-beta.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 (293) hide show
  1. package/dist/cjs/components/DashboardLinks/DashboardLinksEditor.js +366 -0
  2. package/dist/cjs/components/DashboardLinks/EditDashboardLinksButton.js +81 -0
  3. package/dist/cjs/components/DashboardLinks/index.js +31 -0
  4. package/dist/cjs/components/DashboardShortcuts/index.js +23 -0
  5. package/dist/cjs/components/DashboardShortcuts/useDashboardShortcuts.js +373 -0
  6. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +16 -1
  7. package/dist/cjs/components/Datasources/EditDatasourcesButton.js +1 -7
  8. package/dist/cjs/components/GridLayout/GridItemContent.js +19 -6
  9. package/dist/cjs/components/{Panel/PanelLinks.js → LinksDisplay/LinksDisplay.js} +59 -10
  10. package/dist/cjs/components/LinksDisplay/index.js +30 -0
  11. package/dist/cjs/components/Panel/PanelActions.js +58 -35
  12. package/dist/cjs/components/PanelDrawer/PanelQueriesSharedControls.js +16 -1
  13. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +4 -4
  14. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +3 -61
  15. package/dist/cjs/components/Variables/ListVariableListBox.js +6 -6
  16. package/dist/cjs/components/Variables/Variable.js +3 -3
  17. package/dist/cjs/components/index.js +2 -0
  18. package/dist/cjs/constants/user-interface-text.js +1 -0
  19. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +5 -1
  20. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +16 -0
  21. package/dist/cjs/context/DashboardProvider/index.js +7 -0
  22. package/dist/cjs/context/DashboardProvider/links-slice.js +32 -0
  23. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +2 -2
  24. package/dist/cjs/context/DashboardProvider/use-save-dashboard.js +104 -0
  25. package/dist/cjs/context/DatasourceStoreProvider.js +3 -9
  26. package/dist/cjs/context/VariableProvider/VariableProvider.js +7 -6
  27. package/dist/cjs/context/VariableProvider/hydrationUtils.js +3 -3
  28. package/dist/cjs/context/useDashboard.js +7 -4
  29. package/dist/cjs/index.js +2 -0
  30. package/dist/cjs/keyboard-shortcuts/PanelFocusProvider.js +157 -0
  31. package/dist/cjs/keyboard-shortcuts/default-shortcuts/dashboard.js +75 -0
  32. package/dist/cjs/keyboard-shortcuts/default-shortcuts/global.js +121 -0
  33. package/dist/cjs/keyboard-shortcuts/default-shortcuts/index.js +33 -0
  34. package/dist/cjs/keyboard-shortcuts/default-shortcuts/panel.js +90 -0
  35. package/dist/cjs/keyboard-shortcuts/default-shortcuts/time-range.js +142 -0
  36. package/dist/cjs/keyboard-shortcuts/events.js +93 -0
  37. package/dist/cjs/keyboard-shortcuts/index.js +89 -0
  38. package/dist/cjs/keyboard-shortcuts/types.js +42 -0
  39. package/dist/cjs/keyboard-shortcuts/utils.js +76 -0
  40. package/dist/cjs/model/DashboardResource.js +16 -0
  41. package/dist/cjs/model/index.js +30 -0
  42. package/dist/cjs/test/render.js +18 -3
  43. package/dist/cjs/views/ViewDashboard/DashboardApp.js +17 -2
  44. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +2 -1
  45. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  46. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  47. package/dist/components/DashboardLinks/DashboardLinksEditor.d.ts +9 -0
  48. package/dist/components/DashboardLinks/DashboardLinksEditor.d.ts.map +1 -0
  49. package/dist/components/DashboardLinks/DashboardLinksEditor.js +353 -0
  50. package/dist/components/DashboardLinks/DashboardLinksEditor.js.map +1 -0
  51. package/dist/components/DashboardLinks/EditDashboardLinksButton.d.ts +18 -0
  52. package/dist/components/DashboardLinks/EditDashboardLinksButton.d.ts.map +1 -0
  53. package/dist/components/DashboardLinks/EditDashboardLinksButton.js +68 -0
  54. package/dist/components/DashboardLinks/EditDashboardLinksButton.js.map +1 -0
  55. package/dist/components/DashboardLinks/index.d.ts +3 -0
  56. package/dist/components/DashboardLinks/index.d.ts.map +1 -0
  57. package/dist/components/DashboardLinks/index.js +16 -0
  58. package/dist/components/DashboardLinks/index.js.map +1 -0
  59. package/dist/components/DashboardShortcuts/index.d.ts +3 -0
  60. package/dist/components/DashboardShortcuts/index.d.ts.map +1 -0
  61. package/dist/components/DashboardShortcuts/index.js +15 -0
  62. package/dist/components/DashboardShortcuts/index.js.map +1 -0
  63. package/dist/components/DashboardShortcuts/useDashboardShortcuts.d.ts +12 -0
  64. package/dist/components/DashboardShortcuts/useDashboardShortcuts.d.ts.map +1 -0
  65. package/dist/components/DashboardShortcuts/useDashboardShortcuts.js +365 -0
  66. package/dist/components/DashboardShortcuts/useDashboardShortcuts.js.map +1 -0
  67. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  68. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  69. package/dist/components/DashboardToolbar/DashboardToolbar.js +17 -2
  70. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  71. package/dist/components/Datasources/DatasourceEditor.d.ts +1 -1
  72. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  73. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  74. package/dist/components/Datasources/EditDatasourcesButton.d.ts.map +1 -1
  75. package/dist/components/Datasources/EditDatasourcesButton.js +1 -7
  76. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
  77. package/dist/components/DownloadButton/serializeDashboard.d.ts +2 -2
  78. package/dist/components/DownloadButton/serializeDashboard.d.ts.map +1 -1
  79. package/dist/components/DownloadButton/serializeDashboard.js.map +1 -1
  80. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  81. package/dist/components/GridLayout/GridItemContent.js +21 -8
  82. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  83. package/dist/components/GridLayout/GridLayout.d.ts +1 -1
  84. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  85. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  86. package/dist/components/GridLayout/GridTitle.d.ts +1 -1
  87. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  88. package/dist/components/GridLayout/Row.d.ts +2 -1
  89. package/dist/components/GridLayout/Row.d.ts.map +1 -1
  90. package/dist/components/GridLayout/Row.js.map +1 -1
  91. package/dist/components/LeaveDialog/LeaveDialog.d.ts +3 -3
  92. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
  93. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  94. package/dist/components/LinksDisplay/LinksDisplay.d.ts +10 -0
  95. package/dist/components/LinksDisplay/LinksDisplay.d.ts.map +1 -0
  96. package/dist/components/{Panel/PanelLinks.js → LinksDisplay/LinksDisplay.js} +59 -10
  97. package/dist/components/LinksDisplay/LinksDisplay.js.map +1 -0
  98. package/dist/components/LinksDisplay/index.d.ts +2 -0
  99. package/dist/components/LinksDisplay/index.d.ts.map +1 -0
  100. package/dist/components/LinksDisplay/index.js +15 -0
  101. package/dist/components/LinksDisplay/index.js.map +1 -0
  102. package/dist/components/Panel/Panel.d.ts +2 -1
  103. package/dist/components/Panel/Panel.d.ts.map +1 -1
  104. package/dist/components/Panel/Panel.js.map +1 -1
  105. package/dist/components/Panel/PanelActions.d.ts +1 -1
  106. package/dist/components/Panel/PanelActions.d.ts.map +1 -1
  107. package/dist/components/Panel/PanelActions.js +59 -36
  108. package/dist/components/Panel/PanelActions.js.map +1 -1
  109. package/dist/components/Panel/PanelContent.d.ts +1 -1
  110. package/dist/components/Panel/PanelContent.js.map +1 -1
  111. package/dist/components/Panel/PanelHeader.d.ts +1 -1
  112. package/dist/components/Panel/PanelHeader.js.map +1 -1
  113. package/dist/components/Panel/PanelPluginLoader.d.ts +1 -1
  114. package/dist/components/Panel/PanelPluginLoader.js.map +1 -1
  115. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  116. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +2 -1
  117. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  118. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  119. package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -1
  120. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  121. package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts +1 -1
  122. package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts.map +1 -1
  123. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +16 -1
  124. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -1
  125. package/dist/components/PanelDrawer/usePanelEditor.d.ts +1 -1
  126. package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -1
  127. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  128. package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts +1 -1
  129. package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -1
  130. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +1 -1
  131. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  132. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
  133. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +4 -62
  134. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
  135. package/dist/components/Variables/BuiltinVariableAccordions.d.ts +1 -1
  136. package/dist/components/Variables/BuiltinVariableAccordions.js.map +1 -1
  137. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  138. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  139. package/dist/components/Variables/ListVariableListBox.js +1 -1
  140. package/dist/components/Variables/ListVariableListBox.js.map +1 -1
  141. package/dist/components/Variables/Variable.d.ts +1 -1
  142. package/dist/components/Variables/Variable.js +1 -1
  143. package/dist/components/Variables/Variable.js.map +1 -1
  144. package/dist/components/Variables/VariableEditor.d.ts +2 -1
  145. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  146. package/dist/components/Variables/VariableEditor.js.map +1 -1
  147. package/dist/components/Variables/VariableList.d.ts +1 -1
  148. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  149. package/dist/components/Variables/VariableList.js.map +1 -1
  150. package/dist/components/index.d.ts +2 -0
  151. package/dist/components/index.d.ts.map +1 -1
  152. package/dist/components/index.js +2 -0
  153. package/dist/components/index.js.map +1 -1
  154. package/dist/constants/user-interface-text.d.ts +1 -0
  155. package/dist/constants/user-interface-text.d.ts.map +1 -1
  156. package/dist/constants/user-interface-text.js +1 -0
  157. package/dist/constants/user-interface-text.js.map +1 -1
  158. package/dist/context/DashboardProvider/DashboardProvider.d.ts +8 -6
  159. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  160. package/dist/context/DashboardProvider/DashboardProvider.js +5 -1
  161. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  162. package/dist/context/DashboardProvider/common.d.ts +3 -2
  163. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  164. package/dist/context/DashboardProvider/common.js.map +1 -1
  165. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +15 -2
  166. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  167. package/dist/context/DashboardProvider/dashboard-provider-api.js +14 -0
  168. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  169. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +1 -1
  170. package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
  171. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  172. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
  173. package/dist/context/DashboardProvider/index.d.ts +2 -0
  174. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  175. package/dist/context/DashboardProvider/index.js +1 -0
  176. package/dist/context/DashboardProvider/index.js.map +1 -1
  177. package/dist/context/DashboardProvider/links-slice.d.ts +19 -0
  178. package/dist/context/DashboardProvider/links-slice.d.ts.map +1 -0
  179. package/dist/context/DashboardProvider/links-slice.js +27 -0
  180. package/dist/context/DashboardProvider/links-slice.js.map +1 -0
  181. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -1
  182. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  183. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  184. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -1
  185. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  186. package/dist/context/DashboardProvider/panel-group-slice.d.ts +2 -1
  187. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  188. package/dist/context/DashboardProvider/panel-group-slice.js +1 -1
  189. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  190. package/dist/context/DashboardProvider/panel-slice.d.ts +1 -1
  191. package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
  192. package/dist/context/DashboardProvider/use-save-dashboard.d.ts +25 -0
  193. package/dist/context/DashboardProvider/use-save-dashboard.d.ts.map +1 -0
  194. package/dist/context/DashboardProvider/use-save-dashboard.js +105 -0
  195. package/dist/context/DashboardProvider/use-save-dashboard.js.map +1 -0
  196. package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
  197. package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
  198. package/dist/context/DatasourceStoreProvider.d.ts +4 -2
  199. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  200. package/dist/context/DatasourceStoreProvider.js +3 -9
  201. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  202. package/dist/context/VariableProvider/VariableProvider.d.ts +2 -1
  203. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
  204. package/dist/context/VariableProvider/VariableProvider.js +2 -1
  205. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  206. package/dist/context/VariableProvider/hydrationUtils.d.ts +2 -1
  207. package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -1
  208. package/dist/context/VariableProvider/hydrationUtils.js +1 -1
  209. package/dist/context/VariableProvider/hydrationUtils.js.map +1 -1
  210. package/dist/context/VariableProvider/query-params.d.ts +1 -1
  211. package/dist/context/VariableProvider/query-params.js.map +1 -1
  212. package/dist/context/VariableProvider/utils.d.ts +2 -1
  213. package/dist/context/VariableProvider/utils.d.ts.map +1 -1
  214. package/dist/context/VariableProvider/utils.js.map +1 -1
  215. package/dist/context/useDashboard.d.ts +11 -3
  216. package/dist/context/useDashboard.d.ts.map +1 -1
  217. package/dist/context/useDashboard.js +6 -3
  218. package/dist/context/useDashboard.js.map +1 -1
  219. package/dist/index.d.ts +2 -0
  220. package/dist/index.d.ts.map +1 -1
  221. package/dist/index.js +2 -0
  222. package/dist/index.js.map +1 -1
  223. package/dist/keyboard-shortcuts/PanelFocusProvider.d.ts +12 -0
  224. package/dist/keyboard-shortcuts/PanelFocusProvider.d.ts.map +1 -0
  225. package/dist/keyboard-shortcuts/PanelFocusProvider.js +97 -0
  226. package/dist/keyboard-shortcuts/PanelFocusProvider.js.map +1 -0
  227. package/dist/keyboard-shortcuts/default-shortcuts/dashboard.d.ts +6 -0
  228. package/dist/keyboard-shortcuts/default-shortcuts/dashboard.d.ts.map +1 -0
  229. package/dist/keyboard-shortcuts/default-shortcuts/dashboard.js +53 -0
  230. package/dist/keyboard-shortcuts/default-shortcuts/dashboard.js.map +1 -0
  231. package/dist/keyboard-shortcuts/default-shortcuts/global.d.ts +9 -0
  232. package/dist/keyboard-shortcuts/default-shortcuts/global.d.ts.map +1 -0
  233. package/dist/keyboard-shortcuts/default-shortcuts/global.js +90 -0
  234. package/dist/keyboard-shortcuts/default-shortcuts/global.js.map +1 -0
  235. package/dist/keyboard-shortcuts/default-shortcuts/index.d.ts +5 -0
  236. package/dist/keyboard-shortcuts/default-shortcuts/index.d.ts.map +1 -0
  237. package/dist/keyboard-shortcuts/default-shortcuts/index.js +18 -0
  238. package/dist/keyboard-shortcuts/default-shortcuts/index.js.map +1 -0
  239. package/dist/keyboard-shortcuts/default-shortcuts/panel.d.ts +7 -0
  240. package/dist/keyboard-shortcuts/default-shortcuts/panel.d.ts.map +1 -0
  241. package/dist/keyboard-shortcuts/default-shortcuts/panel.js +65 -0
  242. package/dist/keyboard-shortcuts/default-shortcuts/panel.js.map +1 -0
  243. package/dist/keyboard-shortcuts/default-shortcuts/time-range.d.ts +10 -0
  244. package/dist/keyboard-shortcuts/default-shortcuts/time-range.d.ts.map +1 -0
  245. package/dist/keyboard-shortcuts/default-shortcuts/time-range.js +108 -0
  246. package/dist/keyboard-shortcuts/default-shortcuts/time-range.js.map +1 -0
  247. package/dist/keyboard-shortcuts/events.d.ts +18 -0
  248. package/dist/keyboard-shortcuts/events.d.ts.map +1 -0
  249. package/dist/keyboard-shortcuts/events.js +35 -0
  250. package/dist/keyboard-shortcuts/events.js.map +1 -0
  251. package/dist/keyboard-shortcuts/index.d.ts +9 -0
  252. package/dist/keyboard-shortcuts/index.d.ts.map +1 -0
  253. package/dist/keyboard-shortcuts/index.js +21 -0
  254. package/dist/keyboard-shortcuts/index.js.map +1 -0
  255. package/dist/keyboard-shortcuts/types.d.ts +37 -0
  256. package/dist/keyboard-shortcuts/types.d.ts.map +1 -0
  257. package/dist/keyboard-shortcuts/types.js +26 -0
  258. package/dist/keyboard-shortcuts/types.js.map +1 -0
  259. package/dist/keyboard-shortcuts/utils.d.ts +12 -0
  260. package/dist/keyboard-shortcuts/utils.d.ts.map +1 -0
  261. package/dist/keyboard-shortcuts/utils.js +51 -0
  262. package/dist/keyboard-shortcuts/utils.js.map +1 -0
  263. package/dist/model/DashboardResource.d.ts +15 -0
  264. package/dist/model/DashboardResource.d.ts.map +1 -0
  265. package/dist/model/DashboardResource.js +18 -0
  266. package/dist/model/DashboardResource.js.map +1 -0
  267. package/dist/model/index.d.ts +2 -0
  268. package/dist/model/index.d.ts.map +1 -0
  269. package/dist/model/index.js +15 -0
  270. package/dist/model/index.js.map +1 -0
  271. package/dist/test/dashboard-provider.d.ts +1 -1
  272. package/dist/test/dashboard-provider.d.ts.map +1 -1
  273. package/dist/test/dashboard-provider.js.map +1 -1
  274. package/dist/test/datasource-provider.js.map +1 -1
  275. package/dist/test/plugin-registry.js.map +1 -1
  276. package/dist/test/render.d.ts.map +1 -1
  277. package/dist/test/render.js +18 -3
  278. package/dist/test/render.js.map +1 -1
  279. package/dist/test/testDashboard.d.ts +11 -2
  280. package/dist/test/testDashboard.d.ts.map +1 -1
  281. package/dist/test/testDashboard.js.map +1 -1
  282. package/dist/utils/panelUtils.js.map +1 -1
  283. package/dist/views/ViewDashboard/DashboardApp.d.ts +5 -3
  284. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  285. package/dist/views/ViewDashboard/DashboardApp.js +18 -3
  286. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  287. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  288. package/dist/views/ViewDashboard/ViewDashboard.js +3 -2
  289. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  290. package/package.json +6 -4
  291. package/dist/components/Panel/PanelLinks.d.ts +0 -6
  292. package/dist/components/Panel/PanelLinks.d.ts.map +0 -1
  293. package/dist/components/Panel/PanelLinks.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Datasources/EditDatasourcesButton.tsx"],"sourcesContent":["// Copyright 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 { ReactElement, useState } from 'react';\nimport { Button } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { Drawer, InfoTooltip } from '@perses-dev/components';\nimport { DashboardResource, DatasourceSpec, EphemeralDashboardResource } from '@perses-dev/core';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { TOOLTIP_TEXT, editButtonStyle } from '../../constants';\nimport { useDashboard } from '../../context';\nimport { DatasourceEditor } from './DatasourceEditor';\n\nexport function EditDatasourcesButton(): ReactElement {\n const [isDatasourceEditorOpen, setIsDatasourceEditorOpen] = useState(false);\n const { getLocalDatasources, setLocalDatasources, getSavedDatasources, setSavedDatasources } = useDatasourceStore();\n const localDatasources: Record<string, DatasourceSpec> = getLocalDatasources();\n const savedDatasources: Record<string, DatasourceSpec> = getSavedDatasources();\n const { dashboard, setDashboard } = useDashboard();\n\n const openDatasourceEditor = (): void => {\n setIsDatasourceEditorOpen(true);\n };\n\n const closeDatasourceEditor = (): void => {\n setIsDatasourceEditorOpen(false);\n };\n\n const handleChangeDatasources = (datasources: Record<string, DatasourceSpec>): void => {\n // Calculates the new list of datasources that are allowed to be used.\n const newSavedDatasources: Record<string, DatasourceSpec> = Object.keys(datasources)\n .filter((key) => {\n // Datasources are allowed to be used if a) they are direct, or b) they are proxied, and their\n // proxy is the same as what we have saved.\n const isDirect = 'directUrl' in (datasources[key]?.plugin?.spec ?? {});\n const isSavedProxy =\n !isDirect &&\n !('directUrl' in (savedDatasources[key]?.plugin?.spec ?? {})) &&\n datasources[key]?.plugin?.spec?.proxy === savedDatasources[key]?.plugin?.spec?.proxy;\n\n return isDirect || isSavedProxy;\n })\n .reduce(\n (obj, key) => {\n obj[key] = datasources[key] as DatasourceSpec;\n\n return obj;\n },\n {} as Record<string, DatasourceSpec>\n );\n\n setDashboard(\n dashboard.kind === 'Dashboard'\n ? ({\n ...dashboard,\n spec: {\n ...dashboard.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboard,\n spec: {\n ...dashboard.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n setSavedDatasources(newSavedDatasources);\n setLocalDatasources(datasources);\n setIsDatasourceEditorOpen(false);\n };\n\n return (\n <>\n <InfoTooltip description={TOOLTIP_TEXT.editDatasources}>\n <Button\n startIcon={<PencilIcon />}\n onClick={openDatasourceEditor}\n aria-label={TOOLTIP_TEXT.editDatasources}\n variant=\"text\"\n color=\"primary\"\n sx={editButtonStyle}\n >\n Datasources\n </Button>\n </InfoTooltip>\n <Drawer\n isOpen={isDatasourceEditorOpen}\n onClose={closeDatasourceEditor}\n PaperProps={{ sx: { width: '50%' } }}\n data-testid=\"datasource-editor\"\n >\n <DatasourceEditor\n datasources={localDatasources}\n onCancel={closeDatasourceEditor}\n onChange={handleChangeDatasources}\n />\n </Drawer>\n </>\n );\n}\n"],"names":["useState","Button","PencilIcon","Drawer","InfoTooltip","useDatasourceStore","TOOLTIP_TEXT","editButtonStyle","useDashboard","DatasourceEditor","EditDatasourcesButton","isDatasourceEditorOpen","setIsDatasourceEditorOpen","getLocalDatasources","setLocalDatasources","getSavedDatasources","setSavedDatasources","localDatasources","savedDatasources","dashboard","setDashboard","openDatasourceEditor","closeDatasourceEditor","handleChangeDatasources","datasources","newSavedDatasources","Object","keys","filter","key","isDirect","plugin","spec","isSavedProxy","proxy","reduce","obj","kind","description","editDatasources","startIcon","onClick","aria-label","variant","color","sx","isOpen","onClose","PaperProps","width","data-testid","onCancel","onChange"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,MAAM,QAAQ,gBAAgB;AACvC,OAAOC,gBAAgB,gCAAgC;AACvD,SAASC,MAAM,EAAEC,WAAW,QAAQ,yBAAyB;AAE7D,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,YAAY,EAAEC,eAA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AENR,oBAAoBS;QACpBX,oBAAoBU;QACpBZ,0BAA0B;IAC5B;IAEA,qBACE;;0BACE,KAACR;gBAAYkC,aAAahC,aAAaiC,eAAe;0BACpD,cAAA,KAACtC;oBACCuC,yBAAW,KAACtC;oBACZuC,SAASpB;oBACTqB,cAAYpC,aAAaiC,eAAe;oBACxCI,SAAQ;oBACRC,OAAM;oBACNC,IAAItC;8BACL;;;0BAIH,KAACJ;gBACC2C,QAAQnC;gBACRoC,SAASzB;gBACT0B,YAAY;oBAAEH,IAAI;wBAAEI,OAAO;oBAAM;gBAAE;gBACnCC,eAAY;0BAEZ,cAAA,KAACzC;oBACCe,aAAaP;oBACbkC,UAAU7B;oBACV8B,UAAU7B;;;;;AAKpB"}
1
+ {"version":3,"sources":["../../../src/components/Datasources/EditDatasourcesButton.tsx"],"sourcesContent":["// Copyright 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 { ReactElement, useState } from 'react';\nimport { Button } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { Drawer, InfoTooltip } from '@perses-dev/components';\nimport { DatasourceSpec } from '@perses-dev/spec';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { TOOLTIP_TEXT, editButtonStyle } from '../../constants';\nimport { useDashboard } from '../../context';\nimport { DatasourceEditor } from './DatasourceEditor';\n\nexport function EditDatasourcesButton(): ReactElement {\n const [isDatasourceEditorOpen, setIsDatasourceEditorOpen] = useState(false);\n const { getLocalDatasources, setLocalDatasources, getSavedDatasources, setSavedDatasources } = useDatasourceStore();\n const localDatasources: Record<string, DatasourceSpec> = getLocalDatasources();\n const savedDatasources: Record<string, DatasourceSpec> = getSavedDatasources();\n const { dashboard, setDashboard } = useDashboard();\n\n const openDatasourceEditor = (): void => {\n setIsDatasourceEditorOpen(true);\n };\n\n const closeDatasourceEditor = (): void => {\n setIsDatasourceEditorOpen(false);\n };\n\n const handleChangeDatasources = (datasources: Record<string, DatasourceSpec>): void => {\n // Calculates the new list of datasources that are allowed to be used.\n const newSavedDatasources: Record<string, DatasourceSpec> = Object.keys(datasources)\n .filter((key) => {\n // Datasources are allowed to be used if a) they are direct, or b) they are proxied, and their\n // proxy is the same as what we have saved.\n const isDirect = 'directUrl' in (datasources[key]?.plugin?.spec ?? {});\n const isSavedProxy =\n !isDirect &&\n !('directUrl' in (savedDatasources[key]?.plugin?.spec ?? {})) &&\n datasources[key]?.plugin?.spec?.proxy === savedDatasources[key]?.plugin?.spec?.proxy;\n\n return isDirect || isSavedProxy;\n })\n .reduce(\n (obj, key) => {\n obj[key] = datasources[key] as DatasourceSpec;\n\n return obj;\n },\n {} as Record<string, DatasourceSpec>\n );\n\n setDashboard({\n ...dashboard,\n spec: {\n ...dashboard.spec,\n datasources: datasources,\n },\n });\n setSavedDatasources(newSavedDatasources);\n setLocalDatasources(datasources);\n setIsDatasourceEditorOpen(false);\n };\n\n return (\n <>\n <InfoTooltip description={TOOLTIP_TEXT.editDatasources}>\n <Button\n startIcon={<PencilIcon />}\n onClick={openDatasourceEditor}\n aria-label={TOOLTIP_TEXT.editDatasources}\n variant=\"text\"\n color=\"primary\"\n sx={editButtonStyle}\n >\n Datasources\n </Button>\n </InfoTooltip>\n <Drawer\n isOpen={isDatasourceEditorOpen}\n onClose={closeDatasourceEditor}\n PaperProps={{ sx: { width: '50%' } }}\n data-testid=\"datasource-editor\"\n >\n <DatasourceEditor\n datasources={localDatasources}\n onCancel={closeDatasourceEditor}\n onChange={handleChangeDatasources}\n />\n </Drawer>\n </>\n );\n}\n"],"names":["useState","Button","PencilIcon","Drawer","InfoTooltip","useDatasourceStore","TOOLTIP_TEXT","editButtonStyle","useDashboard","DatasourceEditor","EditDatasourcesButton","isDatasourceEditorOpen","setIsDatasourceEditorOpen","getLocalDatasources","setLocalDatasources","getSavedDatasources","setSavedDatasources","localDatasources","savedDatasources","dashboard","setDashboard","openDatasourceEditor","closeDatasourceEditor","handleChangeDatasources","datasources","newSavedDatasources","Object","keys","filter","key","isDirect","plugin","spec","isSavedProxy","proxy","reduce","obj","description","editDatasources","startIcon","onClick","aria-label","variant","color","sx","isOpen","onClose","PaperProps","width","data-testid","onCancel","onChange"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,MAAM,QAAQ,gBAAgB;AACvC,OAAOC,gBAAgB,gCAAgC;AACvD,SAASC,MAAM,EAAEC,WAAW,QAAQ,yBAAyB;AAE7D,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,YAAY,EAAEC,eAAe,QAAQ,kBAAkB;AAChE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,gBAAgB,QAAQ,qBAAqB;AAEtD,OAAO,SAASC;IACd,MAAM,CAACC,wBAAwBC,0BAA0B,GAAGZ,SAAS;IACrE,MAAM,EAAEa,mBAAmB,EAAEC,mBAAmB,EAAEC,mBAAmB,EAAEC,mBAAmB,EAAE,GAAGX;IAC/F,MAAMY,mBAAmDJ;IACzD,MAAMK,mBAAmDH;IACzD,MAAM,EAAEI,SAAS,EAAEC,YAAY,EAAE,GAAGZ;IAEpC,MAAMa,uBAAuB;QAC3BT,0BAA0B;IAC5B;IAEA,MAAMU,wBAAwB;QAC5BV,0BAA0B;IAC5B;IAEA,MAAMW,0BAA0B,CAACC;QAC/B,sEAAsE;QACtE,MAAMC,sBAAsDC,OAAOC,IAAI,CAACH,aACrEI,MAAM,CAAC,CAACC;YACP,8FAA8F;YAC9F,2CAA2C;YAC3C,MAAMC,WAAW,eAAgBN,CAAAA,WAAW,CAACK,IAAI,EAAEE,QAAQC,QAAQ,CAAC,CAAA;YACpE,MAAMC,eACJ,CAACH,YACD,CAAE,CAAA,eAAgBZ,CAAAA,gBAAgB,CAACW,IAAI,EAAEE,QAAQC,QAAQ,CAAC,CAAA,CAAC,KAC3DR,WAAW,CAACK,IAAI,EAAEE,QAAQC,MAAME,UAAUhB,gBAAgB,CAACW,IAAI,EAAEE,QAAQC,MAAME;YAEjF,OAAOJ,YAAYG;QACrB,GACCE,MAAM,CACL,CAACC,KAAKP;YACJO,GAAG,CAACP,IAAI,GAAGL,WAAW,CAACK,IAAI;YAE3B,OAAOO;QACT,GACA,CAAC;QAGLhB,aAAa;YACX,GAAGD,SAAS;YACZa,MAAM;gBACJ,GAAGb,UAAUa,IAAI;gBACjBR,aAAaA;YACf;QACF;QACAR,oBAAoBS;QACpBX,oBAAoBU;QACpBZ,0BAA0B;IAC5B;IAEA,qBACE;;0BACE,KAACR;gBAAYiC,aAAa/B,aAAagC,eAAe;0BACpD,cAAA,KAACrC;oBACCsC,yBAAW,KAACrC;oBACZsC,SAASnB;oBACToB,cAAYnC,aAAagC,eAAe;oBACxCI,SAAQ;oBACRC,OAAM;oBACNC,IAAIrC;8BACL;;;0BAIH,KAACJ;gBACC0C,QAAQlC;gBACRmC,SAASxB;gBACTyB,YAAY;oBAAEH,IAAI;wBAAEI,OAAO;oBAAM;gBAAE;gBACnCC,eAAY;0BAEZ,cAAA,KAACxC;oBACCe,aAAaP;oBACbiC,UAAU5B;oBACV6B,UAAU5B;;;;;AAKpB"}
@@ -1,8 +1,8 @@
1
- import { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';
1
+ import { DashboardResource } from '../../model/DashboardResource';
2
2
  type SerializedDashboard = {
3
3
  contentType: string;
4
4
  content: string;
5
5
  };
6
- export declare function serializeDashboard(dashboard: DashboardResource | EphemeralDashboardResource, format: 'json' | 'yaml', shape?: 'cr-v1alpha1' | 'cr-v1alpha2'): SerializedDashboard;
6
+ export declare function serializeDashboard(dashboard: DashboardResource, format: 'json' | 'yaml', shape?: 'cr-v1alpha1' | 'cr-v1alpha2'): SerializedDashboard;
7
7
  export {};
8
8
  //# sourceMappingURL=serializeDashboard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializeDashboard.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAGjF,KAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAuDF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,iBAAiB,GAAG,0BAA0B,EACzD,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,KAAK,CAAC,EAAE,aAAa,GAAG,aAAa,GACpC,mBAAmB,CAOrB"}
1
+ {"version":3,"file":"serializeDashboard.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAKlE,KAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAoDF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,KAAK,CAAC,EAAE,aAAa,GAAG,aAAa,GACpC,mBAAmB,CAOrB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"sourcesContent":["// Copyright 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 { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';\nimport { stringify } from 'yaml';\n\ntype SerializedDashboard = {\n contentType: string;\n content: string;\n};\n\nfunction serializeYaml(\n dashboard: DashboardResource | EphemeralDashboardResource,\n shape?: 'cr-v1alpha1' | 'cr-v1alpha2'\n): SerializedDashboard {\n let content: string;\n\n if (shape === 'cr-v1alpha1') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha1',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: dashboard.spec,\n },\n { schema: 'yaml-1.1' }\n );\n } else if (shape === 'cr-v1alpha2') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha2',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: {\n config: dashboard.spec,\n },\n },\n { schema: 'yaml-1.1' }\n );\n } else {\n content = stringify(dashboard, { schema: 'yaml-1.1' });\n }\n\n return { contentType: 'application/yaml', content };\n}\n\nexport function serializeDashboard(\n dashboard: DashboardResource | EphemeralDashboardResource,\n format: 'json' | 'yaml',\n shape?: 'cr-v1alpha1' | 'cr-v1alpha2'\n): SerializedDashboard {\n switch (format) {\n case 'json':\n return { contentType: 'application/json', content: JSON.stringify(dashboard, null, 2) };\n case 'yaml':\n return serializeYaml(dashboard, shape);\n }\n}\n"],"names":["stringify","serializeYaml","dashboard","shape","content","name","metadata","toLowerCase","replace","apiVersion","kind","labels","namespace","project","spec","schema","config","contentType","serializeDashboard","format","JSON"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,SAAS,QAAQ,OAAO;AAOjC,SAASC,cACPC,SAAyD,EACzDC,KAAqC;IAErC,IAAIC;IAEJ,IAAID,UAAU,eAAe;QAC3B,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAMZ,UAAUY,IAAI;QACtB,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO,IAAIZ,UAAU,eAAe;QAClC,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAM;gBACJE,QAAQd,UAAUY,IAAI;YACxB;QACF,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO;QACLX,UAAUJ,UAAUE,WAAW;YAAEa,QAAQ;QAAW;IACtD;IAEA,OAAO;QAAEE,aAAa;QAAoBb;IAAQ;AACpD;AAEA,OAAO,SAASc,mBACdhB,SAAyD,EACzDiB,MAAuB,EACvBhB,KAAqC;IAErC,OAAQgB;QACN,KAAK;YACH,OAAO;gBAAEF,aAAa;gBAAoBb,SAASgB,KAAKpB,SAAS,CAACE,WAAW,MAAM;YAAG;QACxF,KAAK;YACH,OAAOD,cAAcC,WAAWC;IACpC;AACF"}
1
+ {"version":3,"sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"sourcesContent":["// Copyright 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 { stringify } from 'yaml';\nimport { DashboardResource } from '../../model/DashboardResource';\n\n//TODO: Although the previous comment suggests the metadata not should not be used, I keep them. Need to be discussed.\n// Check git history to find prev comment\n\ntype SerializedDashboard = {\n contentType: string;\n content: string;\n};\n\nfunction serializeYaml(dashboard: DashboardResource, shape?: 'cr-v1alpha1' | 'cr-v1alpha2'): SerializedDashboard {\n let content: string;\n\n if (shape === 'cr-v1alpha1') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha1',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: dashboard.spec,\n },\n { schema: 'yaml-1.1' }\n );\n } else if (shape === 'cr-v1alpha2') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha2',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: {\n config: dashboard.spec,\n },\n },\n { schema: 'yaml-1.1' }\n );\n } else {\n content = stringify(dashboard, { schema: 'yaml-1.1' });\n }\n\n return { contentType: 'application/yaml', content };\n}\n\nexport function serializeDashboard(\n dashboard: DashboardResource,\n format: 'json' | 'yaml',\n shape?: 'cr-v1alpha1' | 'cr-v1alpha2'\n): SerializedDashboard {\n switch (format) {\n case 'json':\n return { contentType: 'application/json', content: JSON.stringify(dashboard, null, 2) };\n case 'yaml':\n return serializeYaml(dashboard, shape);\n }\n}\n"],"names":["stringify","serializeYaml","dashboard","shape","content","name","metadata","toLowerCase","replace","apiVersion","kind","labels","namespace","project","spec","schema","config","contentType","serializeDashboard","format","JSON"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,QAAQ,OAAO;AAWjC,SAASC,cAAcC,SAA4B,EAAEC,KAAqC;IACxF,IAAIC;IAEJ,IAAID,UAAU,eAAe;QAC3B,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAMZ,UAAUY,IAAI;QACtB,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO,IAAIZ,UAAU,eAAe;QAClC,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAM;gBACJE,QAAQd,UAAUY,IAAI;YACxB;QACF,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO;QACLX,UAAUJ,UAAUE,WAAW;YAAEa,QAAQ;QAAW;IACtD;IAEA,OAAO;QAAEE,aAAa;QAAoBb;IAAQ;AACpD;AAEA,OAAO,SAASc,mBACdhB,SAA4B,EAC5BiB,MAAuB,EACvBhB,KAAqC;IAErC,OAAQgB;QACN,KAAK;YACH,OAAO;gBAAEF,aAAa;gBAAoBb,SAASgB,KAAKpB,SAAS,CAACE,WAAW,MAAM;YAAG;QACxF,KAAK;YACH,OAAOD,cAAcC,WAAWC;IACpC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"GridItemContent.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridItemContent.tsx"],"names":[],"mappings":"AAgBA,OAAc,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAA2B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAqB,YAAY,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAmGzE"}
1
+ {"version":3,"file":"GridItemContent.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridItemContent.tsx"],"names":[],"mappings":"AAgBA,OAAc,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAA2B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG7E,OAAO,EAAqB,YAAY,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAqHzE"}
@@ -11,12 +11,13 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { Box } from '@mui/material';
14
+ import { Box, useForkRef } from '@mui/material';
15
15
  import { useInView } from 'react-intersection-observer';
16
16
  import { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';
17
17
  import React, { useMemo, useState } from 'react';
18
- import { isPanelGroupItemIdEqual } from '@perses-dev/core';
18
+ import { isPanelGroupItemIdEqual } from '@perses-dev/core'; // TODO
19
19
  import { useEditMode, usePanel, usePanelActions, useViewPanelGroup } from '../../context';
20
+ import { usePanelFocusHandlers } from '../../keyboard-shortcuts';
20
21
  import { Panel } from '../Panel';
21
22
  import { QueryViewerDialog } from '../QueryViewerDialog';
22
23
  /**
@@ -28,11 +29,19 @@ import { QueryViewerDialog } from '../QueryViewerDialog';
28
29
  const { isEditMode } = useEditMode();
29
30
  const { openEditPanel, openDeletePanelDialog, duplicatePanel, viewPanel } = usePanelActions(panelGroupItemId);
30
31
  const viewPanelGroupItemId = useViewPanelGroup();
31
- const { ref, inView } = useInView({
32
- threshold: 0.2,
32
+ // Panel focus tracking for keyboard shortcuts
33
+ const { onMouseEnter, onMouseLeave } = usePanelFocusHandlers(`${panelGroupItemId.panelGroupId}-${panelGroupItemId.panelGroupItemLayoutId}`);
34
+ const { ref: queryRef, inView: shouldQuery } = useInView({
35
+ threshold: 0,
33
36
  initialInView: false,
34
37
  triggerOnce: true
35
38
  });
39
+ const { ref: renderRef, inView: shouldRender } = useInView({
40
+ threshold: 0.2,
41
+ initialInView: false,
42
+ triggerOnce: false
43
+ });
44
+ const mergedRef = useForkRef(renderRef, queryRef);
36
45
  const [openQueryViewer, setOpenQueryViewer] = useState(false);
37
46
  const viewQueriesHandler = useMemo(()=>{
38
47
  return isEditMode || !queries?.length ? undefined : {
@@ -75,10 +84,14 @@ import { QueryViewerDialog } from '../QueryViewerDialog';
75
84
  });
76
85
  const pluginQueryOptions = typeof plugin?.queryOptions === 'function' ? plugin?.queryOptions(panelDefinition.spec.plugin.spec) : plugin?.queryOptions;
77
86
  return /*#__PURE__*/ _jsxs(Box, {
78
- ref: ref,
87
+ ref: mergedRef,
88
+ tabIndex: -1,
89
+ onMouseEnter: onMouseEnter,
90
+ onMouseLeave: onMouseLeave,
79
91
  sx: {
80
92
  width: '100%',
81
- height: '100%'
93
+ height: '100%',
94
+ outline: 'none'
82
95
  },
83
96
  children: [
84
97
  /*#__PURE__*/ _jsx(DataQueriesProvider, {
@@ -88,9 +101,9 @@ import { QueryViewerDialog } from '../QueryViewerDialog';
88
101
  ...pluginQueryOptions
89
102
  },
90
103
  queryOptions: {
91
- enabled: inView
104
+ enabled: shouldQuery
92
105
  },
93
- children: inView && /*#__PURE__*/ _jsx(Panel, {
106
+ children: shouldRender && /*#__PURE__*/ _jsx(Panel, {
94
107
  definition: panelDefinition,
95
108
  readHandlers: readHandlers,
96
109
  editHandlers: editHandlers,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/GridLayout/GridItemContent.tsx"],"sourcesContent":["// Copyright 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 { Box } from '@mui/material';\nimport { useInView } from 'react-intersection-observer';\nimport { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';\nimport React, { ReactElement, useMemo, useState } from 'react';\nimport { isPanelGroupItemIdEqual, PanelGroupItemId } from '@perses-dev/core';\nimport { useEditMode, usePanel, usePanelActions, useViewPanelGroup } from '../../context';\nimport { Panel, PanelProps, PanelOptions } from '../Panel';\nimport { QueryViewerDialog } from '../QueryViewerDialog';\n\nexport interface GridItemContentProps {\n panelGroupItemId: PanelGroupItemId;\n width: number; // necessary for determining the suggested step ms\n panelOptions?: PanelOptions;\n}\n\n/**\n * Resolves the reference to panel content in a GridItemDefinition and renders the panel.\n */\nexport function GridItemContent(props: GridItemContentProps): ReactElement {\n const { panelGroupItemId, width } = props;\n const panelDefinition = usePanel(panelGroupItemId);\n\n const {\n spec: { queries },\n } = panelDefinition;\n\n const { isEditMode } = useEditMode();\n const { openEditPanel, openDeletePanelDialog, duplicatePanel, viewPanel } = usePanelActions(panelGroupItemId);\n const viewPanelGroupItemId = useViewPanelGroup();\n const { ref, inView } = useInView({\n threshold: 0.2, // we have the flexibility to adjust this threshold to trigger queries slightly earlier or later based on performance\n initialInView: false,\n triggerOnce: true,\n });\n\n const [openQueryViewer, setOpenQueryViewer] = useState(false);\n\n const viewQueriesHandler = useMemo(() => {\n return isEditMode || !queries?.length\n ? undefined\n : {\n onClick: (): void => {\n setOpenQueryViewer(true);\n },\n };\n }, [isEditMode, queries]);\n\n const readHandlers = {\n isPanelViewed: isPanelGroupItemIdEqual(viewPanelGroupItemId, panelGroupItemId),\n onViewPanelClick: function (): void {\n if (viewPanelGroupItemId === undefined) {\n viewPanel(panelGroupItemId);\n } else {\n viewPanel(undefined);\n }\n },\n };\n\n // Provide actions to the panel when in edit mode\n let editHandlers: PanelProps['editHandlers'] = undefined;\n if (isEditMode) {\n editHandlers = {\n onEditPanelClick: openEditPanel,\n onDuplicatePanelClick: duplicatePanel,\n onDeletePanelClick: openDeletePanelDialog,\n };\n }\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const suggestedStepMs = useSuggestedStepMs(width);\n\n const { data: plugin } = usePlugin('Panel', panelDefinition.spec.plugin.kind);\n\n const queryDefinitions = queries ?? [];\n const definitions = queryDefinitions.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n });\n\n const pluginQueryOptions =\n typeof plugin?.queryOptions === 'function'\n ? plugin?.queryOptions(panelDefinition.spec.plugin.spec)\n : plugin?.queryOptions;\n\n return (\n <Box\n ref={ref}\n sx={{\n width: '100%',\n height: '100%',\n }}\n >\n <DataQueriesProvider\n definitions={definitions}\n options={{ suggestedStepMs, ...pluginQueryOptions }}\n queryOptions={{ enabled: inView }}\n >\n {inView && (\n <Panel\n definition={panelDefinition}\n readHandlers={readHandlers}\n editHandlers={editHandlers}\n viewQueriesHandler={viewQueriesHandler}\n panelOptions={props.panelOptions}\n panelGroupItemId={panelGroupItemId}\n />\n )}\n </DataQueriesProvider>\n <QueryViewerDialog\n open={openQueryViewer}\n queryDefinitions={queryDefinitions}\n onClose={() => setOpenQueryViewer(false)}\n />\n </Box>\n );\n}\n"],"names":["Box","useInView","DataQueriesProvider","usePlugin","useSuggestedStepMs","React","useMemo","useState","isPanelGroupItemIdEqual","useEditMode","usePanel","usePanelActions","useViewPanelGroup","Panel","QueryViewerDialog","GridItemContent","props","panelGroupItemId","width","panelDefinition","spec","queries","isEditMode","openEditPanel","openDeletePanelDialog","duplicatePanel","viewPanel","viewPanelGroupItemId","ref","inView","threshold","initialInView","triggerOnce","openQueryViewer","setOpenQueryViewer","viewQueriesHandler","length","undefined","onClick","readHandlers","isPanelViewed","onViewPanelClick","editHandlers","onEditPanelClick","onDuplicatePanelClick","onDeletePanelClick","suggestedStepMs","data","plugin","kind","queryDefinitions","definitions","map","query","pluginQueryOptions","queryOptions","sx","height","options","enabled","definition","panelOptions","open","onClose"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,QAAQ,gBAAgB;AACpC,SAASC,SAAS,QAAQ,8BAA8B;AACxD,SAASC,mBAAmB,EAAEC,SAAS,EAAEC,kBAAkB,QAAQ,4BAA4B;AAC/F,OAAOC,SAAuBC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC/D,SAASC,uBAAuB,QAA0B,mBAAmB;AAC7E,SAASC,WAAW,EAAEC,QAAQ,EAAEC,eAAe,EAAEC,iBAAiB,QAAQ,gBAAgB;AAC1F,SAASC,KAAK,QAAkC,WAAW;AAC3D,SAASC,iBAAiB,QAAQ,uBAAuB;AAQzD;;CAEC,GACD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGF;IACpC,MAAMG,kBAAkBT,SAASO;IAEjC,MAAM,EACJG,MAAM,EAAEC,OAAO,EAAE,EAClB,GAAGF;IAEJ,MAAM,EAAEG,UAAU,EAAE,GAAGb;IACvB,MAAM,EAAEc,aAAa,EAAEC,qBAAqB,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGf,gBAAgBM;IAC5F,MAAMU,uBAAuBf;IAC7B,MAAM,EAAEgB,GAAG,EAAEC,MAAM,EAAE,GAAG5B,UAAU;QAChC6B,WAAW;QACXC,eAAe;QACfC,aAAa;IACf;IAEA,MAAM,CAACC,iBAAiBC,mBAAmB,GAAG3B,S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A;oBACdP,oBAAoBA;oBACpB0B,cAAc7C,MAAM6C,YAAY;oBAChC5C,kBAAkBA;;;0BAIxB,KAACH;gBACCgD,MAAM7B;gBACNiB,kBAAkBA;gBAClBa,SAAS,IAAM7B,mBAAmB;;;;AAI1C"}
1
+ {"version":3,"sources":["../../../src/components/GridLayout/GridItemContent.tsx"],"sourcesContent":["// Copyright 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 { Box, useForkRef } from '@mui/material';\nimport { useInView } from 'react-intersection-observer';\nimport { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';\nimport React, { ReactElement, useMemo, useState } from 'react';\nimport { isPanelGroupItemIdEqual, PanelGroupItemId } from '@perses-dev/core'; // TODO\nimport { useEditMode, usePanel, usePanelActions, useViewPanelGroup } from '../../context';\nimport { usePanelFocusHandlers } from '../../keyboard-shortcuts';\nimport { Panel, PanelProps, PanelOptions } from '../Panel';\nimport { QueryViewerDialog } from '../QueryViewerDialog';\n\nexport interface GridItemContentProps {\n panelGroupItemId: PanelGroupItemId;\n width: number; // necessary for determining the suggested step ms\n panelOptions?: PanelOptions;\n}\n\n/**\n * Resolves the reference to panel content in a GridItemDefinition and renders the panel.\n */\nexport function GridItemContent(props: GridItemContentProps): ReactElement {\n const { panelGroupItemId, width } = props;\n const panelDefinition = usePanel(panelGroupItemId);\n\n const {\n spec: { queries },\n } = panelDefinition;\n\n const { isEditMode } = useEditMode();\n const { openEditPanel, openDeletePanelDialog, duplicatePanel, viewPanel } = usePanelActions(panelGroupItemId);\n const viewPanelGroupItemId = useViewPanelGroup();\n\n // Panel focus tracking for keyboard shortcuts\n const { onMouseEnter, onMouseLeave } = usePanelFocusHandlers(\n `${panelGroupItemId.panelGroupId}-${panelGroupItemId.panelGroupItemLayoutId}`\n );\n\n const { ref: queryRef, inView: shouldQuery } = useInView({\n threshold: 0,\n initialInView: false,\n triggerOnce: true,\n });\n\n const { ref: renderRef, inView: shouldRender } = useInView({\n threshold: 0.2,\n initialInView: false,\n triggerOnce: false,\n });\n\n const mergedRef = useForkRef(renderRef, queryRef);\n\n const [openQueryViewer, setOpenQueryViewer] = useState(false);\n\n const viewQueriesHandler = useMemo(() => {\n return isEditMode || !queries?.length\n ? undefined\n : {\n onClick: (): void => {\n setOpenQueryViewer(true);\n },\n };\n }, [isEditMode, queries]);\n\n const readHandlers = {\n isPanelViewed: isPanelGroupItemIdEqual(viewPanelGroupItemId, panelGroupItemId),\n onViewPanelClick: function (): void {\n if (viewPanelGroupItemId === undefined) {\n viewPanel(panelGroupItemId);\n } else {\n viewPanel(undefined);\n }\n },\n };\n\n // Provide actions to the panel when in edit mode\n let editHandlers: PanelProps['editHandlers'] = undefined;\n if (isEditMode) {\n editHandlers = {\n onEditPanelClick: openEditPanel,\n onDuplicatePanelClick: duplicatePanel,\n onDeletePanelClick: openDeletePanelDialog,\n };\n }\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const suggestedStepMs = useSuggestedStepMs(width);\n\n const { data: plugin } = usePlugin('Panel', panelDefinition.spec.plugin.kind);\n\n const queryDefinitions = queries ?? [];\n const definitions = queryDefinitions.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n });\n\n const pluginQueryOptions =\n typeof plugin?.queryOptions === 'function'\n ? plugin?.queryOptions(panelDefinition.spec.plugin.spec)\n : plugin?.queryOptions;\n\n return (\n <Box\n ref={mergedRef}\n tabIndex={-1}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n sx={{\n width: '100%',\n height: '100%',\n outline: 'none',\n }}\n >\n <DataQueriesProvider\n definitions={definitions}\n options={{ suggestedStepMs, ...pluginQueryOptions }}\n queryOptions={{ enabled: shouldQuery }}\n >\n {shouldRender && (\n <Panel\n definition={panelDefinition}\n readHandlers={readHandlers}\n editHandlers={editHandlers}\n viewQueriesHandler={viewQueriesHandler}\n panelOptions={props.panelOptions}\n panelGroupItemId={panelGroupItemId}\n />\n )}\n </DataQueriesProvider>\n <QueryViewerDialog\n open={openQueryViewer}\n queryDefinitions={queryDefinitions}\n onClose={() => setOpenQueryViewer(false)}\n />\n </Box>\n );\n}\n"],"names":["Box","useForkRef","useInView","DataQueriesProvider","usePlugin","useSuggestedStepMs","React","useMemo","useState","isPanelGroupItemIdEqual","useEditMode","usePanel","usePanelActions","useViewPanelGroup","usePanelFocusHandlers","Panel","QueryViewerDialog","GridItemContent","props","panelGroupItemId","width","panelDefinition","spec","queries","isEditMode","openEditPanel","openDeletePanelDialog","duplicatePanel","viewPanel","viewPanelGroupItemId","onMouseEnter","onMouseLeave","panelGroupId","panelGroupItemLayoutId","ref","queryRef","inView","shouldQuery","threshold","initialInView","triggerOnce","renderRef","shouldRender","mergedRef","openQueryViewer","setOpenQueryViewer","viewQueriesHandler","length","undefined","onClick","readHandlers","isPanelViewed","onViewPanelClick","editHandlers","onEditPanelClick","onDuplicatePanelClick","onDeletePanelClick","suggestedStepMs","data","plugin","kind","queryDefinitions","definitions","map","query","pluginQueryOptions","queryOptions","tabIndex","sx","height","outline","options","enabled","definition","panelOptions","open","onClose"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,UAAU,QAAQ,gBAAgB;AAChD,SAASC,SAAS,QAAQ,8BAA8B;AACxD,SAASC,mBAAmB,EAAEC,SAAS,EAAEC,kBAAkB,QAAQ,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kBAAkBA;;;0BAIxB,KAACH;gBACC2D,MAAM/B;gBACNiB,kBAAkBA;gBAClBe,SAAS,IAAM/B,mBAAmB;;;;AAI1C"}
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { PanelGroupId } from '@perses-dev/core';
2
+ import { PanelGroupId } from '@perses-dev/spec';
3
3
  import { PanelOptions } from '../Panel';
4
4
  import { RowProps } from './Row';
5
5
  export interface GridLayoutProps {
@@ -1 +1 @@
1
- {"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAwB,MAAM,kBAAkB,CAAC;AAItE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAO,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,CAmE/D;AAED,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IACrD,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,UAAkB,EAClB,cAAc,EACd,aAAa,GACd,EAAE,qBAAqB,GAAG,YAAY,GAAG,IAAI,CA0C7C"}
1
+ {"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAO,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,CAmE/D;AAED,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IACrD,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,UAAkB,EAClB,cAAc,EACd,aAAa,GACd,EAAE,qBAAqB,GAAG,YAAY,GAAG,IAAI,CA0C7C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/GridLayout/GridLayout.tsx"],"sourcesContent":["// Copyright 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.\nimport { ReactElement, useState } from 'react';\nimport { Layouts, Layout } from 'react-grid-layout';\nimport { PanelGroupId, PanelGroupDefinition } from '@perses-dev/core';\nimport { useVariableValues, VariableContext } from '@perses-dev/plugin-system';\nimport { useEditMode, usePanelGroup, usePanelGroupActions, useViewPanelGroup } from '../../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { PanelOptions } from '../Panel';\nimport { Row, RowProps } from './Row';\n\nexport interface GridLayoutProps {\n panelGroupId: PanelGroupId;\n panelOptions?: PanelOptions;\n panelFullHeight?: number;\n}\n\n/**\n * Layout component that arranges children in a Grid based on the definition.\n */\nexport function GridLayout(props: GridLayoutProps): ReactElement {\n const { panelGroupId, panelOptions, panelFullHeight } = props;\n const groupDefinition: PanelGroupDefinition = usePanelGroup(panelGroupId);\n const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);\n const viewPanelItemId = useViewPanelGroup();\n const { isEditMode } = useEditMode();\n\n const [gridColWidth, setGridColWidth] = useState(0);\n\n const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId; // current panelGroup contains the panel extended?\n\n const handleLayoutChange = (currentLayout: Layout[], allLayouts: Layouts): void => {\n // Using the value from `allLayouts` instead of `currentLayout` because of\n // a bug in react-layout-grid where `currentLayout` does not adjust properly\n // when going to a smaller breakpoint and then back to a larger breakpoint.\n // https://github.com/react-grid-layout/react-grid-layout/issues/1663\n const smallLayout = allLayouts[GRID_LAYOUT_SMALL_BREAKPOINT];\n if (smallLayout && !hasViewPanel) {\n updatePanelGroupLayouts(smallLayout);\n }\n };\n\n /**\n * Calculate the column width so we can determine the width of each panel for suggested step ms\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\n const handleWidthChange = (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ): void => {\n const marginX = margin[0];\n const marginWidth = marginX * (cols - 1);\n const containerPaddingWidth = containerPadding[0] * 2;\n // exclude margin and padding from total width\n setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);\n };\n\n return (\n <>\n {!groupDefinition.repeatVariable ? (\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n />\n ) : (\n <RepeatGridLayout\n repeatVariableName={groupDefinition.repeatVariable}\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n />\n )}\n </>\n );\n}\n\nexport interface RepeatGridLayoutProps extends RowProps {\n repeatVariableName: string;\n}\n\n/**\n * Renders a grid layout for a repeated variable, where each value of the variable will create a new row.\n */\nexport function RepeatGridLayout({\n repeatVariableName,\n panelGroupId,\n groupDefinition,\n gridColWidth,\n panelFullHeight,\n panelOptions,\n isEditMode = false,\n onLayoutChange,\n onWidthChange,\n}: RepeatGridLayoutProps): ReactElement | null {\n const variables = useVariableValues();\n const variable = variables[repeatVariableName];\n\n // If the variable is not defined, or if it is defined but has no values, render a standard row without repeating\n if (variable === undefined || !Array.isArray(variable.value) || variable.value.length === 0) {\n return (\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n />\n );\n }\n\n return (\n <>\n {variable.value.map((value) => (\n <VariableContext.Provider\n key={`${repeatVariableName}-${value}`}\n value={{ state: { ...variables, [repeatVariableName]: { value, loading: false } } }}\n >\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n repeatVariable={[repeatVariableName, value]}\n />\n </VariableContext.Provider>\n ))}\n </>\n );\n}\n"],"names":["useState","useVariableValues","VariableContext","useEditMode","usePanelGroup","usePanelGroupActions","useViewPanelGroup","GRID_LAYOUT_SMALL_BREAKPOINT","Row","GridLayout","props","panelGroupId","panelOptions","panelFullHeight","groupDefinition","updatePanelGroupLayouts","viewPanelItemId","isEditMode","gridColWidth","setGridColWidth","hasViewPanel","handleLayoutChange","currentLayout","allLayouts","smallLayout","handleWidthChange","containerWidth","margin","cols","containerPadding","marginX","marginWidth","containerPaddingWidth","repeatVariable","onLayoutChange","onWidthChange","RepeatGridLayout","repeatVariableName","variables","variable","undefined","Array","isArray","value","length","map","Provider","state","loading"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AACjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAG/C,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,4BAA4B;AAC/E,SAASC,WAAW,EAAEC,aAAa,EAAEC,oBAAoB,EAAEC,iBAAiB,QAAQ,gBAAgB;AACpG,SAASC,4BAA4B,QAAQ,kBAAkB;AAE/D,SAASC,GAAG,QAAkB,QAAQ;AAQtC;;CAEC,GACD,OAAO,SAASC,WAAWC,KAAsB;IAC/C,MAAM,EAAEC,YAAY,EAAEC,YAAY,EAAEC,eAAe,EAAE,GAAGH;IACxD,MAAMI,kBAAwCV,cAAcO;IAC5D,MAAM,EAAEI,uBAAuB,EAAE,GAAGV,qBAAqBM;IACzD,MAAMK,kBAAkBV;IACxB,MAAM,EAAEW,UAAU,EAAE,GAAGd;IAEvB,MAAM,CAACe,cAAcC,gBAAgB,GAAGnB,SAAS;IAEjD,MAAMoB,eAAeJ,iBAAiBL,iBAAiBA,cAAc,kDAAkD;IAEvH,MAAMU,qBAAqB,CAACC,eAAyBC;QACnD,0EAA0E;QAC1E,4EAA4E;QAC5E,2EAA2E;QAC3E,qEAAqE;QACrE,MAAMC,cAAcD,UAAU,CAAChB,6BAA6B;QAC5D,IAAIiB,eAAe,CAACJ,cAAc;YAChCL,wBAAwBS;QAC1B;IACF;IA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AAO;oBAAEI,OAAO;wBAAE,GAAGT,SAAS;wBAAE,CAACD,mBAAmB,EAAE;4BAAEM;4BAAOK,SAAS;wBAAM;oBAAE;gBAAE;0BAElF,cAAA,KAACxC;oBACCG,cAAcA;oBACdG,iBAAiBA;oBACjBI,cAAcA;oBACdL,iBAAiBA;oBACjBD,cAAcA;oBACdK,YAAYA;oBACZiB,gBAAgBA;oBAChBC,eAAeA;oBACfF,gBAAgB;wBAACI;wBAAoBM;qBAAM;;eAZxC,GAAGN,mBAAmB,CAAC,EAAEM,OAAO;;AAkB/C"}
1
+ {"version":3,"sources":["../../../src/components/GridLayout/GridLayout.tsx"],"sourcesContent":["// Copyright 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.\nimport { ReactElement, useState } from 'react';\nimport { Layouts, Layout } from 'react-grid-layout';\nimport { PanelGroupDefinition } from '@perses-dev/core'; // TODO what should we do about the PanelGroupDefinition ?\nimport { PanelGroupId } from '@perses-dev/spec';\nimport { useVariableValues, VariableContext } from '@perses-dev/plugin-system';\nimport { useEditMode, usePanelGroup, usePanelGroupActions, useViewPanelGroup } from '../../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { PanelOptions } from '../Panel';\nimport { Row, RowProps } from './Row';\n\nexport interface GridLayoutProps {\n panelGroupId: PanelGroupId;\n panelOptions?: PanelOptions;\n panelFullHeight?: number;\n}\n\n/**\n * Layout component that arranges children in a Grid based on the definition.\n */\nexport function GridLayout(props: GridLayoutProps): ReactElement {\n const { panelGroupId, panelOptions, panelFullHeight } = props;\n const groupDefinition: PanelGroupDefinition = usePanelGroup(panelGroupId);\n const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);\n const viewPanelItemId = useViewPanelGroup();\n const { isEditMode } = useEditMode();\n\n const [gridColWidth, setGridColWidth] = useState(0);\n\n const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId; // current panelGroup contains the panel extended?\n\n const handleLayoutChange = (currentLayout: Layout[], allLayouts: Layouts): void => {\n // Using the value from `allLayouts` instead of `currentLayout` because of\n // a bug in react-layout-grid where `currentLayout` does not adjust properly\n // when going to a smaller breakpoint and then back to a larger breakpoint.\n // https://github.com/react-grid-layout/react-grid-layout/issues/1663\n const smallLayout = allLayouts[GRID_LAYOUT_SMALL_BREAKPOINT];\n if (smallLayout && !hasViewPanel) {\n updatePanelGroupLayouts(smallLayout);\n }\n };\n\n /**\n * Calculate the column width so we can determine the width of each panel for suggested step ms\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\n const handleWidthChange = (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ): void => {\n const marginX = margin[0];\n const marginWidth = marginX * (cols - 1);\n const containerPaddingWidth = containerPadding[0] * 2;\n // exclude margin and padding from total width\n setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);\n };\n\n return (\n <>\n {!groupDefinition.repeatVariable ? (\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n />\n ) : (\n <RepeatGridLayout\n repeatVariableName={groupDefinition.repeatVariable}\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n />\n )}\n </>\n );\n}\n\nexport interface RepeatGridLayoutProps extends RowProps {\n repeatVariableName: string;\n}\n\n/**\n * Renders a grid layout for a repeated variable, where each value of the variable will create a new row.\n */\nexport function RepeatGridLayout({\n repeatVariableName,\n panelGroupId,\n groupDefinition,\n gridColWidth,\n panelFullHeight,\n panelOptions,\n isEditMode = false,\n onLayoutChange,\n onWidthChange,\n}: RepeatGridLayoutProps): ReactElement | null {\n const variables = useVariableValues();\n const variable = variables[repeatVariableName];\n\n // If the variable is not defined, or if it is defined but has no values, render a standard row without repeating\n if (variable === undefined || !Array.isArray(variable.value) || variable.value.length === 0) {\n return (\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n />\n );\n }\n\n return (\n <>\n {variable.value.map((value) => (\n <VariableContext.Provider\n key={`${repeatVariableName}-${value}`}\n value={{ state: { ...variables, [repeatVariableName]: { value, loading: false } } }}\n >\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n repeatVariable={[repeatVariableName, value]}\n />\n </VariableContext.Provider>\n ))}\n </>\n );\n}\n"],"names":["useState","useVariableValues","VariableContext","useEditMode","usePanelGroup","usePanelGroupActions","useViewPanelGroup","GRID_LAYOUT_SMALL_BREAKPOINT","Row","GridLayout","props","panelGroupId","panelOptions","panelFullHeight","groupDefinition","updatePanelGroupLayouts","viewPanelItemId","isEditMode","gridColWidth","setGridColWidth","hasViewPanel","handleLayoutChange","currentLayout","allLayouts","smallLayout","handleWidthChange","containerWidth","margin","cols","containerPadding","marginX","marginWidth","containerPaddingWidth","repeatVariable","onLayoutChange","onWidthChange","RepeatGridLayout","repeatVariableName","variables","variable","undefined","Array","isArray","value","length","map","Prov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AgBA;oBAChBC,eAAeA;oBACfF,gBAAgB;wBAACI;wBAAoBM;qBAAM;;eAZxC,GAAGN,mBAAmB,CAAC,EAAEM,OAAO;;AAkB/C"}
@@ -1,4 +1,4 @@
1
- import { PanelGroupId } from '@perses-dev/core';
1
+ import { PanelGroupId } from '@perses-dev/spec';
2
2
  import { ReactElement } from 'react';
3
3
  export interface GridTitleProps {
4
4
  panelGroupId: PanelGroupId;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/GridLayout/GridTitle.tsx"],"sourcesContent":["// Copyright 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 { Box, IconButton, Stack, Typography } from '@mui/material';\nimport ExpandedIcon from 'mdi-material-ui/ChevronDown';\nimport CollapsedIcon from 'mdi-material-ui/ChevronRight';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport ArrowUpIcon from 'mdi-material-ui/ArrowUp';\nimport ArrowDownIcon from 'mdi-material-ui/ArrowDown';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport { InfoTooltip } from '@perses-dev/components';\nimport { useReplaceVariablesInString } from '@perses-dev/plugin-system';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { ReactElement } from 'react';\nimport { ARIA_LABEL_TEXT, TOOLTIP_TEXT } from '../../constants';\nimport { usePanelGroupActions, useEditMode, useDeletePanelGroupDialog } from '../../context';\n\nexport interface GridTitleProps {\n panelGroupId: PanelGroupId;\n title: string;\n collapse?: {\n isOpen: boolean;\n onToggleOpen: () => void;\n };\n}\n\n/**\n * Renders the title for a Grid section, optionally also supporting expanding\n * and collapsing\n */\nexport function GridTitle(props: GridTitleProps): ReactElement {\n const { panelGroupId, title: rawTitle, collapse } = props;\n\n const title = useReplaceVariablesInString(rawTitle) as string;\n\n const { openAddPanel, openEditPanelGroup, moveUp, moveDown } = usePanelGroupActions(panelGroupId);\n const { openDeletePanelGroupDialog } = useDeletePanelGroupDialog();\n const { isEditMode } = useEditMode();\n\n const text = <Typography variant=\"h2\">{title}</Typography>;\n\n return (\n <Box\n onClick={collapse?.onToggleOpen}\n sx={{\n display: 'flex',\n justifyContent: 'start',\n alignItems: 'center',\n cursor: collapse ? 'pointer' : 'auto',\n backgroundColor: ({ palette }) => palette.background.paper,\n }}\n data-testid=\"panel-group-header\"\n >\n {collapse ? (\n <>\n <IconButton sx={{ marginRight: 1 }} aria-label={`${collapse.isOpen ? 'collapse' : 'expand'} group ${title}`}>\n {collapse.isOpen ? <ExpandedIcon /> : <CollapsedIcon />}\n </IconButton>\n {text}\n {isEditMode && (\n <Stack direction=\"row\" marginLeft=\"auto\">\n <InfoTooltip description={TOOLTIP_TEXT.addPanelToGroup}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.addPanelToGroup(title)}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n openAddPanel();\n }}\n >\n <AddPanelIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.editGroup}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.editGroup(title)}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n openEditPanelGroup();\n }}\n >\n <PencilIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.deleteGroup}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.deleteGroup(title)}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n openDeletePanelGroupDialog(panelGroupId);\n }}\n >\n <DeleteIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.moveGroupDown}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.moveGroupDown(title)}\n disabled={moveDown === undefined}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n moveDown?.();\n }}\n >\n <ArrowDownIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.moveGroupUp}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.moveGroupUp(title)}\n disabled={moveUp === undefined}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n moveUp?.();\n }}\n >\n <ArrowUpIcon />\n </IconButton>\n </InfoTooltip>\n </Stack>\n )}\n </>\n ) : (\n // If we don't need expand/collapse, just render the title text\n text\n )}\n </Box>\n );\n}\n"],"names":["Box","IconButton","Stack","Typography","ExpandedIcon","CollapsedIcon","AddPanelIcon","PencilIcon","ArrowUpIcon","ArrowDownIcon","DeleteIcon","InfoTooltip","useReplaceVariablesInString","ARIA_LABEL_TEXT","TOOLTIP_TEXT","usePanelGroupActions","useEditMode","useDeletePanelGroupDialog","GridTitle","props","panelGroupId","title","rawTitle","collapse","openAddPanel","openEditPanelGroup","moveUp","moveDown","openDeletePanelGroupDialog","isEditMode","text","variant","onClick","onToggleOpen","sx","display","justifyContent","alignItems","cursor","backgroundColor","palette","background","paper","data-testid","marginRight","aria-label","isOpen","direction","marginLeft","description","addPanelToGroup","e","stopPropagation","editGroup","deleteGroup","moveGroupDown","disabled","undefined","moveGroupUp"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAgB;AACnE,OAAOC,kBAAkB,8BAA8B;AACvD,OAA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C,aAAanC,aAAaoC,eAAe;sCACpD,cAAA,KAACjD;gCACC4C,cAAYhC,gBAAgBqC,eAAe,CAAC7B;gCAC5CW,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjB5B;gCACF;0CAEA,cAAA,KAAClB;;;sCAGL,KAACK;4BAAYsC,aAAanC,aAAauC,SAAS;sCAC9C,cAAA,KAACpD;gCACC4C,cAAYhC,gBAAgBwC,SAAS,CAAChC;gCACtCW,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjB3B;gCACF;0CAEA,cAAA,KAAClB;;;sCAGL,KAACI;4BAAYsC,aAAanC,aAAawC,WAAW;sCAChD,cAAA,KAACrD;gCACC4C,cAAYhC,gBAAgByC,WAAW,CAACjC;gCACxCW,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjBxB,2BAA2BR;gCAC7B;0CAEA,cAAA,KAACV;;;sCAGL,KAACC;4BAAYsC,aAAanC,aAAayC,aAAa;sCAClD,cAAA,KAACtD;gCACC4C,cAAYhC,gBAAgB0C,aAAa,CAAClC;gCAC1CmC,UAAU7B,aAAa8B;gCACvBzB,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjBzB;gCACF;0CAEA,cAAA,KAAClB;;;sCAGL,KAACE;4BAAYsC,aAAanC,aAAa4C,WAAW;sCAChD,cAAA,KAACzD;gCACC4C,cAAYhC,gBAAgB6C,WAAW,CAACrC;gCACxCmC,UAAU9B,WAAW+B;gCACrBzB,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjB1B;gCACF;0CAEA,cAAA,KAAClB;;;;;;aAOX,+DAA+D;QAC/DsB;;AAIR"}
1
+ {"version":3,"sources":["../../../src/components/GridLayout/GridTitle.tsx"],"sourcesContent":["// Copyright 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 { Box, IconButton, Stack, Typography } from '@mui/material';\nimport ExpandedIcon from 'mdi-material-ui/ChevronDown';\nimport CollapsedIcon from 'mdi-material-ui/ChevronRight';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport ArrowUpIcon from 'mdi-material-ui/ArrowUp';\nimport ArrowDownIcon from 'mdi-material-ui/ArrowDown';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport { InfoTooltip } from '@perses-dev/components';\nimport { useReplaceVariablesInString } from '@perses-dev/plugin-system';\nimport { PanelGroupId } from '@perses-dev/spec';\nimport { ReactElement } from 'react';\nimport { ARIA_LABEL_TEXT, TOOLTIP_TEXT } from '../../constants';\nimport { usePanelGroupActions, useEditMode, useDeletePanelGroupDialog } from '../../context';\n\nexport interface GridTitleProps {\n panelGroupId: PanelGroupId;\n title: string;\n collapse?: {\n isOpen: boolean;\n onToggleOpen: () => void;\n };\n}\n\n/**\n * Renders the title for a Grid section, optionally also supporting expanding\n * and collapsing\n */\nexport function GridTitle(props: GridTitleProps): ReactElement {\n const { panelGroupId, title: rawTitle, collapse } = props;\n\n const title = useReplaceVariablesInString(rawTitle) as string;\n\n const { openAddPanel, openEditPanelGroup, moveUp, moveDown } = usePanelGroupActions(panelGroupId);\n const { openDeletePanelGroupDialog } = useDeletePanelGroupDialog();\n const { isEditMode } = useEditMode();\n\n const text = <Typography variant=\"h2\">{title}</Typography>;\n\n return (\n <Box\n onClick={collapse?.onToggleOpen}\n sx={{\n display: 'flex',\n justifyContent: 'start',\n alignItems: 'center',\n cursor: collapse ? 'pointer' : 'auto',\n backgroundColor: ({ palette }) => palette.background.paper,\n }}\n data-testid=\"panel-group-header\"\n >\n {collapse ? (\n <>\n <IconButton sx={{ marginRight: 1 }} aria-label={`${collapse.isOpen ? 'collapse' : 'expand'} group ${title}`}>\n {collapse.isOpen ? <ExpandedIcon /> : <CollapsedIcon />}\n </IconButton>\n {text}\n {isEditMode && (\n <Stack direction=\"row\" marginLeft=\"auto\">\n <InfoTooltip description={TOOLTIP_TEXT.addPanelToGroup}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.addPanelToGroup(title)}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n openAddPanel();\n }}\n >\n <AddPanelIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.editGroup}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.editGroup(title)}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n openEditPanelGroup();\n }}\n >\n <PencilIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.deleteGroup}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.deleteGroup(title)}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n openDeletePanelGroupDialog(panelGroupId);\n }}\n >\n <DeleteIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.moveGroupDown}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.moveGroupDown(title)}\n disabled={moveDown === undefined}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n moveDown?.();\n }}\n >\n <ArrowDownIcon />\n </IconButton>\n </InfoTooltip>\n <InfoTooltip description={TOOLTIP_TEXT.moveGroupUp}>\n <IconButton\n aria-label={ARIA_LABEL_TEXT.moveGroupUp(title)}\n disabled={moveUp === undefined}\n onClick={(e) => {\n // Don't trigger expand/collapse\n e.stopPropagation();\n moveUp?.();\n }}\n >\n <ArrowUpIcon />\n </IconButton>\n </InfoTooltip>\n </Stack>\n )}\n </>\n ) : (\n // If we don't need expand/collapse, just render the title text\n text\n )}\n </Box>\n );\n}\n"],"names":["Box","IconButton","Stack","Typography","ExpandedIcon","CollapsedIcon","AddPanelIcon","PencilIcon","ArrowUpIcon","ArrowDownIcon","DeleteIcon","InfoTooltip","useReplaceVariablesInString","ARIA_LABEL_TEXT","TOOLTIP_TEXT","usePanelGroupActions","useEditMode","useDeletePanelGroupDialog","GridTitle","props","panelGroupId","title","rawTitle","collapse","openAddPanel","openEditPanelGroup","moveUp","moveDown","openDeletePanelGroupDialog","isEditMode","text","variant","onClick","onToggleOpen","sx","display","justifyContent","alignItems","cursor","backgroundColor","palette","background","paper","data-testid","marginRight","aria-label","isOpen","direction","marginLeft","description","addPanelToGroup","e","stopPropagation","editGroup","deleteGroup","moveGroupDown","disabled","undefined","moveGroupUp"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAgB;AACnE,OAAOC,kBAAkB,8BAA8B;AACvD,OAAOC,mBAAmB,+BAA+B;AACzD,OAAOC,kBAAkB,sCAAsC;AAC/D,OAAOC,gBAAgB,gCAAgC;AACvD,OAAOC,iBAAiB,0BAA0B;AAClD,OAAOC,mBAAmB,4BAA4B;AACtD,OAAOC,gBAAgB,gCAAgC;AACvD,SAASC,WAAW,QAAQ,yBAAyB;AACrD,SAASC,2BAA2B,QAAQ,4BAA4B;AAGxE,SAASC,eAAe,EAAEC,YAAY,QAAQ,kBAAkB;AAChE,SAASC,oBAAoB,EAAEC,WAAW,EAAEC,yBAAyB,QAAQ,gBAAgB;AAW7F;;;CAGC,GACD,OAAO,SAASC,UAAUC,KAAqB;IAC7C,MAAM,EA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AAawC,WAAW;sCAChD,cAAA,KAACrD;gCACC4C,cAAYhC,gBAAgByC,WAAW,CAACjC;gCACxCW,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjBxB,2BAA2BR;gCAC7B;0CAEA,cAAA,KAACV;;;sCAGL,KAACC;4BAAYsC,aAAanC,aAAayC,aAAa;sCAClD,cAAA,KAACtD;gCACC4C,cAAYhC,gBAAgB0C,aAAa,CAAClC;gCAC1CmC,UAAU7B,aAAa8B;gCACvBzB,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjBzB;gCACF;0CAEA,cAAA,KAAClB;;;sCAGL,KAACE;4BAAYsC,aAAanC,aAAa4C,WAAW;sCAChD,cAAA,KAACzD;gCACC4C,cAAYhC,gBAAgB6C,WAAW,CAACrC;gCACxCmC,UAAU9B,WAAW+B;gCACrBzB,SAAS,CAACmB;oCACR,gCAAgC;oCAChCA,EAAEC,eAAe;oCACjB1B;gCACF;0CAEA,cAAA,KAAClB;;;;;;aAOX,+DAA+D;QAC/DsB;;AAIR"}
@@ -1,4 +1,5 @@
1
- import { PanelGroupId, PanelGroupDefinition } from '@perses-dev/core';
1
+ import { PanelGroupDefinition } from '@perses-dev/core';
2
+ import { PanelGroupId } from '@perses-dev/spec';
2
3
  import { PanelOptions } from '@perses-dev/dashboards';
3
4
  import { ReactElement } from 'react';
4
5
  import { Layout, Layouts } from 'react-grid-layout';
@@ -1 +1 @@
1
- {"version":3,"file":"Row.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/Row.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAwB,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAqB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAgC,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,OAAO,EAA6B,MAAM,mBAAmB,CAAC;AAU/E,M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EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACxE,aAAa,CAAC,EAAE,CACd,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KAC/B,IAAI,CAAC;IACV,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,wBAAgB,GAAG,CAAC,EAClB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,UAAkB,EAClB,cAAc,EACd,aAAa,EACb,cAAc,GACf,EAAE,QAAQ,GAAG,YAAY,CAoGzB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/GridLayout/Row.tsx"],"sourcesContent":["// Copyright 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 { Collapse, useTheme } from '@mui/material';\nimport { PanelGroupId, PanelGroupDefinition, PanelGroupItemLayout } from '@perses-dev/core';\nimport { PanelOptions, useViewPanelGroup } from '@perses-dev/dashboards';\nimport { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Layout, Layouts, Responsive, WidthProvider } from 'react-grid-layout';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { GridContainer } from './GridContainer';\nimport { GridItemContent } from './GridItemContent';\nimport { GridTitle } from './GridTitle';\n\nconst DEFAULT_MARGIN = 10;\nconst ROW_HEIGHT = 30;\n\nexport interface RowProps {\n panelGroupId: PanelGroupId;\n groupDefinition: PanelGroupDefinition;\n gridColWidth: number;\n panelFullHeight?: number;\n panelOptions?: PanelOptions;\n isEditMode?: boolean;\n onLayoutChange?: (currentLayout: Layout[], allLayouts: Layouts) => void;\n onWidthChange?: (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ) => void;\n repeatVariable?: [string, string];\n}\n\nexport function Row({\n panelGroupId,\n groupDefinition,\n gridColWidth,\n panelFullHeight,\n panelOptions,\n isEditMode = false,\n onLayoutChange,\n onWidthChange,\n repeatVariable,\n}: RowProps): ReactElement {\n const ResponsiveGridLayout = useMemo(() => WidthProvider(Responsive), []);\n const theme = useTheme();\n const viewPanelItemId = useViewPanelGroup();\n\n const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed);\n\n const hasViewPanel =\n viewPanelItemId?.panelGroupId === panelGroupId &&\n // Check for repeatVariable panels\n viewPanelItemId.repeatVariable?.[0] === repeatVariable?.[0] &&\n viewPanelItemId.repeatVariable?.[1] === repeatVariable?.[1];\n const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;\n\n // If there is a panel in view mode, we should hide the grid if the panel is not in the current group.\n const isGridDisplayed = !viewPanelItemId || hasViewPanel;\n\n // TODO: handle it without useEffect\n useEffect(() => {\n if (hasViewPanel) {\n setIsOpen(true);\n }\n }, [hasViewPanel]);\n\n // Item layout is override if there is a panel in view mode\n const itemLayouts: PanelGroupItemLayout[] = useMemo(() => {\n if (itemLayoutViewed) {\n return groupDefinition.itemLayouts.map((itemLayout) => {\n if (itemLayout.i === itemLayoutViewed) {\n const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height\n return {\n h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)), // Viewed panel should take the full height remaining\n i: itemLayoutViewed,\n w: 48,\n x: 0,\n y: 0,\n } as PanelGroupItemLayout;\n }\n return itemLayout;\n });\n }\n return groupDefinition.itemLayouts;\n }, [groupDefinition.itemLayouts, itemLayoutViewed, panelFullHeight]);\n\n return (\n <GridContainer\n sx={{\n display: isGridDisplayed ? 'block' : 'none',\n height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',\n overflow: itemLayoutViewed ? 'hidden' : 'unset',\n }}\n >\n {groupDefinition.title && (\n <GridTitle\n panelGroupId={panelGroupId}\n title={groupDefinition.title}\n collapse={\n groupDefinition.isCollapsed === undefined\n ? undefined\n : { isOpen: isOpen, onToggleOpen: () => setIsOpen((current) => !current) }\n }\n />\n )}\n <Collapse in={isOpen} unmountOnExit appear={false} data-testid=\"panel-group-content\">\n <ResponsiveGridLayout\n className=\"layout\"\n breakpoints={{ [GRID_LAYOUT_SMALL_BREAKPOINT]: theme.breakpoints.values.sm, xxs: 0 }}\n cols={GRID_LAYOUT_COLS}\n rowHeight={ROW_HEIGHT}\n draggableHandle=\".drag-handle\"\n resizeHandles={['se']}\n isDraggable={isEditMode && !hasViewPanel}\n isResizable={isEditMode && !hasViewPanel}\n margin={[DEFAULT_MARGIN, DEFAULT_MARGIN]}\n containerPadding={[0, 10]}\n layouts={{ sm: itemLayouts }}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n allowOverlap={hasViewPanel} // Enabling overlap when viewing a specific panel because panel in front of the viewed panel will add empty spaces (empty row height)\n >\n {itemLayouts.map(({ i, w }) => (\n <div\n key={i}\n style={{\n display: itemLayoutViewed ? (itemLayoutViewed === i ? 'unset' : 'none') : 'unset',\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <GridItemContent\n panelOptions={panelOptions}\n panelGroupItemId={{ panelGroupId, panelGroupItemLayoutId: i, repeatVariable }}\n width={calculateGridItemWidth(w, gridColWidth)}\n />\n </ErrorBoundary>\n </div>\n ))}\n </ResponsiveGridLayout>\n </Collapse>\n </GridContainer>\n );\n}\n\nconst calculateGridItemWidth = (w: number, colWidth: number): number => {\n // 0 * Infinity === NaN, which causes problems with resize contraints\n if (!Number.isFinite(w)) return w;\n return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);\n};\n"],"names":["Collapse","useTheme","useViewPanelGroup","useEffect","useMemo","useState","Responsive","WidthProvider","ErrorAlert","ErrorBoundary","GRID_LAYOUT_COLS","GRID_LAYOUT_SMALL_BREAKPOINT","GridContainer","GridItemContent","GridTitle","DEFAULT_MARGIN","ROW_HEIGHT","Row","panelGroupId","groupDefinition","gridColWidth","panelFullHeight","panelOptions","isEditMode","onLayoutChange","onWidthChange","repeatVariable","ResponsiveGridLayout","theme","viewPanelItemId","isOpen","setIsOpen","isCollapsed","hasViewPanel","itemLayoutViewed","panelGroupItemLayoutId","isGridDisplayed","itemLayouts","map","itemLayout","i","rowTitleHeight","h","Math","round","window","innerHeight","w","x","y","sx","display","height","overflow","title","collapse","undefined","onToggleOpen","current","in","unmountOnExit","appear","data-testid","className","breakpoints","values","sm","xxs","cols","rowHeight","draggableHandle","resizeHandles","isDraggable","isResizable","margin","containerPadding","layouts","allowOverlap","div","style","FallbackComponent","panelGroupItemId","width","calculateGridItemWidth","colWidth","Number","isFinite","max"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,QAAQ,EAAEC,QAAQ,QAAQ,gBAAgB;AAEnD,SAAuBC,iBAAiB,QAAQ,yBAAyB;AACzE,SAAuBC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACnE,SAA0BC,UAAU,EAAEC,aAAa,QAAQ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,KAAC+B;4BAECC,OAAO;gCACL5B,SAASjB,mBAAoBA,qBAAqBM,IAAI,UAAU,SAAU;4BAC5E;sCAEA,cAAA,KAAC/B;gCAAcuE,mBAAmBxE;0CAChC,cAAA,KAACK;oCACCS,cAAcA;oCACd2D,kBAAkB;wCAAE/D;wCAAciB,wBAAwBK;wCAAGd;oCAAe;oCAC5EwD,OAAOC,uBAAuBpC,GAAG3B;;;2BAThCoB;;;;;AAkBnB;AAEA,MAAM2C,yBAAyB,CAACpC,GAAWqC;IACzC,qEAAqE;IACrE,IAAI,CAACC,OAAOC,QAAQ,CAACvC,IAAI,OAAOA;IAChC,OAAOJ,KAAKC,KAAK,CAACwC,WAAWrC,IAAIJ,KAAK4C,GAAG,CAAC,GAAGxC,IAAI,KAAKhC;AACxD"}
1
+ {"version":3,"sources":["../../../src/components/GridLayout/Row.tsx"],"sourcesContent":["// Copyright 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 { Collapse, useTheme } from '@mui/material';\nimport { PanelGroupDefinition, PanelGroupItemLayout } from '@perses-dev/core'; // TODO should go somewhere else\nimport { PanelGroupId } from '@perses-dev/spec';\nimport { PanelOptions, useViewPanelGroup } from '@perses-dev/dashboards';\nimport { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Layout, Layouts, Responsive, WidthProvider } from 'react-grid-layout';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { GridContainer } from './GridContainer';\nimport { GridItemContent } from './GridItemContent';\nimport { GridTitle } from './GridTitle';\n\nconst DEFAULT_MARGIN = 10;\nconst ROW_HEIGHT = 30;\n\nexport interface RowProps {\n panelGroupId: PanelGroupId;\n groupDefinition: PanelGroupDefinition;\n gridColWidth: number;\n panelFullHeight?: number;\n panelOptions?: PanelOptions;\n isEditMode?: boolean;\n onLayoutChange?: (currentLayout: Layout[], allLayouts: Layouts) => void;\n onWidthChange?: (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ) => void;\n repeatVariable?: [string, string];\n}\n\nexport function Row({\n panelGroupId,\n groupDefinition,\n gridColWidth,\n panelFullHeight,\n panelOptions,\n isEditMode = false,\n onLayoutChange,\n onWidthChange,\n repeatVariable,\n}: RowProps): ReactElement {\n const ResponsiveGridLayout = useMemo(() => WidthProvider(Responsive), []);\n const theme = useTheme();\n const viewPanelItemId = useViewPanelGroup();\n\n const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed);\n\n const hasViewPanel =\n viewPanelItemId?.panelGroupId === panelGroupId &&\n // Check for repeatVariable panels\n viewPanelItemId.repeatVariable?.[0] === repeatVariable?.[0] &&\n viewPanelItemId.repeatVariable?.[1] === repeatVariable?.[1];\n const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;\n\n // If there is a panel in view mode, we should hide the grid if the panel is not in the current group.\n const isGridDisplayed = !viewPanelItemId || hasViewPanel;\n\n // TODO: handle it without useEffect\n useEffect(() => {\n if (hasViewPanel) {\n setIsOpen(true);\n }\n }, [hasViewPanel]);\n\n // Item layout is override if there is a panel in view mode\n const itemLayouts: PanelGroupItemLayout[] = useMemo(() => {\n if (itemLayoutViewed) {\n return groupDefinition.itemLayouts.map((itemLayout) => {\n if (itemLayout.i === itemLayoutViewed) {\n const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height\n return {\n h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)), // Viewed panel should take the full height remaining\n i: itemLayoutViewed,\n w: 48,\n x: 0,\n y: 0,\n } as PanelGroupItemLayout;\n }\n return itemLayout;\n });\n }\n return groupDefinition.itemLayouts;\n }, [groupDefinition.itemLayouts, itemLayoutViewed, panelFullHeight]);\n\n return (\n <GridContainer\n sx={{\n display: isGridDisplayed ? 'block' : 'none',\n height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',\n overflow: itemLayoutViewed ? 'hidden' : 'unset',\n }}\n >\n {groupDefinition.title && (\n <GridTitle\n panelGroupId={panelGroupId}\n title={groupDefinition.title}\n collapse={\n groupDefinition.isCollapsed === undefined\n ? undefined\n : { isOpen: isOpen, onToggleOpen: () => setIsOpen((current) => !current) }\n }\n />\n )}\n <Collapse in={isOpen} unmountOnExit appear={false} data-testid=\"panel-group-content\">\n <ResponsiveGridLayout\n className=\"layout\"\n breakpoints={{ [GRID_LAYOUT_SMALL_BREAKPOINT]: theme.breakpoints.values.sm, xxs: 0 }}\n cols={GRID_LAYOUT_COLS}\n rowHeight={ROW_HEIGHT}\n draggableHandle=\".drag-handle\"\n resizeHandles={['se']}\n isDraggable={isEditMode && !hasViewPanel}\n isResizable={isEditMode && !hasViewPanel}\n margin={[DEFAULT_MARGIN, DEFAULT_MARGIN]}\n containerPadding={[0, 10]}\n layouts={{ sm: itemLayouts }}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n allowOverlap={hasViewPanel} // Enabling overlap when viewing a specific panel because panel in front of the viewed panel will add empty spaces (empty row height)\n >\n {itemLayouts.map(({ i, w }) => (\n <div\n key={i}\n style={{\n display: itemLayoutViewed ? (itemLayoutViewed === i ? 'unset' : 'none') : 'unset',\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <GridItemContent\n panelOptions={panelOptions}\n panelGroupItemId={{ panelGroupId, panelGroupItemLayoutId: i, repeatVariable }}\n width={calculateGridItemWidth(w, gridColWidth)}\n />\n </ErrorBoundary>\n </div>\n ))}\n </ResponsiveGridLayout>\n </Collapse>\n </GridContainer>\n );\n}\n\nconst calculateGridItemWidth = (w: number, colWidth: number): number => {\n // 0 * Infinity === NaN, which causes problems with resize contraints\n if (!Number.isFinite(w)) return w;\n return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);\n};\n"],"names":["Collapse","useTheme","useViewPanelGroup","useEffect","useMemo","useState","Responsive","WidthProvider","ErrorAlert","ErrorBoundary","GRID_LAYOUT_COLS","GRID_LAYOUT_SMALL_BREAKPOINT","GridContainer","GridItemContent","GridTitle","DEFAULT_MARGIN","ROW_HEIGHT","Row","panelGroupId","groupDefinition","gridColWidth","panelFullHeight","panelOptions","isEditMode","onLayoutChange","onWidthChange","repeatVariable","ResponsiveGridLayout","theme","viewPanelItemId","isOpen","setIsOpen","isCollapsed","hasViewPanel","itemLayoutViewed","panelGroupItemLayoutId","isGridDisplayed","itemLayouts","map","itemLayout","i","rowTitleHeight","h","Math","round","window","innerHeight","w","x","y","sx","display","height","overflow","title","collapse","undefined","onToggleOpen","current","in","unmountOnExit","appear","data-testid","className","breakpoints","values","sm","xxs","cols","rowHeight","draggableHandle","resizeHandles","isDraggable","isResizable","margin","containerPadding","layouts","allowOverlap","div","style","FallbackComponent","panelGroupItemId","width","calculateGridItemWidth","colWidth","Number","isFinite","max"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,QAAQ,EAAEC,QAAQ,QAAQ,gBAAgB;AAGnD,SAAuBC,iBAAiB,QAAQ,yBAAyB;AACzE,SAAuBC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACnE,SAA0BC,UAAU,EAAEC,aAAa,QAAQ,oBAAoB;AAC/E,SAASC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACnE,SAASC,gBAAgB,EAAEC,4BAA4B,QAAQ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AAC/B;gCAAcuE,mBAAmBxE;0CAChC,cAAA,KAACK;oCACCS,cAAcA;oCACd2D,kBAAkB;wCAAE/D;wCAAciB,wBAAwBK;wCAAGd;oCAAe;oCAC5EwD,OAAOC,uBAAuBpC,GAAG3B;;;2BAThCoB;;;;;AAkBnB;AAEA,MAAM2C,yBAAyB,CAACpC,GAAWqC;IACzC,qEAAqE;IACrE,IAAI,CAACC,OAAOC,QAAQ,CAACvC,IAAI,OAAOA;IAChC,OAAOJ,KAAKC,KAAK,CAACwC,WAAWrC,IAAIJ,KAAK4C,GAAG,CAAC,GAAGxC,IAAI,KAAKhC;AACxD"}
@@ -1,13 +1,13 @@
1
- import { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';
2
1
  import { ReactElement, ReactNode } from 'react';
3
2
  import type { BlockerFunction } from '@remix-run/router';
3
+ import { DashboardResource } from '../../model';
4
4
  export interface LeaveDialogProps {
5
5
  isBlocked: BlockerFunction | boolean;
6
6
  message: string;
7
7
  }
8
8
  export declare function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement;
9
9
  export declare function LeaveDialog({ original, current, }: {
10
- original: DashboardResource | EphemeralDashboardResource | undefined;
11
- current: DashboardResource | EphemeralDashboardResource;
10
+ original: DashboardResource | undefined;
11
+ current: DashboardResource;
12
12
  }): ReactNode;
13
13
  //# sourceMappingURL=LeaveDialog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LeaveDialog.d.ts","sourceRoot":"","sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQzD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,YAAY,CA4B7E;AAKD,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,iBAAiB,GAAG,0BAA0B,GAAG,SAAS,CAAC;IACrE,OAAO,EAAE,iBAAiB,GAAG,0BAA0B,CAAC;CACzD,GAAG,SAAS,CAYZ"}
1
+ {"version":3,"file":"LeaveDialog.d.ts","sourceRoot":"","sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQhD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,YAAY,CA4B7E;AAKD,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,SAAS,CAYZ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"sourcesContent":["// Copyright 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 { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';\nimport { ReactElement, ReactNode, useEffect } from 'react';\nimport { useBlocker } from 'react-router-dom';\nimport { DiscardChangesConfirmationDialog } from '@perses-dev/components';\nimport type { BlockerFunction } from '@remix-run/router';\n\nconst handleRouteChange = (event: BeforeUnloadEvent): string => {\n event.preventDefault();\n event.returnValue = ''; // Required for Chrome\n return ''; // Required for other browsers\n};\n\nexport interface LeaveDialogProps {\n isBlocked: BlockerFunction | boolean;\n message: string;\n}\n\n/*\n * Prompt component uses the useBlocker hook to block react-router navigation when there are unsaved changes.\n * It also listens to the beforeunload event to show a browser confirmation dialog when the user tries to close the tab, refresh the page or change url manually.\n */\nexport function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement {\n const blocker = useBlocker(isBlocked);\n const isBlockedState = blocker.state === 'blocked';\n const isProceedingState = blocker.state === 'proceeding';\n\n useEffect(() => {\n if (isBlocked) {\n window.addEventListener('beforeunload', handleRouteChange);\n } else {\n window.removeEventListener('beforeunload', handleRouteChange);\n }\n\n return (): void => {\n window.removeEventListener('beforeunload', handleRouteChange);\n };\n }, [blocker, isBlocked, isBlockedState]);\n\n const handleDiscardChanges = (): void => blocker.proceed?.();\n const handleCancel = (): void => blocker.reset?.();\n\n return (\n <DiscardChangesConfirmationDialog\n description={message}\n isOpen={isBlockedState || isProceedingState}\n onDiscardChanges={handleDiscardChanges}\n onCancel={handleCancel}\n />\n );\n}\n\n/*\n * LeaveDialog prompts the user with a confirmation dialog when they attempt to leave the page with unsaved changes.\n */\nexport function LeaveDialog({\n original,\n current,\n}: {\n original: DashboardResource | EphemeralDashboardResource | undefined;\n current: DashboardResource | EphemeralDashboardResource;\n}): ReactNode {\n const handleIsBlocked: BlockerFunction = (ctx) => {\n if (JSON.stringify(original) !== JSON.stringify(current)) {\n // Only block navigation if the pathname is changing (=> ignore search params changes)\n if (ctx.currentLocation.pathname !== ctx.nextLocation.pathname) {\n return true;\n }\n }\n return false;\n };\n\n return <Prompt isBlocked={handleIsBlocked} message=\"You have unsaved changes, are you sure you want to leave?\" />;\n}\n"],"names":["useEffect","useBlocker","DiscardChangesConfirmationDialog","handleRouteChange","event","preventDefault","returnValue","Prompt","isBlocked","message","blocker","isBlockedState","state","isProceedingState","window","addEventListener","removeEventListener","handleDiscardChanges","proceed","handleCancel","reset","description","isOpen","onDiscardChanges","onCancel","LeaveDialog","original","current","handleIsBlocked","ctx","JSON","stringify","currentLocation","pathname","nextLocation"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAAkCA,SAAS,QAAQ,QAAQ;AAC3D,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,gCAAgC,QAAQ,yBAAyB;AAG1E,MAAMC,oBAAoB,CAACC;IACzBA,MAAMC,cAAc;IACpBD,MAAME,WAAW,GAAG,IAAI,sBAAsB;IAC9C,OAAO,IAAI,8BAA8B;AAC3C;AAOA;;;CAGC,GACD,OAAO,SAASC,OAAO,EAAEC,SAAS,EAAEC,OAAO,EAAoB;IAC7D,MAAMC,UAAUT,WAAWO;IAC3B,MAAMG,iBAAiBD,QAAQE,KAAK,KAAK;IACzC,MAAMC,oBAAoBH,QAAQE,KAAK,KAAK;IAE5CZ,UAAU;QACR,IAAIQ,WAAW;YACbM,OAAOC,gBAAgB,CAAC,gBAAgBZ;QAC1C,OAAO;YACLW,OAAOE,mBAAmB,CAAC,gBAAgBb;QAC7C;QAEA,OAAO;YACLW,OAAOE,mBAAmB,CAAC,gBAAgBb;QAC7C;IACF,GAAG;QAACO;QAASF;QAAWG;KAAe;IAEvC,MAAMM,uBAAuB,IAAYP,QAAQQ,OAAO;IACxD,MAAMC,eAAe,IAAYT,QAAQU,KAAK;IAE9C,qBACE,KAAClB;QACCmB,aAAaZ;QACba,QAAQX,kBAAkBE;QAC1BU,kBAAkBN;QAClBO,UAAUL;;AAGhB;AAEA;;CAEC,GACD,OAAO,SAASM,YAAY,EAC1BC,QAAQ,EACRC,OAAO,EAIR;IACC,MAAMC,kBAAmC,CAACC;QACxC,IAAIC,KAAKC,SAAS,CAACL,cAAcI,KAAKC,SAAS,CAACJ,UAAU;YACxD,sFAAsF;YACtF,IAAIE,IAAIG,eAAe,CAACC,QAAQ,KAAKJ,IAAIK,YAAY,CAACD,QAAQ,EAAE;gBAC9D,OAAO;YACT;QACF;QACA,OAAO;IACT;IAEA,qBAAO,KAAC1B;QAAOC,WAAWoB;QAAiBnB,SAAQ;;AACrD"}
1
+ {"version":3,"sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"sourcesContent":["// Copyright 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 { ReactElement, ReactNode, useEffect } from 'react';\nimport { useBlocker } from 'react-router-dom';\nimport { DiscardChangesConfirmationDialog } from '@perses-dev/components';\nimport type { BlockerFunction } from '@remix-run/router';\nimport { DashboardResource } from '../../model';\n\nconst handleRouteChange = (event: BeforeUnloadEvent): string => {\n event.preventDefault();\n event.returnValue = ''; // Required for Chrome\n return ''; // Required for other browsers\n};\n\nexport interface LeaveDialogProps {\n isBlocked: BlockerFunction | boolean;\n message: string;\n}\n\n/*\n * Prompt component uses the useBlocker hook to block react-router navigation when there are unsaved changes.\n * It also listens to the beforeunload event to show a browser confirmation dialog when the user tries to close the tab, refresh the page or change url manually.\n */\nexport function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement {\n const blocker = useBlocker(isBlocked);\n const isBlockedState = blocker.state === 'blocked';\n const isProceedingState = blocker.state === 'proceeding';\n\n useEffect(() => {\n if (isBlocked) {\n window.addEventListener('beforeunload', handleRouteChange);\n } else {\n window.removeEventListener('beforeunload', handleRouteChange);\n }\n\n return (): void => {\n window.removeEventListener('beforeunload', handleRouteChange);\n };\n }, [blocker, isBlocked, isBlockedState]);\n\n const handleDiscardChanges = (): void => blocker.proceed?.();\n const handleCancel = (): void => blocker.reset?.();\n\n return (\n <DiscardChangesConfirmationDialog\n description={message}\n isOpen={isBlockedState || isProceedingState}\n onDiscardChanges={handleDiscardChanges}\n onCancel={handleCancel}\n />\n );\n}\n\n/*\n * LeaveDialog prompts the user with a confirmation dialog when they attempt to leave the page with unsaved changes.\n */\nexport function LeaveDialog({\n original,\n current,\n}: {\n original: DashboardResource | undefined;\n current: DashboardResource;\n}): ReactNode {\n const handleIsBlocked: BlockerFunction = (ctx) => {\n if (JSON.stringify(original) !== JSON.stringify(current)) {\n // Only block navigation if the pathname is changing (=> ignore search params changes)\n if (ctx.currentLocation.pathname !== ctx.nextLocation.pathname) {\n return true;\n }\n }\n return false;\n };\n\n return <Prompt isBlocked={handleIsBlocked} message=\"You have unsaved changes, are you sure you want to leave?\" />;\n}\n"],"names":["useEffect","useBlocker","DiscardChangesConfirmationDialog","handleRouteChange","event","preventDefault","returnValue","Prompt","isBlocked","message","blocker","isBlockedState","state","isProceedingState","window","addEventListener","removeEventListener","handleDiscardChanges","proceed","handleCancel","reset","description","isOpen","onDiscardChanges","onCancel","LeaveDialog","original","current","handleIsBlocked","ctx","JSON","stringify","currentLocation","pathname","nextLocation"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iC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/spec';
2
+ import { ReactElement } from 'react';
3
+ type LinksVariant = 'dashboard' | 'panel';
4
+ interface LinksProps {
5
+ links: Link[];
6
+ variant: LinksVariant;
7
+ }
8
+ export declare function LinksDisplay({ links, variant }: LinksProps): ReactElement | null;
9
+ export {};
10
+ //# sourceMappingURL=LinksDisplay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinksDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/LinksDisplay/LinksDisplay.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAc,YAAY,EAAY,MAAM,OAAO,CAAC;AAI3D,KAAK,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC;AAE1C,UAAU,UAAU;IAClB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI,CAiFhF"}
@@ -11,12 +11,12 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { IconButton, Link as LinkComponent, Menu, MenuItem } from '@mui/material';
14
+ import { IconButton, Link as LinkComponent, Menu, MenuItem, Chip, capitalize, Stack } from '@mui/material';
15
15
  import LaunchIcon from 'mdi-material-ui/Launch';
16
16
  import { useState } from 'react';
17
17
  import { InfoTooltip } from '@perses-dev/components';
18
18
  import { useReplaceVariablesInString } from '@perses-dev/plugin-system';
19
- export function PanelLinks({ links }) {
19
+ export function LinksDisplay({ links, variant }) {
20
20
  const [anchorEl, setAnchorEl] = useState(null);
21
21
  const isMenuOpened = Boolean(anchorEl);
22
22
  const handleOpenMenu = (event)=>{
@@ -25,21 +25,48 @@ export function PanelLinks({ links }) {
25
25
  const handleClose = ()=>{
26
26
  setAnchorEl(null);
27
27
  };
28
- // If there is only one link, show it directly
29
- if (links.length === 1 && links[0]) {
30
- const link = links[0];
28
+ if (links.length === 0) {
29
+ return null;
30
+ }
31
+ // Panel variant: single link shows as icon button
32
+ if (variant === 'panel' && links.length === 1 && links[0]) {
31
33
  return /*#__PURE__*/ _jsx(LinkButton, {
32
- link: link
34
+ link: links[0]
35
+ });
36
+ }
37
+ // Dashboard variant: 1-3 links show as chips
38
+ // Max character limit for the name and url to prevent overflow
39
+ // in the dashboard title area, but if either the name or url is too long,
40
+ // we will fall back to showing the links in a dropdown menu
41
+ if (variant === 'dashboard' && links.length <= 3) {
42
+ const canRenderAsChips = links.every((link)=>{
43
+ if (link.name) {
44
+ return link.name.length < 30;
45
+ }
46
+ if (link.url) {
47
+ return link.url.length < 70;
48
+ }
49
+ return false;
33
50
  });
51
+ if (canRenderAsChips) {
52
+ return /*#__PURE__*/ _jsx(Stack, {
53
+ direction: "row",
54
+ spacing: 1,
55
+ children: links.map((link)=>/*#__PURE__*/ _jsx(LinkChip, {
56
+ link: link
57
+ }, link.url))
58
+ });
59
+ }
34
60
  }
35
- // Else we show a menu with a list of all links
61
+ // Default: show dropdown menu for multiple links
36
62
  return /*#__PURE__*/ _jsxs(_Fragment, {
37
63
  children: [
38
64
  /*#__PURE__*/ _jsx(InfoTooltip, {
39
65
  description: `${links.length} links`,
40
66
  enterDelay: 100,
41
67
  children: /*#__PURE__*/ _jsx(IconButton, {
42
- "aria-label": "Panel links",
68
+ "aria-label": `${capitalize(variant)}-links`,
69
+ id: `${variant}-links-button`,
43
70
  size: "small",
44
71
  onClick: handleOpenMenu,
45
72
  sx: (theme)=>({
@@ -60,7 +87,7 @@ export function PanelLinks({ links }) {
60
87
  open: isMenuOpened,
61
88
  onClose: handleClose,
62
89
  MenuListProps: {
63
- 'aria-labelledby': 'panel-links'
90
+ 'aria-labelledby': `${variant}-links-button`
64
91
  },
65
92
  children: links.map((link)=>/*#__PURE__*/ _jsx(LinkMenuItem, {
66
93
  link: link
@@ -69,6 +96,28 @@ export function PanelLinks({ links }) {
69
96
  ]
70
97
  });
71
98
  }
99
+ function LinkChip({ link }) {
100
+ const { url, name, tooltip, targetBlank } = useLink(link);
101
+ return /*#__PURE__*/ _jsx(InfoTooltip, {
102
+ description: tooltip ?? url,
103
+ enterDelay: 100,
104
+ children: /*#__PURE__*/ _jsx(Chip, {
105
+ label: name ?? url,
106
+ component: "a",
107
+ href: url,
108
+ target: targetBlank ? '_blank' : '_self',
109
+ clickable: true,
110
+ size: "medium",
111
+ icon: /*#__PURE__*/ _jsx(LaunchIcon, {
112
+ color: "inherit",
113
+ fontSize: "small"
114
+ }),
115
+ sx: (theme)=>({
116
+ height: theme.spacing(3)
117
+ })
118
+ })
119
+ });
120
+ }
72
121
  function LinkButton({ link }) {
73
122
  const { url, name, tooltip, targetBlank } = useLink(link);
74
123
  return /*#__PURE__*/ _jsx(InfoTooltip, {
@@ -120,4 +169,4 @@ function useLink(link) {
120
169
  };
121
170
  }
122
171
 
123
- //# sourceMappingURL=PanelLinks.js.map
172
+ //# sourceMappingURL=LinksDisplay.js.map