@perses-dev/dashboards 0.54.0-beta.0 → 0.54.0-beta.10

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 (276) hide show
  1. package/dist/cjs/components/Annotations/AnnotationsEditor.js +302 -0
  2. package/dist/cjs/components/Annotations/EditAnnotationsButton.js +83 -0
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +4 -2
  4. package/dist/cjs/components/GridLayout/GridItemContent.js +4 -11
  5. package/dist/cjs/components/Panel/Panel.js +4 -1
  6. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +2 -2
  7. package/dist/cjs/components/PanelDrawer/PanelQueriesSharedControls.js +3 -16
  8. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +20 -3
  9. package/dist/cjs/components/Variables/VariableEditor.js +52 -18
  10. package/dist/cjs/constants/defaults.js +32 -0
  11. package/dist/cjs/constants/index.js +1 -0
  12. package/dist/cjs/constants/user-interface-text.js +1 -0
  13. package/dist/cjs/context/AnnotationProvider/AnnotationHydrationWrapper.js +50 -0
  14. package/dist/cjs/context/AnnotationProvider/AnnotationProvider.js +145 -0
  15. package/dist/cjs/context/AnnotationProvider/index.js +30 -0
  16. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +11 -4
  17. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +14 -11
  18. package/dist/cjs/context/DashboardProvider/use-save-dashboard.js +12 -4
  19. package/dist/cjs/context/DatasourceStoreProvider.js +38 -5
  20. package/dist/cjs/context/VariableProvider/VariableProvider.js +11 -6
  21. package/dist/cjs/context/index.js +1 -0
  22. package/dist/cjs/context/useDashboard.js +11 -1
  23. package/dist/cjs/index.js +1 -0
  24. package/dist/cjs/keyboard-shortcuts/index.js +3 -0
  25. package/dist/cjs/keyboard-shortcuts/utils.js +11 -0
  26. package/dist/cjs/model/PanelGroupDefinition.js +25 -0
  27. package/dist/cjs/model/index.js +2 -1
  28. package/dist/cjs/views/ViewDashboard/DashboardApp.js +9 -1
  29. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +33 -28
  30. package/dist/components/AddGroupButton/AddGroupButton.js +1 -1
  31. package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
  32. package/dist/components/AddPanelButton/AddPanelButton.js +1 -1
  33. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  34. package/dist/components/Annotations/AnnotationsEditor.d.ts +8 -0
  35. package/dist/components/Annotations/AnnotationsEditor.d.ts.map +1 -0
  36. package/dist/components/Annotations/AnnotationsEditor.js +289 -0
  37. package/dist/components/Annotations/AnnotationsEditor.js.map +1 -0
  38. package/dist/components/Annotations/EditAnnotationsButton.d.ts +18 -0
  39. package/dist/components/Annotations/EditAnnotationsButton.d.ts.map +1 -0
  40. package/dist/components/Annotations/EditAnnotationsButton.js +70 -0
  41. package/dist/components/Annotations/EditAnnotationsButton.js.map +1 -0
  42. package/dist/components/Dashboard/Dashboard.js +1 -1
  43. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  44. package/dist/components/DashboardLinks/DashboardLinksEditor.js +1 -1
  45. package/dist/components/DashboardLinks/DashboardLinksEditor.js.map +1 -1
  46. package/dist/components/DashboardLinks/EditDashboardLinksButton.js +1 -1
  47. package/dist/components/DashboardLinks/EditDashboardLinksButton.js.map +1 -1
  48. package/dist/components/DashboardShortcuts/useDashboardShortcuts.js.map +1 -1
  49. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +1 -1
  50. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  51. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -0
  52. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  53. package/dist/components/DashboardToolbar/DashboardToolbar.js +5 -3
  54. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  55. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  56. package/dist/components/Datasources/DatasourceEditor.js +1 -1
  57. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  58. package/dist/components/Datasources/EditDatasourcesButton.js +1 -1
  59. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
  60. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  61. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  62. package/dist/components/DownloadButton/DownloadButton.js +1 -1
  63. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  64. package/dist/components/DownloadButton/serializeDashboard.d.ts +1 -1
  65. package/dist/components/DownloadButton/serializeDashboard.d.ts.map +1 -1
  66. package/dist/components/DownloadButton/serializeDashboard.js.map +1 -1
  67. package/dist/components/EditButton/EditButton.js +1 -1
  68. package/dist/components/EditButton/EditButton.js.map +1 -1
  69. package/dist/components/EditJsonButton/EditJsonButton.js +1 -1
  70. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  71. package/dist/components/EditJsonDialog/EditJsonDialog.js +1 -1
  72. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  73. package/dist/components/EmptyDashboard/EmptyDashboard.js +1 -1
  74. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
  75. package/dist/components/GridLayout/GridContainer.js +1 -1
  76. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  77. package/dist/components/GridLayout/GridItemContent.d.ts +1 -1
  78. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  79. package/dist/components/GridLayout/GridItemContent.js +4 -11
  80. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  81. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  82. package/dist/components/GridLayout/GridLayout.js +1 -1
  83. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  84. package/dist/components/GridLayout/GridTitle.js +1 -1
  85. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  86. package/dist/components/GridLayout/Row.d.ts +1 -1
  87. package/dist/components/GridLayout/Row.d.ts.map +1 -1
  88. package/dist/components/GridLayout/Row.js +1 -1
  89. package/dist/components/GridLayout/Row.js.map +1 -1
  90. package/dist/components/LeaveDialog/LeaveDialog.d.ts +1 -1
  91. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
  92. package/dist/components/LeaveDialog/LeaveDialog.js +1 -1
  93. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  94. package/dist/components/LinksDisplay/LinksDisplay.js +1 -1
  95. package/dist/components/LinksDisplay/LinksDisplay.js.map +1 -1
  96. package/dist/components/Panel/Panel.d.ts +1 -1
  97. package/dist/components/Panel/Panel.d.ts.map +1 -1
  98. package/dist/components/Panel/Panel.js +5 -2
  99. package/dist/components/Panel/Panel.js.map +1 -1
  100. package/dist/components/Panel/PanelActions.js +1 -1
  101. package/dist/components/Panel/PanelActions.js.map +1 -1
  102. package/dist/components/Panel/PanelContent.js +1 -1
  103. package/dist/components/Panel/PanelContent.js.map +1 -1
  104. package/dist/components/Panel/PanelHeader.js +1 -1
  105. package/dist/components/Panel/PanelHeader.js.map +1 -1
  106. package/dist/components/Panel/PanelPluginLoader.js +1 -1
  107. package/dist/components/Panel/PanelPluginLoader.js.map +1 -1
  108. package/dist/components/Panel/useSelectionItemActions.js +1 -1
  109. package/dist/components/Panel/useSelectionItemActions.js.map +1 -1
  110. package/dist/components/PanelDrawer/PanelDrawer.js +1 -1
  111. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  112. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
  113. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  114. package/dist/components/PanelDrawer/PanelEditorForm.js +3 -3
  115. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  116. package/dist/components/PanelDrawer/PanelPreview.js +1 -1
  117. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  118. package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts.map +1 -1
  119. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +5 -18
  120. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -1
  121. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
  122. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  123. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  124. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  125. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +1 -1
  126. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  127. package/dist/components/QueryViewerDialog/QueryViewerDialog.js +1 -1
  128. package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -1
  129. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
  130. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +22 -5
  131. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  132. package/dist/components/Variables/EditVariablesButton.js +1 -1
  133. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  134. package/dist/components/Variables/ListVariableListBox.js +1 -1
  135. package/dist/components/Variables/ListVariableListBox.js.map +1 -1
  136. package/dist/components/Variables/Variable.js +2 -2
  137. package/dist/components/Variables/Variable.js.map +1 -1
  138. package/dist/components/Variables/VariableEditor.d.ts +1 -1
  139. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  140. package/dist/components/Variables/VariableEditor.js +57 -23
  141. package/dist/components/Variables/VariableEditor.js.map +1 -1
  142. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  143. package/dist/components/Variables/VariableList.js +1 -1
  144. package/dist/components/Variables/VariableList.js.map +1 -1
  145. package/dist/constants/defaults.d.ts +4 -0
  146. package/dist/constants/defaults.d.ts.map +1 -0
  147. package/dist/{model/DashboardResource.js → constants/defaults.js} +3 -5
  148. package/dist/constants/defaults.js.map +1 -0
  149. package/dist/constants/index.d.ts +1 -0
  150. package/dist/constants/index.d.ts.map +1 -1
  151. package/dist/constants/index.js +1 -0
  152. package/dist/constants/index.js.map +1 -1
  153. package/dist/constants/user-interface-text.d.ts +1 -0
  154. package/dist/constants/user-interface-text.d.ts.map +1 -1
  155. package/dist/constants/user-interface-text.js +1 -0
  156. package/dist/constants/user-interface-text.js.map +1 -1
  157. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts +7 -0
  158. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts.map +1 -0
  159. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js +48 -0
  160. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js.map +1 -0
  161. package/dist/context/AnnotationProvider/AnnotationProvider.d.ts +40 -0
  162. package/dist/context/AnnotationProvider/AnnotationProvider.d.ts.map +1 -0
  163. package/dist/context/AnnotationProvider/AnnotationProvider.js +114 -0
  164. package/dist/context/AnnotationProvider/AnnotationProvider.js.map +1 -0
  165. package/dist/context/AnnotationProvider/index.d.ts +2 -0
  166. package/dist/context/AnnotationProvider/index.d.ts.map +1 -0
  167. package/dist/context/AnnotationProvider/index.js +15 -0
  168. package/dist/context/AnnotationProvider/index.js.map +1 -0
  169. package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -2
  170. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  171. package/dist/context/DashboardProvider/DashboardProvider.js +11 -4
  172. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  173. package/dist/context/DashboardProvider/common.d.ts +1 -1
  174. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  175. package/dist/context/DashboardProvider/common.js.map +1 -1
  176. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -2
  177. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  178. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  179. package/dist/context/DashboardProvider/delete-panel-slice.d.ts +1 -1
  180. package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -1
  181. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  182. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +1 -1
  183. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -1
  184. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
  185. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -1
  186. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  187. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  188. package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -1
  189. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  190. package/dist/context/DashboardProvider/panel-group-slice.js +14 -11
  191. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  192. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +8 -1
  193. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -1
  194. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
  195. package/dist/context/DashboardProvider/use-save-dashboard.d.ts.map +1 -1
  196. package/dist/context/DashboardProvider/use-save-dashboard.js +13 -5
  197. package/dist/context/DashboardProvider/use-save-dashboard.js.map +1 -1
  198. package/dist/context/DashboardProvider/view-panel-slice.d.ts +1 -1
  199. package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
  200. package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
  201. package/dist/context/DatasourceStoreProvider.d.ts +1 -2
  202. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  203. package/dist/context/DatasourceStoreProvider.js +40 -7
  204. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  205. package/dist/context/PanelEditorProvider/PanelEditorProvider.js +1 -1
  206. package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -1
  207. package/dist/context/VariableProvider/VariableProvider.d.ts +3 -2
  208. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
  209. package/dist/context/VariableProvider/VariableProvider.js +13 -8
  210. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  211. package/dist/context/VariableProvider/hydrationUtils.d.ts +1 -1
  212. package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -1
  213. package/dist/context/VariableProvider/hydrationUtils.js.map +1 -1
  214. package/dist/context/VariableProvider/utils.d.ts +1 -1
  215. package/dist/context/VariableProvider/utils.d.ts.map +1 -1
  216. package/dist/context/VariableProvider/utils.js.map +1 -1
  217. package/dist/context/index.d.ts +1 -0
  218. package/dist/context/index.d.ts.map +1 -1
  219. package/dist/context/index.js +1 -0
  220. package/dist/context/index.js.map +1 -1
  221. package/dist/context/useDashboard.d.ts +2 -3
  222. package/dist/context/useDashboard.d.ts.map +1 -1
  223. package/dist/context/useDashboard.js +11 -1
  224. package/dist/context/useDashboard.js.map +1 -1
  225. package/dist/index.d.ts +1 -0
  226. package/dist/index.d.ts.map +1 -1
  227. package/dist/index.js +1 -0
  228. package/dist/index.js.map +1 -1
  229. package/dist/keyboard-shortcuts/PanelFocusProvider.js +1 -1
  230. package/dist/keyboard-shortcuts/PanelFocusProvider.js.map +1 -1
  231. package/dist/keyboard-shortcuts/index.d.ts +1 -1
  232. package/dist/keyboard-shortcuts/index.d.ts.map +1 -1
  233. package/dist/keyboard-shortcuts/index.js +1 -1
  234. package/dist/keyboard-shortcuts/index.js.map +1 -1
  235. package/dist/keyboard-shortcuts/utils.d.ts +8 -0
  236. package/dist/keyboard-shortcuts/utils.d.ts.map +1 -1
  237. package/dist/keyboard-shortcuts/utils.js +13 -0
  238. package/dist/keyboard-shortcuts/utils.js.map +1 -1
  239. package/dist/model/PanelGroupDefinition.d.ts +59 -0
  240. package/dist/model/PanelGroupDefinition.d.ts.map +1 -0
  241. package/dist/model/PanelGroupDefinition.js +19 -0
  242. package/dist/model/PanelGroupDefinition.js.map +1 -0
  243. package/dist/model/VariableDefinition.d.ts +50 -0
  244. package/dist/model/VariableDefinition.d.ts.map +1 -0
  245. package/dist/model/VariableDefinition.js +20 -0
  246. package/dist/model/VariableDefinition.js.map +1 -0
  247. package/dist/model/index.d.ts +2 -1
  248. package/dist/model/index.d.ts.map +1 -1
  249. package/dist/model/index.js +2 -1
  250. package/dist/model/index.js.map +1 -1
  251. package/dist/test/dashboard-provider.d.ts +1 -1
  252. package/dist/test/dashboard-provider.d.ts.map +1 -1
  253. package/dist/test/dashboard-provider.js.map +1 -1
  254. package/dist/test/datasource-provider.d.ts +1 -1
  255. package/dist/test/datasource-provider.d.ts.map +1 -1
  256. package/dist/test/datasource-provider.js.map +1 -1
  257. package/dist/test/render.js +1 -1
  258. package/dist/test/render.js.map +1 -1
  259. package/dist/test/testDashboard.d.ts +1 -1
  260. package/dist/test/testDashboard.d.ts.map +1 -1
  261. package/dist/test/testDashboard.js.map +1 -1
  262. package/dist/utils/panelUtils.d.ts +1 -1
  263. package/dist/utils/panelUtils.d.ts.map +1 -1
  264. package/dist/utils/panelUtils.js.map +1 -1
  265. package/dist/views/ViewDashboard/DashboardApp.d.ts +3 -1
  266. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  267. package/dist/views/ViewDashboard/DashboardApp.js +11 -3
  268. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  269. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  270. package/dist/views/ViewDashboard/ViewDashboard.js +33 -28
  271. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  272. package/package.json +9 -10
  273. package/dist/model/DashboardResource.d.ts +0 -15
  274. package/dist/model/DashboardResource.d.ts.map +0 -1
  275. package/dist/model/DashboardResource.js.map +0 -1
  276. /package/dist/cjs/model/{DashboardResource.js → VariableDefinition.js} +0 -0
@@ -83,7 +83,7 @@ function VariableEditor(props) {
83
83
  externalVariableDefinitions,
84
84
  variableDefinitions
85
85
  ]);
86
- const currentEditingVariableDefinition = typeof variableEditIdx === 'number' && variableDefinitions[variableEditIdx];
86
+ const currentEditingVariableDefinition = variableEditIdx !== null ? variableDefinitions[variableEditIdx] : undefined;
87
87
  const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } = (0, _context.useDiscardChangesConfirmationDialog)();
88
88
  const handleCancel = ()=>{
89
89
  if (JSON.stringify(props.variableDefinitions) !== JSON.stringify(variableDefinitions)) {
@@ -166,25 +166,25 @@ function VariableEditor(props) {
166
166
  };
167
167
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
168
168
  children: [
169
- currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.ValidationProvider, {
170
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.VariableEditorForm, {
171
- initialVariableDefinition: currentEditingVariableDefinition,
172
- action: variableFormAction,
173
- isDraft: true,
174
- onActionChange: setVariableFormAction,
175
- onSave: (definition)=>{
176
- setVariableDefinitions((draft)=>{
177
- draft[variableEditIdx] = definition;
178
- setVariableEditIdx(null);
179
- });
180
- },
181
- onClose: ()=>{
182
- if (variableFormAction === 'create') {
183
- removeVariable(variableEditIdx);
184
- }
169
+ variableEditIdx !== null && currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxruntime.jsx)(VariableEditorFormWithContext, {
170
+ variableDefinitions: variableDefinitions,
171
+ externalVariableDefinitions: externalVariableDefinitions,
172
+ builtinVariableDefinitions: builtinVariableDefinitions,
173
+ currentEditingVariableDefinition: currentEditingVariableDefinition,
174
+ variableFormAction: variableFormAction,
175
+ onActionChange: setVariableFormAction,
176
+ onSave: (definition)=>{
177
+ setVariableDefinitions((draft)=>{
178
+ draft[variableEditIdx] = definition;
185
179
  setVariableEditIdx(null);
180
+ });
181
+ },
182
+ onClose: ()=>{
183
+ if (variableFormAction === 'create') {
184
+ removeVariable(variableEditIdx);
186
185
  }
187
- })
186
+ setVariableEditIdx(null);
187
+ }
188
188
  }),
189
189
  !currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
190
190
  children: [
@@ -535,6 +535,40 @@ function VariableEditor(props) {
535
535
  const TableCell = (0, _material.styled)(_material.TableCell)(({ theme })=>({
536
536
  borderBottom: `solid 1px ${theme.palette.divider}`
537
537
  }));
538
+ function VariableEditorFormWithContext({ variableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, currentEditingVariableDefinition, variableFormAction, onActionChange, onSave, onClose }) {
539
+ const { initialVariableValues, isLoading } = (0, _pluginsystem.useResolveListVariableValues)(variableDefinitions);
540
+ if (isLoading) {
541
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
542
+ sx: {
543
+ display: 'flex',
544
+ alignItems: 'center',
545
+ justifyContent: 'center',
546
+ height: '100%',
547
+ width: '100%',
548
+ overflow: 'hidden'
549
+ },
550
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {
551
+ "aria-label": "loading"
552
+ })
553
+ });
554
+ }
555
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_context.VariableProvider, {
556
+ initialVariableDefinitions: variableDefinitions,
557
+ externalVariableDefinitions: externalVariableDefinitions,
558
+ builtinVariableDefinitions: builtinVariableDefinitions,
559
+ initialVariableValues: initialVariableValues,
560
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.ValidationProvider, {
561
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.VariableEditorForm, {
562
+ initialVariableDefinition: currentEditingVariableDefinition,
563
+ action: variableFormAction,
564
+ isDraft: true,
565
+ onActionChange: onActionChange,
566
+ onSave: onSave,
567
+ onClose: onClose
568
+ })
569
+ })
570
+ });
571
+ }
538
572
  function VariableName(props) {
539
573
  const { name, state } = props;
540
574
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
@@ -0,0 +1,32 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get DEFAULT_DASHBOARD_DURATION () {
25
+ return DEFAULT_DASHBOARD_DURATION;
26
+ },
27
+ get DEFAULT_REFRESH_INTERVAL () {
28
+ return DEFAULT_REFRESH_INTERVAL;
29
+ }
30
+ });
31
+ const DEFAULT_DASHBOARD_DURATION = '1h';
32
+ const DEFAULT_REFRESH_INTERVAL = '0s';
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _export_star(require("./grid-layout-config"), exports);
18
18
  _export_star(require("./styles"), exports);
19
19
  _export_star(require("./user-interface-text"), exports);
20
+ _export_star(require("./defaults"), exports);
20
21
  function _export_star(from, to) {
21
22
  Object.keys(from).forEach(function(k) {
22
23
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -36,6 +36,7 @@ const TOOLTIP_TEXT = {
36
36
  editJson: 'Edit JSON',
37
37
  editLinks: 'Edit links',
38
38
  editVariables: 'Edit variables',
39
+ editAnnotations: 'Edit annotations',
39
40
  viewJson: 'View JSON',
40
41
  // Group buttons
41
42
  addPanelToGroup: 'Add panel to group',
@@ -0,0 +1,50 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "AnnotationHydrationWrapper", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return AnnotationHydrationWrapper;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _react = require("react");
25
+ const _pluginsystem = require("@perses-dev/plugin-system");
26
+ const _AnnotationProvider = require("./AnnotationProvider");
27
+ function AnnotationHydrationWrapper({ children }) {
28
+ const annotationSpecs = (0, _AnnotationProvider.useAnnotationSpecs)();
29
+ const { setAnnotationState } = (0, _AnnotationProvider.useAnnotationActions)();
30
+ const annotations = (0, _pluginsystem.useAnnotations)(annotationSpecs);
31
+ (0, _react.useEffect)(()=>{
32
+ for (const [index, definition] of annotationSpecs.entries()){
33
+ const query = annotations[index] ?? null;
34
+ if (query) {
35
+ setAnnotationState(definition.display.name, {
36
+ data: query.data ?? null,
37
+ isPending: query.isLoading,
38
+ error: query?.error ?? null
39
+ });
40
+ }
41
+ }
42
+ }, [
43
+ annotationSpecs,
44
+ annotations,
45
+ setAnnotationState
46
+ ]);
47
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
48
+ children: children
49
+ });
50
+ }
@@ -0,0 +1,145 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get AnnotationProvider () {
25
+ return AnnotationProvider;
26
+ },
27
+ get useAnnotationActions () {
28
+ return useAnnotationActions;
29
+ },
30
+ get useAnnotationSpecAndState () {
31
+ return useAnnotationSpecAndState;
32
+ },
33
+ get useAnnotationSpecs () {
34
+ return useAnnotationSpecs;
35
+ },
36
+ get useAnnotationStates () {
37
+ return useAnnotationStates;
38
+ },
39
+ get useAnnotationStoreCtx () {
40
+ return useAnnotationStoreCtx;
41
+ },
42
+ get useAnnotationsWithData () {
43
+ return useAnnotationsWithData;
44
+ }
45
+ });
46
+ const _jsxruntime = require("react/jsx-runtime");
47
+ const _react = require("react");
48
+ const _zustand = require("zustand");
49
+ const _traditional = require("zustand/traditional");
50
+ const _shallow = require("zustand/shallow");
51
+ const _middleware = require("zustand/middleware");
52
+ const _immer = require("zustand/middleware/immer");
53
+ const _AnnotationHydrationWrapper = require("./AnnotationHydrationWrapper");
54
+ const AnnotationStoreContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
55
+ function useAnnotationStoreCtx() {
56
+ const context = (0, _react.useContext)(AnnotationStoreContext);
57
+ if (!context) {
58
+ return createAnnotationStore({
59
+ initialAnnotationSpecs: []
60
+ });
61
+ }
62
+ return context;
63
+ }
64
+ function useAnnotationSpecs() {
65
+ const store = useAnnotationStoreCtx();
66
+ return (0, _zustand.useStore)(store, (s)=>s.annotationSpecs);
67
+ }
68
+ function useAnnotationStates(annotationNames) {
69
+ const store = useAnnotationStoreCtx();
70
+ return (0, _traditional.useStoreWithEqualityFn)(store, (s)=>{
71
+ if (annotationNames) {
72
+ const result = {};
73
+ annotationNames.forEach((name)=>{
74
+ const s = store.getState().annotationState[name];
75
+ if (s) {
76
+ result[name] = s;
77
+ }
78
+ });
79
+ return result;
80
+ }
81
+ return s.annotationState;
82
+ }, (left, right)=>{
83
+ return JSON.stringify(left) === JSON.stringify(right);
84
+ });
85
+ }
86
+ function useAnnotationActions() {
87
+ const store = useAnnotationStoreCtx();
88
+ return (0, _traditional.useStoreWithEqualityFn)(store, (s)=>{
89
+ return {
90
+ setAnnotationState: s.setAnnotationState,
91
+ setAnnotationSpecs: s.setAnnotationSpecs
92
+ };
93
+ }, _shallow.shallow);
94
+ }
95
+ function useAnnotationSpecAndState(name) {
96
+ const store = useAnnotationStoreCtx();
97
+ return (0, _zustand.useStore)(store, (s)=>{
98
+ return {
99
+ definition: s.annotationSpecs.find((d)=>d.display.name === name),
100
+ state: s.annotationState[name]
101
+ };
102
+ });
103
+ }
104
+ function useAnnotationsWithData() {
105
+ const store = useAnnotationStoreCtx();
106
+ return (0, _zustand.useStore)(store, (s)=>{
107
+ return s.annotationSpecs.map((definition)=>{
108
+ const state = s.annotationState[definition.display.name];
109
+ return {
110
+ definition,
111
+ data: state?.data
112
+ };
113
+ }).filter((annotation)=>!!annotation.data);
114
+ });
115
+ }
116
+ function createAnnotationStore({ initialAnnotationSpecs = [] }) {
117
+ const store = (0, _zustand.createStore)()((0, _middleware.devtools)((0, _immer.immer)((set, _get)=>({
118
+ annotationSpecs: initialAnnotationSpecs,
119
+ annotationState: {},
120
+ setAnnotationSpecs (definitions) {
121
+ set((s)=>{
122
+ s.annotationSpecs = definitions;
123
+ }, false, '[Annotations] setAnnotationSpecs' // Used for action name in Redux devtools
124
+ );
125
+ },
126
+ setAnnotationState: (name, state)=>{
127
+ set((s)=>{
128
+ s.annotationState[name] = state;
129
+ }, false, '[Annotations] setAnnotationState' // Used for action name in Redux devtools
130
+ );
131
+ }
132
+ }))));
133
+ return store;
134
+ }
135
+ function AnnotationProvider({ children, initialAnnotationSpecs = [] }) {
136
+ const [store] = (0, _react.useState)(()=>createAnnotationStore({
137
+ initialAnnotationSpecs
138
+ }));
139
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(AnnotationStoreContext.Provider, {
140
+ value: store,
141
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_AnnotationHydrationWrapper.AnnotationHydrationWrapper, {
142
+ children: children
143
+ })
144
+ });
145
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _export_star(require("./AnnotationProvider"), exports);
18
+ function _export_star(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ return from;
30
+ }
@@ -38,8 +38,8 @@ const _middleware = require("zustand/middleware");
38
38
  const _immer = require("zustand/middleware/immer");
39
39
  const _shallow = require("zustand/shallow");
40
40
  const _react = require("react");
41
- const _core = require("@perses-dev/core");
42
41
  const _pluginsystem = require("@perses-dev/plugin-system");
42
+ const _constants = require("../../constants");
43
43
  const _panelgroupeditorslice = require("./panel-group-editor-slice");
44
44
  const _panelgroupslice = require("./panel-group-slice");
45
45
  const _paneleditorslice = require("./panel-editor-slice");
@@ -92,7 +92,7 @@ function DashboardProvider(props) {
92
92
  }
93
93
  function initStore(props) {
94
94
  const { initialState: { dashboardResource, isEditMode, viewPanelRef, setViewPanelRef } } = props;
95
- const { kind, metadata, spec: { display, duration, refreshInterval = _core.DEFAULT_REFRESH_INTERVAL, datasources, layouts = [], panels = {} } } = dashboardResource;
95
+ const { kind, metadata, spec: { display, timezone, duration, refreshInterval = _constants.DEFAULT_REFRESH_INTERVAL, datasources, layouts = [], panels = {} } } = dashboardResource;
96
96
  const links = dashboardResource.spec.links ?? [];
97
97
  const ttl = 'ttl' in dashboardResource.spec ? dashboardResource.spec.ttl : undefined;
98
98
  const store = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
@@ -113,6 +113,7 @@ function initStore(props) {
113
113
  kind,
114
114
  metadata,
115
115
  display,
116
+ timezone,
116
117
  duration,
117
118
  refreshInterval,
118
119
  datasources,
@@ -123,21 +124,27 @@ function initStore(props) {
123
124
  isEditMode
124
125
  });
125
126
  },
126
- setDashboard: ({ kind, metadata, spec: { display, panels = {}, layouts = [], duration, refreshInterval, datasources = {}, links = [] } })=>{
127
+ setDashboard: ({ kind, metadata, spec: { display, panels = {}, layouts = [], duration, refreshInterval, datasources = {}, links = [], timezone } })=>{
127
128
  set((state)=>{
128
129
  state.kind = kind;
129
130
  state.metadata = metadata;
130
131
  state.display = display;
132
+ state.timezone = timezone;
131
133
  state.panels = panels;
132
134
  const { panelGroups, panelGroupOrder } = (0, _panelgroupslice.convertLayoutsToPanelGroups)(layouts);
133
135
  state.panelGroups = panelGroups;
134
136
  state.panelGroupOrder = panelGroupOrder;
135
137
  state.duration = duration;
136
- state.refreshInterval = refreshInterval ?? _core.DEFAULT_REFRESH_INTERVAL;
138
+ state.refreshInterval = refreshInterval ?? _constants.DEFAULT_REFRESH_INTERVAL;
137
139
  state.datasources = datasources;
138
140
  state.links = links;
139
141
  // TODO: add ttl here to e.g allow edition from JSON view, but probably requires quite some refactoring
140
142
  });
143
+ },
144
+ setMetadata: (metadata)=>{
145
+ set((state)=>{
146
+ state.metadata = typeof metadata === 'function' ? metadata(state.metadata) : metadata;
147
+ });
141
148
  }
142
149
  };
143
150
  })));
@@ -78,23 +78,26 @@ function convertLayoutsToPanelGroups(layouts) {
78
78
  const itemLayouts = [];
79
79
  const itemPanelKeys = {};
80
80
  // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
81
- for (const item of layout.spec.items){
82
- const panelGroupLayoutId = (0, _common.generateId)().toString();
83
- itemLayouts.push({
84
- i: panelGroupLayoutId,
85
- w: item.width,
86
- h: item.height,
87
- x: item.x,
88
- y: item.y
89
- });
90
- itemPanelKeys[panelGroupLayoutId] = (0, _spec.getPanelKeyFromRef)(item.content);
81
+ if ('items' in layout.spec) {
82
+ for (const item of layout.spec.items){
83
+ const panelGroupLayoutId = (0, _common.generateId)().toString();
84
+ itemLayouts.push({
85
+ i: panelGroupLayoutId,
86
+ w: item.width,
87
+ h: item.height,
88
+ x: item.x,
89
+ y: item.y
90
+ });
91
+ itemPanelKeys[panelGroupLayoutId] = (0, _spec.getPanelKeyFromRef)(item.content);
92
+ }
91
93
  }
92
94
  // Create the panel group and keep track of the ID order
95
+ const repeatVariable = 'repeatVariable' in layout.spec ? layout.spec.repeatVariable : undefined;
93
96
  const panelGroupId = (0, _common.generateId)();
94
97
  panelGroups[panelGroupId] = {
95
98
  id: panelGroupId,
96
99
  isCollapsed: layout.spec.display?.collapse?.open === false,
97
- repeatVariable: layout.spec.repeatVariable,
100
+ repeatVariable,
98
101
  title: layout.spec.display?.title,
99
102
  itemLayouts,
100
103
  itemPanelKeys
@@ -31,6 +31,7 @@ function useSaveDashboard(onSave) {
31
31
  const { dashboard, setDashboard } = (0, _useDashboard.useDashboard)();
32
32
  const { setEditMode } = (0, _dashboardproviderapi.useEditMode)();
33
33
  const { timeRange, refreshInterval } = (0, _pluginsystem.useTimeRange)();
34
+ const { timeZone } = (0, _pluginsystem.useTimeZoneParams)();
34
35
  const { getSavedVariablesStatus, setVariableDefaultValues } = (0, _VariableProvider.useVariableDefinitionActions)();
35
36
  const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = (0, _dashboardproviderapi.useSaveChangesConfirmationDialog)();
36
37
  const performSave = (0, _react.useCallback)(async ()=>{
@@ -59,12 +60,17 @@ function useSaveDashboard(onSave) {
59
60
  const { isSavedVariableModified } = getSavedVariablesStatus();
60
61
  const isSavedDurationModified = (0, _spec.isRelativeTimeRange)(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;
61
62
  const isSavedRefreshIntervalModified = dashboard.spec.refreshInterval !== refreshInterval;
62
- if (isSavedDurationModified || isSavedVariableModified || isSavedRefreshIntervalModified) {
63
+ const isTimeZoneModified = timeZone === 'local' && !dashboard.spec.timezone ? false : dashboard.spec.timezone !== timeZone;
64
+ if (isSavedDurationModified || isSavedVariableModified || isSavedRefreshIntervalModified || isTimeZoneModified) {
63
65
  openSaveChangesConfirmationDialog({
64
- onSaveChanges: (saveDefaultTimeRange, saveDefaultRefreshInterval, saveDefaultVariables)=>{
66
+ onSaveChanges: (options)=>{
67
+ const { saveDefaultRefreshInterval, saveDefaultTimeRange, saveDefaultTimeZone, saveDefaultVariables } = options;
65
68
  if ((0, _spec.isRelativeTimeRange)(timeRange) && saveDefaultTimeRange) {
66
69
  dashboard.spec.duration = timeRange.pastDuration;
67
70
  }
71
+ if (saveDefaultTimeZone) {
72
+ dashboard.spec.timezone = timeZone;
73
+ }
68
74
  if (saveDefaultVariables) {
69
75
  const variables = setVariableDefaultValues();
70
76
  dashboard.spec.variables = variables;
@@ -80,17 +86,19 @@ function useSaveDashboard(onSave) {
80
86
  },
81
87
  isSavedDurationModified,
82
88
  isSavedVariableModified,
83
- isSavedRefreshIntervalModified
89
+ isSavedRefreshIntervalModified,
90
+ isTimeZoneModified
84
91
  });
85
92
  } else {
86
93
  performSave();
87
94
  }
88
95
  }, [
89
96
  isSaving,
90
- getSavedVariablesStatus,
91
97
  timeRange,
92
98
  dashboard,
93
99
  refreshInterval,
100
+ timeZone,
101
+ getSavedVariablesStatus,
94
102
  openSaveChangesConfirmationDialog,
95
103
  setVariableDefaultValues,
96
104
  setDashboard,
@@ -27,15 +27,24 @@ function DatasourceStoreProvider(props) {
27
27
  const { projectName, datasourceApi, onCreate, children } = props;
28
28
  const [dashboardResource, setDashboardResource] = (0, _react.useState)(props.dashboardResource);
29
29
  const [savedDatasources, setSavedDatasources] = (0, _react.useState)(props.savedDatasources ?? {});
30
+ // Cache for synchronous datasource spec access
31
+ const datasourceSpecCache = (0, _react.useRef)(new Map());
30
32
  const project = projectName ?? dashboardResource?.metadata.project;
31
33
  const { getPlugin, listPluginMetadata } = (0, _pluginsystem.usePluginRegistry)();
34
+ // Helper to create cache key from DatasourceSelector
35
+ const createCacheKey = (0, _react.useCallback)((selector)=>{
36
+ const name = selector.name === undefined ? '__undefined__' : selector.name;
37
+ return `${selector.kind}:${name}:${project ?? 'global'}`;
38
+ }, [
39
+ project
40
+ ]);
32
41
  const findDatasource = (0, _pluginsystem.useEvent)(async (selector)=>{
33
42
  // Try to find it in dashboard spec
34
43
  if (dashboardResource) {
35
44
  const { datasources } = dashboardResource.spec;
36
45
  const dashboardDatasource = findDashboardDatasource(datasources, selector);
37
46
  if (dashboardDatasource !== undefined) {
38
- return {
47
+ const result = {
39
48
  spec: dashboardDatasource.spec,
40
49
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
41
50
  project: dashboardResource.metadata.project,
@@ -43,30 +52,42 @@ function DatasourceStoreProvider(props) {
43
52
  name: dashboardDatasource.name
44
53
  })
45
54
  };
55
+ // Cache the spec for synchronous access
56
+ const cacheKey = createCacheKey(selector);
57
+ datasourceSpecCache.current.set(cacheKey, result.spec);
58
+ return result;
46
59
  }
47
60
  }
48
61
  if (project) {
49
62
  // Try to find it at the project level as a Datasource resource
50
63
  const datasource = await datasourceApi.getDatasource(String(project), selector);
51
64
  if (datasource !== undefined) {
52
- return {
65
+ const result = {
53
66
  spec: datasource.spec,
54
67
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
55
68
  project: datasource.metadata.project,
56
69
  name: datasource.metadata.name
57
70
  })
58
71
  };
72
+ // Cache the spec for synchronous access
73
+ const cacheKey = createCacheKey(selector);
74
+ datasourceSpecCache.current.set(cacheKey, result.spec);
75
+ return result;
59
76
  }
60
77
  }
61
78
  // Try to find it at the global level as a GlobalDatasource resource
62
79
  const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
63
80
  if (globalDatasource !== undefined) {
64
- return {
81
+ const result = {
65
82
  spec: globalDatasource.spec,
66
83
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
67
84
  name: globalDatasource.metadata.name
68
85
  })
69
86
  };
87
+ // Cache the spec for synchronous access
88
+ const cacheKey = createCacheKey(selector);
89
+ datasourceSpecCache.current.set(cacheKey, result.spec);
90
+ return result;
70
91
  }
71
92
  throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
72
93
  });
@@ -82,7 +103,10 @@ function DatasourceStoreProvider(props) {
82
103
  const { kind } = selector;
83
104
  const [{ spec, proxyUrl }, plugin] = await Promise.all([
84
105
  findDatasource(selector),
85
- getPlugin('Datasource', kind)
106
+ getPlugin({
107
+ kind: 'Datasource',
108
+ name: kind
109
+ })
86
110
  ]);
87
111
  // allows extending client
88
112
  const client = plugin.createClient(spec.plugin.spec, {
@@ -158,6 +182,13 @@ function DatasourceStoreProvider(props) {
158
182
  }, [
159
183
  savedDatasources
160
184
  ]);
185
+ // Gets a cached datasource spec synchronously if available
186
+ const getDatasourceSpecSync = (0, _react.useCallback)((selector)=>{
187
+ const cacheKey = createCacheKey(selector);
188
+ return datasourceSpecCache.current.get(cacheKey);
189
+ }, [
190
+ createCacheKey
191
+ ]);
161
192
  const setLocalDatasources = (0, _react.useCallback)((datasources)=>{
162
193
  if (dashboardResource) {
163
194
  setDashboardResource({
@@ -174,6 +205,7 @@ function DatasourceStoreProvider(props) {
174
205
  const ctxValue = (0, _react.useMemo)(()=>({
175
206
  getDatasource,
176
207
  getDatasourceClient,
208
+ getDatasourceSpecSync,
177
209
  getLocalDatasources,
178
210
  setLocalDatasources,
179
211
  setSavedDatasources,
@@ -182,6 +214,7 @@ function DatasourceStoreProvider(props) {
182
214
  }), [
183
215
  getDatasource,
184
216
  getDatasourceClient,
217
+ getDatasourceSpecSync,
185
218
  getLocalDatasources,
186
219
  setLocalDatasources,
187
220
  listDatasourceSelectItems,
@@ -263,7 +296,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
263
296
  });
264
297
  usedNames.add(selectorName);
265
298
  const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;
266
- if (results[0] && (isFirst || isExplicitDefault)) {
299
+ if (results[0] && isExplicitDefault) {
267
300
  // If we haven't added a default yet and this is a default, add default option to the beginning of the results
268
301
  results[0].items = [
269
302
  {