@perses-dev/dashboards 0.0.0-snapshot-panel-extra-content-3-17f9c42 → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59

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 +11 -8
  2. package/dist/cjs/components/AddGroupButton/index.js +10 -8
  3. package/dist/cjs/components/AddPanelButton/AddPanelButton.js +12 -13
  4. package/dist/cjs/components/AddPanelButton/index.js +10 -8
  5. package/dist/cjs/components/Dashboard/Dashboard.js +12 -10
  6. package/dist/cjs/components/Dashboard/index.js +10 -8
  7. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +53 -22
  8. package/dist/cjs/components/DashboardStickyToolbar/index.js +10 -8
  9. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +82 -103
  10. package/dist/cjs/components/DashboardToolbar/index.js +10 -8
  11. package/dist/cjs/components/Datasources/DatasourceEditor.js +236 -0
  12. package/dist/cjs/components/Datasources/EditDatasourcesButton.js +112 -0
  13. package/dist/cjs/components/{ToolbarIconButton → Datasources}/index.js +11 -8
  14. package/dist/cjs/components/DeletePanelDialog/DeletePanelDialog.js +16 -14
  15. package/dist/cjs/components/DeletePanelDialog/index.js +10 -8
  16. package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +18 -16
  17. package/dist/cjs/components/DeletePanelGroupDialog/index.js +10 -8
  18. package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +6 -4
  19. package/dist/cjs/components/DiscardChangesConfirmationDialog/index.js +10 -8
  20. package/dist/cjs/components/DownloadButton/DownloadButton.js +13 -12
  21. package/dist/cjs/components/DownloadButton/index.js +10 -8
  22. package/dist/cjs/components/EditButton/EditButton.js +9 -7
  23. package/dist/cjs/components/EditButton/index.js +10 -8
  24. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +15 -12
  25. package/dist/cjs/components/EditJsonButton/index.js +10 -8
  26. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +54 -25
  27. package/dist/cjs/components/EditJsonDialog/index.js +10 -8
  28. package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +21 -19
  29. package/dist/cjs/components/EmptyDashboard/index.js +10 -8
  30. package/dist/cjs/components/GridLayout/GridContainer.js +6 -4
  31. package/dist/cjs/components/GridLayout/GridItemContent.js +37 -19
  32. package/dist/cjs/components/GridLayout/GridLayout.js +21 -19
  33. package/dist/cjs/components/GridLayout/GridTitle.js +40 -39
  34. package/dist/cjs/components/GridLayout/index.js +13 -11
  35. package/dist/cjs/components/Panel/Panel.js +19 -23
  36. package/dist/cjs/components/Panel/PanelContent.js +11 -8
  37. package/dist/cjs/components/Panel/PanelHeader.js +35 -33
  38. package/dist/cjs/components/Panel/index.js +10 -8
  39. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +25 -77
  40. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +237 -144
  41. package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -12
  42. package/dist/cjs/components/PanelDrawer/index.js +11 -8
  43. package/dist/cjs/components/PanelDrawer/usePanelEditor.js +5 -3
  44. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +18 -16
  45. package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +16 -12
  46. package/dist/cjs/components/PanelGroupDialog/index.js +10 -8
  47. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +48 -46
  48. package/dist/cjs/components/QuerySummaryTable/index.js +10 -8
  49. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +26 -24
  50. package/dist/cjs/components/SaveChangesConfirmationDialog/index.js +10 -8
  51. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +14 -14
  52. package/dist/cjs/components/SaveDashboardButton/index.js +10 -8
  53. package/dist/cjs/components/Variables/BuiltinVariableAccordions.js +141 -0
  54. package/dist/cjs/components/Variables/EditVariablesButton.js +19 -17
  55. package/dist/cjs/components/Variables/TemplateVariable.js +261 -107
  56. package/dist/cjs/components/Variables/VariableEditor.js +282 -207
  57. package/dist/cjs/components/Variables/VariableList.js +24 -22
  58. package/dist/cjs/components/Variables/index.js +14 -11
  59. package/dist/cjs/components/index.js +30 -29
  60. package/dist/cjs/constants/grid-layout-config.js +6 -2
  61. package/dist/cjs/constants/index.js +12 -9
  62. package/dist/cjs/constants/styles.js +42 -0
  63. package/dist/cjs/constants/user-interface-text.js +8 -3
  64. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +48 -35
  65. package/dist/cjs/context/DashboardProvider/common.js +6 -2
  66. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +81 -49
  67. package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +4 -2
  68. package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +8 -6
  69. package/dist/cjs/context/DashboardProvider/discard-changes-dialog-slice.js +3 -1
  70. package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +4 -2
  71. package/dist/cjs/context/DashboardProvider/edit-json-dialog-slice.js +3 -1
  72. package/dist/cjs/context/DashboardProvider/index.js +12 -10
  73. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +17 -17
  74. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +8 -6
  75. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -8
  76. package/dist/cjs/context/DashboardProvider/panel-slice.js +3 -1
  77. package/dist/cjs/context/DashboardProvider/save-changes-dialog-slice.js +3 -1
  78. package/dist/cjs/context/DatasourceStoreProvider.js +177 -50
  79. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +150 -39
  80. package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +12 -10
  81. package/dist/cjs/context/TemplateVariableProvider/index.js +10 -8
  82. package/dist/cjs/context/TemplateVariableProvider/query-params.js +17 -7
  83. package/dist/cjs/context/TemplateVariableProvider/utils.js +15 -7
  84. package/dist/cjs/context/index.js +13 -11
  85. package/dist/cjs/context/useDashboard.js +30 -11
  86. package/dist/cjs/index.js +12 -10
  87. package/dist/cjs/stories/decorators/WithDashboard.js +6 -4
  88. package/dist/cjs/stories/decorators/WithDatasourceStore.js +6 -4
  89. package/dist/cjs/stories/decorators/WithTemplateVariables.js +6 -4
  90. package/dist/cjs/stories/decorators/constants.js +5 -3
  91. package/dist/cjs/stories/decorators/index.js +13 -11
  92. package/dist/cjs/test/dashboard-provider.js +8 -4
  93. package/dist/cjs/test/datasource-provider.js +16 -12
  94. package/dist/cjs/test/index.js +13 -11
  95. package/dist/cjs/test/plugin-registry.js +6 -4
  96. package/dist/cjs/test/render.js +28 -21
  97. package/dist/cjs/test/setup-tests.js +2 -2
  98. package/dist/cjs/test/testDashboard.js +13 -11
  99. package/dist/cjs/utils/index.js +10 -9
  100. package/dist/cjs/utils/panelUtils.js +11 -5
  101. package/dist/cjs/{components/TimeRangeControls → validation}/index.js +10 -8
  102. package/dist/cjs/{utils/time.js → validation/panel.js} +11 -9
  103. package/dist/cjs/views/ViewDashboard/DashboardApp.js +32 -18
  104. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +64 -21
  105. package/dist/cjs/views/ViewDashboard/index.js +10 -8
  106. package/dist/cjs/views/index.js +10 -8
  107. package/dist/components/AddGroupButton/AddGroupButton.d.ts +1 -2
  108. package/dist/components/AddGroupButton/AddGroupButton.d.ts.map +1 -1
  109. package/dist/components/AddGroupButton/AddGroupButton.js +3 -2
  110. package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
  111. package/dist/components/AddGroupButton/index.js.map +1 -1
  112. package/dist/components/AddPanelButton/AddPanelButton.d.ts +1 -2
  113. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
  114. package/dist/components/AddPanelButton/AddPanelButton.js +4 -7
  115. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  116. package/dist/components/AddPanelButton/index.js.map +1 -1
  117. package/dist/components/Dashboard/Dashboard.d.ts +2 -3
  118. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  119. package/dist/components/Dashboard/Dashboard.js +1 -1
  120. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  121. package/dist/components/Dashboard/index.js.map +1 -1
  122. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts +1 -2
  123. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -1
  124. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +38 -9
  125. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  126. package/dist/components/DashboardStickyToolbar/index.js.map +1 -1
  127. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -1
  128. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  129. package/dist/components/DashboardToolbar/DashboardToolbar.js +63 -86
  130. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  131. package/dist/components/DashboardToolbar/index.js.map +1 -1
  132. package/dist/components/Datasources/DatasourceEditor.d.ts +7 -0
  133. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -0
  134. package/dist/components/Datasources/DatasourceEditor.js +223 -0
  135. package/dist/components/Datasources/DatasourceEditor.js.map +1 -0
  136. package/dist/components/Datasources/EditDatasourcesButton.d.ts +2 -0
  137. package/dist/components/Datasources/EditDatasourcesButton.d.ts.map +1 -0
  138. package/dist/components/Datasources/EditDatasourcesButton.js +99 -0
  139. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -0
  140. package/dist/components/Datasources/index.d.ts +3 -0
  141. package/dist/components/Datasources/index.d.ts.map +1 -0
  142. package/dist/components/{TimeRangeControls → Datasources}/index.js +2 -1
  143. package/dist/components/Datasources/index.js.map +1 -0
  144. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +1 -2
  145. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -1
  146. package/dist/components/DeletePanelDialog/DeletePanelDialog.js +4 -4
  147. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -1
  148. package/dist/components/DeletePanelDialog/index.js.map +1 -1
  149. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts +1 -2
  150. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
  151. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +3 -3
  152. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  153. package/dist/components/DeletePanelGroupDialog/index.js.map +1 -1
  154. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts +1 -2
  155. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map +1 -1
  156. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  157. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  158. package/dist/components/DiscardChangesConfirmationDialog/index.js.map +1 -1
  159. package/dist/components/DownloadButton/DownloadButton.d.ts +1 -2
  160. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -1
  161. package/dist/components/DownloadButton/DownloadButton.js +3 -4
  162. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  163. package/dist/components/DownloadButton/index.js.map +1 -1
  164. package/dist/components/EditButton/EditButton.d.ts +1 -2
  165. package/dist/components/EditButton/EditButton.d.ts.map +1 -1
  166. package/dist/components/EditButton/EditButton.js +1 -1
  167. package/dist/components/EditButton/EditButton.js.map +1 -1
  168. package/dist/components/EditButton/index.js.map +1 -1
  169. package/dist/components/EditJsonButton/EditJsonButton.d.ts +4 -2
  170. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -1
  171. package/dist/components/EditJsonButton/EditJsonButton.js +7 -6
  172. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  173. package/dist/components/EditJsonButton/index.js.map +1 -1
  174. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +5 -2
  175. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -1
  176. package/dist/components/EditJsonDialog/EditJsonDialog.js +43 -16
  177. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  178. package/dist/components/EditJsonDialog/index.js.map +1 -1
  179. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +1 -1
  180. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -1
  181. package/dist/components/EmptyDashboard/EmptyDashboard.js +3 -3
  182. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
  183. package/dist/components/EmptyDashboard/index.js.map +1 -1
  184. package/dist/components/GridLayout/GridContainer.d.ts +1 -1
  185. package/dist/components/GridLayout/GridContainer.d.ts.map +1 -1
  186. package/dist/components/GridLayout/GridContainer.js +1 -1
  187. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  188. package/dist/components/GridLayout/GridItemContent.d.ts +1 -2
  189. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  190. package/dist/components/GridLayout/GridItemContent.js +31 -15
  191. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  192. package/dist/components/GridLayout/GridLayout.d.ts +1 -2
  193. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  194. package/dist/components/GridLayout/GridLayout.js +6 -6
  195. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  196. package/dist/components/GridLayout/GridTitle.d.ts +1 -2
  197. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  198. package/dist/components/GridLayout/GridTitle.js +5 -6
  199. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  200. package/dist/components/GridLayout/index.js.map +1 -1
  201. package/dist/components/Panel/Panel.d.ts +2 -2
  202. package/dist/components/Panel/Panel.d.ts.map +1 -1
  203. package/dist/components/Panel/Panel.js +7 -13
  204. package/dist/components/Panel/Panel.js.map +1 -1
  205. package/dist/components/Panel/PanelContent.d.ts +3 -3
  206. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  207. package/dist/components/Panel/PanelContent.js +4 -3
  208. package/dist/components/Panel/PanelContent.js.map +1 -1
  209. package/dist/components/Panel/PanelHeader.d.ts +2 -2
  210. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  211. package/dist/components/Panel/PanelHeader.js +2 -2
  212. package/dist/components/Panel/PanelHeader.js.map +1 -1
  213. package/dist/components/Panel/index.js.map +1 -1
  214. package/dist/components/PanelDrawer/PanelDrawer.d.ts +1 -2
  215. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  216. package/dist/components/PanelDrawer/PanelDrawer.js +22 -76
  217. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  218. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +5 -3
  219. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  220. package/dist/components/PanelDrawer/PanelEditorForm.js +231 -142
  221. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  222. package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -2
  223. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  224. package/dist/components/PanelDrawer/PanelPreview.js +4 -5
  225. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  226. package/dist/components/PanelDrawer/index.d.ts +1 -0
  227. package/dist/components/PanelDrawer/index.d.ts.map +1 -1
  228. package/dist/components/PanelDrawer/index.js +1 -0
  229. package/dist/components/PanelDrawer/index.js.map +1 -1
  230. package/dist/components/PanelDrawer/usePanelEditor.js +2 -2
  231. package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -1
  232. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +1 -2
  233. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  234. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  235. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +1 -2
  236. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -1
  237. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  238. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  239. package/dist/components/PanelGroupDialog/index.js.map +1 -1
  240. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +1 -2
  241. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -1
  242. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +8 -8
  243. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  244. package/dist/components/QuerySummaryTable/index.js.map +1 -1
  245. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +1 -2
  246. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
  247. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +8 -8
  248. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  249. package/dist/components/SaveChangesConfirmationDialog/index.js.map +1 -1
  250. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +1 -2
  251. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
  252. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +8 -10
  253. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
  254. package/dist/components/SaveDashboardButton/index.js.map +1 -1
  255. package/dist/components/Variables/BuiltinVariableAccordions.d.ts +7 -0
  256. package/dist/components/Variables/BuiltinVariableAccordions.d.ts.map +1 -0
  257. package/dist/components/Variables/BuiltinVariableAccordions.js +128 -0
  258. package/dist/components/Variables/BuiltinVariableAccordions.js.map +1 -0
  259. package/dist/components/Variables/EditVariablesButton.d.ts +1 -2
  260. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  261. package/dist/components/Variables/EditVariablesButton.js +7 -7
  262. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  263. package/dist/components/Variables/TemplateVariable.d.ts +12 -4
  264. package/dist/components/Variables/TemplateVariable.d.ts.map +1 -1
  265. package/dist/components/Variables/TemplateVariable.js +244 -100
  266. package/dist/components/Variables/TemplateVariable.js.map +1 -1
  267. package/dist/components/Variables/VariableEditor.d.ts +4 -4
  268. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  269. package/dist/components/Variables/VariableEditor.js +232 -161
  270. package/dist/components/Variables/VariableEditor.js.map +1 -1
  271. package/dist/components/Variables/VariableList.d.ts +2 -3
  272. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  273. package/dist/components/Variables/VariableList.js +11 -13
  274. package/dist/components/Variables/VariableList.js.map +1 -1
  275. package/dist/components/Variables/index.d.ts +1 -0
  276. package/dist/components/Variables/index.d.ts.map +1 -1
  277. package/dist/components/Variables/index.js +1 -0
  278. package/dist/components/Variables/index.js.map +1 -1
  279. package/dist/components/index.d.ts +1 -2
  280. package/dist/components/index.d.ts.map +1 -1
  281. package/dist/components/index.js +1 -2
  282. package/dist/components/index.js.map +1 -1
  283. package/dist/constants/grid-layout-config.js.map +1 -1
  284. package/dist/constants/index.d.ts +1 -0
  285. package/dist/constants/index.d.ts.map +1 -1
  286. package/dist/constants/index.js +1 -0
  287. package/dist/constants/index.js.map +1 -1
  288. package/dist/constants/styles.d.ts +5 -0
  289. package/dist/constants/styles.d.ts.map +1 -0
  290. package/dist/{utils/time.js → constants/styles.js} +10 -10
  291. package/dist/constants/styles.js.map +1 -0
  292. package/dist/constants/user-interface-text.d.ts +2 -1
  293. package/dist/constants/user-interface-text.d.ts.map +1 -1
  294. package/dist/constants/user-interface-text.js +2 -1
  295. package/dist/constants/user-interface-text.js.map +1 -1
  296. package/dist/context/DashboardProvider/DashboardProvider.d.ts +7 -4
  297. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  298. package/dist/context/DashboardProvider/DashboardProvider.js +16 -9
  299. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  300. package/dist/context/DashboardProvider/common.d.ts +3 -3
  301. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  302. package/dist/context/DashboardProvider/common.js.map +1 -1
  303. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -1
  304. package/dist/context/DashboardProvider/dashboard-provider-api.js +17 -17
  305. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  306. package/dist/context/DashboardProvider/delete-panel-group-slice.js +1 -1
  307. package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
  308. package/dist/context/DashboardProvider/delete-panel-slice.js +5 -5
  309. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  310. package/dist/context/DashboardProvider/discard-changes-dialog-slice.js.map +1 -1
  311. package/dist/context/DashboardProvider/duplicate-panel-slice.js +1 -1
  312. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
  313. package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -1
  314. package/dist/context/DashboardProvider/index.js.map +1 -1
  315. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -2
  316. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  317. package/dist/context/DashboardProvider/panel-editor-slice.js +11 -13
  318. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  319. package/dist/context/DashboardProvider/panel-group-editor-slice.js +2 -2
  320. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  321. package/dist/context/DashboardProvider/panel-group-slice.d.ts +2 -2
  322. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  323. package/dist/context/DashboardProvider/panel-group-slice.js +4 -4
  324. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  325. package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
  326. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
  327. package/dist/context/DatasourceStoreProvider.d.ts +17 -12
  328. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  329. package/dist/context/DatasourceStoreProvider.js +172 -47
  330. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  331. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +15 -8
  332. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  333. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +115 -23
  334. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  335. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -1
  336. package/dist/context/TemplateVariableProvider/hydrationUtils.js +7 -7
  337. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -1
  338. package/dist/context/TemplateVariableProvider/index.js.map +1 -1
  339. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -1
  340. package/dist/context/TemplateVariableProvider/utils.js +3 -3
  341. package/dist/context/TemplateVariableProvider/utils.js.map +1 -1
  342. package/dist/context/index.js.map +1 -1
  343. package/dist/context/useDashboard.d.ts +3 -3
  344. package/dist/context/useDashboard.d.ts.map +1 -1
  345. package/dist/context/useDashboard.js +24 -7
  346. package/dist/context/useDashboard.js.map +1 -1
  347. package/dist/index.js.map +1 -1
  348. package/dist/stories/decorators/WithDashboard.js.map +1 -1
  349. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
  350. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -1
  351. package/dist/stories/decorators/constants.js +2 -2
  352. package/dist/stories/decorators/constants.js.map +1 -1
  353. package/dist/stories/decorators/index.js.map +1 -1
  354. package/dist/test/dashboard-provider.js.map +1 -1
  355. package/dist/test/datasource-provider.d.ts.map +1 -1
  356. package/dist/test/datasource-provider.js +5 -7
  357. package/dist/test/datasource-provider.js.map +1 -1
  358. package/dist/test/index.js.map +1 -1
  359. package/dist/test/plugin-registry.js.map +1 -1
  360. package/dist/test/render.d.ts.map +1 -1
  361. package/dist/test/render.js +9 -4
  362. package/dist/test/render.js.map +1 -1
  363. package/dist/test/setup-tests.js.map +1 -1
  364. package/dist/test/testDashboard.js +10 -10
  365. package/dist/test/testDashboard.js.map +1 -1
  366. package/dist/utils/index.d.ts +0 -1
  367. package/dist/utils/index.d.ts.map +1 -1
  368. package/dist/utils/index.js +0 -1
  369. package/dist/utils/index.js.map +1 -1
  370. package/dist/utils/panelUtils.d.ts +1 -1
  371. package/dist/utils/panelUtils.d.ts.map +1 -1
  372. package/dist/utils/panelUtils.js +2 -2
  373. package/dist/utils/panelUtils.js.map +1 -1
  374. package/dist/validation/index.d.ts +2 -0
  375. package/dist/validation/index.d.ts.map +1 -0
  376. package/dist/{components/ToolbarIconButton → validation}/index.js +1 -1
  377. package/dist/validation/index.js.map +1 -0
  378. package/dist/validation/panel.d.ts +19 -0
  379. package/dist/validation/panel.d.ts.map +1 -0
  380. package/dist/validation/panel.js +21 -0
  381. package/dist/validation/panel.js.map +1 -0
  382. package/dist/views/ViewDashboard/DashboardApp.d.ts +4 -3
  383. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  384. package/dist/views/ViewDashboard/DashboardApp.js +19 -7
  385. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  386. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -2
  387. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  388. package/dist/views/ViewDashboard/ViewDashboard.js +53 -12
  389. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  390. package/dist/views/ViewDashboard/index.js.map +1 -1
  391. package/dist/views/index.js.map +1 -1
  392. package/package.json +8 -7
  393. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +0 -183
  394. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +0 -38
  395. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +0 -14
  396. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +0 -1
  397. package/dist/components/TimeRangeControls/TimeRangeControls.js +0 -165
  398. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +0 -1
  399. package/dist/components/TimeRangeControls/index.d.ts +0 -2
  400. package/dist/components/TimeRangeControls/index.d.ts.map +0 -1
  401. package/dist/components/TimeRangeControls/index.js.map +0 -1
  402. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +0 -6
  403. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +0 -1
  404. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +0 -32
  405. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +0 -1
  406. package/dist/components/ToolbarIconButton/index.d.ts +0 -2
  407. package/dist/components/ToolbarIconButton/index.d.ts.map +0 -1
  408. package/dist/components/ToolbarIconButton/index.js.map +0 -1
  409. package/dist/utils/time.d.ts +0 -5
  410. package/dist/utils/time.d.ts.map +0 -1
  411. package/dist/utils/time.js.map +0 -1
@@ -11,24 +11,31 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { useCallback, useMemo } from 'react';
14
+ import { useCallback, useMemo, useState } from 'react';
15
15
  import { useEvent } from '@perses-dev/core';
16
16
  import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-system';
17
17
  /**
18
18
  * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
19
19
  */ export function DatasourceStoreProvider(props) {
20
- const { dashboardResource , projectName , datasourceApi , onCreate , children } = props;
20
+ const { projectName, datasourceApi, onCreate, children } = props;
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 : {});
21
24
  const project = projectName !== null && projectName !== void 0 ? projectName : dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.metadata.project;
22
- const { getPlugin , listPluginMetadata } = usePluginRegistry();
25
+ const { getPlugin, listPluginMetadata } = usePluginRegistry();
23
26
  const findDatasource = useEvent(async (selector)=>{
24
27
  // Try to find it in dashboard spec
25
28
  if (dashboardResource) {
26
- const { datasources } = dashboardResource.spec;
29
+ const { datasources } = dashboardResource.spec;
27
30
  const dashboardDatasource = findDashboardDatasource(datasources, selector);
28
31
  if (dashboardDatasource !== undefined) {
29
32
  return {
30
- spec: dashboardDatasource,
31
- proxyUrl: undefined
33
+ spec: dashboardDatasource.spec,
34
+ proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
35
+ project: dashboardResource.metadata.project,
36
+ dashboard: dashboardResource.metadata.name,
37
+ name: dashboardDatasource.name
38
+ })
32
39
  };
33
40
  }
34
41
  }
@@ -37,8 +44,11 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
37
44
  const datasource = await datasourceApi.getDatasource(project, selector);
38
45
  if (datasource !== undefined) {
39
46
  return {
40
- spec: datasource.resource.spec,
41
- proxyUrl: datasource.proxyUrl
47
+ spec: datasource.spec,
48
+ proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
49
+ project: datasource.metadata.project,
50
+ name: datasource.metadata.name
51
+ })
42
52
  };
43
53
  }
44
54
  }
@@ -46,23 +56,25 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
46
56
  const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
47
57
  if (globalDatasource !== undefined) {
48
58
  return {
49
- spec: globalDatasource.resource.spec,
50
- proxyUrl: globalDatasource.proxyUrl
59
+ spec: globalDatasource.spec,
60
+ proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
61
+ name: globalDatasource.metadata.name
62
+ })
51
63
  };
52
64
  }
53
65
  throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
54
66
  });
55
67
  // Gets a datasource spec for a given selector
56
68
  const getDatasource = useCallback(async (selector)=>{
57
- const { spec } = await findDatasource(selector);
69
+ const { spec } = await findDatasource(selector);
58
70
  return spec;
59
71
  }, [
60
72
  findDatasource
61
73
  ]);
62
74
  // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client
63
75
  const getDatasourceClient = useCallback(async function getClient(selector) {
64
- const { kind } = selector;
65
- const [{ spec , proxyUrl }, plugin] = await Promise.all([
76
+ const { kind } = selector;
77
+ const [{ spec, proxyUrl }, plugin] = await Promise.all([
66
78
  findDatasource(selector),
67
79
  getPlugin('Datasource', kind)
68
80
  ]);
@@ -79,53 +91,110 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
79
91
  getPlugin,
80
92
  onCreate
81
93
  ]);
82
- const listDatasourceMetadata = useEvent(async (datasourcePluginKind)=>{
94
+ const listDatasourceSelectItems = useEvent(async (datasourcePluginKind)=>{
83
95
  const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
84
96
  listPluginMetadata('Datasource'),
85
97
  project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],
86
98
  datasourceApi.listGlobalDatasources(datasourcePluginKind)
87
99
  ]);
88
- // Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
100
+ // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource
89
101
  const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.kind === datasourcePluginKind);
90
102
  if (datasourcePluginMetadata === undefined) {
91
103
  throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);
92
104
  }
93
- // Get helper for de-duping results properly
94
- const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
95
- // Start with dashboard datasources that have highest precedence
105
+ // Get helper for computing results properly
106
+ const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);
107
+ // Start with dashboard datasources with the highest precedence
96
108
  if (dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.spec.datasources) {
97
109
  for(const selectorName in dashboardResource.spec.datasources){
98
110
  const spec = dashboardResource.spec.datasources[selectorName];
99
111
  if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
100
- addResult(spec, selectorName);
112
+ const saved = selectorName in savedDatasources;
113
+ addItem({
114
+ spec,
115
+ selectorName,
116
+ selectorGroup: 'dashboard',
117
+ saved
118
+ });
101
119
  }
102
120
  }
103
121
  // Now look at project-level datasources
104
122
  for (const datasource of datasources){
105
- const selectorName1 = datasource.metadata.name;
106
- addResult(datasource.spec, selectorName1);
123
+ const selectorName = datasource.metadata.name;
124
+ addItem({
125
+ spec: datasource.spec,
126
+ selectorName,
127
+ selectorGroup: 'project',
128
+ editLink: `/projects/${project}/datasources`
129
+ });
107
130
  }
108
131
  // And finally global datasources
109
132
  for (const globalDatasource of globalDatasources){
110
- const selectorName2 = globalDatasource.metadata.name;
111
- addResult(globalDatasource.spec, selectorName2);
133
+ const selectorName = globalDatasource.metadata.name;
134
+ addItem({
135
+ spec: globalDatasource.spec,
136
+ selectorName,
137
+ selectorGroup: 'global',
138
+ editLink: '/admin/datasources'
139
+ });
112
140
  }
113
141
  return results;
114
142
  });
143
+ 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 : {};
146
+ }, [
147
+ dashboardResource
148
+ ]);
149
+ const getSavedDatasources = useCallback(()=>{
150
+ return savedDatasources;
151
+ }, [
152
+ savedDatasources
153
+ ]);
154
+ const setLocalDatasources = useCallback((datasources)=>{
155
+ if (dashboardResource) {
156
+ setDashboardResource(dashboardResource.kind === 'Dashboard' ? {
157
+ ...dashboardResource,
158
+ spec: {
159
+ ...dashboardResource.spec,
160
+ datasources: datasources
161
+ }
162
+ } : {
163
+ ...dashboardResource,
164
+ spec: {
165
+ ...dashboardResource.spec,
166
+ datasources: datasources
167
+ }
168
+ });
169
+ }
170
+ }, [
171
+ dashboardResource
172
+ ]);
115
173
  const ctxValue = useMemo(()=>({
116
174
  getDatasource,
117
175
  getDatasourceClient,
118
- listDatasourceMetadata
176
+ getLocalDatasources,
177
+ setLocalDatasources,
178
+ setSavedDatasources,
179
+ getSavedDatasources,
180
+ listDatasourceSelectItems
119
181
  }), [
120
182
  getDatasource,
121
183
  getDatasourceClient,
122
- listDatasourceMetadata
184
+ getLocalDatasources,
185
+ setLocalDatasources,
186
+ listDatasourceSelectItems,
187
+ setSavedDatasources,
188
+ getSavedDatasources
123
189
  ]);
124
190
  return /*#__PURE__*/ _jsx(DatasourceStoreContext.Provider, {
125
191
  value: ctxValue,
126
192
  children: children
127
193
  });
128
194
  }
195
+ function buildDatasourceProxyUrl(api, params) {
196
+ return api.buildProxyUrl ? api.buildProxyUrl(params) : '';
197
+ }
129
198
  // Helper to find a datasource in the list embedded in a dashboard spec
130
199
  function findDashboardDatasource(dashboardDatasources, selector) {
131
200
  if (dashboardDatasources === undefined) return undefined;
@@ -133,43 +202,99 @@ function findDashboardDatasource(dashboardDatasources, selector) {
133
202
  if (selector.name !== undefined) {
134
203
  const named = dashboardDatasources[selector.name];
135
204
  if (named === undefined) return undefined;
136
- return named.plugin.kind === selector.kind ? named : undefined;
205
+ return named.plugin.kind === selector.kind ? {
206
+ name: selector.name,
207
+ spec: named
208
+ } : undefined;
137
209
  }
138
210
  // If only using a kind, try to find one with that kind that is the default
139
- return Object.values(dashboardDatasources).find((ds)=>ds.plugin.kind === selector.kind && ds.default === true);
211
+ const result = Object.entries(dashboardDatasources).find((entry)=>entry[1].plugin.kind === selector.kind && entry[1].default);
212
+ if (!result) {
213
+ return undefined;
214
+ }
215
+ return {
216
+ name: result[0],
217
+ spec: result[1]
218
+ };
140
219
  }
141
- // Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors
142
- function buildListDatasourceMetadataResults(pluginDisplayName) {
220
+ /**
221
+ * Helper for building a list of DatasourceSelectItemGroup results.
222
+ * @param pluginDisplayName
223
+ */ function buildDatasourceSelectItemGroups(pluginDisplayName) {
143
224
  const results = [];
144
225
  const usedNames = new Set();
145
- let defaultAdded = false;
146
- const addResult = (spec, selectorName)=>{
147
- var ref;
148
- // If we haven't added a default yet and this is a default, add default option to the beginning of the results
149
- if (spec.default && defaultAdded === false) {
150
- results.unshift({
151
- name: `Default ${pluginDisplayName}`,
152
- selector: {
153
- kind: spec.plugin.kind
154
- }
226
+ let isFirst = true;
227
+ let explicitDefaultAdded = false;
228
+ const groupIndices = {};
229
+ let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.
230
+ const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved })=>{
231
+ var _spec_display;
232
+ group = group !== null && group !== void 0 ? group : '';
233
+ // Ensure the default group is always present as soon as an item is added.
234
+ if (isFirst) {
235
+ results.push({
236
+ group: `Default ${pluginDisplayName}`,
237
+ items: []
155
238
  });
156
- defaultAdded = true;
157
239
  }
158
- // If we already have a datasource with this selector name, ignore it, otherwise add to end of list
159
- if (usedNames.has(selectorName)) return;
160
- var ref1;
161
- results.push({
162
- name: (ref1 = (ref = spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : selectorName,
240
+ var _groupIndices_group;
241
+ // Create the group if necessary
242
+ let selectItemGroup = results[(_groupIndices_group = groupIndices[group]) !== null && _groupIndices_group !== void 0 ? _groupIndices_group : -1];
243
+ if (!selectItemGroup) {
244
+ groupIndices[group] = currentGroupIndex;
245
+ selectItemGroup = {
246
+ items: [],
247
+ group,
248
+ editLink
249
+ };
250
+ results[currentGroupIndex] = selectItemGroup;
251
+ currentGroupIndex++;
252
+ }
253
+ // Add item to the group
254
+ const isOverridden = usedNames.has(selectorName);
255
+ var _spec_display_name;
256
+ selectItemGroup.items.push({
257
+ 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,
258
+ overridden: isOverridden,
259
+ saved,
163
260
  selector: {
164
261
  kind: spec.plugin.kind,
165
- name: selectorName
262
+ name: selectorName,
263
+ group
166
264
  }
167
265
  });
168
266
  usedNames.add(selectorName);
267
+ const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;
268
+ if (results[0] && (isFirst || isExplicitDefault)) {
269
+ // If we haven't added a default yet and this is a default, add default option to the beginning of the results
270
+ results[0].items = [
271
+ {
272
+ name: `Default (${selectorName} from ${group})`,
273
+ selector: {
274
+ kind: spec.plugin.kind
275
+ }
276
+ }
277
+ ];
278
+ // We consider that we added the default datasource only if it has been explicitly set as default.
279
+ // If we add this datasource as default just because it's the first, it still needs to be overridable by
280
+ // another datasource explicitly set as default.
281
+ explicitDefaultAdded = isExplicitDefault;
282
+ }
283
+ // At the end, we make sure the overriding item(s) is well flagged so
284
+ if (isOverridden) {
285
+ for(let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++){
286
+ var _results_i;
287
+ var _results_i_items;
288
+ ((_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)=>{
289
+ item.overriding = true;
290
+ });
291
+ }
292
+ }
293
+ isFirst = false;
169
294
  };
170
295
  return {
171
296
  results,
172
- addResult
297
+ addItem
173
298
  };
174
299
  }
175
300
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { ReactNode, useCallback, useMemo } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n Datasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n usePluginRegistry,\n DatasourceMetadata,\n DatasourceClient,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\n// The external API for fetching datasource resources\nexport interface DatasourceApi {\n getDatasource: (\n project: string,\n selector: DatasourceSelector\n ) => Promise<{ resource: Datasource; proxyUrl: string } | undefined>;\n\n getGlobalDatasource: (\n selector: DatasourceSelector\n ) => Promise<{ resource: GlobalDatasource; proxyUrl: string } | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { dashboardResource, projectName, datasourceApi, onCreate, children } = props;\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return { spec: dashboardDatasource, proxyUrl: undefined };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return { spec: datasource.resource.spec, proxyUrl: datasource.proxyUrl };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return { spec: globalDatasource.resource.spec, proxyUrl: globalDatasource.proxyUrl };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for de-duping results properly\n const { results, addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources that have highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n addResult(spec, selectorName);\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addResult(datasource.spec, selectorName);\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addResult(globalDatasource.spec, selectorName);\n }\n\n return results;\n });\n\n const ctxValue: DatasourceStore = useMemo(\n () => ({\n getDatasource,\n getDatasourceClient,\n listDatasourceMetadata,\n }),\n [getDatasource, getDatasourceClient, listDatasourceMetadata]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(dashboardDatasources: DashboardSpec['datasources'], selector: DatasourceSelector) {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? named : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n return Object.values(dashboardDatasources).find((ds) => ds.plugin.kind === selector.kind && ds.default === true);\n}\n\n// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors\nfunction buildListDatasourceMetadataResults(pluginDisplayName: string) {\n const results: DatasourceMetadata[] = [];\n const usedNames = new Set<string>();\n let defaultAdded = false;\n const addResult = (spec: DatasourceSpec, selectorName: string) => {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n if (spec.default && defaultAdded === false) {\n results.unshift({\n name: `Default ${pluginDisplayName}`,\n selector: {\n kind: spec.plugin.kind,\n },\n });\n defaultAdded = true;\n }\n\n // If we already have a datasource with this selector name, ignore it, otherwise add to end of list\n if (usedNames.has(selectorName)) return;\n\n results.push({\n name: spec.display?.name ?? selectorName,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n },\n });\n usedNames.add(selectorName);\n };\n\n return { results, addResult };\n}\n"],"names":["useCallback","useMemo","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","dashboardResource","projectName","datasourceApi","onCreate","children","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","datasource","getDatasource","resource","globalDatasource","getGlobalDatasource","Error","kind","name","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceMetadata","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addResult","buildListDatasourceMetadataResults","display","selectorName","ctxValue","Provider","value","dashboardDatasources","named","Object","values","ds","default","pluginDisplayName","usedNames","Set","defaultAdded","unshift","has","push","add"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAAoBA,WAAW,EAAEC,OAAO,QAAQ,OAAO,CAAC;AACxD,SAOEC,QAAQ,QACH,kBAAkB,CAAC;AAC1B,SACEC,sBAAsB,EAEtBC,iBAAiB,QAGZ,2BAA2B,CAAC;AA0BnC;;CAEC,GACD,OAAO,SAASC,uBAAuB,CAACC,KAAmC,EAAE;IAC3E,MAAM,EAAEC,iBAAiB,CAAA,EAAEC,WAAW,CAAA,EAAEC,aAAa,CAAA,EAAEC,QAAQ,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGL,KAAK,AAAC;IACpF,MAAMM,OAAO,GAAGJ,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAID,iBAAiB,aAAjBA,iBAAiB,WAAU,GAA3BA,KAAAA,CAA2B,GAA3BA,iBAAiB,CAAEM,QAAQ,CAACD,OAAO,AAAC;IAEnE,MAAM,EAAEE,SAAS,CAAA,EAAEC,kBAAkB,CAAA,EAAE,GAAGX,iBAAiB,EAAE,AAAC;IAE9D,MAAMY,cAAc,GAAGd,QAAQ,CAAC,OAAOe,QAA4B,GAAK;QACtE,mCAAmC;QACnC,IAAIV,iBAAiB,EAAE;YACrB,MAAM,EAAEW,WAAW,CAAA,EAAE,GAAGX,iBAAiB,CAACY,IAAI,AAAC;YAC/C,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IA,IAAI,CAACyC,OAAO,IAAII,YAAY,KAAK,KAAK,EAAE;YAC1CjB,OAAO,CAACkB,OAAO,CAAC;gBACdlC,IAAI,EAAE,CAAC,QAAQ,EAAE8B,iBAAiB,CAAC,CAAC;gBACpC5C,QAAQ,EAAE;oBACRa,IAAI,EAAEX,IAAI,CAACe,MAAM,CAACJ,IAAI;iBACvB;aACF,CAAC,CAAC;YACHkC,YAAY,GAAG,IAAI,CAAC;QACtB,CAAC;QAED,mGAAmG;QACnG,IAAIF,SAAS,CAACI,GAAG,CAACf,YAAY,CAAC,EAAE,OAAO;YAGhChC,IAAkB;QAD1B4B,OAAO,CAACoB,IAAI,CAAC;YACXpC,IAAI,EAAEZ,CAAAA,IAAkB,GAAlBA,CAAAA,GAAY,GAAZA,IAAI,CAAC+B,OAAO,cAAZ/B,GAAY,WAAM,GAAlBA,KAAAA,CAAkB,GAAlBA,GAAY,CAAEY,IAAI,cAAlBZ,IAAkB,cAAlBA,IAAkB,GAAIgC,YAAY;YACxClC,QAAQ,EAAE;gBACRa,IAAI,EAAEX,IAAI,CAACe,MAAM,CAACJ,IAAI;gBACtBC,IAAI,EAAEoB,YAAY;aACnB;SACF,CAAC,CAAC;QACHW,SAAS,CAACM,GAAG,CAACjB,YAAY,CAAC,CAAC;IAC9B,CAAC,AAAC;IAEF,OAAO;QAAEJ,OAAO;QAAEC,SAAS;KAAE,CAAC;AAChC,CAAC"}
1
+ {"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n ProjectDatasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<ProjectDatasource | undefined>;\n\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<ProjectDatasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved }: AddDatasouceSelectItemParams) => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"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,SAAoBA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClE,SAOEC,QAAQ,QAGH,mBAAmB;AAC1B,SACEC,sBAAsB,EAGtBC,iBAAiB,QAGZ,4BAA4B;AAkCnC;;CAEC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;IACzE,MAAM,EAAEC,WAAW,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGJ;IAC3D,MAAM,CAACK,mBAAmBC,qBAAqB,GAAGX,SAASK,MAAMK,iBAAiB;QAEhFL;IADF,MAAM,CAACO,kBAAkBC,oBAAoB,GAAGb,SAC9CK,CAAAA,0BAAAA,MAAMO,gBAAgB,cAAtBP,qCAAAA,0BAA0B,CAAC;IAE7B,MAAMS,UAAUR,wBAAAA,yBAAAA,cAAeI,8BAAAA,wCAAAA,kBAAmBK,QAAQ,CA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AM,EAAE2B,MAAM,CAAC,CAAC;oBAC/C9D,UAAU;wBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD4C,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;oBACpExC;oBAAAA;gBAAAA,CAAAA,CAAAA,oBAAAA,aAAAA,OAAO,CAACwC,EAAE,cAAVxC,iCAAAA,WAAYiC,KAAK,cAAjBjC,8BAAAA,mBAAqB,EAAE,AAAD,EACpByC,MAAM,CAAC,CAACC,OAA+BA,KAAKzE,QAAQ,CAACS,IAAI,KAAK0B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import { ReactNode } from 'react';
2
2
  import { VariableStateMap, VariableState, VariableStoreStateMap, VariableOption } from '@perses-dev/plugin-system';
3
- import { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';
4
- declare type TemplateVariableStore = {
3
+ import { VariableName, VariableValue, VariableDefinition, BuiltinVariableDefinition } from '@perses-dev/core';
4
+ type TemplateVariableStore = {
5
5
  variableDefinitions: VariableDefinition[];
6
6
  externalVariableDefinitions: ExternalVariableDefinition[];
7
7
  variableState: VariableStoreStateMap;
@@ -17,11 +17,11 @@ declare type TemplateVariableStore = {
17
17
  };
18
18
  export declare function useTemplateVariableStoreCtx(): Omit<Omit<import("zustand").StoreApi<TemplateVariableStore>, "setState"> & {
19
19
  setState<A extends string | {
20
- type: unknown;
20
+ type: string;
21
21
  }>(partial: TemplateVariableStore | Partial<TemplateVariableStore> | ((state: TemplateVariableStore) => TemplateVariableStore | Partial<TemplateVariableStore>), replace?: boolean | undefined, action?: A | undefined): void;
22
22
  }, "setState"> & {
23
23
  setState(nextStateOrUpdater: TemplateVariableStore | Partial<TemplateVariableStore> | ((state: import("immer/dist/internal").WritableDraft<TemplateVariableStore>) => void), shouldReplace?: boolean | undefined, action?: string | {
24
- type: unknown;
24
+ type: string;
25
25
  } | undefined): void;
26
26
  };
27
27
  export declare function useTemplateVariableValues(variableNames?: string[]): VariableStateMap;
@@ -48,12 +48,17 @@ export declare function useTemplateVariableActions(): {
48
48
  export declare function useTemplateVariableDefinitions(): VariableDefinition[];
49
49
  export declare function useTemplateExternalVariableDefinitions(): ExternalVariableDefinition[];
50
50
  export declare function useTemplateVariableStore(): TemplateVariableStore;
51
- export declare type ExternalVariableDefinition = {
51
+ export type ExternalVariableDefinition = {
52
52
  source: string;
53
+ tooltip?: {
54
+ title?: string;
55
+ description?: string;
56
+ };
57
+ editLink?: string;
53
58
  definitions: VariableDefinition[];
54
59
  };
55
60
  export interface TemplateVariableProviderProps {
56
- children: React.ReactNode;
61
+ children: ReactNode;
57
62
  initialVariableDefinitions?: VariableDefinition[];
58
63
  /**
59
64
  * The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.
@@ -64,7 +69,9 @@ export interface TemplateVariableProviderProps {
64
69
  * The order of the sources is important as first one will take precedence on the following ones, in case they have same names.
65
70
  */
66
71
  externalVariableDefinitions?: ExternalVariableDefinition[];
72
+ builtinVariables?: BuiltinVariableDefinition[];
67
73
  }
68
- export declare function TemplateVariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, }: TemplateVariableProviderProps): JSX.Element;
74
+ export declare function TemplateVariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariables, }: TemplateVariableProviderProps): import("react/jsx-runtime").JSX.Element;
75
+ export declare function TemplateVariableProviderWithQueryParams({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariables, }: TemplateVariableProviderProps): import("react/jsx-runtime").JSX.Element;
69
76
  export {};
70
77
  //# sourceMappingURL=TemplateVariableProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAkC,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAKnH,aAAK,qBAAqB,GAAG;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D,aAAa,EAAE,qBAAqB,CAAC;IACrC,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9F,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7F,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpF,sBAAsB,EAAE,CAAC,WAAW,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IACpE,wBAAwB,EAAE,MAAM,kBAAkB,EAAE,CAAC;IACrD,uBAAuB,EAAE,MAAM;QAAE,uBAAuB,EAAE,OAAO,CAAC;QAAC,qBAAqB,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACtG,CAAC;AAKF,wBAAgB,2BAA2B;;;;;;;;EAM1C;AAED,wBAAgB,yBAAyB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,oBAoCjE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;EAWhE;AAED,wBAAgB,0BAA0B;;;;;;;;;;EAYzC;AAED,wBAAgB,8BAA8B,yBAG7C;AAED,wBAAgB,sCAAsC,iCAGrD;AAED,wBAAgB,wBAAwB,0BAGvC;AA0KD,oBAAY,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAClD;;;;;;;OAOG;IACH,2BAA2B,CAAC,EAAE,0BAA0B,EAAE,CAAC;CAC5D;AAED,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,GACjC,EAAE,6BAA6B,eAY/B"}
1
+ {"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,SAAS,EAAiC,MAAM,OAAO,CAAC;AAKhF,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,cAAc,EAGf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAGlB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAK1B,KAAK,qBAAqB,GAAG;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D,aAAa,EAAE,qBAAqB,CAAC;IACrC,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9F,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAA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