@perses-dev/dashboards 0.23.1 → 0.25.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 (178) hide show
  1. package/dist/cjs/components/AddPanelButton/AddPanelButton.js +9 -2
  2. package/dist/cjs/components/Dashboard/Dashboard.js +23 -6
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -17
  4. package/dist/cjs/components/EditButton/EditButton.js +41 -0
  5. package/dist/cjs/components/EditButton/index.js +28 -0
  6. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +42 -0
  7. package/dist/cjs/components/EditJsonButton/index.js +28 -0
  8. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +86 -0
  9. package/dist/cjs/components/EditJsonDialog/index.js +28 -0
  10. package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +127 -0
  11. package/dist/cjs/components/EmptyDashboard/index.js +28 -0
  12. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +185 -0
  13. package/dist/cjs/components/QuerySummaryTable/index.js +28 -0
  14. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +7 -3
  15. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  16. package/dist/cjs/components/Variables/EditVariablesButton.js +9 -2
  17. package/dist/cjs/components/index.js +4 -0
  18. package/dist/cjs/constants/user-interface-text.js +1 -0
  19. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +12 -6
  20. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +10 -1
  21. package/dist/cjs/context/DashboardProvider/edit-json-dialog-slice.js +36 -0
  22. package/dist/cjs/context/DatasourceStoreProvider.js +9 -3
  23. package/dist/cjs/stories/decorators/WithDashboard.js +60 -0
  24. package/dist/cjs/stories/decorators/WithPluginRegistry.js +91 -0
  25. package/dist/cjs/stories/decorators/WithQueryClient.js +29 -0
  26. package/dist/cjs/stories/decorators/WithQueryParams.js +29 -0
  27. package/dist/cjs/stories/decorators/WithTemplateVariables.js +27 -0
  28. package/dist/cjs/stories/decorators/index.js +32 -0
  29. package/dist/cjs/views/ViewDashboard/DashboardApp.js +11 -4
  30. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +2 -1
  31. package/dist/components/AddPanelButton/AddPanelButton.d.ts +16 -1
  32. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
  33. package/dist/components/AddPanelButton/AddPanelButton.js +9 -2
  34. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  35. package/dist/components/Dashboard/Dashboard.d.ts +10 -2
  36. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  37. package/dist/components/Dashboard/Dashboard.js +24 -7
  38. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  39. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  40. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  41. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  42. package/dist/components/EditButton/EditButton.d.ts +13 -0
  43. package/dist/components/EditButton/EditButton.d.ts.map +1 -0
  44. package/dist/components/EditButton/EditButton.js +30 -0
  45. package/dist/components/EditButton/EditButton.js.map +1 -0
  46. package/dist/components/EditButton/index.d.ts +2 -0
  47. package/dist/components/EditButton/index.d.ts.map +1 -0
  48. package/dist/components/EditButton/index.js +15 -0
  49. package/dist/components/EditButton/index.js.map +1 -0
  50. package/dist/components/EditJsonButton/EditJsonButton.d.ts +3 -0
  51. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -0
  52. package/dist/components/EditJsonButton/EditJsonButton.js +31 -0
  53. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -0
  54. package/dist/components/EditJsonButton/index.d.ts +2 -0
  55. package/dist/components/EditJsonButton/index.d.ts.map +1 -0
  56. package/dist/components/EditJsonButton/index.js +15 -0
  57. package/dist/components/EditJsonButton/index.js.map +1 -0
  58. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +3 -0
  59. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -0
  60. package/dist/components/EditJsonDialog/EditJsonDialog.js +80 -0
  61. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -0
  62. package/dist/components/EditJsonDialog/index.d.ts +2 -0
  63. package/dist/components/EditJsonDialog/index.d.ts.map +1 -0
  64. package/dist/components/EditJsonDialog/index.js +15 -0
  65. package/dist/components/EditJsonDialog/index.js.map +1 -0
  66. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +33 -0
  67. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -0
  68. package/dist/components/EmptyDashboard/EmptyDashboard.js +123 -0
  69. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -0
  70. package/dist/components/EmptyDashboard/index.d.ts +2 -0
  71. package/dist/components/EmptyDashboard/index.d.ts.map +1 -0
  72. package/dist/components/EmptyDashboard/index.js +15 -0
  73. package/dist/components/EmptyDashboard/index.js.map +1 -0
  74. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +11 -0
  75. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -0
  76. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +179 -0
  77. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -0
  78. package/dist/components/QuerySummaryTable/index.d.ts +2 -0
  79. package/dist/components/QuerySummaryTable/index.d.ts.map +1 -0
  80. package/dist/components/QuerySummaryTable/index.js +15 -0
  81. package/dist/components/QuerySummaryTable/index.js.map +1 -0
  82. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
  83. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  84. package/dist/components/TimeRangeControls/TimeRangeControls.js +8 -4
  85. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  86. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +1 -1
  87. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +1 -1
  88. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  89. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  90. package/dist/components/Variables/EditVariablesButton.d.ts +16 -1
  91. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  92. package/dist/components/Variables/EditVariablesButton.js +9 -2
  93. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  94. package/dist/components/index.d.ts +4 -0
  95. package/dist/components/index.d.ts.map +1 -1
  96. package/dist/components/index.js +4 -0
  97. package/dist/components/index.js.map +1 -1
  98. package/dist/constants/user-interface-text.d.ts +1 -0
  99. package/dist/constants/user-interface-text.d.ts.map +1 -1
  100. package/dist/constants/user-interface-text.js +1 -0
  101. package/dist/constants/user-interface-text.js.map +1 -1
  102. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  103. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  104. package/dist/context/DashboardProvider/DashboardProvider.js +12 -6
  105. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  106. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +8 -0
  107. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  108. package/dist/context/DashboardProvider/dashboard-provider-api.js +10 -0
  109. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  110. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts +12 -0
  111. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts.map +1 -0
  112. package/dist/context/DashboardProvider/edit-json-dialog-slice.js +30 -0
  113. package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -0
  114. package/dist/context/DatasourceStoreProvider.d.ts +2 -0
  115. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  116. package/dist/context/DatasourceStoreProvider.js +9 -3
  117. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  118. package/dist/stories/decorators/WithDashboard.js +48 -0
  119. package/dist/stories/decorators/WithDashboard.js.map +1 -0
  120. package/dist/stories/decorators/WithPluginRegistry.js +46 -0
  121. package/dist/stories/decorators/WithPluginRegistry.js.map +1 -0
  122. package/dist/stories/decorators/WithQueryClient.js +23 -0
  123. package/dist/stories/decorators/WithQueryClient.js.map +1 -0
  124. package/dist/stories/decorators/WithQueryParams.js +23 -0
  125. package/dist/stories/decorators/WithQueryParams.js.map +1 -0
  126. package/dist/stories/decorators/WithTemplateVariables.js +21 -0
  127. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -0
  128. package/dist/stories/decorators/index.js +19 -0
  129. package/dist/stories/decorators/index.js.map +1 -0
  130. package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -0
  131. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  132. package/dist/views/ViewDashboard/DashboardApp.js +12 -5
  133. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  134. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -8
  135. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  136. package/dist/views/ViewDashboard/ViewDashboard.js +2 -1
  137. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  138. package/package.json +6 -5
  139. package/dist/cjs/components/Panel/Panel.test.js +0 -137
  140. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +0 -131
  141. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +0 -87
  142. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +0 -95
  143. package/dist/cjs/components/Variables/variable-model.test.js +0 -106
  144. package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +0 -82
  145. package/dist/cjs/utils/panelUtils.test.js +0 -195
  146. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +0 -110
  147. package/dist/components/Panel/Panel.test.d.ts +0 -2
  148. package/dist/components/Panel/Panel.test.d.ts.map +0 -1
  149. package/dist/components/Panel/Panel.test.js +0 -130
  150. package/dist/components/Panel/Panel.test.js.map +0 -1
  151. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +0 -2
  152. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +0 -1
  153. package/dist/components/PanelDrawer/PanelDrawer.test.js +0 -124
  154. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +0 -1
  155. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +0 -2
  156. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +0 -1
  157. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +0 -80
  158. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +0 -1
  159. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +0 -2
  160. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +0 -1
  161. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +0 -88
  162. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +0 -1
  163. package/dist/components/Variables/variable-model.test.d.ts +0 -2
  164. package/dist/components/Variables/variable-model.test.d.ts.map +0 -1
  165. package/dist/components/Variables/variable-model.test.js +0 -104
  166. package/dist/components/Variables/variable-model.test.js.map +0 -1
  167. package/dist/context/TemplateVariableProvider/query-params.test.d.ts +0 -2
  168. package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +0 -1
  169. package/dist/context/TemplateVariableProvider/query-params.test.js +0 -80
  170. package/dist/context/TemplateVariableProvider/query-params.test.js.map +0 -1
  171. package/dist/utils/panelUtils.test.d.ts +0 -2
  172. package/dist/utils/panelUtils.test.d.ts.map +0 -1
  173. package/dist/utils/panelUtils.test.js +0 -193
  174. package/dist/utils/panelUtils.test.js.map +0 -1
  175. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +0 -2
  176. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +0 -1
  177. package/dist/views/ViewDashboard/tests/panelGroups.test.js +0 -103
  178. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +0 -1
@@ -0,0 +1,12 @@
1
+ import { StateCreator } from 'zustand';
2
+ import { Middleware } from './common';
3
+ export interface EditJsonDialogSlice {
4
+ editJsonDialog?: EditJsonDialogState;
5
+ openEditJsonDialog: () => void;
6
+ closeEditJsonDialog: () => void;
7
+ }
8
+ export interface EditJsonDialogState {
9
+ isOpen: boolean;
10
+ }
11
+ export declare const createEditJsonDialogSlice: StateCreator<EditJsonDialogSlice, Middleware, [], EditJsonDialogSlice>;
12
+ //# sourceMappingURL=edit-json-dialog-slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-json-dialog-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/edit-json-dialog-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,EAAE,YAAY,CAAC,mBAAmB,EAAE,UAAU,EAAE,EAAE,EAAE,mBAAmB,CAkB3G,CAAC"}
@@ -0,0 +1,30 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export const createEditJsonDialogSlice = (set)=>({
14
+ openEditJsonDialog () {
15
+ set((state)=>{
16
+ state.editJsonDialog = {
17
+ isOpen: true
18
+ };
19
+ });
20
+ },
21
+ closeEditJsonDialog () {
22
+ set((state)=>{
23
+ state.editJsonDialog = {
24
+ isOpen: false
25
+ };
26
+ });
27
+ }
28
+ });
29
+
30
+ //# sourceMappingURL=edit-json-dialog-slice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/edit-json-dialog-slice.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface EditJsonDialogSlice {\n editJsonDialog?: EditJsonDialogState;\n openEditJsonDialog: () => void;\n closeEditJsonDialog: () => void;\n}\n\nexport interface EditJsonDialogState {\n isOpen: boolean;\n}\n\nexport const createEditJsonDialogSlice: StateCreator<EditJsonDialogSlice, Middleware, [], EditJsonDialogSlice> = (\n set\n) => ({\n openEditJsonDialog() {\n set((state) => {\n state.editJsonDialog = {\n isOpen: true,\n };\n });\n },\n\n closeEditJsonDialog() {\n set((state) => {\n state.editJsonDialog = {\n isOpen: false,\n };\n });\n },\n});\n"],"names":["createEditJsonDialogSlice","set","openEditJsonDialog","state","editJsonDialog","isOpen","closeEditJsonDialog"],"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,OAAO,MAAMA,yBAAyB,GAA2E,CAC/GC,GAAG,GACC,CAAA;QACJC,kBAAkB,IAAG;YACnBD,GAAG,CAAC,CAACE,KAAK,GAAK;gBACbA,KAAK,CAACC,cAAc,GAAG;oBACrBC,MAAM,EAAE,IAAI;iBACb,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QAEDC,mBAAmB,IAAG;YACpBL,GAAG,CAAC,CAACE,KAAK,GAAK;gBACbA,KAAK,CAACC,cAAc,GAAG;oBACrBC,MAAM,EAAE,KAAK;iBACd,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAA,AAAC,CAAC"}
@@ -1,9 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { DashboardResource, Datasource, DatasourceSelector, GlobalDatasource } from '@perses-dev/core';
3
+ import { DatasourceClient } from '@perses-dev/plugin-system';
3
4
  export interface DatasourceStoreProviderProps {
4
5
  dashboardResource: DashboardResource;
5
6
  datasourceApi: DatasourceApi;
6
7
  children?: React.ReactNode;
8
+ onCreate?: (client: DatasourceClient) => DatasourceClient;
7
9
  }
8
10
  export interface DatasourceApi {
9
11
  getDatasource: (project: string, selector: DatasourceSelector) => Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":";AAcA,OAAO,EACL,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAElB,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAQ1B,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAGD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,CACb,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,M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E,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAE3E,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAEjF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CAC7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,eAwG1E"}
@@ -17,7 +17,7 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
17
17
  /**
18
18
  * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
19
19
  */ export function DatasourceStoreProvider(props) {
20
- const { dashboardResource , datasourceApi , children } = props;
20
+ const { dashboardResource , datasourceApi , onCreate , children } = props;
21
21
  const { project } = dashboardResource.metadata;
22
22
  const { getPlugin , listPluginMetadata } = usePluginRegistry();
23
23
  const findDatasource = useEvent(async (selector)=>{
@@ -62,12 +62,18 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
62
62
  findDatasource(selector),
63
63
  getPlugin('Datasource', kind)
64
64
  ]);
65
- return plugin.createClient(spec.plugin.spec, {
65
+ // allows extending client
66
+ const client = plugin.createClient(spec.plugin.spec, {
66
67
  proxyUrl
67
68
  });
69
+ if (onCreate !== undefined) {
70
+ return onCreate(client);
71
+ }
72
+ return client;
68
73
  }, [
69
74
  findDatasource,
70
- getPlugin
75
+ getPlugin,
76
+ onCreate
71
77
  ]);
72
78
  const listDatasourceMetadata = useEvent(async (datasourcePluginKind)=>{
73
79
  const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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,GAAGT,iBAAiB,CAACU,IAAI,AAAC;QAC/C,MAAMC,mBAAmB,GAAGC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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 DatasourceClient,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceApi;\n children?: React.ReactNode;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\n// The external API for fetching datasource resources\nexport interface DatasourceApi {\n getDatasource: (\n project: string,\n selector: DatasourceSelector\n ) => Promise<{ resource: Datasource; proxyUrl: string } | undefined>;\n\n getGlobalDatasource: (\n selector: DatasourceSelector\n ) => Promise<{ resource: GlobalDatasource; proxyUrl: string } | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { dashboardResource, datasourceApi, onCreate, 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 extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n 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","onCreate","children","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","datasource","getDatasource","resource","globalDatasource","getGlobalDatasource","Error","kind","name","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceMetadata","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addResult","buildListDatasourceMetadataResults","display","selectorName","ctxValue","Provider","value","dashboardDatasources","named","Object","values","ds","default","pluginDisplayName","usedNames","Set","defaultAdded","unshift","has","push","add"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE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lBZ,IAAkB,cAAlBA,IAAkB,GAAIgC,YAAY;YACxClC,QAAQ,EAAE;gBACRa,IAAI,EAAEX,IAAI,CAACe,MAAM,CAACJ,IAAI;gBACtBC,IAAI,EAAEoB,YAAY;aACnB;SACF,CAAC,CAAC;QACHW,SAAS,CAACM,GAAG,CAACjB,YAAY,CAAC,CAAC;IAC9B,CAAC,AAAC;IAEF,OAAO;QAAEJ,OAAO;QAAEC,SAAS;KAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,48 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { DashboardProvider } from '@perses-dev/dashboards';
15
+ // Type guard because storybook types parameters as `any`
16
+ function isWithDashboardParameter(parameter) {
17
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
18
+ }
19
+ export const DEFAULT_DASHBOARD_INITIAL_STATE = {
20
+ dashboardResource: {
21
+ kind: 'Dashboard',
22
+ metadata: {
23
+ name: 'My Dashboard',
24
+ project: 'Storybook',
25
+ created_at: '2021-11-09T00:00:00Z',
26
+ updated_at: '2021-11-09T00:00:00Z',
27
+ version: 0
28
+ },
29
+ spec: {
30
+ duration: '1h',
31
+ variables: [],
32
+ layouts: [],
33
+ panels: {}
34
+ }
35
+ }
36
+ };
37
+ export const WithDashboard = (Story, context)=>{
38
+ const initParameter = context.parameters.withDashboard;
39
+ const parameter = isWithDashboardParameter(initParameter) ? initParameter : undefined;
40
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
41
+ return /*#__PURE__*/ _jsx(DashboardProvider, {
42
+ initialState: DEFAULT_DASHBOARD_INITIAL_STATE,
43
+ ...props,
44
+ children: /*#__PURE__*/ _jsx(Story, {})
45
+ });
46
+ };
47
+
48
+ //# sourceMappingURL=WithDashboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithDashboard.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 { StoryFn, StoryContext } from '@storybook/react';\nimport { DashboardProvider, DashboardProviderProps, DashboardStoreProps } from '@perses-dev/dashboards';\n\nexport type WithDashboardParameter = {\n props: Partial<DashboardProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDashboardParameter(parameter: unknown | WithDashboardParameter): parameter is WithDashboardParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const DEFAULT_DASHBOARD_INITIAL_STATE: DashboardStoreProps = {\n dashboardResource: {\n kind: 'Dashboard',\n metadata: {\n name: 'My Dashboard',\n project: 'Storybook',\n created_at: '2021-11-09T00:00:00Z',\n updated_at: '2021-11-09T00:00:00Z',\n version: 0,\n },\n spec: {\n duration: '1h',\n variables: [],\n layouts: [],\n panels: {},\n },\n },\n};\n\nexport const WithDashboard = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withDashboard;\n const parameter = isWithDashboardParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <DashboardProvider initialState={DEFAULT_DASHBOARD_INITIAL_STATE} {...props}>\n <Story />\n </DashboardProvider>\n );\n};\n"],"names":["DashboardProvider","isWithDashboardParameter","parameter","DEFAULT_DASHBOARD_INITIAL_STATE","dashboardResource","kind","metadata","name","project","created_at","updated_at","version","spec","duration","variables","layouts","panels","WithDashboard","Story","context","initParameter","parameters","withDashboard","undefined","props","initialState"],"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;AACA,SAASA,iBAAiB,QAAqD,wBAAwB,CAAC;AAMxG,yDAAyD;AACzD,SAASC,wBAAwB,CAACC,SAA2C,EAAuC;IAClH,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,+BAA+B,GAAwB;IAClEC,iBAAiB,EAAE;QACjBC,IAAI,EAAE,WAAW;QACjBC,QAAQ,EAAE;YACRC,IAAI,EAAE,cAAc;YACpBC,OAAO,EAAE,WAAW;YACpBC,UAAU,EAAE,sBAAsB;YAClCC,UAAU,EAAE,sBAAsB;YAClCC,OAAO,EAAE,CAAC;SACX;QACDC,IAAI,EAAE;YACJC,QAAQ,EAAE,IAAI;YACdC,SAAS,EAAE,EAAE;YACbC,OAAO,EAAE,EAAE;YACXC,MAAM,EAAE,EAAE;SACX;KACF;CACF,CAAC;AAEF,OAAO,MAAMC,aAAa,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IAC/E,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,aAAa,AAAC;IACvD,MAAMpB,SAAS,GAAGD,wBAAwB,CAACmB,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IACtF,MAAMC,KAAK,GAAGtB,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEsB,KAAK,AAAC;IAE/B,qBACE,KAACxB,iBAAiB;QAACyB,YAAY,EAAEtB,+BAA+B;QAAG,GAAGqB,KAAK;kBACzE,cAAA,KAACN,KAAK,KAAG;MACS,CACpB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { PluginRegistry, dynamicImportPluginLoader } from '@perses-dev/plugin-system';
15
+ // NOTE: the aliases we use for components break these top level imports, so we
16
+ // import relatively.
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
18
+ const prometheusResource = require('../../../../prometheus-plugin/plugin.json');
19
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
20
+ const panelsResource = require('../../../../panels-plugin/plugin.json');
21
+ const bundledPluginLoader = dynamicImportPluginLoader([
22
+ {
23
+ resource: prometheusResource,
24
+ // This throws an error in CI (but not locally for some reason), likely because
25
+ // this package isn't a dependency for dashboards. We probably do not want to
26
+ // make it one solely for type-checking in storybook.
27
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
28
+ // @ts-ignore
29
+ importPlugin: ()=>import('@perses-dev/prometheus-plugin')
30
+ },
31
+ {
32
+ resource: panelsResource,
33
+ // Same comment as above.
34
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
+ // @ts-ignore
36
+ importPlugin: ()=>import('@perses-dev/panels-plugin')
37
+ }
38
+ ]);
39
+ export const WithPluginRegistry = (Story)=>{
40
+ return /*#__PURE__*/ _jsx(PluginRegistry, {
41
+ pluginLoader: bundledPluginLoader,
42
+ children: /*#__PURE__*/ _jsx(Story, {})
43
+ });
44
+ };
45
+
46
+ //# sourceMappingURL=WithPluginRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithPluginRegistry.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 { StoryFn } from '@storybook/react';\nimport {\n PluginRegistry,\n PluginLoader,\n PluginModuleResource,\n dynamicImportPluginLoader,\n} from '@perses-dev/plugin-system';\n\n// NOTE: the aliases we use for components break these top level imports, so we\n// import relatively.\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst prometheusResource = require('../../../../prometheus-plugin/plugin.json');\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst panelsResource = require('../../../../panels-plugin/plugin.json');\n\nconst bundledPluginLoader: PluginLoader = dynamicImportPluginLoader([\n {\n resource: prometheusResource as PluginModuleResource,\n // This throws an error in CI (but not locally for some reason), likely because\n // this package isn't a dependency for dashboards. We probably do not want to\n // make it one solely for type-checking in storybook.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n importPlugin: () => import('@perses-dev/prometheus-plugin'),\n },\n {\n resource: panelsResource as PluginModuleResource,\n // Same comment as above.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n importPlugin: () => import('@perses-dev/panels-plugin'),\n },\n]);\n\nexport const WithPluginRegistry = (Story: StoryFn) => {\n return (\n <PluginRegistry pluginLoader={bundledPluginLoader}>\n <Story />\n </PluginRegistry>\n );\n};\n"],"names":["PluginRegistry","dynamicImportPluginLoader","prometheusResource","require","panelsResource","bundledPluginLoader","resource","importPlugin","WithPluginRegistry","Story","pluginLoader"],"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;AACA,SACEA,cAAc,EAGdC,yBAAyB,QACpB,2BAA2B,CAAC;AAEnC,+EAA+E;AAC/E,qBAAqB;AACrB,8DAA8D;AAC9D,MAAMC,kBAAkB,GAAGC,OAAO,CAAC,2CAA2C,CAAC,AAAC;AAChF,8DAA8D;AAC9D,MAAMC,cAAc,GAAGD,OAAO,CAAC,uCAAuC,CAAC,AAAC;AAExE,MAAME,mBAAmB,GAAiBJ,yBAAyB,CAAC;IAClE;QACEK,QAAQ,EAAEJ,kBAAkB;QAC5B,+EAA+E;QAC/E,6EAA6E;QAC7E,qDAAqD;QACrD,6DAA6D;QAC7D,aAAa;QACbK,YAAY,EAAE,IAAM,MAAM,CAAC,+BAA+B,CAAC;KAC5D;IACD;QACED,QAAQ,EAAEF,cAAc;QACxB,yBAAyB;QACzB,6DAA6D;QAC7D,aAAa;QACbG,YAAY,EAAE,IAAM,MAAM,CAAC,2BAA2B,CAAC;KACxD;CACF,CAAC,AAAC;AAEH,OAAO,MAAMC,kBAAkB,GAAG,CAACC,KAAc,GAAK;IACpD,qBACE,KAACT,cAAc;QAACU,YAAY,EAAEL,mBAAmB;kBAC/C,cAAA,KAACI,KAAK,KAAG;MACM,CACjB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
15
+ export const WithQueryClient = (Story)=>{
16
+ const queryClient = new QueryClient({});
17
+ return /*#__PURE__*/ _jsx(QueryClientProvider, {
18
+ client: queryClient,
19
+ children: /*#__PURE__*/ _jsx(Story, {})
20
+ });
21
+ };
22
+
23
+ //# sourceMappingURL=WithQueryClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithQueryClient.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 { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { StoryFn } from '@storybook/react';\n\nexport const WithQueryClient = (Story: StoryFn) => {\n const queryClient = new QueryClient({});\n\n return (\n <QueryClientProvider client={queryClient}>\n <Story />\n </QueryClientProvider>\n );\n};\n"],"names":["QueryClient","QueryClientProvider","WithQueryClient","Story","queryClient","client"],"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,mBAAmB,QAAQ,uBAAuB,CAAC;AAGzE,OAAO,MAAMC,eAAe,GAAG,CAACC,KAAc,GAAK;IACjD,MAAMC,WAAW,GAAG,IAAIJ,WAAW,CAAC,EAAE,CAAC,AAAC;IAExC,qBACE,KAACC,mBAAmB;QAACI,MAAM,EAAED,WAAW;kBACtC,cAAA,KAACD,KAAK,KAAG;MACW,CACtB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { WindowHistoryAdapter } from 'use-query-params/adapters/window';
15
+ import { QueryParamProvider } from 'use-query-params';
16
+ export const WithQueryParams = (Story)=>{
17
+ return /*#__PURE__*/ _jsx(QueryParamProvider, {
18
+ adapter: WindowHistoryAdapter,
19
+ children: /*#__PURE__*/ _jsx(Story, {})
20
+ });
21
+ };
22
+
23
+ //# sourceMappingURL=WithQueryParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithQueryParams.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 { WindowHistoryAdapter } from 'use-query-params/adapters/window';\nimport { QueryParamProvider } from 'use-query-params';\nimport { StoryFn } from '@storybook/react';\n\nexport const WithQueryParams = (Story: StoryFn) => {\n return (\n <QueryParamProvider adapter={WindowHistoryAdapter}>\n <Story />\n </QueryParamProvider>\n );\n};\n"],"names":["WindowHistoryAdapter","QueryParamProvider","WithQueryParams","Story","adapter"],"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,oBAAoB,QAAQ,kCAAkC,CAAC;AACxE,SAASC,kBAAkB,QAAQ,kBAAkB,CAAC;AAGtD,OAAO,MAAMC,eAAe,GAAG,CAACC,KAAc,GAAK;IACjD,qBACE,KAACF,kBAAkB;QAACG,OAAO,EAAEJ,oBAAoB;kBAC/C,cAAA,KAACG,KAAK,KAAG;MACU,CACrB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { TemplateVariableProvider } from '@perses-dev/dashboards';
15
+ export const WithTemplateVariables = (Story)=>{
16
+ return /*#__PURE__*/ _jsx(TemplateVariableProvider, {
17
+ children: /*#__PURE__*/ _jsx(Story, {})
18
+ });
19
+ };
20
+
21
+ //# sourceMappingURL=WithTemplateVariables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithTemplateVariables.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 { StoryFn } from '@storybook/react';\nimport { TemplateVariableProvider } from '@perses-dev/dashboards';\n\nexport const WithTemplateVariables = (Story: StoryFn) => {\n return (\n <TemplateVariableProvider>\n <Story />\n </TemplateVariableProvider>\n );\n};\n"],"names":["TemplateVariableProvider","WithTemplateVariables","Story"],"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;AACA,SAASA,wBAAwB,QAAQ,wBAAwB,CAAC;AAElE,OAAO,MAAMC,qBAAqB,GAAG,CAACC,KAAc,GAAK;IACvD,qBACE,KAACF,wBAAwB;kBACvB,cAAA,KAACE,KAAK,KAAG;MACgB,CAC3B;AACJ,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './WithDashboard';
14
+ export * from './WithPluginRegistry';
15
+ export * from './WithQueryClient';
16
+ export * from './WithQueryParams';
17
+ export * from './WithTemplateVariables';
18
+
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/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 './WithDashboard';\nexport * from './WithPluginRegistry';\nexport * from './WithQueryClient';\nexport * from './WithQueryParams';\nexport * from './WithTemplateVariables';\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,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -1,6 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { DashboardResource } from '@perses-dev/core';
3
+ import { EmptyDashboardProps } from '../../components';
3
4
  export interface DashboardAppProps {
5
+ emptyDashboardProps?: Partial<EmptyDashboardProps>;
4
6
  dashboardResource: DashboardResource;
5
7
  dashboardTitleComponent?: JSX.Element;
6
8
  onSave?: (entity: DashboardResource) => Promise<DashboardResource>;
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAChD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,gBAyEpD,CAAC"}
1
+ {"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAQL,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACnD,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IAEtC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAChD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,gBAuFpD,CAAC"}
@@ -14,10 +14,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
15
  import { Box } from '@mui/material';
16
16
  import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
17
- import { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog, DiscardChangesConfirmationDialog, DashboardToolbar, DeletePanelDialog } from '../../components';
17
+ import { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog, DiscardChangesConfirmationDialog, DashboardToolbar, DeletePanelDialog, EditJsonDialog } from '../../components';
18
18
  import { useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';
19
19
  export const DashboardApp = (props)=>{
20
- const { dashboardResource , dashboardTitleComponent , onSave , onDiscard , initialVariableIsSticky , isReadonly } = props;
20
+ const { dashboardResource , dashboardTitleComponent , emptyDashboardProps , onSave , onDiscard , initialVariableIsSticky , isReadonly , } = props;
21
21
  const { setEditMode } = useEditMode();
22
22
  const { dashboard , setDashboard } = useDashboard();
23
23
  const [originalDashboard, setOriginalDashboard] = useState(undefined);
@@ -72,18 +72,25 @@ export const DashboardApp = (props)=>{
72
72
  }),
73
73
  /*#__PURE__*/ _jsxs(Box, {
74
74
  sx: {
75
- padding: (theme)=>theme.spacing(2)
75
+ padding: (theme)=>theme.spacing(2),
76
+ height: '100%'
76
77
  },
77
78
  children: [
78
79
  /*#__PURE__*/ _jsx(ErrorBoundary, {
79
80
  FallbackComponent: ErrorAlert,
80
- children: /*#__PURE__*/ _jsx(Dashboard, {})
81
+ children: /*#__PURE__*/ _jsx(Dashboard, {
82
+ emptyDashboardProps: {
83
+ onEditButtonClick,
84
+ ...emptyDashboardProps
85
+ }
86
+ })
81
87
  }),
82
88
  /*#__PURE__*/ _jsx(PanelDrawer, {}),
83
89
  /*#__PURE__*/ _jsx(PanelGroupDialog, {}),
84
90
  /*#__PURE__*/ _jsx(DeletePanelGroupDialog, {}),
85
91
  /*#__PURE__*/ _jsx(DeletePanelDialog, {}),
86
- /*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {})
92
+ /*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {}),
93
+ /*#__PURE__*/ _jsx(EditJsonDialog, {})
87
94
  ]
88
95
  })
89
96
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.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 { useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport {\n PanelDrawer,\n Dashboard,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n} from '../../components';\nimport { useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n dashboardTitleComponent?: JSX.Element;\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n onDiscard?: (entity: DashboardResource) => void;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n}\n\nexport const DashboardApp = (props: DashboardAppProps) => {\n const { dashboardResource, dashboardTitleComponent, onSave, onDiscard, initialVariableIsSticky, isReadonly } = props;\n const { setEditMode } = useEditMode();\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = () => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard);\n }\n };\n\n const onEditButtonClick = () => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n };\n\n const onCancelButtonClick = () => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={initialVariableIsSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ padding: (theme) => theme.spacing(2) }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard />\n </ErrorBoundary>\n <PanelDrawer />\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DiscardChangesConfirmationDialog />\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ErrorAlert","ErrorBoundary","PanelDrawer","Dashboard","PanelGroupDialog","DeletePanelGroupDialog","DiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","DashboardApp","props","dashboardResource","dashboardTitleComponent","onSave","onDiscard","initialVariableIsSticky","isReadonly","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","onEditButtonClick","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","metadata","name","padding","theme","spacing","FallbackComponent"],"mappings":"AAAA,oCAAoC;AACpC,k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U;kCAC1C,cAAA,KAACG,SAAS,KAAG;sBACC;kCAChB,KAACD,WAAW,KAAG;kCACf,KAACE,gBAAgB,KAAG;kCACpB,KAACC,sBAAsB,KAAG;kCAC1B,KAACG,iBAAiB,KAAG;kCACrB,KAACF,gCAAgC,KAAG;;cAChC;;MACF,CACN;AACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.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 { useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport {\n PanelDrawer,\n Dashboard,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n EmptyDashboardProps,\n EditJsonDialog,\n} from '../../components';\nimport { useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\n\nexport interface DashboardAppProps {\n emptyDashboardProps?: Partial<EmptyDashboardProps>;\n dashboardResource: DashboardResource;\n dashboardTitleComponent?: JSX.Element;\n\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n onDiscard?: (entity: DashboardResource) => void;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n}\n\nexport const DashboardApp = (props: DashboardAppProps) => {\n const {\n dashboardResource,\n dashboardTitleComponent,\n emptyDashboardProps,\n onSave,\n onDiscard,\n initialVariableIsSticky,\n isReadonly,\n } = props;\n const { setEditMode } = useEditMode();\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = () => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard);\n }\n };\n\n const onEditButtonClick = () => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n };\n\n const onCancelButtonClick = () => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={initialVariableIsSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ padding: (theme) => theme.spacing(2), height: '100%' }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard\n emptyDashboardProps={{\n onEditButtonClick,\n ...emptyDashboardProps,\n }}\n />\n </ErrorBoundary>\n <PanelDrawer />\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DiscardChangesConfirmationDialog />\n <EditJsonDialog />\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ErrorAlert","ErrorBoundary","PanelDrawer","Dashboard","PanelGroupDialog","DeletePanelGroupDialog","DiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","EditJsonDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","DashboardApp","props","dashboardResource","dashboardTitleComponent","emptyDashboardProps","onSave","onDiscard","initialVariableIsSticky","isReadonly","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","onEditButtonClick","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","metadata","name","padding","theme","spacing","height","FallbackComponent"],"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,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAwB,CAAC;AAEnE,SACEC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,sBAAsB,EACtBC,gCAAgC,EAChCC,gBAAgB,EAChBC,iBAAiB,EAEjBC,cAAc,QACT,kBAAkB,CAAC;AAC1B,SAASC,YAAY,EAAEC,mCAAmC,EAAEC,WAAW,QAAQ,eAAe,CAAC;AAa/F,OAAO,MAAMC,YAAY,GAAG,CAACC,KAAwB,GAAK;IACxD,MAAM,EACJC,iBAAiB,CAAA,EACjBC,uBAAuB,CAAA,EACvBC,mBAAmB,CAAA,EACnBC,MAAM,CAAA,EACNC,SAAS,CAAA,EACTC,uBAAuB,CAAA,EACvBC,UAAU,CAAA,IACX,GAAGP,KAAK,AAAC;IACV,MAAM,EAAEQ,WAAW,CAAA,EAAE,GAAGV,WAAW,EAAE,AAAC;IACtC,MAAM,EAAEW,SAAS,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGd,YAAY,EAAE,AAAC;IACnD,MAA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AQ,CAACC,IAAI;gBAC9C7B,uBAAuB,EAAEA,uBAAuB;gBAChDI,uBAAuB,EAAEA,uBAAuB;gBAChDF,MAAM,EAAEA,MAAM;gBACdG,UAAU,EAAEA,UAAU;gBACtBU,iBAAiB,EAAEA,iBAAiB;gBACpCC,mBAAmB,EAAEA,mBAAmB;cACxC;0BACF,MAACjC,GAAG;gBAACsC,EAAE,EAAE;oBAAES,OAAO,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC;oBAAEC,MAAM,EAAE,MAAM;iBAAE;;kCAC/D,KAAChD,aAAa;wBAACiD,iBAAiB,EAAElD,UAAU;kCAC1C,cAAA,KAACG,SAAS;4BACRc,mBAAmB,EAAE;gCACnBc,iBAAiB;gCACjB,GAAGd,mBAAmB;6BACvB;0BACD;sBACY;kCAChB,KAACf,WAAW,KAAG;kCACf,KAACE,gBAAgB,KAAG;kCACpB,KAACC,sBAAsB,KAAG;kCAC1B,KAACG,iBAAiB,KAAG;kCACrB,KAACF,gCAAgC,KAAG;kCACpC,KAACG,cAAc,KAAG;;cACd;;MACF,CACN;AACJ,CAAC,CAAC"}
@@ -1,15 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { BoxProps } from '@mui/material';
3
- import { DashboardResource } from '@perses-dev/core';
4
3
  import { DatasourceStoreProviderProps } from '../../context';
5
- export interface ViewDashboardProps extends Omit<BoxProps, 'children'> {
6
- dashboardResource: DashboardResource;
4
+ import { DashboardAppProps } from './DashboardApp';
5
+ export interface ViewDashboardProps extends Omit<BoxProps, 'children'>, DashboardAppProps {
7
6
  datasourceApi: DatasourceStoreProviderProps['datasourceApi'];
8
- dashboardTitleComponent?: JSX.Element;
9
- onSave?: (entity: DashboardResource) => Promise<DashboardResource>;
10
- onDiscard?: (entity: DashboardResource) => void;
11
- initialVariableIsSticky?: boolean;
12
- isReadonly: boolean;
13
7
  isEditing?: boolean;
14
8
  }
15
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAGL,4BAA4B,EAE7B,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;IACpE,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,4BAA4B,CAAC,eAAe,CAAC,CAAC;IAC7D,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAChD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,eAmDtD"}
1
+ {"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EAGL,4BAA4B,EAE7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAgB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEjE,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,iBAAiB;IACvF,aAAa,EAAE,4BAA4B,CAAC,eAAe,CAAC,CAAC;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,eAqDtD"}
@@ -19,7 +19,7 @@ import { DashboardApp } from './DashboardApp';
19
19
  /**
20
20
  * The View for displaying a Dashboard, along with the UI for selecting variable values.
21
21
  */ export function ViewDashboard(props) {
22
- const { dashboardResource , datasourceApi , dashboardTitleComponent , onSave , onDiscard , initialVariableIsSticky , isReadonly , isEditing , sx , ...others } = props;
22
+ const { dashboardResource , datasourceApi , dashboardTitleComponent , emptyDashboardProps , onSave , onDiscard , initialVariableIsSticky , isReadonly , isEditing , sx , ...others } = props;
23
23
  const { spec } = dashboardResource;
24
24
  var _duration;
25
25
  const dashboardDuration = (_duration = spec.duration) !== null && _duration !== void 0 ? _duration : '1h';
@@ -51,6 +51,7 @@ import { DashboardApp } from './DashboardApp';
51
51
  children: /*#__PURE__*/ _jsx(DashboardApp, {
52
52
  dashboardResource: dashboardResource,
53
53
  dashboardTitleComponent: dashboardTitleComponent,
54
+ emptyDashboardProps: emptyDashboardProps,
54
55
  onSave: onSave,
55
56
  onDiscard: onDiscard,
56
57
  initialVariableIsSticky: initialVariableIsSticky,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.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 { Box, BoxProps } from '@mui/material';\nimport { DashboardResource } from '@perses-dev/core';\nimport { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';\nimport { TimeRangeProvider, useInitialTimeRange } from '@perses-dev/plugin-system';\nimport {\n TemplateVariableProvider,\n DashboardProvider,\n DatasourceStoreProviderProps,\n DatasourceStoreProvider,\n} from '../../context';\nimport { DashboardApp } from './DashboardApp';\n\nexport interface ViewDashboardProps extends Omit<BoxProps, 'children'> {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceStoreProviderProps['datasourceApi'];\n dashboardTitleComponent?: JSX.Element;\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n onDiscard?: (entity: DashboardResource) => void;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n isEditing?: boolean;\n}\n\n/**\n * The View for displaying a Dashboard, along with the UI for selecting variable values.\n */\nexport function ViewDashboard(props: ViewDashboardProps) {\n const {\n dashboardResource,\n datasourceApi,\n dashboardTitleComponent,\n onSave,\n onDiscard,\n initialVariableIsSticky,\n isReadonly,\n isEditing,\n sx,\n ...others\n } = props;\n const { spec } = dashboardResource;\n const dashboardDuration = spec.duration ?? '1h';\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n\n return (\n <DatasourceStoreProvider dashboardResource={dashboardResource} datasourceApi={datasourceApi}>\n <DashboardProvider initialState={{ dashboardResource, isEditMode: !!isEditing }}>\n <TimeRangeProvider initialTimeRange={initialTimeRange} enabledURLParams={true}>\n <TemplateVariableProvider initialVariableDefinitions={spec.variables}>\n <Box\n sx={combineSx(\n {\n display: 'flex',\n width: '100%',\n height: '100%',\n position: 'relative',\n overflow: 'hidden',\n },\n sx\n )}\n {...others}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardApp\n dashboardResource={dashboardResource}\n dashboardTitleComponent={dashboardTitleComponent}\n onSave={onSave}\n onDiscard={onDiscard}\n initialVariableIsSticky={initialVariableIsSticky}\n isReadonly={isReadonly}\n />\n </ErrorBoundary>\n </Box>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n </DashboardProvider>\n </DatasourceStoreProvider>\n );\n}\n"],"names":["Box","ErrorBoundary","ErrorAlert","combineSx","TimeRangeProvider","useInitialTimeRange","TemplateVariableProvider","DashboardProvider","DatasourceStoreProvider","DashboardApp","ViewDashboard","props","dashboardResource","datasourceApi","dashboardTitleComponent","onSave","onDiscard","initialVariableIsSticky","isReadonly","isEditing","sx","others","spec","dashboardDuration","duration","initialTimeRange","initialState","isEditMode","enabledURLParams","initialVariableDefinitions","variables","display","width","height","position","overflow","FallbackComponent"],"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,GAAG,QAAkB,eAAe,CAAC;AAE9C,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,QAAQ,wBAAwB,CAAC;AAC9E,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,2BAA2B,CAAC;AACnF,SACEC,wBAAwB,EACxBC,iBAAiB,EAEjBC,uBAAuB,QAClB,eAAe,CAAC;AACvB,SAASC,YAAY,QAAQ,gBAAgB,CAAC;AAa9C;;CAEC,GACD,OAAO,SAASC,aAAa,CAACC,KAAyB,EAAE;IACvD,MAAM,EACJC,iBAAiB,CAAA,EACjBC,aAAa,CAAA,EACbC,uBAAuB,CAAA,EACvBC,MAAM,CAAA,EACNC,SAAS,CAAA,EACTC,uBAAuB,CAAA,EACvBC,UAAU,CAAA,EACVC,SAAS,CAAA,EACTC,EAAE,CAAA,EACF,GAAGC,MAAM,EACV,GAAGV,KAAK,AAAC;IACV,MAAM,EAAEW,IAAI,CAAA,EAAE,GAAGV,iBAAiB,AAAC;QACTU,SAAa;IAAvC,MAAMC,iBAAiB,GAAGD,CAAAA,SAAa,GAAbA,IAAI,CAACE,QAAQ,cAAbF,SAAa,cAAbA,SAAa,GAAI,IAAI,AAAC;IAChD,MAAMG,gBAAgB,GAAGpB,mBAAmB,CAACkB,iBAAiB,CAAC,AAAC;IAEhE,qBACE,KAACf,uBAAuB;QAACI,iBAAiB,EAAEA,iBAAiB;QAAEC,aAAa,EAAEA,aAAa;kBACzF,cAAA,KAACN,iBAAiB;YAACmB,YAAY,EAAE;gBAAEd,iBAAiB;gBAAEe,UAAU,EAAE,CAAC,CAACR,SAAS;aAAE;sBAC7E,cAAA,KAACf,iBAAiB;gBAACqB,gBAAgB,EAAEA,gBAAgB;gBAAEG,gBAAgB,EAAE,IAAI;0BAC3E,cAAA,KAACtB,wBAAwB;oBAACuB,0BAA0B,EAAEP,IAAI,CAACQ,SAAS;8BAClE,cAAA,KAAC9B,GAAG;wBACFoB,EAAE,EAAEjB,SAAS,CACX;4BACE4B,OAAO,EAAE,MAAM;4BACfC,KAAK,EAAE,MAAM;4BACbC,MAAM,EAAE,MAAM;4BACdC,QAAQ,EAAE,UAAU;4BACpBC,QAAQ,EAAE,QAAQ;yBACnB,EACDf,EAAE,CACH;wBACA,GAAGC,MAAM;kCAEV,cAAA,KAACpB,aAAa;4BAACmC,iBAAiB,EAAElC,UAAU;sCAC1C,cAAA,KAACO,YAAY;gCACXG,iBAAiB,EAAEA,iBAAiB;gCACpCE,uBAAuB,EAAEA,uBAAuB;gCAChDC,MAAM,EAAEA,MAAM;gCACdC,SAAS,EAAEA,SAAS;gCACpBC,uBAAuB,EAAEA,uBAAuB;gCAChDC,UAAU,EAAEA,UAAU;8BACtB;0BACY;sBACZ;kBACmB;cACT;UACF;MACI,CAC1B;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.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 { Box, BoxProps } from '@mui/material';\nimport { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';\nimport { TimeRangeProvider, useInitialTimeRange } from '@perses-dev/plugin-system';\nimport {\n TemplateVariableProvider,\n DashboardProvider,\n DatasourceStoreProviderProps,\n DatasourceStoreProvider,\n} from '../../context';\nimport { DashboardApp, DashboardAppProps } from './DashboardApp';\n\nexport interface ViewDashboardProps extends Omit<BoxProps, 'children'>, DashboardAppProps {\n datasourceApi: DatasourceStoreProviderProps['datasourceApi'];\n isEditing?: boolean;\n}\n\n/**\n * The View for displaying a Dashboard, along with the UI for selecting variable values.\n */\nexport function ViewDashboard(props: ViewDashboardProps) {\n const {\n dashboardResource,\n datasourceApi,\n dashboardTitleComponent,\n emptyDashboardProps,\n onSave,\n onDiscard,\n initialVariableIsSticky,\n isReadonly,\n isEditing,\n sx,\n ...others\n } = props;\n const { spec } = dashboardResource;\n const dashboardDuration = spec.duration ?? '1h';\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n\n return (\n <DatasourceStoreProvider dashboardResource={dashboardResource} datasourceApi={datasourceApi}>\n <DashboardProvider initialState={{ dashboardResource, isEditMode: !!isEditing }}>\n <TimeRangeProvider initialTimeRange={initialTimeRange} enabledURLParams={true}>\n <TemplateVariableProvider initialVariableDefinitions={spec.variables}>\n <Box\n sx={combineSx(\n {\n display: 'flex',\n width: '100%',\n height: '100%',\n position: 'relative',\n overflow: 'hidden',\n },\n sx\n )}\n {...others}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardApp\n dashboardResource={dashboardResource}\n dashboardTitleComponent={dashboardTitleComponent}\n emptyDashboardProps={emptyDashboardProps}\n onSave={onSave}\n onDiscard={onDiscard}\n initialVariableIsSticky={initialVariableIsSticky}\n isReadonly={isReadonly}\n />\n </ErrorBoundary>\n </Box>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n </DashboardProvider>\n </DatasourceStoreProvider>\n );\n}\n"],"names":["Box","ErrorBoundary","ErrorAlert","combineSx","TimeRangeProvider","useInitialTimeRange","TemplateVariableProvider","DashboardProvider","DatasourceStoreProvider","DashboardApp","ViewDashboard","props","dashboardResource","datasourceApi","dashboardTitleComponent","emptyDashboardProps","onSave","onDiscard","initialVariableIsSticky","isReadonly","isEditing","sx","others","spec","dashboardDuration","duration","initialTimeRange","initialState","isEditMode","enabledURLParams","initialVariableDefinitions","variables","display","width","height","position","overflow","FallbackComponent"],"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,GAAG,QAAkB,eAAe,CAAC;AAC9C,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,QAAQ,wBAAwB,CAAC;AAC9E,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,2BAA2B,CAAC;AACnF,SACEC,wBAAwB,EACxBC,iBAAiB,EAEjBC,uBAAuB,QAClB,eAAe,CAAC;AACvB,SAASC,YAAY,QAA2B,gBAAgB,CAAC;AAOjE;;CAEC,GACD,OAAO,SAASC,aAAa,CAACC,KAAyB,EAAE;IACvD,MAAM,EACJC,iBAAiB,CAAA,EACjBC,aAAa,CAAA,EACbC,uBAAuB,CAAA,EACvBC,mBAAmB,CAAA,EACnBC,MAAM,CAAA,EACNC,SAAS,CAAA,EACTC,uBAAuB,CAAA,EACvBC,UAAU,CAAA,EACVC,SAAS,CAAA,EACTC,EAAE,CAAA,EACF,GAAGC,MAAM,EACV,GAAGX,KAAK,AAAC;IACV,MAAM,EAAEY,IAAI,CAAA,EAAE,GAAGX,iBAAiB,AAAC;QACTW,SAAa;IAAvC,MAAMC,iBAAiB,GAAGD,CAAAA,SAAa,GAAbA,IAAI,CAACE,QAAQ,cAAbF,SAAa,cAAbA,SAAa,GAAI,IAAI,AAAC;IAChD,MAAMG,gBAAgB,GAAGrB,mBAAmB,C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