@perses-dev/dashboards 0.0.0-snapshot-scatter-chart-embed-8efdfab → 0.0.0-snapshot-explorer-plugin-c4a7621

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 (411) hide show
  1. package/dist/cjs/components/AddGroupButton/AddGroupButton.js +1 -1
  2. package/dist/cjs/components/AddPanelButton/AddPanelButton.js +2 -2
  3. package/dist/cjs/components/Dashboard/Dashboard.js +9 -2
  4. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +4 -4
  5. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +6 -6
  6. package/dist/cjs/components/Datasources/DatasourceEditor.js +19 -20
  7. package/dist/cjs/components/Datasources/EditDatasourcesButton.js +11 -8
  8. package/dist/cjs/components/DeletePanelDialog/DeletePanelDialog.js +4 -4
  9. package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +4 -5
  10. package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  11. package/dist/cjs/components/DownloadButton/DownloadButton.js +3 -4
  12. package/dist/cjs/components/EditButton/EditButton.js +1 -1
  13. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +3 -4
  14. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +21 -17
  15. package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +5 -5
  16. package/dist/cjs/components/GridLayout/GridContainer.js +16 -11
  17. package/dist/cjs/components/GridLayout/GridItemContent.js +24 -10
  18. package/dist/cjs/components/GridLayout/GridLayout.js +63 -14
  19. package/dist/cjs/components/GridLayout/GridTitle.js +8 -9
  20. package/dist/cjs/{validation/panel.js → components/Panel/HeaderIconButton.js} +8 -10
  21. package/dist/cjs/components/Panel/Panel.js +15 -11
  22. package/dist/cjs/components/Panel/PanelActions.js +216 -0
  23. package/dist/cjs/components/Panel/PanelContent.js +6 -6
  24. package/dist/cjs/components/Panel/PanelHeader.js +36 -103
  25. package/dist/cjs/components/Panel/PanelLinks.js +136 -0
  26. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +9 -6
  27. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +67 -62
  28. package/dist/cjs/components/PanelDrawer/PanelPreview.js +9 -6
  29. package/dist/cjs/components/PanelDrawer/usePanelEditor.js +9 -6
  30. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
  31. package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  32. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +5 -7
  33. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +7 -9
  34. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +8 -8
  35. package/dist/cjs/components/Variables/BuiltinVariableAccordions.js +8 -14
  36. package/dist/cjs/components/Variables/EditVariablesButton.js +5 -5
  37. package/dist/cjs/components/Variables/{TemplateVariable.js → Variable.js} +48 -56
  38. package/dist/cjs/components/Variables/VariableEditor.js +39 -46
  39. package/dist/cjs/components/Variables/VariableList.js +23 -22
  40. package/dist/cjs/components/Variables/index.js +2 -2
  41. package/dist/cjs/components/index.js +0 -2
  42. package/dist/cjs/constants/styles.js +17 -9
  43. package/dist/cjs/constants/user-interface-text.js +6 -5
  44. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +24 -17
  45. package/dist/cjs/context/DashboardProvider/DashboardProviderWithQueryParams.js +36 -0
  46. package/dist/cjs/context/DashboardProvider/common.js +5 -5
  47. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +51 -43
  48. package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +1 -1
  49. package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +4 -5
  50. package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +1 -1
  51. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +11 -16
  52. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +1 -2
  53. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +13 -8
  54. package/dist/cjs/context/DashboardProvider/view-panel-slice.js +79 -0
  55. package/dist/cjs/context/DatasourceStoreProvider.js +32 -31
  56. package/dist/cjs/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +128 -131
  57. package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +11 -14
  58. package/dist/cjs/{validation → context/VariableProvider}/index.js +2 -2
  59. package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/query-params.js +8 -8
  60. package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/utils.js +6 -6
  61. package/dist/cjs/context/index.js +2 -2
  62. package/dist/cjs/context/useDashboard.js +24 -9
  63. package/dist/cjs/stories/decorators/WithDashboard.js +1 -1
  64. package/dist/cjs/stories/decorators/WithDatasourceStore.js +1 -1
  65. package/dist/cjs/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +9 -9
  66. package/dist/cjs/stories/decorators/index.js +2 -2
  67. package/dist/cjs/test/dashboard-provider.js +3 -3
  68. package/dist/cjs/test/datasource-provider.js +4 -4
  69. package/dist/cjs/test/plugin-registry.js +4 -2
  70. package/dist/cjs/test/render.js +14 -12
  71. package/dist/cjs/utils/index.js +0 -1
  72. package/dist/cjs/utils/panelUtils.js +5 -5
  73. package/dist/cjs/views/ViewDashboard/DashboardApp.js +8 -8
  74. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +10 -11
  75. package/dist/components/AddGroupButton/AddGroupButton.d.ts +2 -2
  76. package/dist/components/AddGroupButton/AddGroupButton.d.ts.map +1 -1
  77. package/dist/components/AddGroupButton/AddGroupButton.js +1 -1
  78. package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
  79. package/dist/components/AddPanelButton/AddPanelButton.d.ts +2 -2
  80. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
  81. package/dist/components/AddPanelButton/AddPanelButton.js +2 -2
  82. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  83. package/dist/components/Dashboard/Dashboard.d.ts +3 -3
  84. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  85. package/dist/components/Dashboard/Dashboard.js +9 -2
  86. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  87. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts +2 -2
  88. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -1
  89. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +4 -4
  90. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  91. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
  92. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  93. package/dist/components/DashboardToolbar/DashboardToolbar.js +5 -5
  94. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  95. package/dist/components/Datasources/DatasourceEditor.d.ts +2 -2
  96. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  97. package/dist/components/Datasources/DatasourceEditor.js +20 -21
  98. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  99. package/dist/components/Datasources/EditDatasourcesButton.d.ts +2 -2
  100. package/dist/components/Datasources/EditDatasourcesButton.d.ts.map +1 -1
  101. package/dist/components/Datasources/EditDatasourcesButton.js +11 -8
  102. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
  103. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +2 -2
  104. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -1
  105. package/dist/components/DeletePanelDialog/DeletePanelDialog.js +4 -4
  106. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -1
  107. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts +2 -2
  108. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
  109. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +4 -5
  110. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  111. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts +2 -2
  112. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map +1 -1
  113. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  114. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  115. package/dist/components/DownloadButton/DownloadButton.d.ts +2 -2
  116. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -1
  117. package/dist/components/DownloadButton/DownloadButton.js +3 -4
  118. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  119. package/dist/components/EditButton/EditButton.d.ts +2 -2
  120. package/dist/components/EditButton/EditButton.d.ts.map +1 -1
  121. package/dist/components/EditButton/EditButton.js +1 -1
  122. package/dist/components/EditButton/EditButton.js.map +1 -1
  123. package/dist/components/EditJsonButton/EditJsonButton.d.ts +2 -2
  124. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -1
  125. package/dist/components/EditJsonButton/EditJsonButton.js +3 -4
  126. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  127. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +2 -2
  128. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -1
  129. package/dist/components/EditJsonDialog/EditJsonDialog.js +21 -17
  130. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  131. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +3 -3
  132. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -1
  133. package/dist/components/EmptyDashboard/EmptyDashboard.js +5 -5
  134. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
  135. package/dist/components/GridLayout/GridContainer.d.ts +5 -3
  136. package/dist/components/GridLayout/GridContainer.d.ts.map +1 -1
  137. package/dist/components/GridLayout/GridContainer.js +16 -11
  138. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  139. package/dist/components/GridLayout/GridItemContent.d.ts +2 -2
  140. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  141. package/dist/components/GridLayout/GridItemContent.js +25 -11
  142. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  143. package/dist/components/GridLayout/GridLayout.d.ts +4 -3
  144. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  145. package/dist/components/GridLayout/GridLayout.js +65 -16
  146. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  147. package/dist/components/GridLayout/GridTitle.d.ts +3 -3
  148. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  149. package/dist/components/GridLayout/GridTitle.js +8 -9
  150. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  151. package/dist/components/Panel/HeaderIconButton.d.ts +5 -0
  152. package/dist/components/Panel/HeaderIconButton.d.ts.map +1 -0
  153. package/dist/components/{TimeRangeControls/index.js → Panel/HeaderIconButton.js} +7 -3
  154. package/dist/components/Panel/HeaderIconButton.js.map +1 -0
  155. package/dist/components/Panel/Panel.d.ts +13 -7
  156. package/dist/components/Panel/Panel.d.ts.map +1 -1
  157. package/dist/components/Panel/Panel.js +16 -12
  158. package/dist/components/Panel/Panel.js.map +1 -1
  159. package/dist/components/Panel/PanelActions.d.ts +16 -0
  160. package/dist/components/Panel/PanelActions.d.ts.map +1 -0
  161. package/dist/components/Panel/PanelActions.js +203 -0
  162. package/dist/components/Panel/PanelActions.js.map +1 -0
  163. package/dist/components/Panel/PanelContent.d.ts +2 -2
  164. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  165. package/dist/components/Panel/PanelContent.js +6 -6
  166. package/dist/components/Panel/PanelContent.js.map +1 -1
  167. package/dist/components/Panel/PanelHeader.d.ts +9 -9
  168. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  169. package/dist/components/Panel/PanelHeader.js +39 -106
  170. package/dist/components/Panel/PanelHeader.js.map +1 -1
  171. package/dist/components/Panel/PanelLinks.d.ts +6 -0
  172. package/dist/components/Panel/PanelLinks.d.ts.map +1 -0
  173. package/dist/components/Panel/PanelLinks.js +123 -0
  174. package/dist/components/Panel/PanelLinks.js.map +1 -0
  175. package/dist/components/PanelDrawer/PanelDrawer.d.ts +2 -2
  176. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  177. package/dist/components/PanelDrawer/PanelDrawer.js +10 -7
  178. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  179. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -4
  180. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  181. package/dist/components/PanelDrawer/PanelEditorForm.js +70 -65
  182. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  183. package/dist/components/PanelDrawer/PanelPreview.d.ts +3 -3
  184. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  185. package/dist/components/PanelDrawer/PanelPreview.js +9 -6
  186. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  187. package/dist/components/PanelDrawer/usePanelEditor.d.ts +12 -10
  188. package/dist/components/PanelDrawer/usePanelEditor.d.ts.map +1 -1
  189. package/dist/components/PanelDrawer/usePanelEditor.js +9 -6
  190. package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -1
  191. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +2 -2
  192. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  193. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
  194. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  195. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +2 -2
  196. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -1
  197. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  198. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  199. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +2 -2
  200. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -1
  201. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +5 -7
  202. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  203. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +2 -2
  204. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
  205. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +8 -10
  206. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  207. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +2 -2
  208. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
  209. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +9 -9
  210. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
  211. package/dist/components/Variables/BuiltinVariableAccordions.d.ts +3 -3
  212. package/dist/components/Variables/BuiltinVariableAccordions.d.ts.map +1 -1
  213. package/dist/components/Variables/BuiltinVariableAccordions.js +8 -14
  214. package/dist/components/Variables/BuiltinVariableAccordions.js.map +1 -1
  215. package/dist/components/Variables/EditVariablesButton.d.ts +2 -2
  216. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  217. package/dist/components/Variables/EditVariablesButton.js +6 -6
  218. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  219. package/dist/components/Variables/{TemplateVariable.d.ts → Variable.d.ts} +6 -6
  220. package/dist/components/Variables/Variable.d.ts.map +1 -0
  221. package/dist/components/Variables/{TemplateVariable.js → Variable.js} +49 -57
  222. package/dist/components/Variables/Variable.js.map +1 -0
  223. package/dist/components/Variables/VariableEditor.d.ts +3 -3
  224. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  225. package/dist/components/Variables/VariableEditor.js +40 -47
  226. package/dist/components/Variables/VariableEditor.js.map +1 -1
  227. package/dist/components/Variables/VariableList.d.ts +4 -4
  228. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  229. package/dist/components/Variables/VariableList.js +21 -20
  230. package/dist/components/Variables/VariableList.js.map +1 -1
  231. package/dist/components/Variables/index.d.ts +1 -1
  232. package/dist/components/Variables/index.d.ts.map +1 -1
  233. package/dist/components/Variables/index.js +2 -2
  234. package/dist/components/Variables/index.js.map +1 -1
  235. package/dist/components/index.d.ts +0 -2
  236. package/dist/components/index.d.ts.map +1 -1
  237. package/dist/components/index.js +0 -2
  238. package/dist/components/index.js.map +1 -1
  239. package/dist/constants/styles.d.ts +4 -2
  240. package/dist/constants/styles.d.ts.map +1 -1
  241. package/dist/constants/styles.js +5 -3
  242. package/dist/constants/styles.js.map +1 -1
  243. package/dist/constants/user-interface-text.d.ts +3 -2
  244. package/dist/constants/user-interface-text.d.ts.map +1 -1
  245. package/dist/constants/user-interface-text.js +3 -2
  246. package/dist/constants/user-interface-text.js.map +1 -1
  247. package/dist/context/DashboardProvider/DashboardProvider.d.ts +11 -6
  248. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  249. package/dist/context/DashboardProvider/DashboardProvider.js +22 -15
  250. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  251. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts +4 -0
  252. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts.map +1 -0
  253. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +28 -0
  254. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -0
  255. package/dist/context/DashboardProvider/common.d.ts +3 -3
  256. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  257. package/dist/context/DashboardProvider/common.js +2 -2
  258. package/dist/context/DashboardProvider/common.js.map +1 -1
  259. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +36 -23
  260. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  261. package/dist/context/DashboardProvider/dashboard-provider-api.js +26 -19
  262. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  263. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +2 -1
  264. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -1
  265. package/dist/context/DashboardProvider/delete-panel-group-slice.js +1 -1
  266. package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
  267. package/dist/context/DashboardProvider/delete-panel-slice.js +4 -5
  268. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  269. package/dist/context/DashboardProvider/discard-changes-dialog-slice.js.map +1 -1
  270. package/dist/context/DashboardProvider/duplicate-panel-slice.js +1 -1
  271. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
  272. package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -1
  273. package/dist/context/DashboardProvider/index.d.ts +1 -2
  274. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  275. package/dist/context/DashboardProvider/index.js.map +1 -1
  276. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -9
  277. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  278. package/dist/context/DashboardProvider/panel-editor-slice.js +8 -13
  279. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  280. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +2 -1
  281. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  282. package/dist/context/DashboardProvider/panel-group-editor-slice.js +1 -2
  283. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  284. package/dist/context/DashboardProvider/panel-group-slice.d.ts +3 -3
  285. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  286. package/dist/context/DashboardProvider/panel-group-slice.js +8 -4
  287. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  288. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
  289. package/dist/context/DashboardProvider/view-panel-slice.d.ts +21 -0
  290. package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -0
  291. package/dist/context/DashboardProvider/view-panel-slice.js +73 -0
  292. package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -0
  293. package/dist/context/DatasourceStoreProvider.d.ts +10 -10
  294. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  295. package/dist/context/DatasourceStoreProvider.js +32 -31
  296. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  297. package/dist/context/VariableProvider/VariableProvider.d.ts +119 -0
  298. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -0
  299. package/dist/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +117 -116
  300. package/dist/context/VariableProvider/VariableProvider.js.map +1 -0
  301. package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.d.ts +1 -1
  302. package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -0
  303. package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +9 -12
  304. package/dist/context/VariableProvider/hydrationUtils.js.map +1 -0
  305. package/dist/context/VariableProvider/index.d.ts +2 -0
  306. package/dist/context/VariableProvider/index.d.ts.map +1 -0
  307. package/dist/{validation → context/VariableProvider}/index.js +2 -2
  308. package/dist/context/VariableProvider/index.js.map +1 -0
  309. package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.d.ts +2 -6
  310. package/dist/context/VariableProvider/query-params.d.ts.map +1 -0
  311. package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
  312. package/dist/context/VariableProvider/query-params.js.map +1 -0
  313. package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.d.ts +1 -1
  314. package/dist/context/VariableProvider/utils.d.ts.map +1 -0
  315. package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.js +3 -3
  316. package/dist/context/VariableProvider/utils.js.map +1 -0
  317. package/dist/context/index.d.ts +1 -1
  318. package/dist/context/index.d.ts.map +1 -1
  319. package/dist/context/index.js +2 -2
  320. package/dist/context/index.js.map +1 -1
  321. package/dist/context/useDashboard.d.ts +3 -3
  322. package/dist/context/useDashboard.d.ts.map +1 -1
  323. package/dist/context/useDashboard.js +24 -9
  324. package/dist/context/useDashboard.js.map +1 -1
  325. package/dist/stories/decorators/WithDashboard.js +1 -1
  326. package/dist/stories/decorators/WithDashboard.js.map +1 -1
  327. package/dist/stories/decorators/WithDatasourceStore.js +1 -1
  328. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
  329. package/dist/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +9 -9
  330. package/dist/stories/decorators/WithVariables.js.map +1 -0
  331. package/dist/stories/decorators/index.js +2 -2
  332. package/dist/stories/decorators/index.js.map +1 -1
  333. package/dist/test/dashboard-provider.d.ts +1 -1
  334. package/dist/test/dashboard-provider.d.ts.map +1 -1
  335. package/dist/test/dashboard-provider.js.map +1 -1
  336. package/dist/test/datasource-provider.d.ts +2 -2
  337. package/dist/test/datasource-provider.d.ts.map +1 -1
  338. package/dist/test/datasource-provider.js.map +1 -1
  339. package/dist/test/plugin-registry.d.ts.map +1 -1
  340. package/dist/test/plugin-registry.js +4 -2
  341. package/dist/test/plugin-registry.js.map +1 -1
  342. package/dist/test/render.d.ts +2 -2
  343. package/dist/test/render.d.ts.map +1 -1
  344. package/dist/test/render.js +10 -8
  345. package/dist/test/render.js.map +1 -1
  346. package/dist/test/setup-tests.js.map +1 -1
  347. package/dist/utils/index.d.ts +0 -1
  348. package/dist/utils/index.d.ts.map +1 -1
  349. package/dist/utils/index.js +0 -1
  350. package/dist/utils/index.js.map +1 -1
  351. package/dist/utils/panelUtils.d.ts +1 -1
  352. package/dist/utils/panelUtils.d.ts.map +1 -1
  353. package/dist/utils/panelUtils.js +2 -2
  354. package/dist/utils/panelUtils.js.map +1 -1
  355. package/dist/views/ViewDashboard/DashboardApp.d.ts +4 -4
  356. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  357. package/dist/views/ViewDashboard/DashboardApp.js +8 -8
  358. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  359. package/dist/views/ViewDashboard/ViewDashboard.d.ts +4 -4
  360. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  361. package/dist/views/ViewDashboard/ViewDashboard.js +11 -12
  362. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  363. package/package.json +9 -9
  364. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +0 -210
  365. package/dist/cjs/components/TimeRangeControls/index.js +0 -30
  366. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +0 -40
  367. package/dist/cjs/components/ToolbarIconButton/index.js +0 -30
  368. package/dist/cjs/context/TemplateVariableProvider/index.js +0 -30
  369. package/dist/cjs/utils/time.js +0 -29
  370. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +0 -14
  371. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +0 -1
  372. package/dist/components/TimeRangeControls/TimeRangeControls.js +0 -186
  373. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +0 -1
  374. package/dist/components/TimeRangeControls/index.d.ts +0 -2
  375. package/dist/components/TimeRangeControls/index.d.ts.map +0 -1
  376. package/dist/components/TimeRangeControls/index.js.map +0 -1
  377. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +0 -6
  378. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +0 -1
  379. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +0 -32
  380. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +0 -1
  381. package/dist/components/ToolbarIconButton/index.d.ts +0 -2
  382. package/dist/components/ToolbarIconButton/index.d.ts.map +0 -1
  383. package/dist/components/ToolbarIconButton/index.js +0 -15
  384. package/dist/components/ToolbarIconButton/index.js.map +0 -1
  385. package/dist/components/Variables/TemplateVariable.d.ts.map +0 -1
  386. package/dist/components/Variables/TemplateVariable.js.map +0 -1
  387. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +0 -77
  388. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +0 -1
  389. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +0 -1
  390. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +0 -1
  391. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +0 -1
  392. package/dist/context/TemplateVariableProvider/index.d.ts +0 -2
  393. package/dist/context/TemplateVariableProvider/index.d.ts.map +0 -1
  394. package/dist/context/TemplateVariableProvider/index.js +0 -15
  395. package/dist/context/TemplateVariableProvider/index.js.map +0 -1
  396. package/dist/context/TemplateVariableProvider/query-params.d.ts.map +0 -1
  397. package/dist/context/TemplateVariableProvider/query-params.js.map +0 -1
  398. package/dist/context/TemplateVariableProvider/utils.d.ts.map +0 -1
  399. package/dist/context/TemplateVariableProvider/utils.js.map +0 -1
  400. package/dist/stories/decorators/WithTemplateVariables.js.map +0 -1
  401. package/dist/utils/time.d.ts +0 -5
  402. package/dist/utils/time.d.ts.map +0 -1
  403. package/dist/utils/time.js +0 -23
  404. package/dist/utils/time.js.map +0 -1
  405. package/dist/validation/index.d.ts +0 -2
  406. package/dist/validation/index.d.ts.map +0 -1
  407. package/dist/validation/index.js.map +0 -1
  408. package/dist/validation/panel.d.ts +0 -19
  409. package/dist/validation/panel.d.ts.map +0 -1
  410. package/dist/validation/panel.js +0 -21
  411. package/dist/validation/panel.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils/panelUtils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n groupId: PanelGroupId;\n panelDefinition: PanelDefinition;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,yBAAyB;AACzE,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAMEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AA0D7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC;QAAS,OAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;oBAKXC;gBAJjB,MAAM,EAAEC,OAAM,EAAED,YAAW,EAAE,GAAGL;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,aAAY,EAAEC,wBAAwBC,mBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWL,CAAAA,4BAAAA,WAAW,CAACE,aAAa,cAAzBF,uCAAAA,KAAAA,IAAAA,0BAA2BM,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,iBAAiB,CAAC;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcP,MAAM,CAACI,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CAAC;gBAC5D;gBAEA,MAAMI,cAAgC;oBACpCC,MAAM;oBACNC,eAAe;wBACbC,SAASb,iBAAiBG;wBAC1BW,iBAAiBL;oBACnB;oBACAM,cAAc,CAACC;wBACbrB,IAAI,CAACsB;4BACHA,MAAMf,MAAM,CAACI,SAAS,GAAGU,KAAKF;4BAE9B,wDAAwD;4BACxD,IAAIE,KAAKH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3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId): void {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,cAAc;AAC9D,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAkD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,iBAAiB,CAAC;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CAAC;gBAC5D;gBAEA,MAAMI,cAAgC;oBACpCC,MAAM;oBACNC,eAAe;wBACbC,SAASb,iBAAiBG,YAAY;wBACtCW,iBAAiBL;oBACnB;oBACAM,cAAc,CAACC;wBACbrB,IAAI,CAACsB;4BACHA,MAAMhB,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U,aAAa7B,WAAW;wBAC1BN,cAAcyB,OAAOU;oBACvB;oBAEA,qCAAqC;oBACrCV,MAAMpB,WAAW,GAAGa;gBACtB;YACF;QACF,CAAA;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { StateCreator } from 'zustand';
2
+ import { PanelGroupId } from '@perses-dev/core';
2
3
  import { Middleware } from './common';
3
- import { PanelGroupSlice, PanelGroupId } from './panel-group-slice';
4
+ import { PanelGroupSlice } from './panel-group-slice';
4
5
  export interface PanelGroupEditor {
5
6
  mode: 'Add' | 'Edit';
6
7
  initialValues: PanelGroupEditorValues;
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAwC,MAAM,qBAAqB,CAAC;AAE1G,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAoErB,CAAC"}
1
+ {"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAwC,MAAM,qBAAqB,CAAC;AAE5F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAoErB,CAAC"}
@@ -45,12 +45,11 @@ export const createPanelGroupEditorSlice = (set, get)=>({
45
45
  if (existingGroup === undefined) {
46
46
  throw new Error(`Panel group with Id ${panelGroupId} does not exist`);
47
47
  }
48
- var _existingGroup_title;
49
48
  // Create the editor state
50
49
  const editor = {
51
50
  mode: 'Edit',
52
51
  initialValues: {
53
- title: (_existingGroup_title = existingGroup.title) !== null && _existingGroup_title !== void 0 ? _existingGroup_title : '',
52
+ title: existingGroup.title ?? '',
54
53
  isCollapsed: existingGroup.isCollapsed
55
54
  },
56
55
  applyChanges (next) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupId, addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup = createEmptyPanelGroup();\n newGroup.title = next.title;\n newGroup.isCollapsed = next.isCollapsed;\n set((draft) => {\n addPanelGroup(draft, newGroup);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["addPanelGroup","createEmptyPanelGroup","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","draft","close","openEditPanelGroup","panelGroupId","existingGroup","panelGroups","Error","group"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAAwCA,aAAa,EAAEC,qBAAqB,QAAQ,sBAAsB;AAkC1G,OAAO,MAAMC,8BAMT,CAACC,KAAKC,MAAS,CAAA;QACjBC,kBAAkBC;QAElBC,mBAAmB;YACjB,0BAA0B;YAC1B,MAAMC,SAA2B;gBAC/BC,MAAM;gBACNC,eAAe;oBACbC,OAAO;oBACPC,aAAa;gBACf;gBACAC,cAAaC,IAAI;oBACf,MAAMC,WAAWd;oBACjBc,SAASJ,QAAQG,KAAKH;oBACtBI,SAASH,cAAcE,KAAKF;oBAC5BT,IAAI,CAACa;wBACHhB,cAAcgB,OAAOD;oBACvB;gBACF;gBACAE;oBACEd,IAAI,CAACa;wBACHA,MAAMX,mBAAmBC;oBAC3B;gBACF;YACF;YAEA,kBAAkB;YAClBH,IAAI,CAACa;gBACHA,MAAMX,mBAAmBG;YAC3B;QACF;QAEAU,oBAAoB,CAACC;YACnB,MAAMC,gBAAgBhB,MAAMiB,WAAW,CAACF,aAAa;YACrD,IAAIC,kBAAkBd,WAAW;gBAC/B,MAAM,IAAIgB,MAAM,CAAC,oBAAoB,EAAEH,aAAa,eAAe,CAAC;YACtE;gBAMWC;YAJX,0BAA0B;YAC1B,MAAMZ,SAA2B;gBAC/BC,MAAM;gBACNC,eAAe;oBACbC,OAAOS,CAAAA,uBAAAA,cAAcT,mBAAdS,kCAAAA,uBAAuB;oBAC9BR,aAAaQ,cAAcR;gBAC7B;gBACAC,cAAaC,IAAI;oBACfX,IAAI,CAACa;wBACH,MAAMO,QAAQP,MAAMK,WAAW,CAACF,aAAa;wBAC7C,IAAII,UAAUjB,WAAW;4BACvB,MAAM,IAAIgB,MAAM,CAAC,oBAAoB,EAAEH,aAAa,eAAe,CAAC;wBACtE;wBACAI,MAAMZ,QAAQG,KAAKH;wBACnBY,MAAMX,cAAcE,KAAKF;oBAC3B;gBACF;gBACAK;oBACEd,IAAI,CAACa;wBACHA,MAAMX,mBAAmBC;oBAC3B;gBACF;YACF;YAEA,kBAAkB;YAClBH,IAAI,CAACa;gBACHA,MAAMX,mBAAmBG;YAC3B;QACF;IACF,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: (): void => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup = createEmptyPanelGroup();\n newGroup.title = next.title;\n newGroup.isCollapsed = next.isCollapsed;\n set((draft) => {\n addPanelGroup(draft, newGroup);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId): void => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["addPanelGroup","createEmptyPanelGroup","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","draft","close","openEditPanelGroup","panelGroupId","existingGroup","panelGroups","Error","group"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC,SAA0BA,aAAa,EAAEC,qBAAqB,QAAQ,sBAAsB;AAkC5F,OAAO,MAAMC,8BAMT,CAACC,KAAKC,MAAS,CAAA;QACjBC,kBAAkBC;QAElBC,mBAAmB;YACjB,0BAA0B;YAC1B,MAAMC,SAA2B;gBAC/BC,MAAM;gBACNC,eAAe;oBACbC,OAAO;oBACPC,aAAa;gBACf;gBACAC,cAAaC,IAAI;oBACf,MAAMC,WAAWd;oBACjBc,SAASJ,KAAK,GAAGG,KAAKH,KAAK;oBAC3BI,SAASH,WAAW,GAAGE,KAAKF,WAAW;oBACvCT,IAAI,CAACa;wBACHhB,cAAcgB,OAAOD;oBACvB;gBACF;gBACAE;oBACEd,IAAI,CAACa;wBACHA,MAAMX,gBAAgB,GAAGC;oBAC3B;gBACF;YACF;YAEA,kBAAkB;YAClBH,IAAI,CAACa;gBACHA,MAAMX,gBAAgB,GAAGG;YAC3B;QACF;QAEAU,oBAAoB,CAACC;YACnB,MAAMC,gBAAgBhB,MAAMiB,WAAW,CAACF,aAAa;YACrD,IAAIC,kBAAkBd,WAAW;gBAC/B,MAAM,IAAIgB,MAAM,CAAC,oBAAoB,EAAEH,aAAa,eAAe,CAAC;YACtE;YAEA,0BAA0B;YAC1B,MAAMX,SAA2B;gBAC/BC,MAAM;gBACNC,eAAe;oBACbC,OAAOS,cAAcT,KAAK,IAAI;oBAC9BC,aAAaQ,cAAcR,WAAW;gBACxC;gBACAC,cAAaC,IAAI;oBACfX,IAAI,CAACa;wBACH,MAAMO,QAAQP,MAAMK,WAAW,CAACF,aAAa;wBAC7C,IAAII,UAAUjB,WAAW;4BACvB,MAAM,IAAIgB,MAAM,CAAC,oBAAoB,EAAEH,aAAa,eAAe,CAAC;wBACtE;wBACAI,MAAMZ,KAAK,GAAGG,KAAKH,KAAK;wBACxBY,MAAMX,WAAW,GAAGE,KAAKF,WAAW;oBACtC;gBACF;gBACAK;oBACEd,IAAI,CAACa;wBACHA,MAAMX,gBAAgB,GAAGC;oBAC3B;gBACF;YACF;YAEA,kBAAkB;YAClBH,IAAI,CAACa;gBACHA,MAAMX,gBAAgB,GAAGG;YAC3B;QACF;IACF,CAAA,EAAG"}
@@ -1,4 +1,4 @@
1
- import { LayoutDefinition } from '@perses-dev/core';
1
+ import { LayoutDefinition, PanelGroupId } from '@perses-dev/core';
2
2
  import { WritableDraft } from 'immer/dist/internal';
3
3
  import { Layout } from 'react-grid-layout';
4
4
  import { StateCreator } from 'zustand';
@@ -24,7 +24,6 @@ export interface PanelGroupSlice {
24
24
  */
25
25
  updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
26
26
  }
27
- export declare type PanelGroupId = number;
28
27
  export interface PanelGroupDefinition {
29
28
  id: PanelGroupId;
30
29
  isCollapsed: boolean;
@@ -35,7 +34,7 @@ export interface PanelGroupDefinition {
35
34
  export interface PanelGroupItemLayout extends Layout {
36
35
  i: PanelGroupItemLayoutId;
37
36
  }
38
- export declare type PanelGroupItemLayoutId = string;
37
+ export type PanelGroupItemLayoutId = string;
39
38
  /**
40
39
  * Uniquely identifies an item in a PanelGroup.
41
40
  */
@@ -43,6 +42,7 @@ export interface PanelGroupItemId {
43
42
  panelGroupId: PanelGroupId;
44
43
  panelGroupItemLayoutId: PanelGroupItemLayoutId;
45
44
  }
45
+ export declare function isPanelGroupItemIdEqual(a?: PanelGroupItemId, b?: PanelGroupItemId): boolean;
46
46
  /**
47
47
  * Curried function for creating a PanelGroupSlice.
48
48
  */
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAQ5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,QAGlG"}
1
+ {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY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I,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAQ5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAGzG"}
@@ -12,10 +12,15 @@
12
12
  // limitations under the License.
13
13
  import { getPanelKeyFromRef } from '@perses-dev/core';
14
14
  import { generateId } from './common';
15
+ /*
16
+ * Check if two PanelGroupItemId are equal
17
+ */ export function isPanelGroupItemIdEqual(a, b) {
18
+ return a?.panelGroupId === b?.panelGroupId && a?.panelGroupItemLayoutId === b?.panelGroupItemLayoutId;
19
+ }
15
20
  /**
16
21
  * Curried function for creating a PanelGroupSlice.
17
22
  */ export function createPanelGroupSlice(layouts) {
18
- const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
23
+ const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
19
24
  // Return the state creator function for Zustand
20
25
  return (set)=>({
21
26
  panelGroups,
@@ -53,7 +58,6 @@ export function convertLayoutsToPanelGroups(layouts) {
53
58
  const panelGroups = {};
54
59
  const panelGroupIdOrder = [];
55
60
  for (const layout of layouts){
56
- var _layout_spec_display, _layout_spec_display_collapse, _layout_spec_display1;
57
61
  const itemLayouts = [];
58
62
  const itemPanelKeys = {};
59
63
  // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
@@ -72,8 +76,8 @@ export function convertLayoutsToPanelGroups(layouts) {
72
76
  const panelGroupId = generateId();
73
77
  panelGroups[panelGroupId] = {
74
78
  id: panelGroupId,
75
- isCollapsed: ((_layout_spec_display = layout.spec.display) === null || _layout_spec_display === void 0 ? void 0 : (_layout_spec_display_collapse = _layout_spec_display.collapse) === null || _layout_spec_display_collapse === void 0 ? void 0 : _layout_spec_display_collapse.open) === false,
76
- title: (_layout_spec_display1 = layout.spec.display) === null || _layout_spec_display1 === void 0 ? void 0 : _layout_spec_display1.title,
79
+ isCollapsed: layout.spec.display?.collapse?.open === false,
80
+ title: layout.spec.display?.title,
77
81
  itemLayouts,
78
82
  itemPanelKeys
79
83
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition) {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup","draft","newGroup","unshift"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,QAA0B,mBAAmB;AAIxE,SAASC,UAAU,QAAoB,WAAW;AAmDlD;;CAEC,GACD,OA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fC,GAAGH;gBACHI,GAAGP,KAAKQ;gBACRC,GAAGT,KAAKU;gBACRzB,GAAGe,KAAKf;gBACRC,GAAGc,KAAKd;YACV;YACAa,aAAa,CAACI,mBAAmB,GAAG3B,mBAAmBwB,KAAKW;QAC9D;QAEA,wDAAwD;QACxD,MAAMjB,eAAejB;QACrBG,WAAW,CAACc,aAAa,GAAG;YAC1BkB,IAAIlB;YACJmB,aAAaf,CAAAA,CAAAA,uBAAAA,OAAOG,KAAKa,qBAAZhB,kCAAAA,KAAAA,IAAAA,iCAAAA,qBAAqBiB,iEAArBjB,KAAAA,kCAA+BkB,IAAH,MAAY;YACrDC,OAAOnB,CAAAA,wBAAAA,OAAOG,KAAKa,qBAAZhB,mCAAAA,KAAAA,IAAAA,sBAAqBmB;YAC5BtB;YACAI;QACF;QACAF,kBAAkBQ,KAAKX;IACzB;IACA,OAAO;QACLd;QACAC,iBAAiBgB;IACnB;AACF;AAEA;;CAEC,GACD,OAAO,SAASqB;IACd,OAAO;QACLN,IAAInC;QACJwC,OAAOzB;QACPqB,aAAa;QACblB,aAAa,EAAE;QACfI,eAAe,CAAC;IAClB;AACF;AAEA;;CAEC,GACD,OAAO,SAASoB,cAAcC,KAAqC,EAAEC,QAA8B;IACjGD,MAAMxC,WAAW,CAACyC,SAAST,GAAG,GAAGS;IACjCD,MAAMvC,gBAAgByC,QAAQD,SAAST;AACzC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition, PanelGroupId } from '@perses-dev/core';\nimport { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/*\n * Check if two PanelGroupItemId are equal\n */\nexport function isPanelGroupItemIdEqual(a?: PanelGroupItemId, b?: PanelGroupItemId): boolean {\n return a?.panelGroupId === b?.panelGroupId && a?.panelGroupItemLayoutId === b?.panelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y): void {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts): void {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","isPanelGroupItemIdEqual","a","b","panelGroupId","panelGroupItemLayoutId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup","draft","newGroup","unshift"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,QAAwC,mBAAmB;AAItF,SAASC,UAAU,QAAoB,WAAW;AAiDlD;;CAEC,GACD,OAAO,SAASC,wBAAwBC,CAAoB,EAAEC,CAAoB;IAChF,OAAOD,GAAGE,iBAAiBD,GAAGC,gBAAgBF,GAAGG,2BAA2BF,GAAGE;AACjF;AAEA;;CAEC,GACD,OAAO,SAASC,sBACdC,OAA2B;IAE3B,MAAM,EAAEC,WAAW,EAAEC,eAAe,EAAE,GAAGC,4BAA4BH;IAErE,gDAAgD;IAChD,OAAO,CAACI,MAAS,CAAA;YACfH;YACAC;YAEAG,iBAAgBC,CAAC,EAAEC,CAAC;gBAClBH,I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GAAG/B,mBAAmB4B,KAAKW,OAAO;QACrE;QAEA,wDAAwD;QACxD,MAAMlC,eAAeJ;QACrBQ,WAAW,CAACJ,aAAa,GAAG;YAC1BmC,IAAInC;YACJoC,aAAaf,OAAOG,IAAI,CAACa,OAAO,EAAEC,UAAUC,SAAS;YACrDC,OAAOnB,OAAOG,IAAI,CAACa,OAAO,EAAEG;YAC5BtB;YACAI;QACF;QACAF,kBAAkBQ,IAAI,CAAC5B;IACzB;IACA,OAAO;QACLI;QACAC,iBAAiBe;IACnB;AACF;AAEA;;CAEC,GACD,OAAO,SAASqB;IACd,OAAO;QACLN,IAAIvC;QACJ4C,OAAOxB;QACPoB,aAAa;QACblB,aAAa,EAAE;QACfI,eAAe,CAAC;IAClB;AACF;AAEA;;CAEC,GACD,OAAO,SAASoB,cAAcC,KAAqC,EAAEC,QAA8B;IACjGD,MAAMvC,WAAW,CAACwC,SAAST,EAAE,CAAC,GAAGS;IACjCD,MAAMtC,eAAe,CAACwC,OAAO,CAACD,SAAST,EAAE;AAC3C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface SaveChangesConfirmationDialogSlice {\n saveChangesConfirmationDialog?: SaveChangesConfirmationDialogState;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n closeSaveChangesConfirmationDialog: () => void;\n}\n\nexport interface SaveChangesConfirmationDialogState {\n onSaveChanges: (saveDefaultTimeRange: boolean, saveDefaultVariables: boolean) => void;\n onCancel: () => void;\n isSavedDurationModified: boolean;\n isSavedVariableModified: boolean;\n description?: string;\n}\n\nexport const createSaveChangesDialogSlice: StateCreator<\n SaveChangesConfirmationDialogSlice,\n Middleware,\n [],\n SaveChangesConfirmationDialogSlice\n> = (set) => ({\n isOpen: false,\n\n openSaveChangesConfirmationDialog(dialog) {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = dialog;\n },\n false,\n 'openSaveChangesConfirmationDialog'\n );\n },\n\n closeSaveChangesConfirmationDialog() {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = undefined;\n },\n false,\n 'closeSaveChangesConfirmationDialog'\n );\n },\n});\n"],"names":["createSaveChangesDialogSlice","set","isOpen","openSaveChangesConfirmationDialog","dialog","state","saveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","undefined"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAmBjC,OAAO,MAAMA,+BAKT,CAACC,MAAS,CAAA;QACZC,QAAQ;QAERC,mCAAkCC,MAAM;YACtCH,IACE,CAACI;gBACCA,MAAMC,gCAAgCF;YACxC,GACA,OACA;QAEJ;QAEAG;YACEN,IACE,CAACI;gBACCA,MAAMC,gCAAgCE;YACxC,GACA,OACA;QAEJ;IACF,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface SaveChangesConfirmationDialogSlice {\n saveChangesConfirmationDialog?: SaveChangesConfirmationDialogState;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n closeSaveChangesConfirmationDialog: () => void;\n}\n\nexport interface SaveChangesConfirmationDialogState {\n onSaveChanges: (saveDefaultTimeRange: boolean, saveDefaultVariables: boolean) => void;\n onCancel: () => void;\n isSavedDurationModified: boolean;\n isSavedVariableModified: boolean;\n description?: string;\n}\n\nexport const createSaveChangesDialogSlice: StateCreator<\n SaveChangesConfirmationDialogSlice,\n Middleware,\n [],\n SaveChangesConfirmationDialogSlice\n> = (set) => ({\n isOpen: false,\n\n openSaveChangesConfirmationDialog(dialog): void {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = dialog;\n },\n false,\n 'openSaveChangesConfirmationDialog'\n );\n },\n\n closeSaveChangesConfirmationDialog(): void {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = undefined;\n },\n false,\n 'closeSaveChangesConfirmationDialog'\n );\n },\n});\n"],"names":["createSaveChangesDialogSlice","set","isOpen","openSaveChangesConfirmationDialog","dialog","state","saveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","undefined"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAmBjC,OAAO,MAAMA,+BAKT,CAACC,MAAS,CAAA;QACZC,QAAQ;QAERC,mCAAkCC,MAAM;YACtCH,IACE,CAACI;gBACCA,MAAMC,6BAA6B,GAAGF;YACxC,GACA,OACA;QAEJ;QAEAG;YACEN,IACE,CAACI;gBACCA,MAAMC,6BAA6B,GAAGE;YACxC,GACA,OACA;QAEJ;IACF,CAAA,EAAG"}
@@ -0,0 +1,21 @@
1
+ import { StateCreator } from 'zustand';
2
+ import { PanelGroupItemId } from '@perses-dev/dashboards';
3
+ import { Middleware } from './common';
4
+ import { PanelGroupSlice } from './panel-group-slice';
5
+ /**
6
+ * Slice that handles viewing Panels in max size ("full screen").
7
+ */
8
+ export interface ViewPanelSlice {
9
+ viewPanel: ViewPanelState;
10
+ getViewPanel: () => PanelGroupItemId | undefined;
11
+ setViewPanel: (panelGroupItemId?: PanelGroupItemId) => void;
12
+ }
13
+ export interface ViewPanelState {
14
+ panelGroupItemId?: PanelGroupItemId;
15
+ panelRef?: string;
16
+ }
17
+ /**
18
+ * Curried function for viewing panel in max size ("full screen").
19
+ */
20
+ export declare function createViewPanelSlice(viewPanelRef?: string, setViewPanelRef?: (ref: string | undefined) => void): StateCreator<ViewPanelSlice & PanelGroupSlice, Middleware, [], ViewPanelSlice>;
21
+ //# sourceMappingURL=view-panel-slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAwB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,EAAE,MAAM,gBAAgB,GAAG,SAAS,CAAC;IACjD,YAAY,EAAE,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,cAAc;IAE7B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,CAAC,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GAClD,YAAY,CAAC,cAAc,GAAG,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,cAAc,CAAC,CAwBhF"}
@@ -0,0 +1,73 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ /**
14
+ * Curried function for viewing panel in max size ("full screen").
15
+ */ export function createViewPanelSlice(viewPanelRef, setViewPanelRef) {
16
+ return (set, get)=>({
17
+ viewPanel: {
18
+ panelGroupItemId: undefined,
19
+ panelRef: viewPanelRef
20
+ },
21
+ getViewPanel () {
22
+ return getViewPanelGroupId(get().panelGroups, get().viewPanel.panelGroupItemId, get().viewPanel.panelRef);
23
+ },
24
+ setViewPanel (panelGroupItemId) {
25
+ set((state)=>{
26
+ state.viewPanel = {
27
+ panelRef: undefined,
28
+ panelGroupItemId: panelGroupItemId
29
+ };
30
+ const panelRef = findPanelRefOfPanelGroupItemId(get().panelGroups, panelGroupItemId);
31
+ if (setViewPanelRef) {
32
+ setViewPanelRef(panelRef);
33
+ }
34
+ });
35
+ }
36
+ });
37
+ }
38
+ function getViewPanelGroupId(panelGroups, panelGroupItemId, panelRef) {
39
+ if (panelGroupItemId) {
40
+ return panelGroupItemId;
41
+ }
42
+ if (panelRef) {
43
+ return findPanelGroupItemIdOfPanelRef(panelGroups, panelRef);
44
+ }
45
+ return undefined;
46
+ }
47
+ // Find the PanelGroupItemId of a Panel from a PanelRef
48
+ function findPanelGroupItemIdOfPanelRef(panelGroups, panelRef) {
49
+ for (const panelGroup of Object.values(panelGroups)){
50
+ const itemPanel = Object.entries(panelGroup.itemPanelKeys ?? []).find(([_, value])=>value === panelRef);
51
+ if (itemPanel) {
52
+ const [key] = itemPanel;
53
+ return {
54
+ panelGroupId: panelGroup.id,
55
+ panelGroupItemLayoutId: key
56
+ };
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ // Find the PanelRef from a PanelGroupItemId
62
+ function findPanelRefOfPanelGroupItemId(panelGroups, panelGroupItemId) {
63
+ if (!panelGroupItemId) {
64
+ return undefined;
65
+ }
66
+ const panelGroup = panelGroups[panelGroupItemId.panelGroupId];
67
+ if (panelGroup) {
68
+ return panelGroup.itemPanelKeys[panelGroupItemId.panelGroupItemLayoutId];
69
+ }
70
+ return undefined;
71
+ }
72
+
73
+ //# sourceMappingURL=view-panel-slice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { PanelGroupDefinition, PanelGroupItemId } from '@perses-dev/dashboards';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { Middleware } from './common';\nimport { PanelGroupSlice } from './panel-group-slice';\n\n/**\n * Slice that handles viewing Panels in max size (\"full screen\").\n */\nexport interface ViewPanelSlice {\n viewPanel: ViewPanelState;\n getViewPanel: () => PanelGroupItemId | undefined;\n setViewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n}\n\nexport interface ViewPanelState {\n // Do not use directly, use `getViewPanel()` instead for getting the current viewed PanelGroupItemId!\n panelGroupItemId?: PanelGroupItemId;\n panelRef?: string;\n}\n\n/**\n * Curried function for viewing panel in max size (\"full screen\").\n */\nexport function createViewPanelSlice(\n viewPanelRef?: string,\n setViewPanelRef?: (ref: string | undefined) => void\n): StateCreator<ViewPanelSlice & PanelGroupSlice, Middleware, [], ViewPanelSlice> {\n return (set, get) => ({\n viewPanel: {\n panelGroupItemId: undefined,\n panelRef: viewPanelRef,\n },\n\n getViewPanel(): PanelGroupItemId | undefined {\n return getViewPanelGroupId(get().panelGroups, get().viewPanel.panelGroupItemId, get().viewPanel.panelRef);\n },\n\n setViewPanel(panelGroupItemId?: PanelGroupItemId): void {\n set((state) => {\n state.viewPanel = {\n panelRef: undefined,\n panelGroupItemId: panelGroupItemId,\n };\n const panelRef = findPanelRefOfPanelGroupItemId(get().panelGroups, panelGroupItemId);\n if (setViewPanelRef) {\n setViewPanelRef(panelRef);\n }\n });\n },\n });\n}\n\nfunction getViewPanelGroupId(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelGroupItemId?: PanelGroupItemId,\n panelRef?: string\n): PanelGroupItemId | undefined {\n if (panelGroupItemId) {\n return panelGroupItemId;\n }\n\n if (panelRef) {\n return findPanelGroupItemIdOfPanelRef(panelGroups, panelRef);\n }\n\n return undefined;\n}\n\n// Find the PanelGroupItemId of a Panel from a PanelRef\nfunction findPanelGroupItemIdOfPanelRef(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelRef?: string\n): PanelGroupItemId | undefined {\n for (const panelGroup of Object.values(panelGroups)) {\n const itemPanel = Object.entries(panelGroup.itemPanelKeys ?? []).find(([_, value]) => value === panelRef);\n if (itemPanel) {\n const [key] = itemPanel;\n return {\n panelGroupId: panelGroup.id,\n panelGroupItemLayoutId: key,\n };\n }\n }\n return undefined;\n}\n\n// Find the PanelRef from a PanelGroupItemId\nfunction findPanelRefOfPanelGroupItemId(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelGroupItemId?: PanelGroupItemId\n): string | undefined {\n if (!panelGroupItemId) {\n return undefined;\n }\n const panelGroup = panelGroups[panelGroupItemId.panelGroupId];\n if (panelGroup) {\n return panelGroup.itemPanelKeys[panelGroupItemId.panelGroupItemLayoutId];\n }\n return undefined;\n}\n"],"names":["createViewPanelSlice","viewPanelRef","setViewPanelRef","set","get","viewPanel","panelGroupItemId","undefined","panelRef","getViewPanel","getViewPanelGroupId","panelGroups","setViewPanel","state","findPanelRefOfPanelGroupItemId","findPanelGroupItemIdOfPanelRef","panelGroup","Object","values","itemPanel","entries","itemPanelKeys","find","_","value","key","panelGroupId","id","panelGroupItemLayoutId"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAuBjC;;CAEC,GACD,OAAO,SAASA,qBACdC,YAAqB,EACrBC,eAAmD;IAEnD,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,WAAW;gBACTC,kBAAkBC;gBAClBC,UAAUP;YACZ;YAEAQ;gBACE,OAAOC,oBAAoBN,MAAMO,WAAW,EAAEP,MAAMC,SAAS,CAACC,gBAAgB,EAAEF,MAAMC,SAAS,CAACG,QAAQ;YAC1G;YAEAI,cAAaN,gBAAmC;gBAC9CH,IAAI,CAACU;oBACHA,MAAMR,SAAS,GAAG;wBAChBG,UAAUD;wBACVD,kBAAkBA;oBACpB;oBACA,MAAME,WAAWM,+BAA+BV,MAAMO,WAAW,EAAEL;oBACnE,IAAIJ,iBAAiB;wBACnBA,gBAAgBM;oBAClB;gBACF;YACF;QACF,CAAA;AACF;AAEA,SAASE,oBACPC,WAAuD,EACvDL,gBAAmC,EACnCE,QAAiB;IAEjB,IAAIF,kBAAkB;QACpB,OAAOA;IACT;IAEA,IAAIE,UAAU;QACZ,OAAOO,+BAA+BJ,aAAaH;IACrD;IAEA,OAAOD;AACT;AAEA,uDAAuD;AACvD,SAASQ,+BACPJ,WAAuD,EACvDH,QAAiB;IAEjB,KAAK,MAAMQ,cAAcC,OAAOC,MAAM,CAACP,aAAc;QACnD,MAAMQ,YAAYF,OAAOG,OAAO,CAACJ,WAAWK,aAAa,IAAI,EAAE,EAAEC,IAAI,CAAC,CAAC,CAACC,GAAGC,MAAM,GAAKA,UAAUhB;QAChG,IAAIW,WAAW;YACb,MAAM,CAACM,IAAI,GAAGN;YACd,OAAO;gBACLO,cAAcV,WAAWW,EAAE;gBAC3BC,wBAAwBH;YAC1B;QACF;IACF;IACA,OAAOlB;AACT;AAEA,4CAA4C;AAC5C,SAASO,+BACPH,WAAuD,EACvDL,gBAAmC;IAEnC,IAAI,CAACA,kBAAkB;QACrB,OAAOC;IACT;IACA,MAAMS,aAAaL,WAAW,CAACL,iBAAiBoB,YAAY,CAAC;IAC7D,IAAIV,YAAY;QACd,OAAOA,WAAWK,aAAa,CAACf,iBAAiBsB,sBAAsB,CAAC;IAC1E;IACA,OAAOrB;AACT"}
@@ -1,32 +1,32 @@
1
- import { ReactNode } from 'react';
2
- import { DashboardResource, ProjectDatasource, DatasourceSelector, DatasourceSpec, GlobalDatasource } from '@perses-dev/core';
1
+ import { ReactElement, ReactNode } from 'react';
2
+ import { DashboardResource, DatasourceResource, DatasourceSelector, DatasourceSpec, GlobalDatasourceResource, EphemeralDashboardResource } from '@perses-dev/core';
3
3
  import { DatasourceClient } from '@perses-dev/plugin-system';
4
4
  export interface DatasourceStoreProviderProps {
5
- dashboardResource?: DashboardResource;
5
+ dashboardResource?: DashboardResource | EphemeralDashboardResource;
6
6
  projectName?: string;
7
7
  datasourceApi: DatasourceApi;
8
8
  children?: ReactNode;
9
9
  savedDatasources?: Record<string, DatasourceSpec>;
10
10
  onCreate?: (client: DatasourceClient) => DatasourceClient;
11
11
  }
12
- export declare type BuildDatasourceProxyUrlParams = {
12
+ export type BuildDatasourceProxyUrlParams = {
13
13
  project?: string;
14
14
  dashboard?: string;
15
15
  name: string;
16
16
  };
17
- export declare type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;
17
+ export type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;
18
18
  /**
19
19
  * The external API for fetching datasource resources
20
20
  */
21
21
  export interface DatasourceApi {
22
22
  buildProxyUrl?: BuildDatasourceProxyUrlFunc;
23
- getDatasource: (project: string, selector: DatasourceSelector) => Promise<ProjectDatasource | undefined>;
24
- getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;
25
- listDatasources: (project: string, pluginKind?: string) => Promise<ProjectDatasource[]>;
26
- listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;
23
+ getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;
24
+ getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;
25
+ listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;
26
+ listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;
27
27
  }
28
28
  /**
29
29
  * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
30
30
  */
31
- export declare function DatasourceStoreProvider(props: DatasourceStoreProviderProps): JSX.Element;
31
+ export declare function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement;
32
32
  //# sourceMappingURL=DatasourceStoreProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAClE,OAAO,EACL,iBAAiB,EAEjB,iBAAiB,EACjB,kBAAkB,EAClB,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E,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACzF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CACrF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,GAAG,YAAY,CAyLzF"}
@@ -17,16 +17,15 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
17
17
  /**
18
18
  * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
19
19
  */ export function DatasourceStoreProvider(props) {
20
- const { projectName , datasourceApi , onCreate , children } = props;
20
+ const { projectName, datasourceApi, onCreate, children } = props;
21
21
  const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);
22
- var _props_savedDatasources;
23
- const [savedDatasources, setSavedDatasources] = useState((_props_savedDatasources = props.savedDatasources) !== null && _props_savedDatasources !== void 0 ? _props_savedDatasources : {});
24
- const project = projectName !== null && projectName !== void 0 ? projectName : dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.metadata.project;
25
- const { getPlugin , listPluginMetadata } = usePluginRegistry();
22
+ const [savedDatasources, setSavedDatasources] = useState(props.savedDatasources ?? {});
23
+ const project = projectName ?? dashboardResource?.metadata.project;
24
+ const { getPlugin, listPluginMetadata } = usePluginRegistry();
26
25
  const findDatasource = useEvent(async (selector)=>{
27
26
  // Try to find it in dashboard spec
28
27
  if (dashboardResource) {
29
- const { datasources } = dashboardResource.spec;
28
+ const { datasources } = dashboardResource.spec;
30
29
  const dashboardDatasource = findDashboardDatasource(datasources, selector);
31
30
  if (dashboardDatasource !== undefined) {
32
31
  return {
@@ -66,15 +65,15 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
66
65
  });
67
66
  // Gets a datasource spec for a given selector
68
67
  const getDatasource = useCallback(async (selector)=>{
69
- const { spec } = await findDatasource(selector);
68
+ const { spec } = await findDatasource(selector);
70
69
  return spec;
71
70
  }, [
72
71
  findDatasource
73
72
  ]);
74
73
  // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client
75
74
  const getDatasourceClient = useCallback(async function getClient(selector) {
76
- const { kind } = selector;
77
- const [{ spec , proxyUrl }, plugin] = await Promise.all([
75
+ const { kind } = selector;
76
+ const [{ spec, proxyUrl }, plugin] = await Promise.all([
78
77
  findDatasource(selector),
79
78
  getPlugin('Datasource', kind)
80
79
  ]);
@@ -91,24 +90,26 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
91
90
  getPlugin,
92
91
  onCreate
93
92
  ]);
94
- const listDatasourceSelectItems = useEvent(async (datasourcePluginKind)=>{
93
+ const listDatasourceSelectItems = useEvent(async (datasourcePluginName)=>{
95
94
  const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
96
- listPluginMetadata('Datasource'),
97
- project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],
98
- datasourceApi.listGlobalDatasources(datasourcePluginKind)
95
+ listPluginMetadata([
96
+ 'Datasource'
97
+ ]),
98
+ project ? datasourceApi.listDatasources(project, datasourcePluginName) : [],
99
+ datasourceApi.listGlobalDatasources(datasourcePluginName)
99
100
  ]);
100
101
  // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource
101
- const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.kind === datasourcePluginKind);
102
+ const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.spec.name === datasourcePluginName);
102
103
  if (datasourcePluginMetadata === undefined) {
103
- throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);
104
+ throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);
104
105
  }
105
106
  // Get helper for computing results properly
106
- const { results , addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);
107
+ const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);
107
108
  // Start with dashboard datasources with the highest precedence
108
- if (dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.spec.datasources) {
109
+ if (dashboardResource?.spec.datasources) {
109
110
  for(const selectorName in dashboardResource.spec.datasources){
110
111
  const spec = dashboardResource.spec.datasources[selectorName];
111
- if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
112
+ if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;
112
113
  const saved = selectorName in savedDatasources;
113
114
  addItem({
114
115
  spec,
@@ -141,8 +142,7 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
141
142
  return results;
142
143
  });
143
144
  const getLocalDatasources = useCallback(()=>{
144
- var _dashboardResource_spec_datasources;
145
- return (_dashboardResource_spec_datasources = dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.spec.datasources) !== null && _dashboardResource_spec_datasources !== void 0 ? _dashboardResource_spec_datasources : {};
145
+ return dashboardResource?.spec.datasources ?? {};
146
146
  }, [
147
147
  dashboardResource
148
148
  ]);
@@ -153,7 +153,13 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
153
153
  ]);
154
154
  const setLocalDatasources = useCallback((datasources)=>{
155
155
  if (dashboardResource) {
156
- setDashboardResource({
156
+ setDashboardResource(dashboardResource.kind === 'Dashboard' ? {
157
+ ...dashboardResource,
158
+ spec: {
159
+ ...dashboardResource.spec,
160
+ datasources: datasources
161
+ }
162
+ } : {
157
163
  ...dashboardResource,
158
164
  spec: {
159
165
  ...dashboardResource.spec,
@@ -221,9 +227,8 @@ function findDashboardDatasource(dashboardDatasources, selector) {
221
227
  let explicitDefaultAdded = false;
222
228
  const groupIndices = {};
223
229
  let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.
224
- const addItem = ({ spec , selectorName , selectorGroup: group , editLink , saved })=>{
225
- var _spec_display;
226
- group = group !== null && group !== void 0 ? group : '';
230
+ const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved })=>{
231
+ group = group ?? '';
227
232
  // Ensure the default group is always present as soon as an item is added.
228
233
  if (isFirst) {
229
234
  results.push({
@@ -231,9 +236,8 @@ function findDashboardDatasource(dashboardDatasources, selector) {
231
236
  items: []
232
237
  });
233
238
  }
234
- var _groupIndices_group;
235
239
  // Create the group if necessary
236
- let selectItemGroup = results[(_groupIndices_group = groupIndices[group]) !== null && _groupIndices_group !== void 0 ? _groupIndices_group : -1];
240
+ let selectItemGroup = results[groupIndices[group] ?? -1];
237
241
  if (!selectItemGroup) {
238
242
  groupIndices[group] = currentGroupIndex;
239
243
  selectItemGroup = {
@@ -246,9 +250,8 @@ function findDashboardDatasource(dashboardDatasources, selector) {
246
250
  }
247
251
  // Add item to the group
248
252
  const isOverridden = usedNames.has(selectorName);
249
- var _spec_display_name;
250
253
  selectItemGroup.items.push({
251
- name: (_spec_display_name = (_spec_display = spec.display) === null || _spec_display === void 0 ? void 0 : _spec_display.name) !== null && _spec_display_name !== void 0 ? _spec_display_name : selectorName,
254
+ name: spec.display?.name ?? selectorName,
252
255
  overridden: isOverridden,
253
256
  saved,
254
257
  selector: {
@@ -277,9 +280,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
277
280
  // At the end, we make sure the overriding item(s) is well flagged so
278
281
  if (isOverridden) {
279
282
  for(let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++){
280
- var _results_i;
281
- var _results_i_items;
282
- ((_results_i_items = (_results_i = results[i]) === null || _results_i === void 0 ? void 0 : _results_i.items) !== null && _results_i_items !== void 0 ? _results_i_items : []).filter((item)=>item.selector.name === selectorName).forEach((item)=>{
283
+ (results[i]?.items ?? []).filter((item)=>item.selector.name === selectorName).forEach((item)=>{
283
284
  item.overriding = true;
284
285
  });
285
286
  }