@perses-dev/dashboards 0.7.1 → 0.8.1

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 (175) hide show
  1. package/dist/cjs/components/Dashboard.js +1 -1
  2. package/dist/cjs/components/DashboardToolbar.js +3 -18
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +3 -3
  4. package/dist/cjs/components/GridLayout/GridLayout.js +4 -7
  5. package/dist/cjs/components/GridLayout/GridTitle.js +15 -9
  6. package/dist/cjs/components/Panel/Panel.js +11 -6
  7. package/dist/cjs/components/Panel/Panel.test.js +17 -13
  8. package/dist/cjs/components/Panel/PanelContent.js +15 -0
  9. package/dist/cjs/components/Panel/index.js +29 -0
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +124 -0
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +111 -0
  12. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +19 -0
  13. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +60 -0
  14. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -0
  15. package/dist/cjs/components/{TimeRangeControls.js → TimeRangeControls/TimeRangeControls.js} +20 -31
  16. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +51 -0
  17. package/dist/cjs/components/TimeRangeControls/index.js +29 -0
  18. package/dist/cjs/components/Variables/Variable.js +57 -0
  19. package/dist/cjs/components/Variables/VariableList.js +27 -0
  20. package/dist/cjs/components/{VariableList → Variables}/index.js +1 -0
  21. package/dist/cjs/components/index.js +2 -3
  22. package/dist/cjs/context/DashboardAppSlice.js +45 -0
  23. package/dist/cjs/context/DashboardProvider.js +54 -36
  24. package/dist/cjs/context/LayoutsSlice.js +42 -0
  25. package/dist/cjs/context/QueryStringProvider.js +35 -0
  26. package/dist/cjs/context/TemplateVariableProvider.js +216 -0
  27. package/dist/cjs/context/TimeRangeProvider.js +66 -0
  28. package/dist/cjs/context/index.js +6 -3
  29. package/dist/cjs/css/styles.js +173 -169
  30. package/dist/cjs/test/plugin-registry.js +24 -17
  31. package/dist/cjs/test/render.js +11 -2
  32. package/dist/cjs/test/testDashboard.js +14 -37
  33. package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -0
  34. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +52 -0
  35. package/dist/cjs/views/ViewDashboard/index.js +29 -0
  36. package/dist/cjs/views/index.js +1 -1
  37. package/dist/components/Dashboard.d.ts.map +1 -1
  38. package/dist/components/Dashboard.js +1 -1
  39. package/dist/components/DashboardToolbar.d.ts +0 -1
  40. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  41. package/dist/components/DashboardToolbar.js +1 -1
  42. package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
  43. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  44. package/dist/components/GridLayout/GridItemContent.js +1 -1
  45. package/dist/components/GridLayout/GridLayout.d.ts +2 -1
  46. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  47. package/dist/components/GridLayout/GridLayout.js +1 -1
  48. package/dist/components/GridLayout/GridTitle.d.ts +1 -0
  49. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  50. package/dist/components/GridLayout/GridTitle.js +1 -1
  51. package/dist/components/Panel/Panel.d.ts +2 -0
  52. package/dist/components/Panel/Panel.d.ts.map +1 -1
  53. package/dist/components/Panel/Panel.js +1 -1
  54. package/dist/components/Panel/Panel.test.d.ts.map +1 -1
  55. package/dist/components/Panel/Panel.test.js +1 -1
  56. package/dist/components/Panel/PanelContent.d.ts +11 -0
  57. package/dist/components/Panel/PanelContent.d.ts.map +1 -0
  58. package/dist/components/Panel/PanelContent.js +1 -0
  59. package/dist/components/Panel/index.d.ts +2 -0
  60. package/dist/components/Panel/index.d.ts.map +1 -0
  61. package/dist/components/Panel/index.js +1 -0
  62. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -0
  63. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -0
  64. package/dist/components/PanelDrawer/PanelDrawer.js +1 -0
  65. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +2 -0
  66. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +1 -0
  67. package/dist/components/PanelDrawer/PanelDrawer.test.js +1 -0
  68. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +9 -0
  69. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +1 -0
  70. package/dist/components/PanelDrawer/PanelOptionsEditor.js +1 -0
  71. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -0
  72. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -0
  73. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
  74. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +2 -0
  75. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +1 -0
  76. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -0
  77. package/dist/components/{TimeRangeControls.d.ts → TimeRangeControls/TimeRangeControls.d.ts} +0 -0
  78. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
  79. package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -0
  80. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +2 -0
  81. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +1 -0
  82. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -0
  83. package/dist/components/TimeRangeControls/index.d.ts +2 -0
  84. package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
  85. package/dist/components/TimeRangeControls/index.js +1 -0
  86. package/dist/components/Variables/Variable.d.ts +8 -0
  87. package/dist/components/Variables/Variable.d.ts.map +1 -0
  88. package/dist/components/Variables/Variable.js +1 -0
  89. package/dist/components/Variables/VariableList.d.ts +3 -0
  90. package/dist/components/Variables/VariableList.d.ts.map +1 -0
  91. package/dist/components/Variables/VariableList.js +1 -0
  92. package/dist/components/Variables/index.d.ts +3 -0
  93. package/dist/components/Variables/index.d.ts.map +1 -0
  94. package/dist/components/Variables/index.js +1 -0
  95. package/dist/components/index.d.ts +2 -3
  96. package/dist/components/index.d.ts.map +1 -1
  97. package/dist/components/index.js +1 -1
  98. package/dist/context/DashboardAppSlice.d.ts +26 -0
  99. package/dist/context/DashboardAppSlice.d.ts.map +1 -0
  100. package/dist/context/DashboardAppSlice.js +1 -0
  101. package/dist/context/DashboardProvider.d.ts +8 -19
  102. package/dist/context/DashboardProvider.d.ts.map +1 -1
  103. package/dist/context/DashboardProvider.js +1 -1
  104. package/dist/context/LayoutsSlice.d.ts +12 -0
  105. package/dist/context/LayoutsSlice.d.ts.map +1 -0
  106. package/dist/context/LayoutsSlice.js +1 -0
  107. package/dist/context/QueryStringProvider.d.ts +13 -0
  108. package/dist/context/QueryStringProvider.d.ts.map +1 -0
  109. package/dist/context/QueryStringProvider.js +1 -0
  110. package/dist/context/TemplateVariableProvider.d.ts +25 -0
  111. package/dist/context/TemplateVariableProvider.d.ts.map +1 -0
  112. package/dist/context/TemplateVariableProvider.js +1 -0
  113. package/dist/context/TimeRangeProvider.d.ts +12 -0
  114. package/dist/context/TimeRangeProvider.d.ts.map +1 -0
  115. package/dist/context/TimeRangeProvider.js +1 -0
  116. package/dist/context/index.d.ts +5 -2
  117. package/dist/context/index.d.ts.map +1 -1
  118. package/dist/context/index.js +1 -1
  119. package/dist/css/styles.d.ts +7 -7
  120. package/dist/css/styles.d.ts.map +1 -1
  121. package/dist/css/styles.js +1 -1
  122. package/dist/test/plugin-registry.d.ts +4 -2
  123. package/dist/test/plugin-registry.d.ts.map +1 -1
  124. package/dist/test/plugin-registry.js +1 -1
  125. package/dist/test/render.d.ts +2 -1
  126. package/dist/test/render.d.ts.map +1 -1
  127. package/dist/test/render.js +1 -1
  128. package/dist/test/testDashboard.d.ts.map +1 -1
  129. package/dist/test/testDashboard.js +1 -1
  130. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
  131. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
  132. package/dist/views/ViewDashboard/DashboardApp.js +1 -0
  133. package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +1 -1
  134. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
  135. package/dist/views/ViewDashboard/ViewDashboard.js +1 -0
  136. package/dist/views/ViewDashboard/index.d.ts +2 -0
  137. package/dist/views/ViewDashboard/index.d.ts.map +1 -0
  138. package/dist/views/ViewDashboard/index.js +1 -0
  139. package/package.json +9 -11
  140. package/dist/cjs/components/AddPanel/AddPanel.js +0 -75
  141. package/dist/cjs/components/VariableAutocomplete.js +0 -63
  142. package/dist/cjs/components/VariableList/VariableList.js +0 -42
  143. package/dist/cjs/components/VariableList/VariableList.test.js +0 -86
  144. package/dist/cjs/context/TemplateVariablesProvider.js +0 -142
  145. package/dist/cjs/context/TimeRangeStateProvider.js +0 -49
  146. package/dist/cjs/views/DashboardApp.js +0 -46
  147. package/dist/cjs/views/ViewDashboard.js +0 -15
  148. package/dist/components/AddPanel/AddPanel.d.ts +0 -8
  149. package/dist/components/AddPanel/AddPanel.d.ts.map +0 -1
  150. package/dist/components/AddPanel/AddPanel.js +0 -1
  151. package/dist/components/TimeRangeControls.d.ts.map +0 -1
  152. package/dist/components/TimeRangeControls.js +0 -1
  153. package/dist/components/VariableAutocomplete.d.ts +0 -21
  154. package/dist/components/VariableAutocomplete.d.ts.map +0 -1
  155. package/dist/components/VariableAutocomplete.js +0 -1
  156. package/dist/components/VariableList/VariableList.d.ts +0 -11
  157. package/dist/components/VariableList/VariableList.d.ts.map +0 -1
  158. package/dist/components/VariableList/VariableList.js +0 -1
  159. package/dist/components/VariableList/VariableList.test.d.ts +0 -2
  160. package/dist/components/VariableList/VariableList.test.d.ts.map +0 -1
  161. package/dist/components/VariableList/VariableList.test.js +0 -1
  162. package/dist/components/VariableList/index.d.ts +0 -2
  163. package/dist/components/VariableList/index.d.ts.map +0 -1
  164. package/dist/components/VariableList/index.js +0 -1
  165. package/dist/context/TemplateVariablesProvider.d.ts +0 -23
  166. package/dist/context/TemplateVariablesProvider.d.ts.map +0 -1
  167. package/dist/context/TemplateVariablesProvider.js +0 -1
  168. package/dist/context/TimeRangeStateProvider.d.ts +0 -22
  169. package/dist/context/TimeRangeStateProvider.d.ts.map +0 -1
  170. package/dist/context/TimeRangeStateProvider.js +0 -1
  171. package/dist/views/DashboardApp.d.ts +0 -4
  172. package/dist/views/DashboardApp.d.ts.map +0 -1
  173. package/dist/views/DashboardApp.js +0 -1
  174. package/dist/views/ViewDashboard.d.ts.map +0 -1
  175. package/dist/views/ViewDashboard.js +0 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockPluginRegistryProps = void 0;
3
+ exports.FAKE_PANEL_PLUGIN = exports.mockPluginRegistryProps = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
5
  /**
5
6
  * Helper for mocking `PluginRegistry` data during tests. Returns props that can be spread on the `PluginRegistry`
6
7
  * component so that it will load the mock plugins you setup. You can use the `addMockPlugin` function that's returned
@@ -8,29 +9,26 @@ exports.mockPluginRegistryProps = void 0;
8
9
  */
9
10
  function mockPluginRegistryProps() {
10
11
  const mockPluginResource = {
11
- kind: 'Plugin',
12
+ kind: 'PluginModule',
12
13
  metadata: {
13
- name: 'Fake Plugin for Tests',
14
+ name: 'Fake Plugin Module for Tests',
14
15
  },
15
16
  spec: {
16
- supported_kinds: {},
17
+ plugins: [],
17
18
  },
18
19
  };
20
+ const mockPluginModule = {};
19
21
  // Allow adding mock plugins in tests
20
- const mockSetupFunctions = [];
21
- const addMockPlugin = (config) => {
22
- mockPluginResource.spec.supported_kinds[config.kind] = config.pluginType;
23
- mockSetupFunctions.push((registerPlugin) => {
24
- registerPlugin(config);
22
+ const addMockPlugin = (pluginType, kind, plugin) => {
23
+ mockPluginResource.spec.plugins.push({
24
+ pluginType,
25
+ kind,
26
+ display: {
27
+ name: `Fake ${pluginType} Plugin for ${kind}`,
28
+ },
25
29
  });
26
- };
27
- // Our mock plugin module just calls all the setup functions that were added
28
- const mockPluginModule = {
29
- setup(registerPlugin) {
30
- for (const setup of mockSetupFunctions) {
31
- setup(registerPlugin);
32
- }
33
- },
30
+ // "Export" on the module under the same name as the kind the plugin handles
31
+ mockPluginModule[kind] = plugin;
34
32
  };
35
33
  const pluginRegistryProps = {
36
34
  getInstalledPlugins() {
@@ -46,3 +44,12 @@ function mockPluginRegistryProps() {
46
44
  };
47
45
  }
48
46
  exports.mockPluginRegistryProps = mockPluginRegistryProps;
47
+ exports.FAKE_PANEL_PLUGIN = {
48
+ PanelComponent: () => {
49
+ return (0, jsx_runtime_1.jsx)("div", { role: "figure", children: "FakePanel chart" });
50
+ },
51
+ OptionsEditorComponent: () => {
52
+ return (0, jsx_runtime_1.jsx)("div", { children: "Edit options here" });
53
+ },
54
+ createInitialOptions: () => ({}),
55
+ };
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.renderWithContext = void 0;
4
7
  const jsx_runtime_1 = require("react/jsx-runtime");
@@ -16,11 +19,17 @@ const jsx_runtime_1 = require("react/jsx-runtime");
16
19
  // limitations under the License.
17
20
  const react_1 = require("@testing-library/react");
18
21
  const react_query_1 = require("react-query");
22
+ const context_1 = require("../context");
23
+ const testDashboard_1 = __importDefault(require("./testDashboard"));
19
24
  const queryClient = new react_query_1.QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false } } });
25
+ const initialStore = {
26
+ isEditMode: true,
27
+ dashboardSpec: testDashboard_1.default.spec,
28
+ };
20
29
  /**
21
30
  * Test helper to render a React component with some common app-level providers wrapped around it.
22
31
  */
23
- function renderWithContext(ui, options) {
24
- return (0, react_1.render)((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: ui }), options);
32
+ function renderWithContext(ui, initialState = initialStore, options) {
33
+ return (0, react_1.render)((0, jsx_runtime_1.jsx)(context_1.DashboardProvider, { initialState: initialState, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: ui }) }), options);
25
34
  }
26
35
  exports.renderWithContext = renderWithContext;
@@ -23,53 +23,30 @@ const testDashboard = {
23
23
  },
24
24
  spec: {
25
25
  datasource: { kind: 'Prometheus', global: true, name: 'Public Prometheus Demo Server' },
26
- // TODO: Should duration actually be a time range?
27
26
  duration: '24h',
28
- variables: {
29
- job: {
30
- kind: 'PrometheusLabelValues',
27
+ variables: [
28
+ {
29
+ name: 'job',
30
+ kind: 'TextVariable',
31
31
  options: {
32
- label_name: 'job',
33
- match: ['node_uname_info'],
34
- },
35
- display: {
36
- label: 'Job',
37
- },
38
- selection: {
39
- default_value: 'node',
32
+ value: 'node',
40
33
  },
41
34
  },
42
- instance: {
43
- kind: 'PrometheusLabelValues',
35
+ {
36
+ name: 'instance',
37
+ kind: 'TextVariable',
44
38
  options: {
45
- label_name: 'instance',
46
- match: ['node_uname_info{job="node"}'],
47
- },
48
- display: {
49
- label: 'Node',
50
- },
51
- selection: {
52
- default_value: ['demo.do.prometheus.io:9100'],
53
- all_value: '$__all',
39
+ value: 'demo.do.prometheus.io:9100',
54
40
  },
55
41
  },
56
- interval: {
57
- kind: 'Interval',
42
+ {
43
+ name: 'interval',
44
+ kind: 'TextVariable',
58
45
  options: {
59
- values: ['1m', '5m', '10m', '1h'],
60
- auto: {
61
- step_count: 50,
62
- min_interval: '1m',
63
- },
64
- },
65
- display: {
66
- label: 'Interval',
67
- },
68
- selection: {
69
- default_value: '1m',
46
+ value: '1m',
70
47
  },
71
48
  },
72
- },
49
+ ],
73
50
  panels: {
74
51
  cpu: {
75
52
  kind: 'LineChart',
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DashboardApp = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ // Copyright 2022 The Perses Authors
9
+ // Licensed under the Apache License, Version 2.0 (the "License");
10
+ // you may not use this file except in compliance with the License.
11
+ // You may obtain a copy of the License at
12
+ //
13
+ // http://www.apache.org/licenses/LICENSE-2.0
14
+ //
15
+ // Unless required by applicable law or agreed to in writing, software
16
+ // distributed under the License is distributed on an "AS IS" BASIS,
17
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ // See the License for the specific language governing permissions and
19
+ // limitations under the License.
20
+ const material_1 = require("@mui/material");
21
+ const components_1 = require("@perses-dev/components");
22
+ const components_2 = require("../../components");
23
+ const PanelGroupDialog_1 = __importDefault(require("../../components/PanelGroupDialog/PanelGroupDialog"));
24
+ const PanelDrawer_1 = __importDefault(require("../../components/PanelDrawer/PanelDrawer"));
25
+ const DashboardToolbar_1 = require("../../components/DashboardToolbar");
26
+ const context_1 = require("../../context");
27
+ const DashboardApp = (props) => {
28
+ const { dashboardResource } = props;
29
+ const { dashboard } = (0, context_1.useDashboard)();
30
+ const { panelGroupDialog } = (0, context_1.useDashboardApp)();
31
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
32
+ padding: (theme) => theme.spacing(1, 2),
33
+ flexGrow: 1,
34
+ overflowX: 'hidden',
35
+ overflowY: 'auto',
36
+ display: 'flex',
37
+ flexDirection: 'column',
38
+ }, children: [(0, jsx_runtime_1.jsx)(DashboardToolbar_1.DashboardToolbar, { dashboardName: dashboardResource.metadata.name }), (0, jsx_runtime_1.jsx)(components_1.ErrorBoundary, { FallbackComponent: components_1.ErrorAlert, children: (0, jsx_runtime_1.jsx)(components_2.TemplateVariableList, {}) }), (0, jsx_runtime_1.jsx)(components_1.ErrorBoundary, { FallbackComponent: components_1.ErrorAlert, children: (0, jsx_runtime_1.jsx)(components_2.Dashboard, { spec: dashboard }) }), (0, jsx_runtime_1.jsx)(PanelDrawer_1.default, {}), panelGroupDialog && (0, jsx_runtime_1.jsx)(PanelGroupDialog_1.default, {})] }));
39
+ };
40
+ exports.DashboardApp = DashboardApp;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewDashboard = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const react_1 = require("react");
18
+ const material_1 = require("@mui/material");
19
+ const core_1 = require("@perses-dev/core");
20
+ const plugin_system_1 = require("@perses-dev/plugin-system");
21
+ const components_1 = require("@perses-dev/components");
22
+ const context_1 = require("../../context");
23
+ const DashboardApp_1 = require("./DashboardApp");
24
+ /**
25
+ * The View for displaying a Dashboard, along with the UI for selecting variable values.
26
+ */
27
+ function ViewDashboard(props) {
28
+ var _a;
29
+ const { dashboardResource, sx, ...others } = props;
30
+ const { spec } = dashboardResource;
31
+ const { queryString, setQueryString } = (0, plugin_system_1.useQueryString)();
32
+ const dashboardDuration = (_a = spec.duration) !== null && _a !== void 0 ? _a : '1h';
33
+ const defaultTimeRange = (0, core_1.getDefaultTimeRange)(dashboardDuration, queryString);
34
+ // TODO: add reusable sync query string or no-op util
35
+ (0, react_1.useEffect)(() => {
36
+ const currentParams = Object.fromEntries([...queryString]);
37
+ // if app does not provide query string implementation, setTimeRange is used instead
38
+ if (!currentParams.start && setQueryString) {
39
+ // default to duration in dashboard definition if start param is not already set
40
+ queryString.set('start', dashboardDuration);
41
+ setQueryString(queryString);
42
+ }
43
+ }, [dashboardDuration, queryString, setQueryString]);
44
+ return ((0, jsx_runtime_1.jsx)(context_1.DashboardProvider, { initialState: { dashboardSpec: spec }, children: (0, jsx_runtime_1.jsx)(context_1.TimeRangeProvider, { initialTimeRange: defaultTimeRange, children: (0, jsx_runtime_1.jsx)(context_1.TemplateVariableProvider, { initialVariableDefinitions: spec.variables, children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: (0, components_1.combineSx)({
45
+ display: 'flex',
46
+ width: '100%',
47
+ height: '100%',
48
+ position: 'relative',
49
+ overflow: 'hidden',
50
+ }, sx), ...others, children: (0, jsx_runtime_1.jsx)(components_1.ErrorBoundary, { FallbackComponent: components_1.ErrorAlert, children: (0, jsx_runtime_1.jsx)(DashboardApp_1.DashboardApp, { dashboardResource: dashboardResource }) }) }) }) }) }));
51
+ }
52
+ exports.ViewDashboard = ViewDashboard;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright 2022 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./ViewDashboard"), exports);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021 The Perses Authors
2
+ // Copyright 2022 The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"file":"Dashboard.d.ts","sourceRoot":"","sources":["../../src/components/Dashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,IAAI,EAAE,aAAa,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAgB9C"}
1
+ {"version":3,"file":"Dashboard.d.ts","sourceRoot":"","sources":["../../src/components/Dashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,IAAI,EAAE,aAAa,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAmB9C"}
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{Box}from"@mui/material";import{ErrorBoundary,ErrorAlert}from"@perses-dev/components";import{GridLayout,GridItemContent}from"./GridLayout";export function Dashboard(r){const{spec:o,...t}=r;return _jsx(Box,{...t,children:_jsx(ErrorBoundary,{FallbackComponent:ErrorAlert,children:o.layouts.map(((r,t)=>_jsx(GridLayout,{definition:r,renderGridItemContent:r=>_jsx(GridItemContent,{content:r.content,spec:o})},t)))})})}
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Box}from"@mui/material";import{ErrorBoundary,ErrorAlert}from"@perses-dev/components";import{GridLayout,GridItemContent}from"./GridLayout";export function Dashboard(r){const{spec:o,...t}=r;return _jsx(Box,{...t,children:_jsx(ErrorBoundary,{FallbackComponent:ErrorAlert,children:o.layouts.map(((r,t)=>_jsx(GridLayout,{groupIndex:t,definition:r,renderGridItemContent:(r,t)=>_jsx(GridItemContent,{content:r.content,spec:o,groupIndex:t})},`${JSON.stringify(o.layouts)} ${t}`)))})})}
@@ -1,7 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export interface DashboardToolbarProps {
3
3
  dashboardName: string;
4
- onAddPanel: () => void;
5
4
  }
6
5
  export declare const DashboardToolbar: (props: DashboardToolbarProps) => JSX.Element;
7
6
  //# sourceMappingURL=DashboardToolbar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../src/components/DashboardToolbar.tsx"],"names":[],"mappings":";AAoBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBA4E5D,CAAC"}
1
+ {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../src/components/DashboardToolbar.tsx"],"names":[],"mappings":";AAmBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBA2D5D,CAAC"}
@@ -1 +1 @@
1
- import{jsxs as _jsxs,jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{Toolbar,Typography,Stack,Button,Box}from"@mui/material";import PencilIcon from"mdi-material-ui/PencilOutline";import AddIcon from"mdi-material-ui/Plus";import{useEditMode,useLayouts}from"../context";import{TimeRangeControls}from"../components";export const DashboardToolbar=i=>{const{dashboardName:t,onAddPanel:n}=i,{isEditMode:o,setEditMode:s}=useEditMode(),{addLayout:a}=useLayouts();return _jsx(Toolbar,{disableGutters:!0,sx:{display:"block",padding:i=>i.spacing(2,0)},children:o?_jsxs(_Fragment,{children:[_jsxs(Box,{sx:{display:"flex",width:"100%"},children:[_jsxs(Typography,{variant:"h2",children:["Edit ",t]}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(TimeRangeControls,{}),_jsx(Button,{variant:"outlined",onClick:()=>{s(!1)},children:"Cancel"}),_jsx(Button,{variant:"contained",children:"Save"})]})]}),_jsxs(Stack,{direction:"row",spacing:1,sx:{display:"flex",justifyContent:"flex-end",width:"100%",padding:i=>i.spacing(2,0)},children:[_jsx(Button,{startIcon:_jsx(AddIcon,{}),onClick:()=>{a({kind:"Grid",spec:{display:{title:"New Group",collapse:{open:!0}},items:[]}})},children:"Add Group"}),_jsx(Button,{startIcon:_jsx(AddIcon,{}),onClick:n,children:"Add Panel"})]})]}):_jsxs(Box,{sx:{display:"flex",width:"100%"},children:[_jsx(Typography,{variant:"h2",children:t}),_jsxs(Stack,{direction:"row",spacing:2,sx:{marginLeft:"auto"},children:[_jsx(TimeRangeControls,{}),_jsx(Button,{variant:"contained",startIcon:_jsx(PencilIcon,{}),onClick:()=>{s(!0)},sx:{marginLeft:"auto"},children:"Edit"})]})]})})};
1
+ import{jsxs as _jsxs,jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{Toolbar,Typography,Stack,Button,Box}from"@mui/material";import PencilIcon from"mdi-material-ui/PencilOutline";import AddIcon from"mdi-material-ui/Plus";import{useDashboardApp,useEditMode}from"../context";import{TimeRangeControls}from"../components";export const DashboardToolbar=n=>{const{dashboardName:o}=n,{isEditMode:i,setEditMode:t}=useEditMode(),{openPanelDrawer:a,openPanelGroupDialog:s}=useDashboardApp();return _jsx(Toolbar,{disableGutters:!0,sx:{display:"block",padding:n=>n.spacing(2,0)},children:i?_jsxs(_Fragment,{children:[_jsxs(Box,{sx:{display:"flex",width:"100%"},children:[_jsxs(Typography,{variant:"h2",children:["Edit ",o]}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(TimeRangeControls,{}),_jsx(Button,{variant:"outlined",onClick:()=>{t(!1)},children:"Cancel"}),_jsx(Button,{variant:"contained",children:"Save"})]})]}),_jsxs(Stack,{direction:"row",spacing:1,sx:{display:"flex",justifyContent:"flex-end",width:"100%",padding:n=>n.spacing(2,0)},children:[_jsx(Button,{startIcon:_jsx(AddIcon,{}),onClick:()=>s(),children:"Add Group"}),_jsx(Button,{startIcon:_jsx(AddIcon,{}),onClick:()=>a({groupIndex:0}),children:"Add Panel"})]})]}):_jsxs(Box,{sx:{display:"flex",width:"100%"},children:[_jsx(Typography,{variant:"h2",children:o}),_jsxs(Stack,{direction:"row",spacing:2,sx:{marginLeft:"auto"},children:[_jsx(TimeRangeControls,{}),_jsx(Button,{variant:"contained",startIcon:_jsx(PencilIcon,{}),onClick:()=>{t(!0)},sx:{marginLeft:"auto"},children:"Edit"})]})]})})};
@@ -3,6 +3,7 @@ import { DashboardSpec, GridItemDefinition } from '@perses-dev/core';
3
3
  export interface GridItemContentProps {
4
4
  spec: DashboardSpec;
5
5
  content: GridItemDefinition['content'];
6
+ groupIndex: number;
6
7
  }
7
8
  /**
8
9
  * Resolves the reference to panel content in a GridItemDefinition and renders the panel.
@@ -1 +1 @@
1
- {"version":3,"file":"GridItemContent.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridItemContent.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,kBAAkB,CAAC;AAGtF,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAQ1D"}
1
+ {"version":3,"file":"GridItemContent.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridItemContent.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,kBAAkB,CAAC;AAGtF,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAQ1D"}
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{ErrorAlert}from"@perses-dev/components";import{resolvePanelRef}from"@perses-dev/core";import{Panel}from"../Panel/Panel";export function GridItemContent(e){const{content:r,spec:o}=e;try{const e=resolvePanelRef(o,r);return _jsx(Panel,{definition:e})}catch(e){return _jsx(ErrorAlert,{error:e})}}
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{ErrorAlert}from"@perses-dev/components";import{resolvePanelRef}from"@perses-dev/core";import{Panel}from"../Panel/Panel";export function GridItemContent(e){const{content:r,spec:n,groupIndex:o}=e;try{const{panelDefinition:e,panelsKey:t}=resolvePanelRef(n,r);return _jsx(Panel,{definition:e,groupIndex:o,panelKey:t})}catch(e){return _jsx(ErrorAlert,{error:e})}}
@@ -2,8 +2,9 @@
2
2
  import { BoxProps } from '@mui/material';
3
3
  import { GridDefinition, GridItemDefinition } from '@perses-dev/core';
4
4
  export interface GridLayoutProps extends BoxProps {
5
+ groupIndex: number;
5
6
  definition: GridDefinition;
6
- renderGridItemContent: (definition: GridItemDefinition) => React.ReactNode;
7
+ renderGridItemContent: (definition: GridItemDefinition, groupIndex: number) => React.ReactNode;
7
8
  }
8
9
  /**
9
10
  * Layout component that arranges children in a Grid based on the definition.
@@ -1 +1 @@
1
- {"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAO,QAAQ,EAA0B,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtE,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,UAAU,EAAE,cAAc,CAAC;IAC3B,qBAAqB,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,KAAK,CAAC,SAAS,CAAC;CAC5E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAsDhD"}
1
+ {"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAO,QAAQ,EAA0B,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtE,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,qBAAqB,EAAE,CAAC,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;CAChG;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAwDhD"}
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useState}from"react";import{Responsive,WidthProvider}from"react-grid-layout";import{Box,Collapse,GlobalStyles}from"@mui/material";import styles from"../../css/styles";import{useEditMode}from"../../context";import{GridTitle}from"./GridTitle";const ResponsiveGridLayout=WidthProvider(Responsive);export function GridLayout(s){var e,i,o;const{definition:{spec:t},renderGridItemContent:l,...r}=s,[d,a]=useState(null===(o=null===(i=null===(e=t.display)||void 0===e?void 0:e.collapse)||void 0===i?void 0:i.open)||void 0===o||o),{isEditMode:n}=useEditMode(),m=[];return t.items.forEach(((s,e)=>{const{x:i,y:o,width:t,height:r}=s;m.push(_jsx("div",{"data-grid":{x:i,y:o,w:t,h:r},children:l(s)},e))})),_jsxs(_Fragment,{children:[_jsx(GlobalStyles,{styles}),_jsxs(Box,{...r,component:"section",sx:{"& + &":{marginTop:s=>s.spacing(1)}},children:[void 0!==t.display&&_jsx(GridTitle,{title:t.display.title,collapse:void 0===t.display.collapse?void 0:{isOpen:d,onToggleOpen:()=>a((s=>!s))}}),_jsx(Collapse,{in:d,unmountOnExit:!0,children:_jsx(ResponsiveGridLayout,{className:"layout",breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:24,md:24,sm:24,xs:24,xxs:2},rowHeight:30,draggableHandle:".drag-handle",resizeHandles:["se"],isDraggable:n,isResizable:n,children:m})})]})]})}
1
+ import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useState}from"react";import{Responsive,WidthProvider}from"react-grid-layout";import{Box,Collapse,GlobalStyles}from"@mui/material";import{styles}from"../../css/styles";import{useEditMode}from"../../context";import{GridTitle}from"./GridTitle";const ResponsiveGridLayout=WidthProvider(Responsive);export function GridLayout(e){var s,i,o;const{groupIndex:t,definition:{spec:r},renderGridItemContent:l,...d}=e,[a,n]=useState(null===(o=null===(i=null===(s=r.display)||void 0===s?void 0:s.collapse)||void 0===i?void 0:i.open)||void 0===o||o),{isEditMode:p}=useEditMode(),m=[];return r.items.forEach(((e,s)=>{const{x:i,y:o,width:r,height:d}=e;m.push(_jsx("div",{"data-grid":{x:i,y:o,w:r,h:d},children:l(e,t)},s))})),_jsxs(_Fragment,{children:[_jsx(GlobalStyles,{styles}),_jsxs(Box,{...d,component:"section",sx:{"& + &":{marginTop:e=>e.spacing(1)}},children:[void 0!==r.display&&_jsx(GridTitle,{groupIndex:t,title:r.display.title,collapse:void 0===r.display.collapse?void 0:{isOpen:a,onToggleOpen:()=>n((e=>!e))}}),_jsx(Collapse,{in:a,unmountOnExit:!0,children:_jsx(ResponsiveGridLayout,{className:"layout",breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:24,md:24,sm:24,xs:24,xxs:2},rowHeight:30,draggableHandle:".drag-handle",resizeHandles:["se"],isDraggable:p,isResizable:p,children:m})})]})]})}
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export interface GridTitleProps {
3
+ groupIndex: number;
3
4
  title: string;
4
5
  collapse?: {
5
6
  isOpen: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"GridTitle.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridTitle.tsx"],"names":[],"mappings":";AAiBA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,YAAY,EAAE,MAAM,IAAI,CAAC;KAC1B,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eA6B9C"}
1
+ {"version":3,"file":"GridTitle.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridTitle.tsx"],"names":[],"mappings":";AAqBA,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,YAAY,EAAE,MAAM,IAAI,CAAC;KAC1B,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAgD9C"}
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{ButtonBase,Typography}from"@mui/material";import ExpandedIcon from"mdi-material-ui/ChevronUp";import CollapsedIcon from"mdi-material-ui/ChevronDown";export function GridTitle(o){const{title:e,collapse:n}=o,t=_jsx(Typography,{variant:"h5",sx:{marginLeft:void 0!==n?1:void 0},children:e});return void 0===n?t:_jsxs(ButtonBase,{component:"header",sx:{display:"flex",justifyContent:"start",alignItems:"center"},onClick:n.onToggleOpen,children:[n.isOpen?_jsx(ExpandedIcon,{}):_jsx(CollapsedIcon,{}),t]})}
1
+ import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{Box,IconButton,Stack,Typography}from"@mui/material";import ExpandedIcon from"mdi-material-ui/ChevronUp";import CollapsedIcon from"mdi-material-ui/ChevronDown";import AddIcon from"mdi-material-ui/Plus";import PencilIcon from"mdi-material-ui/PencilOutline";import{useState}from"react";import{useDashboardApp,useEditMode}from"../../context";export function GridTitle(o){const{groupIndex:e,title:n,collapse:t}=o,[r,i]=useState(!1),{openPanelDrawer:a,openPanelGroupDialog:s}=useDashboardApp(),{isEditMode:d}=useEditMode(),c=_jsx(Typography,{variant:"h2",sx:{marginLeft:void 0!==t?1:void 0},children:n});return _jsx(Box,{sx:{display:"flex",justifyContent:"start",alignItems:"center",padding:o=>o.spacing(1),backgroundColor:o=>o.palette.background.default},onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:t?_jsxs(_Fragment,{children:[_jsx(IconButton,{onClick:t.onToggleOpen,children:t.isOpen?_jsx(ExpandedIcon,{}):_jsx(CollapsedIcon,{})}),c,d&&r&&_jsxs(Stack,{direction:"row",sx:{marginLeft:"auto"},children:[_jsx(IconButton,{onClick:()=>a({groupIndex:e}),children:_jsx(AddIcon,{})}),_jsx(IconButton,{onClick:()=>s(e),children:_jsx(PencilIcon,{})})]})]}):c})}
@@ -3,6 +3,8 @@ import { PanelDefinition } from '@perses-dev/core';
3
3
  import { CardProps } from '@mui/material';
4
4
  export interface PanelProps extends CardProps {
5
5
  definition: PanelDefinition;
6
+ groupIndex: number;
7
+ panelKey: string;
6
8
  }
7
9
  /**
8
10
  * Renders a PanelDefinition's content inside of a Card.
@@ -1 +1 @@
1
- {"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAGL,SAAS,EAOV,MAAM,eAAe,CAAC;AAOvB,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,UAAU,EAAE,eAAe,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,eAoHtC"}
1
+ {"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAGL,SAAS,EAOV,MAAM,eAAe,CAAC;AAOvB,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,UAAU,EAAE,eAAe,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,eA2HtC"}
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useMemo}from"react";import useResizeObserver from"use-resize-observer";import{useInView}from"react-intersection-observer";import{PluginBoundary,PanelComponent}from"@perses-dev/plugin-system";import{ErrorAlert,InfoTooltip,TooltipPlacement}from"@perses-dev/components";import{Box,Card,CardHeader,CardContent,Typography,IconButton as MuiIconButton,Stack,styled}from"@mui/material";import InformationOutlineIcon from"mdi-material-ui/InformationOutline";import PencilIcon from"mdi-material-ui/Pencil";import MenuIcon from"mdi-material-ui/DotsVertical";import DragIcon from"mdi-material-ui/Drag";import{useEditMode}from"../../context";export function Panel(e){const{definition:i,...o}=e,[n,r]=useState(null),{width:t,height:a}=useResizeObserver({ref:n}),s=useMemo((()=>{if(void 0!==t&&void 0!==a)return{width:t,height:a}}),[t,a]),{ref:l,inView:d}=useInView({threshold:.3,initialInView:!1,triggerOnce:!0}),{isEditMode:c}=useEditMode();return _jsxs(Card,{ref:l,sx:{...o.sx,width:"100%",height:"100%",display:"flex",flexFlow:"column nowrap"},variant:"outlined",...o,children:[_jsx(CardHeader,{title:_jsxs(Box,{sx:{display:"flex",alignItems:"center",minHeight:"24px"},children:[_jsx(Typography,{component:"h2",variant:"body2",fontWeight:e=>e.typography.fontWeightMedium,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",children:i.display.name}),_jsxs(Box,{sx:{display:"flex",alignItems:"center",marginLeft:"auto"},children:[!c&&i.display.description&&_jsx(InfoTooltip,{id:"info-tooltip",description:i.display.description,placement:TooltipPlacement.Bottom,children:_jsx(InformationOutlineIcon,{"aria-describedby":"info-tooltip","aria-hidden":!1,fontSize:"small",sx:{cursor:"pointer"}})}),c&&_jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[_jsx(IconButton,{"aria-label":"drag handle",size:"small",children:_jsx(DragIcon,{className:"drag-handle",sx:{cursor:"grab"}})}),_jsx(IconButton,{"aria-label":"edit panel",size:"small",children:_jsx(PencilIcon,{})}),_jsx(IconButton,{"aria-label":"more",size:"small",children:_jsx(MenuIcon,{})})]})]})]}),sx:{display:"block",padding:e=>e.spacing(1,1.5),borderBottom:e=>`solid 1px ${e.palette.divider}`}}),_jsx(CardContent,{sx:{position:"relative",overflow:"hidden",flexGrow:1,padding:e=>e.spacing(1.5),":last-child":{padding:e=>e.spacing(1.5)}},ref:r,children:_jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:!0===d&&_jsx(PanelComponent,{definition:i,contentDimensions:s})})})]})}const IconButton=styled(MuiIconButton)((({theme:e})=>({borderRadius:e.shape.borderRadius,padding:"4px"})));
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useMemo}from"react";import useResizeObserver from"use-resize-observer";import{useInView}from"react-intersection-observer";import{PluginBoundary}from"@perses-dev/plugin-system";import{ErrorAlert,InfoTooltip,TooltipPlacement}from"@perses-dev/components";import{Box,Card,CardHeader,CardContent,Typography,IconButton as MuiIconButton,Stack,styled}from"@mui/material";import InformationOutlineIcon from"mdi-material-ui/InformationOutline";import PencilIcon from"mdi-material-ui/Pencil";import DragIcon from"mdi-material-ui/DragVertical";import{useDashboardApp,useEditMode}from"../../context";import{PanelContent}from"./PanelContent";export function Panel(e){const{definition:i,groupIndex:o,panelKey:n,...r}=e,[t,a]=useState(null),[s,l]=useState(!1),{width:d,height:p}=useResizeObserver({ref:t}),c=useMemo((()=>{if(void 0!==d&&void 0!==p)return{width:d,height:p}}),[d,p]),{ref:m,inView:u}=useInView({threshold:.3,initialInView:!1,triggerOnce:!0}),{isEditMode:x}=useEditMode(),{openPanelDrawer:f}=useDashboardApp();return _jsxs(Card,{ref:m,sx:{...r.sx,width:"100%",height:"100%",display:"flex",flexFlow:"column nowrap"},variant:"outlined",...r,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),children:[_jsx(CardHeader,{title:_jsxs(Box,{sx:{display:"flex",alignItems:"center",minHeight:"24px"},children:[_jsx(Typography,{component:"h2",variant:"body2",fontWeight:e=>e.typography.fontWeightMedium,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",children:i.display.name}),_jsxs(Box,{sx:{display:"flex",alignItems:"center",marginLeft:"auto"},children:[!x&&s&&i.display.description&&_jsx(InfoTooltip,{id:"info-tooltip",description:i.display.description,placement:TooltipPlacement.Bottom,children:_jsx(InformationOutlineIcon,{"aria-describedby":"info-tooltip","aria-hidden":!1,fontSize:"small",sx:{cursor:"pointer"}})}),x&&s&&_jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[_jsx(IconButton,{"aria-label":"edit panel",size:"small",onClick:()=>{f({groupIndex:o,panelKey:n})},children:_jsx(PencilIcon,{})}),_jsx(IconButton,{"aria-label":"drag handle",size:"small",children:_jsx(DragIcon,{className:"drag-handle",sx:{cursor:"grab"}})})]})]})]}),sx:{display:"block",padding:e=>e.spacing(1,1.5),borderBottom:e=>`solid 1px ${e.palette.divider}`}}),_jsx(CardContent,{sx:{position:"relative",overflow:"hidden",flexGrow:1,padding:e=>e.spacing(1.5),":last-child":{padding:e=>e.spacing(1.5)}},ref:a,children:_jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:!0===u&&_jsx(PanelContent,{definition:i,contentDimensions:c})})})]})}const IconButton=styled(MuiIconButton)((({theme:e})=>({borderRadius:e.shape.borderRadius,padding:"4px"})));
@@ -1 +1 @@
1
- {"version":3,"file":"Panel.test.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.test.tsx"],"names":[],"mappings":"AAeA,OAAO,uBAAuB,CAAC"}
1
+ {"version":3,"file":"Panel.test.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.test.tsx"],"names":[],"mappings":"AAcA,OAAO,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{PluginRegistry}from"@perses-dev/plugin-system";import"intersection-observer";import{screen}from"@testing-library/react";import{renderWithContext,mockPluginRegistryProps}from"../../test";import testDashboard from"../../test/testDashboard";import{DashboardProvider}from"../../context";import{Panel}from"./Panel";const FAKE_PANEL_PLUGIN={pluginType:"Panel",kind:"FakePanel",plugin:{PanelComponent:()=>_jsx("div",{role:"figure",children:"FakePanel chart"})}};describe("Panel",(()=>{let e,r;beforeEach((()=>{e={definition:{display:{name:"Fake Panel",description:"This is a fake panel"},kind:"FakePanel",options:{}}},r={isEditMode:!1,dashboardSpec:testDashboard.spec}}));const i=r=>{const{addMockPlugin:i,pluginRegistryProps:n}=mockPluginRegistryProps();i(FAKE_PANEL_PLUGIN),renderWithContext(_jsx(DashboardProvider,{initialState:r,children:_jsx(PluginRegistry,{...n,children:_jsx(Panel,{...e})})}))};it("should render name and info icon",(async()=>{i(r),await screen.findByText("Fake Panel"),screen.queryByLabelText("info-tooltip")})),it("should render edit icons when in edit mode",(async()=>{r.isEditMode=!0,i(r),await screen.queryByLabelText("drag handle"),screen.queryByLabelText("edit panel"),screen.queryByLabelText("more")}))}));
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{PluginRegistry}from"@perses-dev/plugin-system";import"intersection-observer";import{screen}from"@testing-library/react";import{renderWithContext,mockPluginRegistryProps,FAKE_PANEL_PLUGIN}from"../../test";import testDashboard from"../../test/testDashboard";import{Panel}from"./Panel";describe("Panel",(()=>{let e,r;beforeEach((()=>{e={definition:{display:{name:"Fake Panel",description:"This is a fake panel"},kind:"FakePanel",options:{}},groupIndex:0,panelKey:"panelRef"},r={isEditMode:!1,dashboardSpec:testDashboard.spec}}));const n=r=>{const{addMockPlugin:n,pluginRegistryProps:t}=mockPluginRegistryProps();n("Panel","FakePanel",FAKE_PANEL_PLUGIN),renderWithContext(_jsx(PluginRegistry,{...t,children:_jsx(Panel,{...e})}),r)};it("should render name and info icon",(async()=>{n(),await screen.findByText("Fake Panel"),screen.queryByLabelText("info-tooltip")})),it("should render edit icons when in edit mode",(async()=>{r.isEditMode=!0,n(r),await screen.queryByLabelText("drag handle"),screen.queryByLabelText("edit panel"),screen.queryByLabelText("more")}))}));
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { JsonObject } from '@perses-dev/core';
3
+ import { PanelProps } from '@perses-dev/plugin-system';
4
+ export declare type PanelContentProps = PanelProps<JsonObject>;
5
+ /**
6
+ * A small wrapper component that renders the appropriate PanelComponent from a Panel plugin based on the panel
7
+ * definition's kind. Used so that a PluginLoadingBoundary can be wrapped around this for fallback UI while
8
+ * the plugin is loading.
9
+ */
10
+ export declare function PanelContent(props: PanelContentProps): JSX.Element;
11
+ //# sourceMappingURL=PanelContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelContent.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/PanelContent.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAkB,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvE,oBAAY,iBAAiB,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAGpD"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{usePanelPlugin}from"@perses-dev/plugin-system";export function PanelContent(n){const{PanelComponent:e}=usePanelPlugin(n.definition.kind);return _jsx(e,{...n})}
@@ -0,0 +1,2 @@
1
+ export * from './Panel';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC"}
@@ -0,0 +1 @@
1
+ export*from"./Panel";
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ declare const PanelDrawer: () => JSX.Element;
3
+ export default PanelDrawer;
4
+ //# sourceMappingURL=PanelDrawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelDrawer.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelDrawer.tsx"],"names":[],"mappings":";AAuCA,QAAA,MAAM,WAAW,mBA0JhB,CAAC;AA2BF,eAAe,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{MenuItem,Stack,Select,TextField,InputLabel,FormControl,Grid,Box,Button,Typography}from"@mui/material";import{Drawer,ErrorAlert}from"@perses-dev/components";import{PluginBoundary}from"@perses-dev/plugin-system";import{useState,useEffect}from"react";import{useDashboardApp,useLayouts,usePanels}from"../../context";import{removeWhiteSpacesAndSpecialCharacters}from"../../utils/functions";import{PanelOptionsEditor}from"./PanelOptionsEditor";const PanelDrawer=()=>{var e,l,n,a;const{layouts:r}=useLayouts(),{panels:i,updatePanel:t}=usePanels(),{panelDrawer:o,closePanelDrawer:s}=useDashboardApp();let d="",u="";(null==o?void 0:o.panelKey)&&(d=null!==(l=null===(e=i[o.panelKey])||void 0===e?void 0:e.display.name)&&void 0!==l?l:"",u=null!==(a=null===(n=i[o.panelKey])||void 0===n?void 0:n.display.description)&&void 0!==a?a:"");const[p,c]=useState(null==o?void 0:o.groupIndex),[x,v]=useState(d),[m,h]=useState(u),[y,g]=useState(""),[j,_]=useState({});useEffect((()=>{var e,l,n,a;c(null==o?void 0:o.groupIndex),(null==o?void 0:o.panelKey)?(v(null!==(l=null===(e=i[o.panelKey])||void 0===e?void 0:e.display.name)&&void 0!==l?l:""),h(null!==(a=null===(n=i[o.panelKey])||void 0===n?void 0:n.display.description)&&void 0!==a?a:"")):(v(""),h(""))}),[o,i]);return _jsx(Drawer,{isOpen:!!o,onClose:()=>s(),children:_jsxs("form",{onSubmit:e=>{e.preventDefault(),void 0===(null==o?void 0:o.groupIndex)||(null==o?void 0:o.panelKey)?(null==o?void 0:o.panelKey)&&(void 0!==(null==o?void 0:o.panelKey)&&t(o.panelKey,{...i[o.panelKey],kind:y,options:j,display:{name:null!=x?x:"",description:m}})):(()=>{if(void 0===(null==o?void 0:o.groupIndex))return;const e=removeWhiteSpacesAndSpecialCharacters(x);t(e,{kind:y,options:j,display:{name:x,description:m}},o.groupIndex)})(),s()},children:[_jsx(PanelDrawerHeader,{panelKey:null==o?void 0:o.panelKey,onClose:()=>s()}),_jsxs(Grid,{container:!0,spacing:2,children:[_jsx(Grid,{item:!0,xs:4,children:_jsxs(FormControl,{children:[_jsx(InputLabel,{id:"select-group",children:"Group"}),_jsx(Select,{required:!0,labelId:"select-group",label:"Group",value:null!=p?p:0,onChange:e=>{const{value:l}=e.target;"string"!=typeof l&&c(l)},children:r.map(((e,l)=>{var n;return _jsx(MenuItem,{value:l,children:(null===(n=e.spec.display)||void 0===n?void 0:n.title)||`Group ${l+1}`},l)}))})]})}),_jsx(Grid,{item:!0,xs:8,children:_jsxs(Stack,{spacing:2,sx:{flexGrow:"1"},children:[_jsx(TextField,{required:!0,label:"Panel Name",value:x,variant:"outlined",onChange:e=>{v(e.target.value)}}),_jsx(TextField,{label:"Description",value:m,variant:"outlined",onChange:e=>{h(e.target.value)}})]})}),_jsx(Grid,{item:!0,xs:4,children:_jsxs(FormControl,{children:[_jsx(InputLabel,{id:"panel-type-label",children:"Panel Type"}),_jsxs(Select,{required:!0,labelId:"panel-type-label",label:"Panel Type",value:y,onChange:e=>{g(e.target.value)},children:[_jsx(MenuItem,{value:"LineChart",children:"Line Chart"}),_jsx(MenuItem,{value:"GaugeChart",children:"Gauge Chart"}),_jsx(MenuItem,{value:"StatChart",children:"Stat Chart"})]})]})}),_jsx(Grid,{item:!0,xs:8,children:_jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:""!==y&&_jsx(PanelOptionsEditor,{kind:y,value:j,onChange:e=>{_(e)}})})})]})]})})},PanelDrawerHeader=({panelKey:e,onClose:l})=>_jsxs(Box,{sx:{display:"flex",alignItems:"center",marginBottom:e=>e.spacing(2),paddingBottom:e=>e.spacing(2),borderBottom:e=>`1px solid ${e.palette.grey[100]}`},children:[_jsx(Typography,{variant:"h2",children:(e?"Edit":"Add")+" Panel"}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(Button,{type:"submit",variant:"contained",children:e?"Apply":"Add"}),_jsx(Button,{variant:"outlined",onClick:l,children:"Cancel"})]})]});export default PanelDrawer;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PanelDrawer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelDrawer.test.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelDrawer.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{PluginRegistry}from"@perses-dev/plugin-system";import{screen}from"@testing-library/react";import userEvent from"@testing-library/user-event";import*as dashboardAppSlice from"../../context/DashboardAppSlice";import*as layoutsSlice from"../../context/LayoutsSlice";import*as context from"../../context/DashboardProvider";import{FAKE_PANEL_PLUGIN,mockPluginRegistryProps,renderWithContext}from"../../test";import testDashboard from"../../test/testDashboard";import PanelDrawer from"./PanelDrawer";const updatePanel=jest.fn();jest.spyOn(context,"usePanels").mockReturnValue({updatePanel,panels:{}});const addItemToLayout=jest.fn();jest.spyOn(layoutsSlice,"useLayouts").mockReturnValue({addItemToLayout,updateLayout:jest.fn(),layouts:testDashboard.spec.layouts});const dashboardApp={panelDrawer:{groupIndex:0},openPanelDrawer:jest.fn(),closePanelDrawer:jest.fn(),panelGroupDialog:void 0,openPanelGroupDialog:jest.fn(),closePanelGroupDialog:jest.fn()};describe("Panel Drawer",(()=>{beforeEach((()=>{jest.clearAllMocks()}));const e=()=>{const{addMockPlugin:e,pluginRegistryProps:t}=mockPluginRegistryProps();e("Panel","FakePanel",FAKE_PANEL_PLUGIN),renderWithContext(_jsxs(PluginRegistry,{...t,children:[_jsx(PanelDrawer,{}),","]}))};it("should add new panel",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue(dashboardApp),e();const t=screen.getByLabelText(/Panel Name/);userEvent.type(t,"New Panel"),userEvent.click(screen.getByText("Add")),expect(updatePanel).toHaveBeenCalledWith("NewPanel",{kind:"",display:{name:"New Panel",description:""},options:{}},0)})),it("should edit an existing panel",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue({...dashboardApp,panelDrawer:{groupIndex:0,panelKey:"cpu"}}),e();const t=screen.getByLabelText(/Panel Name/);userEvent.type(t,"cpu usage"),userEvent.click(screen.getByText("Apply")),expect(updatePanel).toHaveBeenCalledWith("cpu",{display:{name:"cpu usage",description:""},kind:"",options:{}})}))}));
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { JsonObject } from '@perses-dev/core';
3
+ export interface PanelOptionsEditorProps {
4
+ kind: string;
5
+ value: JsonObject;
6
+ onChange: (next: JsonObject) => void;
7
+ }
8
+ export declare function PanelOptionsEditor(props: PanelOptionsEditorProps): JSX.Element;
9
+ //# sourceMappingURL=PanelOptionsEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelOptionsEditor.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACtC;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,eAchE"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{usePanelPlugin}from"@perses-dev/plugin-system";import{useEffect}from"react";export function PanelOptionsEditor(e){const{kind:n,value:t,onChange:o}=e,{OptionsEditorComponent:s,createInitialOptions:i}=usePanelPlugin(n);return useEffect((()=>{o(i())}),[n]),_jsx(s,{value:t,onChange:o})}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ declare const PanelGroupDialog: () => JSX.Element;
3
+ export default PanelGroupDialog;
4
+ //# sourceMappingURL=PanelGroupDialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelGroupDialog.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.tsx"],"names":[],"mappings":";AAkCA,QAAA,MAAM,gBAAgB,mBA4FrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState}from"react";import{IconButton,Dialog,DialogTitle,DialogContent,FormControl,InputLabel,TextField,Stack,Box,DialogActions,Button,Select,MenuItem}from"@mui/material";import CloseIcon from"mdi-material-ui/Close";import{useDashboardApp,useLayouts}from"../../context";const PanelGroupDialog=()=>{var e,l,o,t,i;const{layouts:s,updateLayout:n}=useLayouts(),{panelGroupDialog:a,closePanelGroupDialog:r}=useDashboardApp(),{groupIndex:u}=a,d=void 0!==u,[p,c]=useState(d&&!(null===(o=null===(l=null===(e=s[u])||void 0===e?void 0:e.spec.display)||void 0===l?void 0:l.collapse)||void 0===o?void 0:o.open)),[x,m]=useState(d?null===(i=null===(t=s[u])||void 0===t?void 0:t.spec.display)||void 0===i?void 0:i.title:"");return _jsxs(Dialog,{open:!0,children:[_jsx(DialogTitle,{children:"Panel Group"}),_jsx(IconButton,{"aria-label":"Close",onClick:()=>r(),sx:e=>({position:"absolute",top:e.spacing(.5),right:e.spacing(.5)}),children:_jsx(CloseIcon,{})}),_jsxs("form",{onSubmit:e=>{var l,o;e.preventDefault();const t={kind:"Grid",spec:{display:{title:null!=x?x:"",collapse:{open:!p}},items:void 0===u?[]:null!==(o=null===(l=s[u])||void 0===l?void 0:l.spec.items)&&void 0!==o?o:[]}};n(t,u),r()},children:[_jsx(DialogContent,{sx:{width:"500px"},children:_jsxs(Stack,{spacing:2,children:[_jsx(FormControl,{children:_jsx(TextField,{required:!0,label:"Name",variant:"outlined",value:x,onChange:e=>m(e.target.value)})}),_jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[_jsx(InputLabel,{children:"Collapse State"}),_jsxs(Select,{required:!0,displayEmpty:!0,labelId:"select-collapse-state",size:"small",value:p?"Close":"Open",onChange:e=>{const l="Close"===e.target.value;c(l)},children:[_jsx(MenuItem,{value:"Open",children:"Open"},"open"),_jsx(MenuItem,{value:"Close",children:"Close"},"close")]})]})]})}),_jsxs(DialogActions,{children:[_jsx(Button,{variant:"contained",type:"submit",children:d?"Apply":"Add"}),_jsx(Button,{onClick:()=>r(),children:"Cancel"})]})]})]})};export default PanelGroupDialog;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PanelGroupDialog.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelGroupDialog.test.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{screen}from"@testing-library/react";import userEvent from"@testing-library/user-event";import produce from"immer";import*as dashboardAppSlice from"../../context/DashboardAppSlice";import*as layoutsSlice from"../../context/LayoutsSlice";import{renderWithContext}from"../../test";import testDashboard from"../../test/testDashboard";import PanelGroupDialog from"./PanelGroupDialog";const dashboardApp={panelDrawer:void 0,openPanelDrawer:jest.fn(),closePanelDrawer:jest.fn(),panelGroupDialog:{groupIndex:void 0},openPanelGroupDialog:jest.fn(),closePanelGroupDialog:jest.fn()},updateLayout=jest.fn();jest.spyOn(layoutsSlice,"useLayouts").mockReturnValue({updateLayout,addItemToLayout:jest.fn(),layouts:testDashboard.spec.layouts}),describe("Add Panel Group",(()=>{beforeEach((()=>{jest.clearAllMocks()})),it("should add new panel group",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue(dashboardApp),renderWithContext(_jsx(PanelGroupDialog,{}));const e=screen.getByLabelText(/Name/);userEvent.type(e,"New Panel Group"),userEvent.click(screen.getByText("Add")),expect(updateLayout).toHaveBeenCalledWith({kind:"Grid",spec:{display:{title:"New Panel Group",collapse:{open:!0}},items:[]}},void 0)})),it("should edit existing panel group",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue({...dashboardApp,panelGroupDialog:{groupIndex:0}}),renderWithContext(_jsx(PanelGroupDialog,{}));const e=screen.getByLabelText(/Name/);userEvent.type(e,"New Name"),userEvent.click(screen.getByText("Apply")),expect(updateLayout).toHaveBeenCalledWith(produce(testDashboard.spec.layouts[0],(e=>{e.spec.display.title+="New Name",e.spec.display.collapse={open:!1}})),0)}))}));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAyC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAY3F,eAAO,MAAM,YAAY,EAAE,UAAU,EAUpC,CAAC;AAEF,wBAAgB,iBAAiB,gBA2DhC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useRef,useState}from"react";import{Box,FormControl,Popover,Stack}from"@mui/material";import{AbsoluteTimePicker,TimeRangeSelector}from"@perses-dev/components";import{getDefaultTimeRange}from"@perses-dev/core";import{useTimeRange,useQueryString}from"@perses-dev/plugin-system";import{useDashboard}from"../../context";export const TIME_OPTIONS=[{value:{pastDuration:"5m"},display:"Last 5 minutes"},{value:{pastDuration:"15m"},display:"Last 15 minutes"},{value:{pastDuration:"30m"},display:"Last 30 minutes"},{value:{pastDuration:"1h"},display:"Last 1 hour"},{value:{pastDuration:"6h"},display:"Last 6 hours"},{value:{pastDuration:"12h"},display:"Last 12 hours"},{value:{pastDuration:"24h"},display:"Last 1 day"},{value:{pastDuration:"7d"},display:"Last 7 days"},{value:{pastDuration:"14d"},display:"Last 14 days"}];export function TimeRangeControls(){const{timeRange:e,setTimeRange:t}=useTimeRange(),{dashboard:a}=useDashboard(),{queryString:s}=useQueryString(),r=getDefaultTimeRange(a.duration,s),[o,i]=useState(r),[n,u]=useState(!1),l=useRef();return _jsxs(Stack,{direction:"row",spacing:1,children:[_jsx(Popover,{anchorEl:l.current,anchorOrigin:{vertical:"bottom",horizontal:"center"},open:n,onClose:()=>u(!1),sx:e=>({padding:e.spacing(2)}),children:_jsx(AbsoluteTimePicker,{initialTimeRange:e,onChange:e=>{t(e),i(e),u(!1)}})}),_jsx(FormControl,{fullWidth:!0,children:_jsx(Box,{ref:l,children:_jsx(TimeRangeSelector,{timeOptions:TIME_OPTIONS,value:o,onSelectChange:e=>{const a={pastDuration:e.target.value,end:new Date};t(a),i(a),u(!1)},onCustomClick:()=>{u(!0)}})})})]})}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TimeRangeControls.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeControls.test.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.test.tsx"],"names":[],"mappings":""}