@perses-dev/dashboards 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/dist/cjs/components/AddGroupButton/AddGroupButton.js +43 -0
  2. package/dist/cjs/components/AddGroupButton/index.js +28 -0
  3. package/dist/cjs/components/AddPanelButton/AddPanelButton.js +43 -0
  4. package/dist/cjs/components/AddPanelButton/index.js +28 -0
  5. package/dist/cjs/components/Dashboard/Dashboard.js +1 -1
  6. package/dist/cjs/components/Dashboard/index.js +1 -1
  7. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +47 -22
  8. package/dist/cjs/components/DashboardToolbar/index.js +1 -1
  9. package/dist/cjs/components/DeletePanelDialog/DeletePanelDialog.js +1 -1
  10. package/dist/cjs/components/DeletePanelDialog/index.js +1 -1
  11. package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +1 -1
  12. package/dist/cjs/components/DeletePanelGroupDialog/index.js +1 -1
  13. package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  14. package/dist/cjs/components/DiscardChangesConfirmationDialog/index.js +1 -1
  15. package/dist/cjs/components/DownloadButton/DownloadButton.js +17 -53
  16. package/dist/cjs/components/DownloadButton/index.js +1 -1
  17. package/dist/cjs/components/GridLayout/GridContainer.js +2 -1
  18. package/dist/cjs/components/GridLayout/GridItemContent.js +1 -1
  19. package/dist/cjs/components/GridLayout/GridLayout.js +2 -1
  20. package/dist/cjs/components/GridLayout/GridTitle.js +14 -11
  21. package/dist/cjs/components/GridLayout/index.js +1 -1
  22. package/dist/cjs/components/Panel/Panel.js +2 -1
  23. package/dist/cjs/components/Panel/Panel.test.js +1 -1
  24. package/dist/cjs/components/Panel/PanelContent.js +1 -1
  25. package/dist/cjs/components/Panel/PanelHeader.js +9 -8
  26. package/dist/cjs/components/Panel/index.js +1 -1
  27. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +2 -1
  28. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +1 -1
  29. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +1 -1
  30. package/dist/cjs/components/PanelDrawer/PanelPreview.js +1 -1
  31. package/dist/cjs/components/PanelDrawer/index.js +1 -1
  32. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +3 -1
  33. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
  34. package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  35. package/dist/cjs/components/PanelGroupDialog/index.js +1 -1
  36. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +14 -16
  37. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  38. package/dist/cjs/components/TimeRangeControls/index.js +1 -1
  39. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +35 -0
  40. package/dist/cjs/components/ToolbarIconButton/index.js +28 -0
  41. package/dist/cjs/components/Variables/EditVariablesButton.js +74 -0
  42. package/dist/cjs/components/Variables/Variable.js +1 -1
  43. package/dist/cjs/components/Variables/VariableEditor.js +9 -5
  44. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +6 -7
  45. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -1
  46. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +1 -1
  47. package/dist/cjs/components/Variables/VariableList.js +38 -110
  48. package/dist/cjs/components/Variables/index.js +4 -2
  49. package/dist/cjs/components/Variables/variable-model.js +1 -1
  50. package/dist/cjs/components/Variables/variable-model.test.js +1 -1
  51. package/dist/cjs/components/index.js +5 -2
  52. package/dist/cjs/constants/index.js +28 -0
  53. package/dist/cjs/constants/user-interface-text.js +59 -0
  54. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +1 -1
  55. package/dist/cjs/context/DashboardProvider/common.js +1 -1
  56. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +1 -1
  57. package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +1 -1
  58. package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +1 -1
  59. package/dist/cjs/context/DashboardProvider/discard-changes-dialog-slice.js +1 -1
  60. package/dist/cjs/context/DashboardProvider/index.js +1 -1
  61. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -1
  62. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +1 -1
  63. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +1 -1
  64. package/dist/cjs/context/DashboardProvider/panel-slice.js +1 -1
  65. package/dist/cjs/context/DatasourceStoreProvider.js +1 -1
  66. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +8 -8
  67. package/dist/cjs/context/TemplateVariableProvider/index.js +1 -1
  68. package/dist/cjs/context/TemplateVariableProvider/query-params.js +1 -1
  69. package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +1 -1
  70. package/dist/cjs/context/index.js +1 -1
  71. package/dist/cjs/context/useDashboard.js +1 -1
  72. package/dist/cjs/index.js +1 -1
  73. package/dist/cjs/test/dashboard-provider.js +1 -1
  74. package/dist/cjs/test/index.js +1 -1
  75. package/dist/cjs/test/plugin-registry.js +1 -1
  76. package/dist/cjs/test/render.js +1 -1
  77. package/dist/cjs/test/setup-tests.js +1 -1
  78. package/dist/cjs/test/testDashboard.js +1 -1
  79. package/dist/cjs/utils/functions.js +1 -1
  80. package/dist/cjs/utils/index.js +28 -0
  81. package/dist/cjs/views/ViewDashboard/DashboardApp.js +1 -1
  82. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +1 -1
  83. package/dist/cjs/views/ViewDashboard/index.js +1 -1
  84. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  85. package/dist/cjs/views/index.js +1 -1
  86. package/dist/components/AddGroupButton/AddGroupButton.d.ts +3 -0
  87. package/dist/components/AddGroupButton/AddGroupButton.d.ts.map +1 -0
  88. package/dist/components/AddGroupButton/AddGroupButton.js +32 -0
  89. package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -0
  90. package/dist/components/AddGroupButton/index.d.ts +2 -0
  91. package/dist/components/AddGroupButton/index.d.ts.map +1 -0
  92. package/dist/components/AddGroupButton/index.js +15 -0
  93. package/dist/components/AddGroupButton/index.js.map +1 -0
  94. package/dist/components/AddPanelButton/AddPanelButton.d.ts +3 -0
  95. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -0
  96. package/dist/components/AddPanelButton/AddPanelButton.js +32 -0
  97. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -0
  98. package/dist/components/AddPanelButton/index.d.ts +2 -0
  99. package/dist/components/AddPanelButton/index.d.ts.map +1 -0
  100. package/dist/components/AddPanelButton/index.js +15 -0
  101. package/dist/components/AddPanelButton/index.js.map +1 -0
  102. package/dist/components/Dashboard/Dashboard.js +1 -1
  103. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  104. package/dist/components/Dashboard/index.js +1 -1
  105. package/dist/components/Dashboard/index.js.map +1 -1
  106. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  107. package/dist/components/DashboardToolbar/DashboardToolbar.js +48 -23
  108. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  109. package/dist/components/DashboardToolbar/index.js +1 -1
  110. package/dist/components/DashboardToolbar/index.js.map +1 -1
  111. package/dist/components/DeletePanelDialog/DeletePanelDialog.js +1 -1
  112. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -1
  113. package/dist/components/DeletePanelDialog/index.js +1 -1
  114. package/dist/components/DeletePanelDialog/index.js.map +1 -1
  115. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +1 -1
  116. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  117. package/dist/components/DeletePanelGroupDialog/index.js +1 -1
  118. package/dist/components/DeletePanelGroupDialog/index.js.map +1 -1
  119. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  120. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  121. package/dist/components/DiscardChangesConfirmationDialog/index.js +1 -1
  122. package/dist/components/DiscardChangesConfirmationDialog/index.js.map +1 -1
  123. package/dist/components/DownloadButton/DownloadButton.d.ts +5 -1
  124. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -1
  125. package/dist/components/DownloadButton/DownloadButton.js +18 -15
  126. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  127. package/dist/components/DownloadButton/index.js +1 -1
  128. package/dist/components/DownloadButton/index.js.map +1 -1
  129. package/dist/components/GridLayout/GridContainer.d.ts.map +1 -1
  130. package/dist/components/GridLayout/GridContainer.js +2 -1
  131. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  132. package/dist/components/GridLayout/GridItemContent.js +1 -1
  133. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  134. package/dist/components/GridLayout/GridLayout.js +2 -1
  135. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  136. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  137. package/dist/components/GridLayout/GridTitle.js +14 -11
  138. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  139. package/dist/components/GridLayout/index.js +1 -1
  140. package/dist/components/GridLayout/index.js.map +1 -1
  141. package/dist/components/Panel/Panel.d.ts.map +1 -1
  142. package/dist/components/Panel/Panel.js +2 -1
  143. package/dist/components/Panel/Panel.js.map +1 -1
  144. package/dist/components/Panel/Panel.test.js +1 -1
  145. package/dist/components/Panel/Panel.test.js.map +1 -1
  146. package/dist/components/Panel/PanelContent.js +1 -1
  147. package/dist/components/Panel/PanelContent.js.map +1 -1
  148. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  149. package/dist/components/Panel/PanelHeader.js +9 -8
  150. package/dist/components/Panel/PanelHeader.js.map +1 -1
  151. package/dist/components/Panel/index.js +1 -1
  152. package/dist/components/Panel/index.js.map +1 -1
  153. package/dist/components/PanelDrawer/PanelDrawer.js +2 -1
  154. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  155. package/dist/components/PanelDrawer/PanelDrawer.test.js +1 -1
  156. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  157. package/dist/components/PanelDrawer/PanelEditorForm.js +1 -1
  158. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  159. package/dist/components/PanelDrawer/PanelPreview.js +1 -1
  160. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  161. package/dist/components/PanelDrawer/index.js +1 -1
  162. package/dist/components/PanelDrawer/index.js.map +1 -1
  163. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  164. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +3 -1
  165. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  166. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
  167. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  168. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  169. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  170. package/dist/components/PanelGroupDialog/index.js +1 -1
  171. package/dist/components/PanelGroupDialog/index.js.map +1 -1
  172. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  173. package/dist/components/TimeRangeControls/TimeRangeControls.js +15 -17
  174. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  175. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  176. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  177. package/dist/components/TimeRangeControls/index.js +1 -1
  178. package/dist/components/TimeRangeControls/index.js.map +1 -1
  179. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +6 -0
  180. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +1 -0
  181. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +29 -0
  182. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +1 -0
  183. package/dist/components/ToolbarIconButton/index.d.ts +2 -0
  184. package/dist/components/ToolbarIconButton/index.d.ts.map +1 -0
  185. package/dist/components/ToolbarIconButton/index.js +15 -0
  186. package/dist/components/ToolbarIconButton/index.js.map +1 -0
  187. package/dist/components/Variables/EditVariablesButton.d.ts +3 -0
  188. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -0
  189. package/dist/components/Variables/EditVariablesButton.js +63 -0
  190. package/dist/components/Variables/EditVariablesButton.js.map +1 -0
  191. package/dist/components/Variables/Variable.js +1 -1
  192. package/dist/components/Variables/Variable.js.map +1 -1
  193. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  194. package/dist/components/Variables/VariableEditor.js +9 -5
  195. package/dist/components/Variables/VariableEditor.js.map +1 -1
  196. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  197. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +8 -9
  198. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  199. package/dist/components/Variables/VariableEditorForm/index.js +1 -1
  200. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  201. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +1 -1
  202. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  203. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  204. package/dist/components/Variables/VariableList.js +40 -73
  205. package/dist/components/Variables/VariableList.js.map +1 -1
  206. package/dist/components/Variables/index.d.ts +3 -1
  207. package/dist/components/Variables/index.d.ts.map +1 -1
  208. package/dist/components/Variables/index.js +4 -2
  209. package/dist/components/Variables/index.js.map +1 -1
  210. package/dist/components/Variables/variable-model.js +1 -1
  211. package/dist/components/Variables/variable-model.js.map +1 -1
  212. package/dist/components/Variables/variable-model.test.js +1 -1
  213. package/dist/components/Variables/variable-model.test.js.map +1 -1
  214. package/dist/components/index.d.ts +4 -1
  215. package/dist/components/index.d.ts.map +1 -1
  216. package/dist/components/index.js +5 -2
  217. package/dist/components/index.js.map +1 -1
  218. package/dist/constants/index.d.ts +2 -0
  219. package/dist/constants/index.d.ts.map +1 -0
  220. package/dist/constants/index.js +15 -0
  221. package/dist/constants/index.js.map +1 -0
  222. package/dist/constants/user-interface-text.d.ts +28 -0
  223. package/dist/constants/user-interface-text.d.ts.map +1 -0
  224. package/dist/constants/user-interface-text.js +47 -0
  225. package/dist/constants/user-interface-text.js.map +1 -0
  226. package/dist/context/DashboardProvider/DashboardProvider.js +1 -1
  227. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  228. package/dist/context/DashboardProvider/common.js +1 -1
  229. package/dist/context/DashboardProvider/common.js.map +1 -1
  230. package/dist/context/DashboardProvider/dashboard-provider-api.js +1 -1
  231. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  232. package/dist/context/DashboardProvider/delete-panel-group-slice.js +1 -1
  233. package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
  234. package/dist/context/DashboardProvider/delete-panel-slice.js +1 -1
  235. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  236. package/dist/context/DashboardProvider/discard-changes-dialog-slice.js +1 -1
  237. package/dist/context/DashboardProvider/discard-changes-dialog-slice.js.map +1 -1
  238. package/dist/context/DashboardProvider/index.js +1 -1
  239. package/dist/context/DashboardProvider/index.js.map +1 -1
  240. package/dist/context/DashboardProvider/panel-editor-slice.js +1 -1
  241. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  242. package/dist/context/DashboardProvider/panel-group-editor-slice.js +1 -1
  243. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  244. package/dist/context/DashboardProvider/panel-group-slice.js +1 -1
  245. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  246. package/dist/context/DashboardProvider/panel-slice.js +1 -1
  247. package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
  248. package/dist/context/DatasourceStoreProvider.js +1 -1
  249. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  250. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +8 -8
  251. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  252. package/dist/context/TemplateVariableProvider/index.js +1 -1
  253. package/dist/context/TemplateVariableProvider/index.js.map +1 -1
  254. package/dist/context/TemplateVariableProvider/query-params.js +1 -1
  255. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -1
  256. package/dist/context/TemplateVariableProvider/query-params.test.js +1 -1
  257. package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -1
  258. package/dist/context/index.js +1 -1
  259. package/dist/context/index.js.map +1 -1
  260. package/dist/context/useDashboard.js +1 -1
  261. package/dist/context/useDashboard.js.map +1 -1
  262. package/dist/index.js +1 -1
  263. package/dist/index.js.map +1 -1
  264. package/dist/test/dashboard-provider.js +1 -1
  265. package/dist/test/dashboard-provider.js.map +1 -1
  266. package/dist/test/index.js +1 -1
  267. package/dist/test/index.js.map +1 -1
  268. package/dist/test/plugin-registry.js +1 -1
  269. package/dist/test/plugin-registry.js.map +1 -1
  270. package/dist/test/render.js +1 -1
  271. package/dist/test/render.js.map +1 -1
  272. package/dist/test/setup-tests.js +1 -1
  273. package/dist/test/setup-tests.js.map +1 -1
  274. package/dist/test/testDashboard.js +1 -1
  275. package/dist/test/testDashboard.js.map +1 -1
  276. package/dist/utils/functions.js +1 -1
  277. package/dist/utils/functions.js.map +1 -1
  278. package/dist/utils/index.d.ts +2 -0
  279. package/dist/utils/index.d.ts.map +1 -0
  280. package/dist/utils/index.js +15 -0
  281. package/dist/utils/index.js.map +1 -0
  282. package/dist/views/ViewDashboard/DashboardApp.js +1 -1
  283. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  284. package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
  285. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  286. package/dist/views/ViewDashboard/index.js +1 -1
  287. package/dist/views/ViewDashboard/index.js.map +1 -1
  288. package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  289. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  290. package/dist/views/index.js +1 -1
  291. package/dist/views/index.js.map +1 -1
  292. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-slice.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n}\n\n/**\n * Curried function for creating the PanelSlice.\n */\nexport function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice> {\n return () => ({\n panels,\n });\n}\n"],"names":["createPanelSlice","panels"],"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;AAajC;;CAEC,GACD,OAAO,SAASA,gBAAgB,CAACC,MAA4B,EAAwD;IACnH,OAAO,IAAO,CAAA;YACZA,MAAM;SACP,CAAA,AAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/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 { PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n}\n\n/**\n * Curried function for creating the PanelSlice.\n */\nexport function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice> {\n return () => ({\n panels,\n });\n}\n"],"names":["createPanelSlice","panels"],"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;AAajC;;CAEC,GACD,OAAO,SAASA,gBAAgB,CAACC,MAA4B,EAAwD;IACnH,OAAO,IAAO,CAAA;YACZA,MAAM;SACP,CAAA,AAAC,CAAC;AACL,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceApi;\n children?: React.ReactNode;\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, datasourceApi, children } = props;\n const { project } = dashboardResource.metadata;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return { spec: dashboardDatasource, proxyUrl: undefined };\n }\n\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 // 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>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n return plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n },\n [findDatasource, getPlugin]\n );\n\n const listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n 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 !== undefined) {\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","datasourceApi","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","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,SAASA,WAAW,EAAEC,OAAO,QAAQ,OAAO,CAAC;AAC7C,SAOEC,QAAQ,QACH,kBAAkB,CAAC;AAC1B,SACEC,sBAAsB,EAEtBC,iBAAiB,QAEZ,2BAA2B,CAAC;AAwBnC;;CAEC,GACD,OAAO,SAASC,uBAAuB,CAACC,KAAmC,EAAE;IAC3E,MAAM,EAAEC,iBAAiB,CAAA,EAAEC,aAAa,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGH,KAAK,AAAC;IAC7D,MAAM,EAAEI,OAAO,CAAA,EAAE,GAAGH,iBAAiB,CAACI,QAAQ,AAAC;IAE/C,MAAM,EAAEC,SAAS,CAAA,EAAEC,kBAAkB,CAAA,EAAE,GAAGT,iBAAiB,EAAE,AAAC;IAE9D,MAAMU,cAAc,GAAGZ,QAAQ,CAAC,OAAOa,QAA4B,GAAK;QACtE,mCAAmC;QACnC,MAAM,EAAEC,WAAW,CAAA,EAAE,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IAAI,CAAC;QACtB,CAAC;QAED,mGAAmG;QACnG,IAAIF,SAAS,CAACI,GAAG,CAACf,YAAY,CAAC,EAAE,OAAO;YAGhC/B,IAAkB;QAD1B2B,OAAO,CAACoB,IAAI,CAAC;YACXnC,IAAI,EAAEZ,CAAAA,IAAkB,GAAlBA,CAAAA,GAAY,GAAZA,IAAI,CAAC8B,OAAO,cAAZ9B,GAAY,WAAM,GAAlBA,KAAAA,CAAkB,GAAlBA,GAAY,CAAEY,IAAI,cAAlBZ,IAAkB,cAAlBA,IAAkB,GAAI+B,YAAY;YACxCjC,QAAQ,EAAE;gBACRa,IAAI,EAAEX,IAAI,CAACe,MAAM,CAACJ,IAAI;gBACtBC,IAAI,EAAEmB,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 { 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} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceApi;\n children?: React.ReactNode;\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, datasourceApi, children } = props;\n const { project } = dashboardResource.metadata;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return { spec: dashboardDatasource, proxyUrl: undefined };\n }\n\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 // 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>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n return plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n },\n [findDatasource, getPlugin]\n );\n\n const listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n 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 !== undefined) {\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","datasourceApi","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","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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AAS;KAAE,CAAC;AAChC,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -169,25 +169,25 @@ export function TemplateVariableProvider({ children , initialVariableDefinitions
169
169
  })
170
170
  });
171
171
  }
172
- /** Helpers */ function hydrateTemplateVariableState(definition, initialValue) {
173
- const v = definition;
174
- var ref;
172
+ /** Helpers */ function hydrateTemplateVariableState(variable, initialValue) {
175
173
  const varState = {
176
- value: (ref = initialValue !== null && initialValue !== void 0 ? initialValue : v.spec.default_value) !== null && ref !== void 0 ? ref : null,
174
+ value: null,
177
175
  loading: false
178
176
  };
179
- switch(v.kind){
177
+ switch(variable.kind){
180
178
  case 'TextVariable':
181
- varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : v.spec.value;
179
+ varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.value;
182
180
  break;
183
181
  case 'ListVariable':
184
182
  varState.options = [];
183
+ var ref;
184
+ varState.value = (ref = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.default_value) !== null && ref !== void 0 ? ref : null;
185
185
  if (varState.options.length > 0 && !varState.value) {
186
186
  var ref1;
187
187
  var ref2;
188
188
  const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
189
189
  if (firstOptionValue !== null) {
190
- varState.value = v.spec.allow_multiple ? [
190
+ varState.value = variable.spec.allow_multiple ? [
191
191
  firstOptionValue
192
192
  ] : firstOptionValue;
193
193
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\n\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [], queryParams }: TemplateVariableSrvArgs) {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),\n variableDefinitions: initialVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set((state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateTemplateVariableStates(definitions, initialParams);\n });\n },\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n if (queryParams) {\n const setQueryParams = queryParams[1];\n setQueryParams({ [getURLQueryParamName(name)]: val });\n }\n varState.value = val;\n }),\n }))\n )\n );\n\n return store;\n}\n\nexport function TemplateVariableProvider({\n children,\n initialVariableDefinitions = [],\n}: {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}) {\n const queryParams = useVariableQueryParams(initialVariableDefinitions);\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions, queryParams }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n\n/** Helpers */\n\nfunction hydrateTemplateVariableState(definition: VariableDefinition, initialValue?: VariableValue) {\n const v = definition;\n const varState: VariableState = {\n value: initialValue ?? v.spec.default_value ?? null,\n loading: false,\n };\n switch (v.kind) {\n case 'TextVariable':\n varState.value = initialValue ?? v.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = v.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nfunction hydrateTemplateVariableStates(\n definitions: VariableDefinition[],\n initialValues: Record<string, VariableValue>\n): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state[name] = hydrateTemplateVariableState(v, initialValue);\n });\n return state;\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","useVariableQueryParams","getInitalValuesFromQueryParameters","getURLQueryParamName","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","queryParams","initialParams","set","hydrateTemplateVariableStates","definitions","loading","val","Array","isArray","includes","at","filter","setQueryParams","TemplateVariableProvider","hydrateTemplateVariableState","initialValue","default_value","kind","length","firstOptionValue","allow_multiple","initialValues","param"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,SAAS,CAAC;AAChD,SAASC,KAAK,QAAQ,0BAA0B,CAAC;AACjD,SAASC,QAAQ,QAAQ,oBAAoB,CAAC;AAE9C,SACEC,uBAAuB,EAIvBC,iBAAiB,IAAIC,SAAS,QACzB,2BAA2B,CAAC;AAEnC,SAASC,sBAAsB,EAAEC,kCAAkC,EAAEC,oBAAoB,QAAQ,gBAAgB,CAAC;AAWlH,MAAMC,4BAA4B,iBAAGd,aAAa,CAChDe,SAAS,CACV,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AM8C,YAAY,GAAGO,KAAK,GAAGA,KAAK,GAAG,IAAI,AAAC;QAC1C7D,KAAK,CAACQ,IAAI,CAAC,GAAG6C,4BAA4B,CAACnC,CAAC,EAAEoC,YAAY,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IACH,OAAOtD,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.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 { createContext, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\n\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [], queryParams }: TemplateVariableSrvArgs) {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),\n variableDefinitions: initialVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set((state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateTemplateVariableStates(definitions, initialParams);\n });\n },\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n if (queryParams) {\n const setQueryParams = queryParams[1];\n setQueryParams({ [getURLQueryParamName(name)]: val });\n }\n varState.value = val;\n }),\n }))\n )\n );\n\n return store;\n}\n\nexport function TemplateVariableProvider({\n children,\n initialVariableDefinitions = [],\n}: {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}) {\n const queryParams = useVariableQueryParams(initialVariableDefinitions);\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions, queryParams }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n\n/** Helpers */\n\nfunction hydrateTemplateVariableState(variable: VariableDefinition, initialValue?: VariableValue) {\n const varState: VariableState = {\n value: null,\n loading: false,\n };\n switch (variable.kind) {\n case 'TextVariable':\n varState.value = initialValue ?? variable.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n varState.value = initialValue ?? variable.spec.default_value ?? null;\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = variable.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nfunction hydrateTemplateVariableStates(\n definitions: VariableDefinition[],\n initialValues: Record<string, VariableValue>\n): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state[name] = hydrateTemplateVariableState(v, initialValue);\n });\n return state;\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","useVariableQueryParams","getInitalValuesFromQueryParameters","getURLQueryParamName","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","queryParams","initialParams","set","hydrateTemplateVariableStates","definitions","loading","val","Array","isArray","includes","at","filter","setQueryParams","TemplateVariableProvider","hydrateTemplateVariableState","variable","initialValue","kind","default_value","length","firstOptionValue","allow_multiple","initialValues","param"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,aAAa,EAAEC,UAAU,E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gBAAgB,CAAC;gBACxF,CAAC;YACH,CAAC;YACD,MAAM;QACR;YACE,MAAM;KACT;IACD,OAAOlD,QAAQ,CAAC;AAClB,CAAC;AAED,SAASiC,6BAA6B,CACpCC,WAAiC,EACjCkB,aAA4C,EAC1B;IAClB,MAAM7D,KAAK,GAAqB,EAAE,AAAC;IACnC2C,WAAW,CAACpC,OAAO,CAAC,CAACW,CAAC,GAAK;QACzB,MAAMV,IAAI,GAAGU,CAAC,CAACC,IAAI,CAACX,IAAI,AAAC;QACzB,MAAMsD,KAAK,GAAGD,aAAa,CAACrD,IAAI,CAAC,AAAC;QAClC,MAAM+C,YAAY,GAAGO,KAAK,GAAGA,KAAK,GAAG,IAAI,AAAC;QAC1C9D,KAAK,CAACQ,IAAI,CAAC,GAAG6C,4BAA4B,CAACnC,CAAC,EAAEqC,YAAY,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IACH,OAAOvD,KAAK,CAAC;AACf,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/TemplateVariableProvider/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TemplateVariableProvider';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/TemplateVariableProvider/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TemplateVariableProvider';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,4BAA4B,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/TemplateVariableProvider/query-params.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { QueryParamConfig, useQueryParams } from 'use-query-params';\n\nconst variableQueryParameterPrefix = 'var-';\n\nexport function getURLQueryParamName(name: string) {\n return `${variableQueryParameterPrefix}${name}`;\n}\n\nexport function encodeVariableValue(value: VariableValue) {\n if (Array.isArray(value)) {\n return value.join(',');\n }\n return value;\n}\n\nexport function decodeVariableValue(value: string): VariableValue {\n if (!value) {\n return null;\n }\n const values = value.split(',');\n if (values.length === 1) {\n return values[0] as string;\n }\n return values;\n}\n\nconst VariableValueParam: QueryParamConfig<VariableValue> = {\n encode: encodeVariableValue,\n decode: (v) => {\n if (typeof v === 'string') {\n return decodeVariableValue(v);\n }\n return '';\n },\n};\n\nexport function useVariableQueryParams(defs: VariableDefinition[]) {\n const config: Record<string, typeof VariableValueParam> = {};\n defs.forEach((def) => {\n const name = getURLQueryParamName(def.spec.name);\n config[name] = VariableValueParam;\n });\n return useQueryParams(config, { updateType: 'replaceIn' });\n}\n\nexport function getInitalValuesFromQueryParameters(\n queryParamValues: Record<string, VariableValue>\n): Record<string, VariableValue> {\n const values: Record<string, VariableValue> = {};\n Object.keys(queryParamValues).forEach((key) => {\n const value = queryParamValues[key];\n if (!value) {\n return;\n }\n const name = key.replace(variableQueryParameterPrefix, '');\n values[name] = value;\n });\n return values;\n}\n"],"names":["useQueryParams","variableQueryParameterPrefix","getURLQueryParamName","name","encodeVariableValue","value","Array","isArray","join","decodeVariableValue","values","split","length","VariableValueParam","encode","decode","v","useVariableQueryParams","defs","config","forEach","def","spec","updateType","getInitalValuesFromQueryParameters","queryParamValues","Object","keys","key","replace"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAA2BA,cAAc,QAAQ,kBAAkB,CAAC;AAEpE,MAAMC,4BAA4B,GAAG,MAAM,AAAC;AAE5C,OAAO,SAAS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WAAW;KAAE,CAAC,CAAC;AAC7D,CAAC;AAED,OAAO,SAASC,kCAAkC,CAChDC,gBAA+C,EAChB;IAC/B,MAAMf,MAAM,GAAkC,EAAE,AAAC;IACjDgB,MAAM,CAACC,IAAI,CAACF,gBAAgB,CAAC,CAACL,OAAO,CAAC,CAACQ,GAAG,GAAK;QAC7C,MAAMvB,KAAK,GAAGoB,gBAAgB,CAACG,GAAG,CAAC,AAAC;QACpC,IAAI,CAACvB,KAAK,EAAE;YACV,OAAO;QACT,CAAC;QACD,MAAMF,IAAI,GAAGyB,GAAG,CAACC,OAAO,CAAC5B,4BAA4B,EAAE,EAAE,CAAC,AAAC;QAC3DS,MAAM,CAACP,IAAI,CAAC,GAAGE,KAAK,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,OAAOK,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/TemplateVariableProvider/query-params.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 { VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { QueryParamConfig, useQueryParams } from 'use-query-params';\n\nconst variableQueryParameterPrefix = 'var-';\n\nexport function getURLQueryParamName(name: string) {\n return `${variableQueryParameterPrefix}${name}`;\n}\n\nexport function encodeVariableValue(value: VariableValue) {\n if (Array.isArray(value)) {\n return value.join(',');\n }\n return value;\n}\n\nexport function decodeVariableValue(value: string): VariableValue {\n if (!value) {\n return null;\n }\n const values = value.split(',');\n if (values.length === 1) {\n return values[0] as string;\n }\n return values;\n}\n\nconst VariableValueParam: QueryParamConfig<VariableValue> = {\n encode: encodeVariableValue,\n decode: (v) => {\n if (typeof v === 'string') {\n return decodeVariableValue(v);\n }\n return '';\n },\n};\n\nexport function useVariableQueryParams(defs: VariableDefinition[]) {\n const config: Record<string, typeof VariableValueParam> = {};\n defs.forEach((def) => {\n const name = getURLQueryParamName(def.spec.name);\n config[name] = VariableValueParam;\n });\n return useQueryParams(config, { updateType: 'replaceIn' });\n}\n\nexport function getInitalValuesFromQueryParameters(\n queryParamValues: Record<string, VariableValue>\n): Record<string, VariableValue> {\n const values: Record<string, VariableValue> = {};\n Object.keys(queryParamValues).forEach((key) => {\n const value = queryParamValues[key];\n if (!value) {\n return;\n }\n const name = key.replace(variableQueryParameterPrefix, '');\n values[name] = value;\n });\n return values;\n}\n"],"names":["useQueryParams","variableQueryParameterPrefix","getURLQueryParamName","name","encodeVariableValue","value","Array","isArray","join","decodeVariableValue","values","split","length","VariableValueParam","encode","decode","v","useVariableQueryParams","defs","config","forEach","def","spec","updateType","getInitalValuesFromQueryParameters","queryParamValues","Object","keys","key","replace"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAA2BA,cAAc,QAAQ,kBAAkB,CAAC;AAEpE,MAAMC,4BAA4B,GAAG,MAAM,AAAC;AAE5C,OAAO,SAASC,oBAAoB,CAACC,IAAY,EAAE;IACjD,OAAO,CAAC,EAAEF,4BAA4B,CAAC,EAAEE,IAAI,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,OAAO,SAASC,mBAAmB,CAACC,KAAoB,EAAE;IACxD,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;QACxB,OAAOA,KAAK,CAACG,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAOH,KAAK,CAAC;AACf,CAAC;AAED,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AAC;QACD,MAAMF,IAAI,GAAGyB,GAAG,CAACC,OAAO,CAAC5B,4BAA4B,EAAE,EAAE,CAAC,AAAC;QAC3DS,MAAM,CAACP,IAAI,CAAC,GAAGE,KAAK,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,OAAOK,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/TemplateVariableProvider/query-params.test.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue } from '@perses-dev/core';\nimport { getInitalValuesFromQueryParameters, decodeVariableValue, encodeVariableValue } from './query-params';\n\ndescribe('getInitalValuesFromQueryParameters', () => {\n test('base case', () => {\n expect(\n getInitalValuesFromQueryParameters({\n 'var-foo': 'bar',\n 'var-baz': ['qux', 'quux'],\n })\n ).toEqual({\n foo: 'bar',\n baz: ['qux', 'quux'],\n });\n });\n});\n\ndescribe('encodeVariableValue', () => {\n const testCases = [\n {\n input: 'foo',\n expected: 'foo',\n },\n {\n input: ['foo', 'bar'],\n expected: 'foo,bar',\n },\n {\n input: '$__all',\n expected: '$__all',\n },\n ];\n\n testCases.forEach(({ input, expected }) => {\n test(`encodes ${input} as ${expected}`, () => {\n expect(encodeVariableValue(input)).toEqual(expected);\n });\n });\n});\n\ndescribe('decodeVariableValue', () => {\n const testCases: Array<{ input: string; expected: VariableValue }> = [\n {\n input: 'foo',\n expected: 'foo',\n },\n {\n input: 'foo,bar',\n expected: ['foo', 'bar'],\n },\n {\n input: '$__all',\n expected: '$__all',\n },\n ];\n\n testCases.forEach(({ input, expected }) => {\n test(`encodes ${input} as ${expected}`, () => {\n expect(decodeVariableValue(input)).toEqual(expected);\n });\n });\n});\n"],"names":["getInitalValuesFromQueryParameters","decodeVariableValue","encodeVariableValue","describe","test","expect","toEqual","foo","baz","testCases","input","expected","forEach"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,kCAAkC,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,gBAAgB,CAAC;AAE9GC,QAAQ,CAAC,oCAAoC,EAAE,IAAM;IACnDC,IAAI,CAAC,WAAW,EAAE,IAAM;QACtBC,MAAM,CACJL,kCAAkC,CAAC;YACjC,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE;gBAAC,KAAK;gBAAE,MAAM;aAAC;SAC3B,CAAC,CACH,CAACM,OAAO,CAAC;YACRC,GAAG,EAAE,KAAK;YACVC,GAAG,EAAE;gBAAC,KAAK;gBAAE,MAAM;aAAC;SACrB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEHL,QAAQ,CAAC,qBAAqB,EAAE,IAAM;IACpC,MAAMM,SAAS,GAAG;QAChB;YACEC,KAAK,EAAE,KAAK;YACZC,QAAQ,EAAE,KAAK;SAChB;QACD;YACED,KAAK,EAAE;gBAAC,KAAK;gBAAE,KAAK;aAAC;YACrBC,QAAQ,EAAE,SAAS;SACpB;QACD;YACED,KAAK,EAAE,QAAQ;YACfC,QAAQ,EAAE,QAAQ;SACnB;KACF,AAAC;IAEFF,SAAS,CAACG,OAAO,CAAC,CAAC,EAAEF,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAK;QACzCP,IAAI,CAAC,CAAC,QAAQ,EAAEM,KAAK,CAAC,IAAI,EAAEC,QAAQ,CAAC,CAAC,EAAE,IAAM;YAC5CN,MAAM,CAACH,mBAAmB,CAACQ,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACK,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEHR,QAAQ,CAAC,qBAAqB,EAAE,IAAM;IACpC,MAAMM,SAAS,GAAsD;QACnE;YACEC,KAAK,EAAE,KAAK;YACZC,QAAQ,EAAE,KAAK;SAChB;QACD;YACED,KAAK,EAAE,SAAS;YAChBC,QAAQ,EAAE;gBAAC,KAAK;gBAAE,KAAK;aAAC;SACzB;QACD;YACED,KAAK,EAAE,QAAQ;YACfC,QAAQ,EAAE,QAAQ;SACnB;KACF,AAAC;IAEFF,SAAS,CAACG,OAAO,CAAC,CAAC,EAAEF,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAK;QACzCP,IAAI,CAAC,CAAC,QAAQ,EAAEM,KAAK,CAAC,IAAI,EAAEC,QAAQ,CAAC,CAAC,EAAE,IAAM;YAC5CN,MAAM,CAACJ,mBAAmB,CAACS,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACK,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/TemplateVariableProvider/query-params.test.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue } from '@perses-dev/core';\nimport { getInitalValuesFromQueryParameters, decodeVariableValue, encodeVariableValue } from './query-params';\n\ndescribe('getInitalValuesFromQueryParameters', () => {\n test('base case', () => {\n expect(\n getInitalValuesFromQueryParameters({\n 'var-foo': 'bar',\n 'var-baz': ['qux', 'quux'],\n })\n ).toEqual({\n foo: 'bar',\n baz: ['qux', 'quux'],\n });\n });\n});\n\ndescribe('encodeVariableValue', () => {\n const testCases = [\n {\n input: 'foo',\n expected: 'foo',\n },\n {\n input: ['foo', 'bar'],\n expected: 'foo,bar',\n },\n {\n input: '$__all',\n expected: '$__all',\n },\n ];\n\n testCases.forEach(({ input, expected }) => {\n test(`encodes ${input} as ${expected}`, () => {\n expect(encodeVariableValue(input)).toEqual(expected);\n });\n });\n});\n\ndescribe('decodeVariableValue', () => {\n const testCases: Array<{ input: string; expected: VariableValue }> = [\n {\n input: 'foo',\n expected: 'foo',\n },\n {\n input: 'foo,bar',\n expected: ['foo', 'bar'],\n },\n {\n input: '$__all',\n expected: '$__all',\n },\n ];\n\n testCases.forEach(({ input, expected }) => {\n test(`encodes ${input} as ${expected}`, () => {\n expect(decodeVariableValue(input)).toEqual(expected);\n });\n });\n});\n"],"names":["getInitalValuesFromQueryParameters","decodeVariableValue","encodeVariableValue","describe","test","expect","toEqual","foo","baz","testCases","input","expected","forEach"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,kCAAkC,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,gBAAgB,CAAC;AAE9GC,QAAQ,CAAC,oCAAoC,EAAE,IAAM;IACnDC,IAAI,CAAC,WAAW,EAAE,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AO,CAAC,CAAC,EAAEF,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAK;QACzCP,IAAI,CAAC,CAAC,QAAQ,EAAEM,KAAK,CAAC,IAAI,EAAEC,QAAQ,CAAC,CAAC,EAAE,IAAM;YAC5CN,MAAM,CAACJ,mBAAmB,CAACS,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACK,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './TemplateVariableProvider';\nexport * from './useDashboard';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './TemplateVariableProvider';\nexport * from './useDashboard';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardResource, GridDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupId, useDashboardStore } from './DashboardProvider';\nimport { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';\n\nexport function useDashboard() {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n metadata,\n setDashboard: setDashboardResource,\n } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, defaultTimeRange, setDashboard, metadata }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n setDashboard,\n metadata,\n }));\n const { setVariableDefinitions } = useTemplateVariableActions();\n const variables = useTemplateVariableDefinitions();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata,\n spec: {\n panels,\n layouts,\n variables,\n duration: defaultTimeRange.pastDuration,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource) => {\n setVariableDefinitions(dashboardResource.spec.variables);\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title) {\n display = {\n title,\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useTemplateVariableActions","useTemplateVariableDefinitions","useDashboard","panels","panelGroups","panelGroupOrder","defaultTimeRange","metadata","setDashboard","setDashboardResource","setVariableDefinitions","variables","layouts","convertPanelGroupsToLayouts","dashboard","kind","spec","duration","pastDuration","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","itemLayouts","itemPanelKeys","display","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAA2C,kBAAkB,CAAC;AACrF,SAA6CC,iBAAiB,QAAQ,qBAAqB,CAAC;AAC5F,SAASC,0BAA0B,EAAEC,8BAA8B,QAAQ,4BAA4B,CAAC;AAExG,OAAO,SAASC,YAAY,GAAG;IAC7B,MAAM,EACJC,MAAM,CAAA,EACNC,WAAW,CAAA,EACXC,eAAe,CAAA,EACfC,gBAAgB,CAAA,EAChBC,QAAQ,CAAA,EACRC,YAAY,EAAEC,oBAAoB,CAAA,IACnC,GAAGV,iBAAiB,CAAC,CAAC,EAAEI,MAAM,CAAA,EAAEC,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAEC,gBAAgB,CAAA,EAAEE,YAAY,CAAA,EAAED,QAAQ,CAAA,EAAE,GAAM,CAAA;YAC7GJ,MAAM;YACNC,WAAW;YACXC,eAAe;YACfC,gBAAgB;YAChBE,YAAY;YACZD,QAAQ;SACT,CAAA,AAAC,CAAC,AAAC;IACJ,MAAM,EAAEG,sBAAsB,CAAA,EAAE,GAAGV,0BAA0B,EAAE,AAAC;IAChE,MAAMW,SAAS,GAAGV,8BAA8B,EAAE,AAAC;IACnD,MAAMW,OAAO,GAAGC,2BAA2B,CAACT,WAAW,EAAEC,eAAe,CAAC,AAAC;IAE1E,MAAMS,SAAS,GAAsB;QACnCC,IAAI,EAAE,WAAW;QACjBR,Q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AC,CAAC,4BAA4B,EAAEQ,MAAM,CAACG,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC7D,CAAC;oBACD,OAAO;wBACLC,CAAC,EAAEJ,MAAM,CAACI,CAAC;wBACXC,CAAC,EAAEL,MAAM,CAACK,CAAC;wBACXC,KAAK,EAAEN,MAAM,CAACO,CAAC;wBACfC,MAAM,EAAER,MAAM,CAACS,CAAC;wBAChBC,OAAO,EAAE5C,cAAc,CAACoC,QAAQ,CAAC;qBAClC,CAAC;gBACJ,CAAC,CAAC;aACH;SACF,AAAC;QACFtB,OAAO,CAAC+B,IAAI,CAACX,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAOpB,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardResource, GridDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupId, useDashboardStore } from './DashboardProvider';\nimport { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';\n\nexport function useDashboard() {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n metadata,\n setDashboard: setDashboardResource,\n } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, defaultTimeRange, setDashboard, metadata }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n setDashboard,\n metadata,\n }));\n const { setVariableDefinitions } = useTemplateVariableActions();\n const variables = useTemplateVariableDefinitions();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata,\n spec: {\n panels,\n layouts,\n variables,\n duration: defaultTimeRange.pastDuration,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource) => {\n setVariableDefinitions(dashboardResource.spec.variables);\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title) {\n display = {\n title,\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useTemplateVariableActions","useTemplateVariableDefinitions","useDashboard","panels","panelGroups","panelGroupOrder","defaultTimeRange","metadata","setDashboard","setDashboardResource","setVariableDefinitions","variables","layouts","convertPanelGroupsToLayouts","dashboard","kind","spec","duration","pastDuration","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","itemLayouts","itemPanelKeys","display","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2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AO,CAAC+B,IAAI,CAACX,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAOpB,OAAO,CAAC;AACjB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './components';\nexport * from './context';\nexport * from './views';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './components';\nexport * from './context';\nexport * from './views';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/dashboard-provider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DashboardResource } from '@perses-dev/core';\nimport { useContext } from 'react';\nimport { StoreApi } from 'zustand';\nimport { DashboardContext, DashboardStoreState } from '../context';\nimport testDashboard from './testDashboard';\n\n/**\n * Helper to get a test dashboard resource.\n */\nexport function getTestDashboard(): DashboardResource {\n // TODO: Should we be cloning this to create a new object each time?\n return testDashboard;\n}\n\n/**\n * Test helper to create a \"spy\" component that will capture the DashboardProvider's store, allowing you to inspect\n * its state in tests. Be sure to render the DashboardProviderSpy component that's returned in the component test\n * underneath the DashboardProvider.\n */\nexport function createDashboardProviderSpy() {\n const store: { value?: StoreApi<DashboardStoreState> } = {};\n\n // Spy component just captures the store value so it can be inspected in tests\n function DashboardProviderSpy() {\n const ctx = useContext(DashboardContext);\n store.value = ctx;\n return null;\n }\n\n return {\n DashboardProviderSpy,\n store,\n };\n}\n"],"names":["useContext","DashboardContext","testDashboard","getTestDashboard","createDashboardProviderSpy","store","DashboardProviderSpy","ctx","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,QAAQ,OAAO,CAAC;AAEnC,SAASC,gBAAgB,QAA6B,YAAY,CAAC;AACnE,OAAOC,aAAa,MAAM,iBAAiB,CAAC;AAE5C;;CAEC,GACD,OAAO,SAASC,gBAAgB,GAAsB;IACpD,oEAAoE;IACpE,OAAOD,aAAa,CAAC;AACvB,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASE,0BAA0B,GAAG;IAC3C,MAAMC,KAAK,GAA8C,EAAE,AAAC;IAE5D,8EAA8E;IAC9E,SAASC,oBAAoB,GAAG;QAC9B,MAAMC,GAAG,GAAGP,UAAU,CAACC,gBAAgB,CAAC,AAAC;QACzCI,KAAK,CAACG,KAAK,GAAGD,GAAG,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACLD,oBAAoB;QACpBD,KAAK;KACN,CAAC;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/test/dashboard-provider.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 { DashboardResource } from '@perses-dev/core';\nimport { useContext } from 'react';\nimport { StoreApi } from 'zustand';\nimport { DashboardContext, DashboardStoreState } from '../context';\nimport testDashboard from './testDashboard';\n\n/**\n * Helper to get a test dashboard resource.\n */\nexport function getTestDashboard(): DashboardResource {\n // TODO: Should we be cloning this to create a new object each time?\n return testDashboard;\n}\n\n/**\n * Test helper to create a \"spy\" component that will capture the DashboardProvider's store, allowing you to inspect\n * its state in tests. Be sure to render the DashboardProviderSpy component that's returned in the component test\n * underneath the DashboardProvider.\n */\nexport function createDashboardProviderSpy() {\n const store: { value?: StoreApi<DashboardStoreState> } = {};\n\n // Spy component just captures the store value so it can be inspected in tests\n function DashboardProviderSpy() {\n const ctx = useContext(DashboardContext);\n store.value = ctx;\n return null;\n }\n\n return {\n DashboardProviderSpy,\n store,\n };\n}\n"],"names":["useContext","DashboardContext","testDashboard","getTestDashboard","createDashboardProviderSpy","store","DashboardProviderSpy","ctx","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,QAAQ,OAAO,CAAC;AAEnC,SAASC,gBAAgB,QAA6B,YAAY,CAAC;AACnE,OAAOC,aAAa,MAAM,iBAAiB,CAAC;AAE5C;;CAEC,GACD,OAAO,SAASC,gBAAgB,GAAsB;IACpD,oEAAoE;IACpE,OAAOD,aAAa,CAAC;AACvB,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASE,0BAA0B,GAAG;IAC3C,MAAMC,KAAK,GAA8C,EAAE,AAAC;IAE5D,8EAA8E;IAC9E,SAASC,oBAAoB,GAAG;QAC9B,MAAMC,GAAG,GAAGP,UAAU,CAACC,gBAAgB,CAAC,AAAC;QACzCI,KAAK,CAACG,KAAK,GAAGD,GAAG,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACLD,oBAAoB;QACpBD,KAAK;KACN,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-provider';\nexport * from './plugin-registry';\nexport * from './render';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
1
+ {"version":3,"sources":["../../src/test/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-provider';\nexport * from './plugin-registry';\nexport * from './render';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/plugin-registry.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PanelPlugin, MockPlugin } from '@perses-dev/plugin-system';\n\nconst FakeTimeSeriesPlugin: PanelPlugin<UnknownSpec> = {\n PanelComponent: () => {\n return <div>TimeSeriesChart panel</div>;\n },\n OptionsEditorComponent: () => {\n return <div>TimeSeriesChart options</div>;\n },\n createInitialOptions: () => ({}),\n};\n\nconst MOCK_TIME_SERIES_PANEL: MockPlugin = {\n pluginType: 'Panel',\n kind: 'TimeSeriesChart',\n plugin: FakeTimeSeriesPlugin,\n};\n\n// Array of default mock plugins added to the PluginRegistry during test renders\nexport const MOCK_PLUGINS: MockPlugin[] = [MOCK_TIME_SERIES_PANEL];\n"],"names":["FakeTimeSeriesPlugin","PanelComponent","div","OptionsEditorComponent","createInitialOptions","MOCK_TIME_SERIES_PANEL","pluginType","kind","plugin","MOCK_PLUGINS"],"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;AAGA,MAAMA,oBAAoB,GAA6B;IACrDC,cAAc,EAAE,IAAM;QACpB,qBAAO,KAACC,KAAG;sBAAC,uBAAqB;UAAM,CAAC;IAC1C,CAAC;IACDC,sBAAsB,EAAE,IAAM;QAC5B,qBAAO,KAACD,KAAG;sBAAC,yBAAuB;UAAM,CAAC;IAC5C,CAAC;IACDE,oBAAoB,EAAE,IAAO,CAAA,EAAE,CAAA,AAAC;CACjC,AAAC;AAEF,MAAMC,sBAAsB,GAAe;IACzCC,UAAU,EAAE,OAAO;IACnBC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAER,oBAAoB;CAC7B,AAAC;AAEF,gFAAgF;AAChF,OAAO,MAAMS,YAAY,GAAiB;IAACJ,sBAAsB;CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/test/plugin-registry.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 { UnknownSpec } from '@perses-dev/core';\nimport { PanelPlugin, MockPlugin } from '@perses-dev/plugin-system';\n\nconst FakeTimeSeriesPlugin: PanelPlugin<UnknownSpec> = {\n PanelComponent: () => {\n return <div>TimeSeriesChart panel</div>;\n },\n OptionsEditorComponent: () => {\n return <div>TimeSeriesChart options</div>;\n },\n createInitialOptions: () => ({}),\n};\n\nconst MOCK_TIME_SERIES_PANEL: MockPlugin = {\n pluginType: 'Panel',\n kind: 'TimeSeriesChart',\n plugin: FakeTimeSeriesPlugin,\n};\n\n// Array of default mock plugins added to the PluginRegistry during test renders\nexport const MOCK_PLUGINS: MockPlugin[] = [MOCK_TIME_SERIES_PANEL];\n"],"names":["FakeTimeSeriesPlugin","PanelComponent","div","OptionsEditorComponent","createInitialOptions","MOCK_TIME_SERIES_PANEL","pluginType","kind","plugin","MOCK_PLUGINS"],"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;AAGA,MAAMA,oBAAoB,GAA6B;IACrDC,cAAc,EAAE,IAAM;QACpB,qBAAO,KAACC,KAAG;sBAAC,uBAAqB;UAAM,CAAC;IAC1C,CAAC;IACDC,sBAAsB,EAAE,IAAM;QAC5B,qBAAO,KAACD,KAAG;sBAAC,yBAAuB;UAAM,CAAC;IAC5C,CAAC;IACDE,oBAAoB,EAAE,IAAO,CAAA,EAAE,CAAA,AAAC;CACjC,AAAC;AAEF,MAAMC,sBAAsB,GAAe;IACzCC,UAAU,EAAE,OAAO;IACnBC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAER,oBAAoB;CAC7B,AAAC;AAEF,gFAAgF;AAChF,OAAO,MAAMS,YAAY,GAAiB;IAACJ,sBAAsB;CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { render, RenderOptions } from '@testing-library/react';\nimport { unstable_HistoryRouter } from 'react-router-dom';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ChartsThemeProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { MOCK_PLUGINS } from './plugin-registry';\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n) {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const BaseRender = () => {\n const HistoryRouter = unstable_HistoryRouter;\n history = history ?? createMemoryHistory();\n return (\n <HistoryRouter history={history}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <ChartsThemeProvider chartsTheme={testChartsTheme}>\n <PluginRegistry {...mockPluginRegistry(...MOCK_PLUGINS)}>{ui}</PluginRegistry>\n </ChartsThemeProvider>\n </QueryParamProvider>\n </QueryClientProvider>\n </HistoryRouter>\n );\n };\n\n return render(<BaseRender />, options);\n}\n"],"names":["render","unstable_HistoryRouter","createMemoryHistory","QueryParamProvider","ReactRouter6Adapter","QueryClient","QueryClientProvider","ChartsThemeProvider","testChartsTheme","mockPluginRegistry","PluginRegistry","MOCK_PLUGINS","renderWithContext","ui","options","history","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","BaseRender","HistoryRouter","client","adapter","chartsTheme"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,QAAuB,wBAAwB,CAAC;AAC/D,SAASC,sBAAsB,QAAQ,kBAAkB,CAAC;AAC1D,SAASC,mBAAmB,QAAuB,SAAS,CAAC;AAC7D,SAASC,kBAAkB,QAAQ,kBAAkB,CAAC;AACtD,SAASC,mBAAmB,QAAQ,0CAA0C,CAAC;AAC/E,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB,CAAC;AACzE,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,wBAAwB,CAAC;AAC9E,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,2BAA2B,CAAC;AAC/E,SAASC,YAAY,QAAQ,mBAAmB,CAAC;AAEjD;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAC/BC,EAAsB,EACtBC,OAAwC,EACxCC,OAAuB,EACvB;IACA,iEAAiE;IACjE,MAAMC,WAAW,GAAG,IAAIX,WAAW,CAAC;QAAEY,cAAc,EAAE;YAAEC,OAAO,EAAE;gBAAEC,oBAAoB,EAAE,KAAK;gBAAEC,KAAK,EAAE,KAAK;aAAE;SAAE;KAAE,CAAC,AAAC;IAEpH,MAAMC,UAAU,GAAG,IAAM;QACvB,MAAMC,aAAa,GAAGrB,sBAAsB,AAAC;QAC7Cc,OAAO,GAAGA,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAIb,mBAAmB,EAAE,CAAC;QAC3C,qBACE,KAACoB,aAAa;YAACP,OAAO,EAAEA,OAAO;sBAC7B,cAAA,KAACT,mBAAmB;gBAACiB,MAAM,EAAEP,WAAW;0BACtC,cAAA,KAACb,kBAAkB;oBAACqB,OAAO,EAAEpB,mBAAmB;8BAC9C,cAAA,KAACG,mBAAmB;wBAACkB,WAAW,EAAEjB,eAAe;kCAC/C,cAAA,KAACE,cAAc;4BAAE,GAAGD,kBAAkB,IAAIE,YAAY,CAAC;sCAAGE,EAAE;0BAAkB;sBAC1D;kBACH;cACD;UACR,CAChB;IACJ,CAAC,AAAC;IAEF,OAAOb,MAAM,eAAC,KAACqB,UAAU,KAAG,EAAEP,OAAO,CAAC,CAAC;AACzC,CAAC"}
1
+ {"version":3,"sources":["../../src/test/render.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 { render, RenderOptions } from '@testing-library/react';\nimport { unstable_HistoryRouter } from 'react-router-dom';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ChartsThemeProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { MOCK_PLUGINS } from './plugin-registry';\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n) {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const BaseRender = () => {\n const HistoryRouter = unstable_HistoryRouter;\n history = history ?? createMemoryHistory();\n return (\n <HistoryRouter history={history}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <ChartsThemeProvider chartsTheme={testChartsTheme}>\n <PluginRegistry {...mockPluginRegistry(...MOCK_PLUGINS)}>{ui}</PluginRegistry>\n </ChartsThemeProvider>\n </QueryParamProvider>\n </QueryClientProvider>\n </HistoryRouter>\n );\n };\n\n return render(<BaseRender />, options);\n}\n"],"names":["render","unstable_HistoryRouter","createMemoryHistory","QueryParamProvider","ReactRouter6Adapter","QueryClient","QueryClientProvider","ChartsThemeProvider","testChartsTheme","mockPluginRegistry","PluginRegistry","MOCK_PLUGINS","renderWithContext","ui","options","history","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","BaseRender","HistoryRouter","client","adapter","chartsTheme"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,QAAuB,wBAAwB,CAAC;AAC/D,SAASC,sBAAsB,QAAQ,kBAAkB,CAAC;AAC1D,SAASC,mBAAmB,QAAuB,SAAS,CAAC;AAC7D,SAASC,kBAAkB,QAAQ,kBAAkB,CAAC;AACtD,SAASC,mBAAmB,QAAQ,0CAA0C,CAAC;AAC/E,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB,CAAC;AACzE,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,wBAAwB,CAAC;AAC9E,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,2BAA2B,CAAC;AAC/E,SAASC,YAAY,QAAQ,mBAAmB,CAAC;AAEjD;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAC/BC,EAAsB,EACtBC,OAAwC,EACxCC,OAAuB,EACvB;IACA,iEAAiE;IACjE,MAAMC,WAAW,GAAG,IAAIX,WAAW,CAAC;QAAEY,cAAc,EAAE;YAAEC,OAAO,EAAE;gBAAEC,oBAAoB,EAAE,KAAK;gBAAEC,KAAK,EAAE,KAAK;aAAE;SAAE;KAAE,CAAC,AAAC;IAEpH,MAAMC,UAAU,GAAG,IAAM;QACvB,MAAMC,aAAa,GAAGrB,sBAAsB,AAAC;QAC7Cc,OAAO,GAAGA,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAIb,mBAAmB,EAAE,CAAC;QAC3C,qBACE,KAACoB,aAAa;YAACP,OAAO,EAAEA,OAAO;sBAC7B,cAAA,KAACT,mBAAmB;gBAACiB,MAAM,EAAEP,WAAW;0BACtC,cAAA,KAACb,kBAAkB;oBAACqB,OAAO,EAAEpB,mBAAmB;8BAC9C,cAAA,KAACG,mBAAmB;wBAACkB,WAAW,EAAEjB,eAAe;kCAC/C,cAAA,KAACE,cAAc;4BAAE,GAAGD,kBAAkB,IAAIE,YAAY,CAAC;sCAAGE,EAAE;0BAAkB;sBAC1D;kBACH;cACD;UACR,CAChB;IACJ,CAAC,AAAC;IAEF,OAAOb,MAAM,eAAC,KAACqB,UAAU,KAAG,EAAEP,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/setup-tests.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { defaultFallbackInView } from 'react-intersection-observer';\n\n// Add testing library assertions\nimport '@testing-library/jest-dom/extend-expect';\n\n// Always mock e-charts during tests since we don't have a proper canvas in jsdom\njest.mock('echarts/core');\n\n// Tell react-intersection-observer that everything should be considered in-view for tests (see package documentation\n// for other options)\ndefaultFallbackInView(true);\n"],"names":["defaultFallbackInView","jest","mock"],"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,qBAAqB,QAAQ,6BAA6B,CAAC;AAEpE,iCAAiC;AACjC,OAAO,yCAAyC,CAAC;AAEjD,iFAAiF;AACjFC,IAAI,CAACC,IAAI,CAAC,cAAc,CAAC,CAAC;AAE1B,qHAAqH;AACrH,qBAAqB;AACrBF,qBAAqB,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/test/setup-tests.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 { defaultFallbackInView } from 'react-intersection-observer';\n\n// Add testing library assertions\nimport '@testing-library/jest-dom/extend-expect';\n\n// Always mock e-charts during tests since we don't have a proper canvas in jsdom\njest.mock('echarts/core');\n\n// Tell react-intersection-observer that everything should be considered in-view for tests (see package documentation\n// for other options)\ndefaultFallbackInView(true);\n"],"names":["defaultFallbackInView","jest","mock"],"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,qBAAqB,QAAQ,6BAA6B,CAAC;AAEpE,iCAAiC;AACjC,OAAO,yCAAyC,CAAC;AAEjD,iFAAiF;AACjFC,IAAI,CAACC,IAAI,CAAC,cAAc,CAAC,CAAC;AAE1B,qHAAqH;AACrH,qBAAqB;AACrBF,qBAAqB,CAAC,IAAI,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/testDashboard.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DashboardResource } from '@perses-dev/core';\n\nconst testDashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata: {\n name: 'Node Stats',\n project: 'perses',\n created_at: '2021-11-09',\n updated_at: '2021-11-09',\n version: 0,\n },\n spec: {\n duration: '30m',\n variables: [\n {\n kind: 'TextVariable',\n spec: {\n name: 'job',\n value: 'node',\n },\n },\n {\n kind: 'TextVariable',\n spec: {\n name: 'instance',\n value: 'demo.do.prometheus.io:9100',\n },\n },\n {\n kind: 'TextVariable',\n spec: {\n name: 'interval',\n value: '1m',\n },\n },\n ],\n panels: {\n cpu: {\n kind: 'Panel',\n spec: {\n display: { name: 'CPU' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n 'avg without (cpu)(rate(node_cpu_seconds_total{job=\"node\",instance=\"$instance\",mode!=\"idle\"}[$interval]))',\n },\n },\n },\n },\n ],\n unit: { kind: '%' },\n },\n },\n },\n },\n memory: {\n kind: 'Panel',\n spec: {\n display: { name: 'Memory' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n 'node_memory_MemTotal_bytes{job=\"node\",instance=\"$instance\"} - node_memory_MemFree_bytes{job=\"node\",instance=\"$instance\"} - node_memory_Buffers_bytes{job=\"node\",instance=\"$instance\"} - node_memory_Cached_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query: 'node_memory_Buffers_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query: 'node_memory_Cached_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query: 'node_memory_MemFree_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n ],\n unit: { kind: 'Bytes' },\n },\n },\n },\n },\n // This panel is referenced in more than one layout below\n diskIO: {\n kind: 'Panel',\n spec: {\n display: { name: 'Disk I/O Utilization' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n 'rate(node_disk_io_time_seconds_total{job=\"node\",instance=\"$instance\",device!~\"^(md\\\\\\\\d+$|dm-)\"}[$interval])',\n },\n },\n },\n },\n ],\n unit: { kind: 'Percent' },\n },\n },\n },\n },\n filesystemFullness: {\n kind: 'Panel',\n spec: {\n display: { name: 'Filesystem Fullness' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n '1 - node_filesystem_free_bytes{job=\"node\",instance=\"$instance\",fstype!=\"rootfs\",mountpoint!~\"/(run|var).*\",mountpoint!=\"\"} / node_filesystem_size_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n ],\n unit: { kind: 'Percent' },\n },\n },\n },\n },\n },\n layouts: [\n // Regular Title, no collapse enabled\n {\n kind: 'Grid',\n spec: {\n display: {\n title: 'CPU Stats',\n collapse: {\n open: true,\n },\n },\n items: [\n // First Row\n {\n x: 0,\n y: 0,\n width: 12,\n height: 4,\n content: { $ref: '#/spec/panels/cpu' },\n },\n {\n x: 0,\n y: 5,\n width: 6,\n height: 2,\n content: { $ref: '#/spec/panels/diskIO' },\n },\n ],\n },\n },\n // No title,\n {\n kind: 'Grid',\n spec: {\n items: [\n {\n x: 0,\n y: 0,\n width: 6,\n height: 2,\n content: { $ref: '#/spec/panels/diskIO' },\n },\n {\n x: 8,\n y: 0,\n width: 8,\n height: 3,\n content: { $ref: '#/spec/panels/memory' },\n },\n ],\n },\n },\n // Collapsed\n {\n kind: 'Grid',\n spec: {\n display: {\n title: 'Disk Stats',\n collapse: {\n open: false,\n },\n },\n items: [\n {\n x: 18,\n y: 0,\n width: 6,\n height: 2,\n content: { $ref: '#/spec/panels/filesystemFullness' },\n },\n ],\n },\n },\n ],\n },\n};\n\nexport default testDashboard;\n"],"names":["testDashboard","kind","metadata","name","project","created_at","updated_at","version","spec","duration","variables","value","panels","cpu","display","plugin","queries","query","unit","memory","diskIO","filesystemFullness","layouts","title","collapse","open","items","x","y","width","height","content","$ref"],"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,MAAMA,aAAa,GAAsB;IACvCC,IAAI,EAAE,WAAW;IACjBC,QAAQ,EAAE;QACRC,IAAI,EAAE,YAAY;QAClBC,OAAO,EAAE,QAAQ;QACjBC,UAAU,EAAE,YAAY;QACxBC,UAAU,EAAE,YAAY;QACxBC,OAAO,EAAE,CAAC;KACX;IACDC,IAAI,EAAE;QACJC,QAAQ,EAAE,KAAK;QACfC,SAAS,EAAE;YACT;gBACET,IAAI,EAAE,cAAc;gBACpBO,IAAI,EAAE;oBACJL,IAAI,EAAE,KAAK;oBACXQ,KAAK,EAAE,MAAM;iBACd;aACF;YACD;gBACEV,IAAI,EAAE,cAAc;gBACpBO,IAAI,EAAE;oBACJL,IAAI,EAAE,UAAU;oBAChBQ,KAAK,EAAE,4BAA4B;iBACpC;aACF;YACD;gBACEV,IAAI,EAAE,cAAc;gBACpBO,IAAI,EAAE;oBACJL,IAAI,EAAE,UAAU;oBAChBQ,KAAK,EAAE,IAAI;iBACZ;aACF;SACF;QACDC,MAAM,EAAE;YACNC,GAAG,EAAE;gBACHZ,IAAI,EAAE,OAAO;gBACbO,IAAI,EAAE;oBACJM,OAAO,EAAE;wBAAEX,IAAI,EAAE,KAAK;qBAAE;oBACxBY,MAAM,EAAE;wBACNd,IAAI,EAAE,iBAAiB;wBACvBO,IAAI,EAAE;4BACJQ,OAAO,EAAE;gCACP;oCACEf,IAAI,EAAE,iBAAiB;oCACvBO,IAAI,EAAE;wCACJO,MAAM,EAAE;4CACNd,IAAI,EAAE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E;gCAAEC,IAAI,EAAE,mBAAmB;6BAAE;yBACvC;wBACD;4BACEL,CAAC,EAAE,CAAC;4BACJC,CAAC,EAAE,CAAC;4BACJC,KAAK,EAAE,CAAC;4BACRC,MAAM,EAAE,CAAC;4BACTC,OAAO,EAAE;gCAAEC,IAAI,EAAE,sBAAsB;6BAAE;yBAC1C;qBACF;iBACF;aACF;YACD,YAAY;YACZ;gBACE/B,IAAI,EAAE,MAAM;gBACZO,IAAI,EAAE;oBACJkB,KAAK,EAAE;wBACL;4BACEC,CAAC,EAAE,CAAC;4BACJC,CAAC,EAAE,CAAC;4BACJC,KAAK,EAAE,CAAC;4BACRC,MAAM,EAAE,CAAC;4BACTC,OAAO,EAAE;gCAAEC,IAAI,EAAE,sBAAsB;6BAAE;yBAC1C;wBACD;4BACEL,CAAC,EAAE,CAAC;4BACJC,CAAC,EAAE,CAAC;4BACJC,KAAK,EAAE,CAAC;4BACRC,MAAM,EAAE,CAAC;4BACTC,OAAO,EAAE;gCAAEC,IAAI,EAAE,sBAAsB;6BAAE;yBAC1C;qBACF;iBACF;aACF;YACD,YAAY;YACZ;gBACE/B,IAAI,EAAE,MAAM;gBACZO,IAAI,EAAE;oBACJM,OAAO,EAAE;wBACPS,KAAK,EAAE,YAAY;wBACnBC,QAAQ,EAAE;4BACRC,IAAI,EAAE,KAAK;yBACZ;qBACF;oBACDC,KAAK,EAAE;wBACL;4BACEC,CAAC,EAAE,EAAE;4BACLC,CAAC,EAAE,CAAC;4BACJC,KAAK,EAAE,CAAC;4BACRC,MAAM,EAAE,CAAC;4BACTC,OAAO,EAAE;gCAAEC,IAAI,EAAE,kCAAkC;6BAAE;yBACtD;qBACF;iBACF;aACF;SACF;KACF;CACF,AAAC;AAEF,eAAehC,aAAa,CAAC"}
1
+ {"version":3,"sources":["../../src/test/testDashboard.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 { DashboardResource } from '@perses-dev/core';\n\nconst testDashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata: {\n name: 'Node Stats',\n project: 'perses',\n created_at: '2021-11-09',\n updated_at: '2021-11-09',\n version: 0,\n },\n spec: {\n duration: '30m',\n variables: [\n {\n kind: 'TextVariable',\n spec: {\n name: 'job',\n value: 'node',\n },\n },\n {\n kind: 'TextVariable',\n spec: {\n name: 'instance',\n value: 'demo.do.prometheus.io:9100',\n },\n },\n {\n kind: 'TextVariable',\n spec: {\n name: 'interval',\n value: '1m',\n },\n },\n ],\n panels: {\n cpu: {\n kind: 'Panel',\n spec: {\n display: { name: 'CPU' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n 'avg without (cpu)(rate(node_cpu_seconds_total{job=\"node\",instance=\"$instance\",mode!=\"idle\"}[$interval]))',\n },\n },\n },\n },\n ],\n unit: { kind: '%' },\n },\n },\n },\n },\n memory: {\n kind: 'Panel',\n spec: {\n display: { name: 'Memory' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n 'node_memory_MemTotal_bytes{job=\"node\",instance=\"$instance\"} - node_memory_MemFree_bytes{job=\"node\",instance=\"$instance\"} - node_memory_Buffers_bytes{job=\"node\",instance=\"$instance\"} - node_memory_Cached_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query: 'node_memory_Buffers_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query: 'node_memory_Cached_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query: 'node_memory_MemFree_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n ],\n unit: { kind: 'Bytes' },\n },\n },\n },\n },\n // This panel is referenced in more than one layout below\n diskIO: {\n kind: 'Panel',\n spec: {\n display: { name: 'Disk I/O Utilization' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n 'rate(node_disk_io_time_seconds_total{job=\"node\",instance=\"$instance\",device!~\"^(md\\\\\\\\d+$|dm-)\"}[$interval])',\n },\n },\n },\n },\n ],\n unit: { kind: 'Percent' },\n },\n },\n },\n },\n filesystemFullness: {\n kind: 'Panel',\n spec: {\n display: { name: 'Filesystem Fullness' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {\n queries: [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: 'PrometheusTimeSeriesQuery',\n spec: {\n query:\n '1 - node_filesystem_free_bytes{job=\"node\",instance=\"$instance\",fstype!=\"rootfs\",mountpoint!~\"/(run|var).*\",mountpoint!=\"\"} / node_filesystem_size_bytes{job=\"node\",instance=\"$instance\"}',\n },\n },\n },\n },\n ],\n unit: { kind: 'Percent' },\n },\n },\n },\n },\n },\n layouts: [\n // Regular Title, no collapse enabled\n {\n kind: 'Grid',\n spec: {\n display: {\n title: 'CPU Stats',\n collapse: {\n open: true,\n },\n },\n items: [\n // First Row\n {\n x: 0,\n y: 0,\n width: 12,\n height: 4,\n content: { $ref: '#/spec/panels/cpu' },\n },\n {\n x: 0,\n y: 5,\n width: 6,\n height: 2,\n content: { $ref: '#/spec/panels/diskIO' },\n },\n ],\n },\n },\n // No title,\n {\n kind: 'Grid',\n spec: {\n items: [\n {\n x: 0,\n y: 0,\n width: 6,\n height: 2,\n content: { $ref: '#/spec/panels/diskIO' },\n },\n {\n x: 8,\n y: 0,\n width: 8,\n height: 3,\n content: { $ref: '#/spec/panels/memory' },\n },\n ],\n },\n },\n // Collapsed\n {\n kind: 'Grid',\n spec: {\n display: {\n title: 'Disk Stats',\n collapse: {\n open: false,\n },\n },\n items: [\n {\n x: 18,\n y: 0,\n width: 6,\n height: 2,\n content: { $ref: '#/spec/panels/filesystemFullness' },\n },\n ],\n },\n },\n ],\n },\n};\n\nexport default testDashboard;\n"],"names":["testDashboard","kind","metadata","name","project","created_at","updated_at","version","spec","duration","variables","value","panels","cpu","display","plugin","queries","query","unit","memory","diskIO","filesystemFullness","layouts","title","collapse","open","items","x","y","width","height","content","$ref"],"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,MAAMA,aAAa,GAAsB;IACvCC,IAAI,EAAE,WAAW;IACjBC,QAAQ,EAAE;QACRC,IAAI,EAAE,YAAY;QAClBC,OAAO,EAAE,QAAQ;QACjBC,UAAU,EAAE,YAAY;QACxBC,UAAU,EAAE,YAAY;QACxBC,OAAO,EAAE,CAAC;KACX;IACDC,IAAI,EAAE;QACJC,QAAQ,EAAE,KAAK;QACfC,SAAS,EAAE;YACT;gBACET,IAAI,EAAE,cAAc;gBACpBO,IAAI,EAAE;oBACJL,IAAI,EAAE,KAAK;oBACXQ,KAAK,EAAE,MAAM;iBACd;aACF;YACD;gBACEV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;gBACE/B,IAAI,EAAE,MAAM;gBACZO,IAAI,EAAE;oBACJM,OAAO,EAAE;wBACPS,KAAK,EAAE,YAAY;wBACnBC,QAAQ,EAAE;4BACRC,IAAI,EAAE,KAAK;yBACZ;qBACF;oBACDC,KAAK,EAAE;wBACL;4BACEC,CAAC,EAAE,EAAE;4BACLC,CAAC,EAAE,CAAC;4BACJC,KAAK,EAAE,CAAC;4BACRC,MAAM,EAAE,CAAC;4BACTC,OAAO,EAAE;gCAAEC,IAAI,EAAE,kCAAkC;6BAAE;yBACtD;qBACF;iBACF;aACF;SACF;KACF;CACF,AAAC;AAEF,eAAehC,aAAa,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at