@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/dashboards",
3
- "version": "0.23.1",
3
+ "version": "0.25.0",
4
4
  "description": "The dashboards feature in Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -20,7 +20,8 @@
20
20
  "build": "concurrently \"npm:build:*\"",
21
21
  "build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
22
22
  "build:esm": "swc ./src -d dist --config-file ../.swcrc",
23
- "build:types": "tsc --emitDeclarationOnly --declaration --preserveWatchOutput",
23
+ "build:types": "tsc --project tsconfig.build.json",
24
+ "type-check": "tsc --noEmit",
24
25
  "start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
25
26
  "test": "TZ=UTC jest",
26
27
  "test:watch": "npm run test -- --watch",
@@ -28,9 +29,9 @@
28
29
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
29
30
  },
30
31
  "dependencies": {
31
- "@perses-dev/components": "0.23.1",
32
- "@perses-dev/core": "0.23.1",
33
- "@perses-dev/plugin-system": "0.23.1",
32
+ "@perses-dev/components": "0.25.0",
33
+ "@perses-dev/core": "0.25.0",
34
+ "@perses-dev/plugin-system": "0.25.0",
34
35
  "@types/react-grid-layout": "^1.3.2",
35
36
  "date-fns": "^2.28.0",
36
37
  "immer": "^9.0.15",
@@ -1,137 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
20
- const _test = require("../../test");
21
- const _panel = require("./Panel");
22
- function _interopRequireDefault(obj) {
23
- return obj && obj.__esModule ? obj : {
24
- default: obj
25
- };
26
- }
27
- describe('Panel', ()=>{
28
- const createTestPanel = ()=>({
29
- kind: 'Panel',
30
- spec: {
31
- display: {
32
- name: 'Fake Panel Title',
33
- description: 'This is a fake panel'
34
- },
35
- plugin: {
36
- kind: 'TimeSeriesChart',
37
- spec: {}
38
- }
39
- }
40
- });
41
- // Helper to render the panel with some context set
42
- const renderPanel = (definition, editHandlers)=>{
43
- definition !== null && definition !== void 0 ? definition : definition = createTestPanel();
44
- (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panel.Panel, {
45
- definition: definition,
46
- editHandlers: editHandlers
47
- }));
48
- };
49
- // Helper to get the panel once rendered
50
- const getPanel = ()=>_react.screen.getByRole('region', {
51
- name: 'Fake Panel Title'
52
- });
53
- it('should render panel', async ()=>{
54
- renderPanel();
55
- const panel = getPanel();
56
- expect(panel).toBeInTheDocument();
57
- // Should diplay header with panel's title
58
- const header = _react.screen.getByRole('banner');
59
- expect(header).toHaveTextContent('Fake Panel Title');
60
- // Should display chart's content from the fake panel plugin
61
- const content = _react.screen.getByRole('figure');
62
- await (0, _react.waitFor)(()=>{
63
- expect(content).toHaveTextContent('TimeSeriesChart panel');
64
- });
65
- expect(content);
66
- });
67
- it('shows panel description', async ()=>{
68
- renderPanel();
69
- const panel = getPanel();
70
- // Description button should not be visible until hover on panel
71
- const missingButton = _react.screen.queryByRole('button', {
72
- name: /description/i
73
- });
74
- expect(missingButton).not.toBeInTheDocument();
75
- _userEvent.default.hover(panel);
76
- const descriptionButton = _react.screen.getByRole('button', {
77
- name: /description/i
78
- });
79
- expect(descriptionButton).toBeInTheDocument();
80
- // Can hover to see panel description in tooltip
81
- _userEvent.default.hover(descriptionButton);
82
- const tooltip = await _react.screen.findByRole('tooltip');
83
- expect(tooltip).toHaveTextContent('This is a fake panel');
84
- });
85
- it('does not show description when panel does not have one', ()=>{
86
- // Render a panel without a description set
87
- const withoutDescription = createTestPanel();
88
- withoutDescription.spec.display.description = undefined;
89
- renderPanel(withoutDescription);
90
- const panel = getPanel();
91
- _userEvent.default.hover(panel);
92
- const descriptionButton = _react.screen.queryByRole('button', {
93
- name: /description/i
94
- });
95
- expect(descriptionButton).not.toBeInTheDocument();
96
- });
97
- it('does not show description in edit mode', ()=>{
98
- renderPanel(undefined, {
99
- onEditPanelClick: jest.fn(),
100
- onDeletePanelClick: jest.fn(),
101
- onDuplicatePanelClick: jest.fn()
102
- });
103
- const panel = getPanel();
104
- _userEvent.default.hover(panel);
105
- const descriptionButton = _react.screen.queryByRole('button', {
106
- name: /description/i
107
- });
108
- expect(descriptionButton).not.toBeInTheDocument();
109
- });
110
- it('can trigger panel actions in edit mode', ()=>{
111
- const onEditPanelClick = jest.fn();
112
- const onDeletePanelClick = jest.fn();
113
- const onDuplicatePanelClick = jest.fn();
114
- renderPanel(undefined, {
115
- onEditPanelClick,
116
- onDeletePanelClick,
117
- onDuplicatePanelClick
118
- });
119
- const panel = getPanel();
120
- _userEvent.default.hover(panel);
121
- const editButton = _react.screen.getByRole('button', {
122
- name: /edit/i
123
- });
124
- _userEvent.default.click(editButton);
125
- const deleteButton = _react.screen.getByRole('button', {
126
- name: /delete/i
127
- });
128
- _userEvent.default.click(deleteButton);
129
- const duplicateButton = _react.screen.getByRole('button', {
130
- name: /duplicate/i
131
- });
132
- _userEvent.default.click(duplicateButton);
133
- expect(onEditPanelClick).toHaveBeenCalledTimes(1);
134
- expect(onDeletePanelClick).toHaveBeenCalledTimes(1);
135
- expect(onDuplicatePanelClick).toHaveBeenCalledTimes(1);
136
- });
137
- });
@@ -1,131 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
20
- const _testUtils = require("react-dom/test-utils");
21
- const _test = require("../../test");
22
- const _dashboardProvider = require("../../context/DashboardProvider");
23
- const _panelDrawer = require("./PanelDrawer");
24
- function _interopRequireDefault(obj) {
25
- return obj && obj.__esModule ? obj : {
26
- default: obj
27
- };
28
- }
29
- describe('Panel Drawer', ()=>{
30
- const renderPanelDrawer = ()=>{
31
- const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
32
- (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_dashboardProvider.DashboardProvider, {
33
- initialState: {
34
- dashboardResource: (0, _test.getTestDashboard)(),
35
- isEditMode: true
36
- },
37
- children: [
38
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
39
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
40
- ]
41
- }));
42
- const { value: storeApi } = store;
43
- if (storeApi === undefined) {
44
- throw new Error('Expected dashboard store to be set after initial render');
45
- }
46
- return storeApi;
47
- };
48
- it('should add new panel', async ()=>{
49
- const storeApi = renderPanelDrawer();
50
- // Open the drawer for a new panel
51
- (0, _testUtils.act)(()=>storeApi.getState().openAddPanel());
52
- const nameInput = await _react.screen.findByLabelText(/Name/);
53
- _userEvent.default.type(nameInput, 'New Panel');
54
- _userEvent.default.click(_react.screen.getByText('Add'));
55
- // TODO: Assert drawer is closed?
56
- const panels = storeApi.getState().panels;
57
- expect(panels).toMatchObject({
58
- // Should have the new panel in the store
59
- NewPanel: {
60
- kind: 'Panel',
61
- spec: {
62
- display: {
63
- name: 'New Panel'
64
- },
65
- plugin: {
66
- kind: '',
67
- spec: {}
68
- }
69
- }
70
- }
71
- });
72
- });
73
- it('should add panel with duplicate panel name', async ()=>{
74
- const storeApi = renderPanelDrawer();
75
- (0, _testUtils.act)(()=>storeApi.getState().openAddPanel());
76
- const nameInput = await _react.screen.findByLabelText(/Name/);
77
- _userEvent.default.type(nameInput, 'cpu');
78
- _userEvent.default.click(_react.screen.getByText('Add'));
79
- const panels = storeApi.getState().panels;
80
- expect(panels).toMatchObject({
81
- // make sure we don't have duplicate panel key by appending "-1"
82
- 'cpu-1': {
83
- kind: 'Panel',
84
- spec: {
85
- display: {
86
- name: 'cpu'
87
- },
88
- plugin: {
89
- kind: '',
90
- spec: {}
91
- }
92
- }
93
- }
94
- });
95
- });
96
- it('should edit an existing panel', async ()=>{
97
- const storeApi = renderPanelDrawer();
98
- // Open the drawer for an existing panel
99
- const group = Object.values(storeApi.getState().panelGroups).find((group)=>group.title === 'CPU Stats');
100
- if (group === undefined) {
101
- throw new Error('Test group not found');
102
- }
103
- const layout = Object.entries(group.itemPanelKeys).find(([, panelKey])=>panelKey === 'cpu');
104
- if (layout === undefined) {
105
- throw new Error('Test panel not found');
106
- }
107
- (0, _testUtils.act)(()=>storeApi.getState().openEditPanel({
108
- panelGroupId: group.id,
109
- panelGroupItemLayoutId: layout[0]
110
- }));
111
- const nameInput = await _react.screen.findByLabelText(/Name/);
112
- _userEvent.default.clear(nameInput);
113
- _userEvent.default.type(nameInput, 'cpu usage');
114
- _userEvent.default.click(_react.screen.getByText('Apply'));
115
- const panels = storeApi.getState().panels;
116
- expect(panels).toMatchObject({
117
- cpu: {
118
- kind: 'Panel',
119
- spec: {
120
- display: {
121
- name: 'cpu usage'
122
- },
123
- plugin: {
124
- kind: 'TimeSeriesChart',
125
- spec: {}
126
- }
127
- }
128
- }
129
- });
130
- });
131
- });
@@ -1,87 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
20
- const _testUtils = require("react-dom/test-utils");
21
- const _context = require("../../context");
22
- const _test = require("../../test");
23
- const _panelGroupDialog = require("./PanelGroupDialog");
24
- function _interopRequireDefault(obj) {
25
- return obj && obj.__esModule ? obj : {
26
- default: obj
27
- };
28
- }
29
- describe('Add Panel Group', ()=>{
30
- const renderDialog = ()=>{
31
- const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
32
- (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_context.DashboardProvider, {
33
- initialState: {
34
- dashboardResource: (0, _test.getTestDashboard)(),
35
- isEditMode: true
36
- },
37
- children: [
38
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
39
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelGroupDialog.PanelGroupDialog, {})
40
- ]
41
- }));
42
- const { value: storeApi } = store;
43
- if (storeApi === undefined) {
44
- throw new Error('Expected dashboard store to be set after initial render');
45
- }
46
- return storeApi;
47
- };
48
- it('should add new panel group', async ()=>{
49
- const storeApi = renderDialog();
50
- // Open the dialog for a new panel group
51
- (0, _testUtils.act)(()=>storeApi.getState().openAddPanelGroup());
52
- const nameInput = await _react.screen.findByLabelText(/Name/);
53
- _userEvent.default.type(nameInput, 'New Panel Group');
54
- _userEvent.default.click(_react.screen.getByText('Add'));
55
- // TODO: Figure out how to test this without coupling to the store state
56
- const panelGroups = Object.values(storeApi.getState().panelGroups);
57
- expect(panelGroups).toContainEqual({
58
- id: expect.any(Number),
59
- title: 'New Panel Group',
60
- isCollapsed: false,
61
- itemLayouts: expect.any(Array),
62
- itemPanelKeys: expect.any(Object)
63
- });
64
- });
65
- it('should edit existing panel group', async ()=>{
66
- const storeApi = renderDialog();
67
- // Open the dialog for an existing panel group
68
- const group = Object.values(storeApi.getState().panelGroups).find((group)=>group.title === 'CPU Stats');
69
- if (group === undefined) {
70
- throw new Error('Missing test group');
71
- }
72
- (0, _testUtils.act)(()=>storeApi.getState().openEditPanelGroup(group.id));
73
- const nameInput = await _react.screen.findByLabelText(/Name/);
74
- _userEvent.default.clear(nameInput);
75
- _userEvent.default.type(nameInput, 'New Name');
76
- _userEvent.default.click(_react.screen.getByText('Apply'));
77
- // TODO: Figure out how to test this without coupling to the store state
78
- const panelGroups = storeApi.getState().panelGroups;
79
- expect(panelGroups).toMatchObject({
80
- [group.id]: {
81
- id: group.id,
82
- title: 'New Name',
83
- isCollapsed: false
84
- }
85
- });
86
- });
87
- });
@@ -1,95 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _reactRouter = require("react-router");
19
- const _history = require("history");
20
- const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
21
- const _react = require("@testing-library/react");
22
- const _pluginSystem = require("@perses-dev/plugin-system");
23
- const _test = require("../../test");
24
- const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../test/testDashboard"));
25
- const _context = require("../../context");
26
- const _timeRangeControls = require("./TimeRangeControls");
27
- function _interopRequireDefault(obj) {
28
- return obj && obj.__esModule ? obj : {
29
- default: obj
30
- };
31
- }
32
- const history = (0, _history.createMemoryHistory)({
33
- initialEntries: [
34
- (0, _reactRouter.generatePath)('/home'),
35
- (0, _reactRouter.generatePath)('/dashboards/:id', {
36
- id: 'test'
37
- })
38
- ]
39
- });
40
- describe('TimeRangeControls', ()=>{
41
- let initialState;
42
- const testDefaultTimeRange = {
43
- pastDuration: _testDashboard.default.spec.duration
44
- };
45
- beforeEach(()=>{
46
- initialState = {
47
- dashboardResource: _testDashboard.default
48
- };
49
- });
50
- const renderTimeRangeControls = (testURLParams)=>{
51
- (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
52
- initialState: initialState,
53
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.TimeRangeProvider, {
54
- initialTimeRange: testDefaultTimeRange,
55
- enabledURLParams: testURLParams,
56
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
57
- })
58
- }), undefined, history);
59
- };
60
- it('should default to dashboard duration and update selected time option when clicked', async ()=>{
61
- renderTimeRangeControls(false);
62
- expect(_react.screen.getByText('Last 30 minutes')).toBeInTheDocument();
63
- const dateButton = _react.screen.getByRole('button', {
64
- name: /time range/i
65
- });
66
- _userEvent.default.click(dateButton);
67
- const firstSelected = _react.screen.getByRole('option', {
68
- name: 'Last 5 minutes'
69
- });
70
- _userEvent.default.click(firstSelected);
71
- expect(dateButton).toHaveTextContent(/5 minutes/i);
72
- });
73
- it('should update URL params with correct time range values', ()=>{
74
- renderTimeRangeControls(true);
75
- const dateButton = _react.screen.getByRole('button', {
76
- name: /time range/i
77
- });
78
- _userEvent.default.click(dateButton);
79
- const firstSelected = _react.screen.getByRole('option', {
80
- name: 'Last 5 minutes'
81
- });
82
- _userEvent.default.click(firstSelected);
83
- expect(history.location.search).toEqual('?start=5m');
84
- // pick another option from TimeRangeSelector dropdown
85
- const secondSelected = _react.screen.getByText('Last 12 hours');
86
- _userEvent.default.click(secondSelected);
87
- expect(history.location.search).toEqual('?start=12h');
88
- // back button should return to previous page selected
89
- (0, _react.act)(()=>{
90
- history.back();
91
- });
92
- expect(history.location.pathname).toEqual('/home');
93
- });
94
- // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
95
- });
@@ -1,106 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- const _variableModel = require("./variable-model");
18
- describe('filterVariableList', ()=>{
19
- const testSuite = [
20
- {
21
- title: 'basic case',
22
- capturing_regexp: /([^-]*)-host-([^-]*)/g,
23
- originalValues: [
24
- {
25
- label: 'l1',
26
- value: 'us1-host-ahdix'
27
- },
28
- {
29
- label: 'l2',
30
- value: 'us1-host-diua'
31
- },
32
- {
33
- label: 'l3',
34
- value: 'eu1-host-adf'
35
- },
36
- {
37
- label: 'l4',
38
- value: 'bar'
39
- }
40
- ],
41
- result: [
42
- {
43
- label: 'l1',
44
- value: 'us1ahdix'
45
- },
46
- {
47
- label: 'l2',
48
- value: 'us1diua'
49
- },
50
- {
51
- label: 'l3',
52
- value: 'eu1adf'
53
- }
54
- ]
55
- },
56
- {
57
- title: 'duplicate captured value',
58
- capturing_regexp: /prometheus-(.+):\d+/g,
59
- originalValues: [
60
- {
61
- label: 'l1',
62
- value: 'prometheus-app:9090'
63
- },
64
- {
65
- label: 'l2',
66
- value: 'prometheus-app:9091'
67
- },
68
- {
69
- label: 'l3',
70
- value: 'prometheus-platform:9091'
71
- },
72
- {
73
- label: 'l4',
74
- value: 'prometheus-database:9091'
75
- },
76
- {
77
- label: 'l5',
78
- value: 'prometheus-perses:9091'
79
- }
80
- ],
81
- result: [
82
- {
83
- label: 'l1',
84
- value: 'app'
85
- },
86
- {
87
- label: 'l3',
88
- value: 'platform'
89
- },
90
- {
91
- label: 'l4',
92
- value: 'database'
93
- },
94
- {
95
- label: 'l5',
96
- value: 'perses'
97
- }
98
- ]
99
- }
100
- ];
101
- testSuite.forEach(({ title , capturing_regexp , originalValues , result })=>{
102
- it(title, ()=>{
103
- expect((0, _variableModel.filterVariableList)(originalValues, capturing_regexp)).toEqual(result);
104
- });
105
- });
106
- });
@@ -1,82 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- const _queryParams = require("./query-params");
18
- describe('getInitalValuesFromQueryParameters', ()=>{
19
- test('base case', ()=>{
20
- expect((0, _queryParams.getInitalValuesFromQueryParameters)({
21
- 'var-foo': 'bar',
22
- 'var-baz': [
23
- 'qux',
24
- 'quux'
25
- ]
26
- })).toEqual({
27
- foo: 'bar',
28
- baz: [
29
- 'qux',
30
- 'quux'
31
- ]
32
- });
33
- });
34
- });
35
- describe('encodeVariableValue', ()=>{
36
- const testCases = [
37
- {
38
- input: 'foo',
39
- expected: 'foo'
40
- },
41
- {
42
- input: [
43
- 'foo',
44
- 'bar'
45
- ],
46
- expected: 'foo,bar'
47
- },
48
- {
49
- input: '$__all',
50
- expected: '$__all'
51
- }
52
- ];
53
- testCases.forEach(({ input , expected })=>{
54
- test(`encodes ${input} as ${expected}`, ()=>{
55
- expect((0, _queryParams.encodeVariableValue)(input)).toEqual(expected);
56
- });
57
- });
58
- });
59
- describe('decodeVariableValue', ()=>{
60
- const testCases = [
61
- {
62
- input: 'foo',
63
- expected: 'foo'
64
- },
65
- {
66
- input: 'foo,bar',
67
- expected: [
68
- 'foo',
69
- 'bar'
70
- ]
71
- },
72
- {
73
- input: '$__all',
74
- expected: '$__all'
75
- }
76
- ];
77
- testCases.forEach(({ input , expected })=>{
78
- test(`encodes ${input} as ${expected}`, ()=>{
79
- expect((0, _queryParams.decodeVariableValue)(input)).toEqual(expected);
80
- });
81
- });
82
- });