@perses-dev/dashboards 0.8.0 → 0.9.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 (196) hide show
  1. package/dist/cjs/components/Dashboard.js +29 -14
  2. package/dist/cjs/components/DashboardToolbar.js +148 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
  4. package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
  5. package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
  6. package/dist/cjs/components/GridLayout/index.js +18 -19
  7. package/dist/cjs/components/Panel/Panel.js +145 -55
  8. package/dist/cjs/components/Panel/Panel.test.js +50 -41
  9. package/dist/cjs/components/Panel/PanelContent.js +40 -12
  10. package/dist/cjs/components/Panel/index.js +16 -17
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
  12. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
  13. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
  14. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
  15. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
  16. package/dist/cjs/components/PanelDrawer/index.js +28 -0
  17. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
  19. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
  21. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
  22. package/dist/cjs/components/TimeRangeControls/index.js +16 -17
  23. package/dist/cjs/components/Variables/Variable.js +186 -35
  24. package/dist/cjs/components/Variables/VariableList.js +100 -13
  25. package/dist/cjs/components/Variables/index.js +17 -18
  26. package/dist/cjs/components/index.js +21 -21
  27. package/dist/cjs/context/DashboardAppSlice.js +43 -31
  28. package/dist/cjs/context/DashboardProvider.js +88 -58
  29. package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
  30. package/dist/cjs/context/LayoutsSlice.js +40 -27
  31. package/dist/cjs/context/QueryStringProvider.js +69 -15
  32. package/dist/cjs/context/TemplateVariableProvider.js +128 -136
  33. package/dist/cjs/context/TimeRangeProvider.js +79 -30
  34. package/dist/cjs/context/index.js +22 -22
  35. package/dist/cjs/css/styles.js +43 -39
  36. package/dist/cjs/index.js +19 -20
  37. package/dist/cjs/test/dashboard-provider.js +51 -0
  38. package/dist/cjs/test/index.js +18 -18
  39. package/dist/cjs/test/plugin-registry.js +52 -25
  40. package/dist/cjs/test/render.js +25 -22
  41. package/dist/cjs/test/setup-tests.js +4 -2
  42. package/dist/cjs/test/testDashboard.js +193 -109
  43. package/dist/cjs/utils/functions.js +9 -5
  44. package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
  45. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
  46. package/dist/cjs/views/ViewDashboard/index.js +28 -0
  47. package/dist/cjs/views/index.js +16 -17
  48. package/dist/components/Dashboard.js +38 -1
  49. package/dist/components/Dashboard.js.map +1 -0
  50. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  51. package/dist/components/DashboardToolbar.js +154 -1
  52. package/dist/components/DashboardToolbar.js.map +1 -0
  53. package/dist/components/GridLayout/GridItemContent.js +35 -1
  54. package/dist/components/GridLayout/GridItemContent.js.map +1 -0
  55. package/dist/components/GridLayout/GridLayout.js +99 -1
  56. package/dist/components/GridLayout/GridLayout.js.map +1 -0
  57. package/dist/components/GridLayout/GridTitle.js +77 -1
  58. package/dist/components/GridLayout/GridTitle.js.map +1 -0
  59. package/dist/components/GridLayout/index.js +16 -1
  60. package/dist/components/GridLayout/index.js.map +1 -0
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +170 -1
  63. package/dist/components/Panel/Panel.js.map +1 -0
  64. package/dist/components/Panel/Panel.test.js +71 -1
  65. package/dist/components/Panel/Panel.test.js.map +1 -0
  66. package/dist/components/Panel/PanelContent.d.ts +2 -4
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +40 -1
  69. package/dist/components/Panel/PanelContent.js.map +1 -0
  70. package/dist/components/Panel/index.js +15 -1
  71. package/dist/components/Panel/index.js.map +1 -0
  72. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
  73. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  74. package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
  75. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
  76. package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
  77. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
  78. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
  79. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
  80. package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
  81. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
  82. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
  83. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
  84. package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
  85. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
  86. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
  87. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
  88. package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
  89. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
  90. package/dist/components/PanelDrawer/index.d.ts +2 -0
  91. package/dist/components/PanelDrawer/index.d.ts.map +1 -0
  92. package/dist/components/PanelDrawer/index.js +15 -0
  93. package/dist/components/PanelDrawer/index.js.map +1 -0
  94. package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
  95. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
  96. package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
  97. package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
  98. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  99. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
  100. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
  101. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
  102. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
  103. package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
  104. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  105. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
  106. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
  107. package/dist/components/TimeRangeControls/index.js +15 -1
  108. package/dist/components/TimeRangeControls/index.js.map +1 -0
  109. package/dist/components/Variables/Variable.d.ts.map +1 -1
  110. package/dist/components/Variables/Variable.js +202 -1
  111. package/dist/components/Variables/Variable.js.map +1 -0
  112. package/dist/components/Variables/VariableList.js +108 -1
  113. package/dist/components/Variables/VariableList.js.map +1 -0
  114. package/dist/components/Variables/index.js +16 -1
  115. package/dist/components/Variables/index.js.map +1 -0
  116. package/dist/components/index.d.ts +1 -0
  117. package/dist/components/index.d.ts.map +1 -1
  118. package/dist/components/index.js +20 -1
  119. package/dist/components/index.js.map +1 -0
  120. package/dist/context/DashboardAppSlice.js +45 -1
  121. package/dist/context/DashboardAppSlice.js.map +1 -0
  122. package/dist/context/DashboardProvider.d.ts +4 -2
  123. package/dist/context/DashboardProvider.d.ts.map +1 -1
  124. package/dist/context/DashboardProvider.js +107 -1
  125. package/dist/context/DashboardProvider.js.map +1 -0
  126. package/dist/context/DatasourceStoreProvider.d.ts +16 -0
  127. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
  128. package/dist/context/DatasourceStoreProvider.js +64 -0
  129. package/dist/context/DatasourceStoreProvider.js.map +1 -0
  130. package/dist/context/LayoutsSlice.js +43 -1
  131. package/dist/context/LayoutsSlice.js.map +1 -0
  132. package/dist/context/QueryStringProvider.js +40 -1
  133. package/dist/context/QueryStringProvider.js.map +1 -0
  134. package/dist/context/TemplateVariableProvider.d.ts +6 -3
  135. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  136. package/dist/context/TemplateVariableProvider.js +192 -1
  137. package/dist/context/TemplateVariableProvider.js.map +1 -0
  138. package/dist/context/TimeRangeProvider.js +72 -1
  139. package/dist/context/TimeRangeProvider.js.map +1 -0
  140. package/dist/context/index.d.ts +3 -2
  141. package/dist/context/index.d.ts.map +1 -1
  142. package/dist/context/index.js +21 -1
  143. package/dist/context/index.js.map +1 -0
  144. package/dist/css/styles.js +186 -1
  145. package/dist/css/styles.js.map +1 -0
  146. package/dist/index.js +17 -1
  147. package/dist/index.js.map +1 -0
  148. package/dist/test/dashboard-provider.d.ts +19 -0
  149. package/dist/test/dashboard-provider.d.ts.map +1 -0
  150. package/dist/test/dashboard-provider.js +40 -0
  151. package/dist/test/dashboard-provider.js.map +1 -0
  152. package/dist/test/index.d.ts +1 -0
  153. package/dist/test/index.d.ts.map +1 -1
  154. package/dist/test/index.js +17 -1
  155. package/dist/test/index.js.map +1 -0
  156. package/dist/test/plugin-registry.d.ts +2 -3
  157. package/dist/test/plugin-registry.d.ts.map +1 -1
  158. package/dist/test/plugin-registry.js +74 -1
  159. package/dist/test/plugin-registry.js.map +1 -0
  160. package/dist/test/render.d.ts +1 -2
  161. package/dist/test/render.d.ts.map +1 -1
  162. package/dist/test/render.js +34 -1
  163. package/dist/test/render.js.map +1 -0
  164. package/dist/test/setup-tests.js +18 -1
  165. package/dist/test/setup-tests.js.map +1 -0
  166. package/dist/test/testDashboard.d.ts.map +1 -1
  167. package/dist/test/testDashboard.js +274 -1
  168. package/dist/test/testDashboard.js.map +1 -0
  169. package/dist/utils/functions.js +17 -1
  170. package/dist/utils/functions.js.map +1 -0
  171. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
  172. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
  173. package/dist/views/ViewDashboard/DashboardApp.js +56 -0
  174. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
  175. package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
  176. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
  177. package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
  178. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
  179. package/dist/views/ViewDashboard/index.d.ts +2 -0
  180. package/dist/views/ViewDashboard/index.d.ts.map +1 -0
  181. package/dist/views/ViewDashboard/index.js +15 -0
  182. package/dist/views/ViewDashboard/index.js.map +1 -0
  183. package/dist/views/index.js +15 -1
  184. package/dist/views/index.js.map +1 -0
  185. package/package.json +13 -7
  186. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
  187. package/dist/cjs/views/DashboardApp.js +0 -46
  188. package/dist/cjs/views/ViewDashboard.js +0 -43
  189. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
  190. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
  191. package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
  192. package/dist/views/DashboardApp.d.ts +0 -4
  193. package/dist/views/DashboardApp.d.ts.map +0 -1
  194. package/dist/views/DashboardApp.js +0 -1
  195. package/dist/views/ViewDashboard.d.ts.map +0 -1
  196. package/dist/views/ViewDashboard.js +0 -1
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeRangeControls = exports.TIME_OPTIONS = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
1
  // Copyright 2022 The Perses Authors
6
2
  // Licensed under the Apache License, Version 2.0 (the "License");
7
3
  // you may not use this file except in compliance with the License.
@@ -14,53 +10,139 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
11
  // See the License for the specific language governing permissions and
16
12
  // limitations under the License.
17
- const react_1 = require("react");
18
- const material_1 = require("@mui/material");
19
- const components_1 = require("@perses-dev/components");
20
- const core_1 = require("@perses-dev/core");
21
- const plugin_system_1 = require("@perses-dev/plugin-system");
22
- const context_1 = require("../../context");
23
- // TODO: add time shortcut if one does not match duration
24
- exports.TIME_OPTIONS = [
25
- { value: { pastDuration: '5m' }, display: 'Last 5 minutes' },
26
- { value: { pastDuration: '15m' }, display: 'Last 15 minutes' },
27
- { value: { pastDuration: '30m' }, display: 'Last 30 minutes' },
28
- { value: { pastDuration: '1h' }, display: 'Last 1 hour' },
29
- { value: { pastDuration: '6h' }, display: 'Last 6 hours' },
30
- { value: { pastDuration: '12h' }, display: 'Last 12 hours' },
31
- { value: { pastDuration: '24h' }, display: 'Last 1 day' },
32
- { value: { pastDuration: '7d' }, display: 'Last 7 days' },
33
- { value: { pastDuration: '14d' }, display: 'Last 14 days' },
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ TIME_OPTIONS: ()=>TIME_OPTIONS,
25
+ TimeRangeControls: ()=>TimeRangeControls
26
+ });
27
+ const _jsxRuntime = require("react/jsx-runtime");
28
+ const _react = require("react");
29
+ const _material = require("@mui/material");
30
+ const _components = require("@perses-dev/components");
31
+ const _core = require("@perses-dev/core");
32
+ const _pluginSystem = require("@perses-dev/plugin-system");
33
+ const _context = require("../../context");
34
+ const TIME_OPTIONS = [
35
+ {
36
+ value: {
37
+ pastDuration: '5m'
38
+ },
39
+ display: 'Last 5 minutes'
40
+ },
41
+ {
42
+ value: {
43
+ pastDuration: '15m'
44
+ },
45
+ display: 'Last 15 minutes'
46
+ },
47
+ {
48
+ value: {
49
+ pastDuration: '30m'
50
+ },
51
+ display: 'Last 30 minutes'
52
+ },
53
+ {
54
+ value: {
55
+ pastDuration: '1h'
56
+ },
57
+ display: 'Last 1 hour'
58
+ },
59
+ {
60
+ value: {
61
+ pastDuration: '6h'
62
+ },
63
+ display: 'Last 6 hours'
64
+ },
65
+ {
66
+ value: {
67
+ pastDuration: '12h'
68
+ },
69
+ display: 'Last 12 hours'
70
+ },
71
+ {
72
+ value: {
73
+ pastDuration: '24h'
74
+ },
75
+ display: 'Last 1 day'
76
+ },
77
+ {
78
+ value: {
79
+ pastDuration: '7d'
80
+ },
81
+ display: 'Last 7 days'
82
+ },
83
+ {
84
+ value: {
85
+ pastDuration: '14d'
86
+ },
87
+ display: 'Last 14 days'
88
+ }
34
89
  ];
35
90
  function TimeRangeControls() {
36
- const { timeRange, setTimeRange } = (0, plugin_system_1.useTimeRange)();
37
- const { dashboard } = (0, context_1.useDashboard)();
38
- const { queryString } = (0, plugin_system_1.useQueryString)();
39
- const defaultTimeRange = (0, core_1.getDefaultTimeRange)(dashboard.duration, queryString);
91
+ const { timeRange , setTimeRange } = (0, _pluginSystem.useTimeRange)();
92
+ const { dashboard } = (0, _context.useDashboard)();
93
+ const { queryString } = (0, _pluginSystem.useQueryString)();
94
+ const defaultTimeRange = (0, _core.getDefaultTimeRange)(dashboard.duration, queryString);
40
95
  // selected form value can be relative or absolute, timeRange from plugin-system is only absolute
41
- const [selectedTimeRange, setSelectedTimeRange] = (0, react_1.useState)(defaultTimeRange);
42
- const [showCustomDateSelector, setShowCustomDateSelector] = (0, react_1.useState)(false);
43
- const anchorEl = (0, react_1.useRef)();
44
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Popover, { anchorEl: anchorEl.current, anchorOrigin: {
96
+ const [selectedTimeRange, setSelectedTimeRange] = (0, _react.useState)(defaultTimeRange);
97
+ const [showCustomDateSelector, setShowCustomDateSelector] = (0, _react.useState)(false);
98
+ const anchorEl = (0, _react.useRef)();
99
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
100
+ direction: "row",
101
+ spacing: 1,
102
+ children: [
103
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Popover, {
104
+ anchorEl: anchorEl.current,
105
+ anchorOrigin: {
45
106
  vertical: 'bottom',
46
- horizontal: 'center',
47
- }, open: showCustomDateSelector, onClose: () => setShowCustomDateSelector(false), sx: (theme) => ({
48
- padding: theme.spacing(2),
49
- }), children: (0, jsx_runtime_1.jsx)(components_1.AbsoluteTimePicker, { initialTimeRange: timeRange, onChange: (timeRange) => {
107
+ horizontal: 'center'
108
+ },
109
+ open: showCustomDateSelector,
110
+ onClose: ()=>setShowCustomDateSelector(false),
111
+ sx: (theme)=>({
112
+ padding: theme.spacing(2)
113
+ }),
114
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.AbsoluteTimePicker, {
115
+ initialTimeRange: timeRange,
116
+ onChange: (timeRange)=>{
50
117
  setTimeRange(timeRange);
51
118
  setSelectedTimeRange(timeRange);
52
119
  setShowCustomDateSelector(false);
53
- } }) }), (0, jsx_runtime_1.jsx)(material_1.FormControl, { fullWidth: true, children: (0, jsx_runtime_1.jsx)(material_1.Box, { ref: anchorEl, children: (0, jsx_runtime_1.jsx)(components_1.TimeRangeSelector, { timeOptions: exports.TIME_OPTIONS, value: selectedTimeRange, onSelectChange: (event) => {
120
+ }
121
+ })
122
+ }),
123
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControl, {
124
+ fullWidth: true,
125
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
126
+ ref: anchorEl,
127
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.TimeRangeSelector, {
128
+ timeOptions: TIME_OPTIONS,
129
+ value: selectedTimeRange,
130
+ onSelectChange: (event)=>{
54
131
  const duration = event.target.value;
55
132
  const relativeTimeInput = {
56
133
  pastDuration: duration,
57
- end: new Date(),
134
+ end: new Date()
58
135
  };
59
136
  setTimeRange(relativeTimeInput);
60
137
  setSelectedTimeRange(relativeTimeInput);
61
138
  setShowCustomDateSelector(false);
62
- }, onCustomClick: () => {
139
+ },
140
+ onCustomClick: ()=>{
63
141
  setShowCustomDateSelector(true);
64
- } }) }) })] }));
142
+ }
143
+ })
144
+ })
145
+ })
146
+ ]
147
+ });
65
148
  }
66
- exports.TimeRangeControls = TimeRangeControls;
@@ -1,9 +1,3 @@
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
- const jsx_runtime_1 = require("react/jsx-runtime");
7
1
  // Copyright 2022 The Perses Authors
8
2
  // Licensed under the Apache License, Version 2.0 (the "License");
9
3
  // you may not use this file except in compliance with the License.
@@ -16,36 +10,57 @@ const jsx_runtime_1 = require("react/jsx-runtime");
16
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
11
  // See the License for the specific language governing permissions and
18
12
  // limitations under the License.
19
- const user_event_1 = __importDefault(require("@testing-library/user-event"));
20
- const core_1 = require("@perses-dev/core");
21
- const react_1 = require("@testing-library/react");
22
- const test_1 = require("../../test");
23
- const testDashboard_1 = __importDefault(require("../../test/testDashboard"));
24
- const context_1 = require("../../context");
25
- const TimeRangeControls_1 = require("./TimeRangeControls");
26
- describe('TimeRangeControls', () => {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _jsxRuntime = require("react/jsx-runtime");
18
+ const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
19
+ const _core = require("@perses-dev/core");
20
+ const _react = require("@testing-library/react");
21
+ const _test = require("../../test");
22
+ const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../test/testDashboard"));
23
+ const _context = require("../../context");
24
+ const _timeRangeControls = require("./TimeRangeControls");
25
+ function _interopRequireDefault(obj) {
26
+ return obj && obj.__esModule ? obj : {
27
+ default: obj
28
+ };
29
+ }
30
+ describe('TimeRangeControls', ()=>{
27
31
  let initialState;
28
- beforeEach(() => {
32
+ beforeEach(()=>{
29
33
  initialState = {
30
- dashboardSpec: testDashboard_1.default.spec,
34
+ dashboardSpec: _testDashboard.default.spec
31
35
  };
32
36
  });
33
- const renderTimeRangeControls = () => {
37
+ const renderTimeRangeControls = ()=>{
34
38
  const queryString = new URLSearchParams();
35
- const defaultTimeRange = (0, core_1.getDefaultTimeRange)(initialState.dashboardSpec.duration, queryString);
36
- (0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(context_1.QueryStringProvider, { queryString: queryString, children: (0, jsx_runtime_1.jsx)(context_1.DashboardProvider, { initialState: initialState, children: (0, jsx_runtime_1.jsx)(context_1.TimeRangeProvider, { initialTimeRange: defaultTimeRange, children: (0, jsx_runtime_1.jsx)(TimeRangeControls_1.TimeRangeControls, {}) }) }) }));
39
+ const defaultTimeRange = (0, _core.getDefaultTimeRange)(initialState.dashboardSpec.duration, queryString);
40
+ (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.QueryStringProvider, {
41
+ queryString: queryString,
42
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
43
+ initialState: initialState,
44
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
45
+ initialTimeRange: defaultTimeRange,
46
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
47
+ })
48
+ })
49
+ }));
37
50
  };
38
- it('should render correct initial relative time shortcut', async () => {
51
+ it('should render correct initial relative time shortcut', async ()=>{
39
52
  renderTimeRangeControls();
40
- expect(react_1.screen.getByText('Last 1 day')).toBeInTheDocument();
53
+ expect(_react.screen.getByText('Last 1 day')).toBeInTheDocument();
41
54
  });
42
- it('should be able to select the first option', () => {
55
+ it('should be able to select the first option', ()=>{
43
56
  renderTimeRangeControls();
44
- const dateButton = react_1.screen.getByRole('button');
45
- user_event_1.default.click(dateButton);
46
- const firstOption = react_1.screen.getByRole('option', { name: 'Last 5 minutes' });
47
- user_event_1.default.click(firstOption);
57
+ const dateButton = _react.screen.getByRole('button');
58
+ _userEvent.default.click(dateButton);
59
+ const firstOption = _react.screen.getByRole('option', {
60
+ name: 'Last 5 minutes'
61
+ });
62
+ _userEvent.default.click(firstOption);
48
63
  expect(dateButton).toHaveTextContent(/5 minutes/i);
49
64
  });
50
- // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
65
+ // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
51
66
  });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,19 +10,19 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // 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("./TimeRangeControls"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./TimeRangeControls"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateVariable = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
1
  // Copyright 2022 The Perses Authors
6
2
  // Licensed under the Apache License, Version 2.0 (the "License");
7
3
  // you may not use this file except in compliance with the License.
@@ -14,44 +10,199 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
11
  // See the License for the specific language governing permissions and
16
12
  // limitations under the License.
17
- const react_1 = require("react");
18
- const material_1 = require("@mui/material");
19
- const mdi_material_ui_1 = require("mdi-material-ui");
20
- const context_1 = require("../../context");
21
- function TemplateVariable({ name }) {
22
- var _a;
23
- const ctx = (0, context_1.useTemplateVariable)(name);
24
- const kind = (_a = ctx.definition) === null || _a === void 0 ? void 0 : _a.kind;
25
- switch (kind) {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TemplateVariable", {
18
+ enumerable: true,
19
+ get: ()=>TemplateVariable
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _pluginSystem = require("@perses-dev/plugin-system");
25
+ const _reactQuery = require("@tanstack/react-query");
26
+ const _context = require("../../context");
27
+ function TemplateVariable({ name }) {
28
+ var ref;
29
+ const ctx = (0, _context.useTemplateVariable)(name);
30
+ const kind = (ref = ctx.definition) === null || ref === void 0 ? void 0 : ref.kind;
31
+ switch(kind){
26
32
  case 'TextVariable':
27
- return (0, jsx_runtime_1.jsx)(TextVariable, { name: name });
33
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(TextVariable, {
34
+ name: name
35
+ });
28
36
  case 'ListVariable':
29
- return (0, jsx_runtime_1.jsx)(ListVariable, { name: name });
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(ListVariable, {
38
+ name: name
39
+ });
30
40
  }
31
- return (0, jsx_runtime_1.jsxs)("div", { children: ["Unsupported Variable Kind: $", kind] });
41
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
42
+ children: [
43
+ "Unsupported Variable Kind: $",
44
+ kind
45
+ ]
46
+ });
47
+ }
48
+ /**
49
+ * Returns a serialized string of the current state of variable values.
50
+ */ function getVariableValuesKey(v) {
51
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
32
52
  }
33
- exports.TemplateVariable = TemplateVariable;
34
- function ListVariable({ name }) {
35
- var _a, _b, _c, _d;
36
- const ctx = (0, context_1.useTemplateVariable)(name);
53
+ function ListVariable({ name }) {
54
+ var ref, ref1, ref2;
55
+ const ctx = (0, _context.useTemplateVariable)(name);
37
56
  const definition = ctx.definition;
38
- const { setVariableValue, loadTemplateVariable } = (0, context_1.useTemplateVariableActions)();
39
- const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.options.allowMultiple) === true;
40
- (0, react_1.useEffect)(() => {
41
- loadTemplateVariable(name);
42
- }, [name, loadTemplateVariable]);
43
- let value = (_a = ctx.state) === null || _a === void 0 ? void 0 : _a.value;
57
+ const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
58
+ const { setVariableValue , setVariableLoading , setVariableOptions } = (0, _context.useTemplateVariableActions)();
59
+ const datasourceStore = (0, _pluginSystem.useDatasourceStore)();
60
+ const spec = definition.spec.plugin.spec;
61
+ let dependsOnVariables;
62
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
63
+ dependsOnVariables = variablePlugin.dependsOn(spec);
64
+ }
65
+ const variables = (0, _pluginSystem.useTemplateVariableValues)(dependsOnVariables);
66
+ const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
67
+ const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
68
+ let waitToLoad = false;
69
+ if (dependsOnVariables) {
70
+ waitToLoad = dependsOnVariables.some((v)=>{
71
+ var ref;
72
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
73
+ });
74
+ }
75
+ const variablesValueKey = getVariableValuesKey(variables);
76
+ const variablesOptionsQuery = (0, _reactQuery.useQuery)([
77
+ name,
78
+ definition,
79
+ variablesValueKey
80
+ ], async ()=>{
81
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
82
+ datasourceStore,
83
+ variables
84
+ }));
85
+ var ref;
86
+ return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
87
+ }, {
88
+ enabled: !!variablePlugin || waitToLoad
89
+ });
90
+ (0, _react.useEffect)(()=>{
91
+ setVariableLoading(name, variablesOptionsQuery.isFetching);
92
+ if (variablesOptionsQuery.data) {
93
+ setVariableOptions(name, variablesOptionsQuery.data);
94
+ }
95
+ }, [
96
+ variablesOptionsQuery,
97
+ name,
98
+ setVariableLoading,
99
+ setVariableOptions
100
+ ]);
101
+ let value = (ref = ctx.state) === null || ref === void 0 ? void 0 : ref.value;
102
+ const options = (ref1 = ctx.state) === null || ref1 === void 0 ? void 0 : ref1.options;
103
+ const loading = (ref2 = ctx.state) === null || ref2 === void 0 ? void 0 : ref2.loading;
104
+ // Make sure value is an array if allowMultiple is true
44
105
  if (allowMultiple && !Array.isArray(value)) {
45
- value = [];
106
+ value = typeof value === 'string' ? [
107
+ value
108
+ ] : [];
46
109
  }
47
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { display: 'flex', children: [(0, jsx_runtime_1.jsxs)(material_1.FormControl, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { id: name, children: name }), (0, jsx_runtime_1.jsx)(material_1.Select, { id: name, label: name, value: value, onChange: (e) => {
48
- setVariableValue(name, e.target.value);
49
- }, multiple: allowMultiple, children: (_c = (_b = ctx.state) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.map((option) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: option.value, children: option.label }, option.value))) }), ((_d = ctx.state) === null || _d === void 0 ? void 0 : _d.loading) && (0, jsx_runtime_1.jsx)(material_1.LinearProgress, {})] }), (0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: () => loadTemplateVariable(name), children: (0, jsx_runtime_1.jsx)(mdi_material_ui_1.Reload, {}) })] }));
110
+ const finalOptions = (0, _react.useMemo)(()=>{
111
+ let computedOptions = options ? [
112
+ ...options
113
+ ] : [];
114
+ // Add the all value if it's allowed
115
+ if (allowAllValue) {
116
+ computedOptions = [
117
+ {
118
+ value: _pluginSystem.DEFAULT_ALL_VALUE,
119
+ label: 'All'
120
+ },
121
+ ...computedOptions
122
+ ];
123
+ }
124
+ return computedOptions;
125
+ }, [
126
+ options,
127
+ allowAllValue
128
+ ]);
129
+ (0, _react.useEffect)(()=>{
130
+ const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
131
+ const valueIsInOptions = Boolean(finalOptions.find((v)=>{
132
+ if (allowMultiple) {
133
+ return value.includes(v.value);
134
+ }
135
+ return value === v.value;
136
+ }));
137
+ // If there is no value but there are options, set the value to the first option.
138
+ if (!value && firstOption) {
139
+ setVariableValue(name, firstOption.value);
140
+ }
141
+ // If there is a value but it's not in the options, select the first value or set to null
142
+ if (value && !valueIsInOptions && !definition.spec.default_value) {
143
+ setVariableValue(name, (firstOption === null || firstOption === void 0 ? void 0 : firstOption.value) || null);
144
+ }
145
+ }, [
146
+ finalOptions,
147
+ setVariableValue,
148
+ value,
149
+ name,
150
+ allowMultiple
151
+ ]);
152
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
153
+ display: 'flex',
154
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
155
+ children: [
156
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
157
+ id: name,
158
+ children: name
159
+ }),
160
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
161
+ sx: {
162
+ minWidth: 100,
163
+ maxWidth: 250
164
+ },
165
+ id: name,
166
+ label: name,
167
+ value: value !== null && value !== void 0 ? value : '',
168
+ onChange: (e)=>{
169
+ // Must be selected
170
+ if (e.target.value === null || e.target.value.length === 0) {
171
+ if (allowAllValue) {
172
+ setVariableValue(name, _pluginSystem.DEFAULT_ALL_VALUE);
173
+ }
174
+ return;
175
+ }
176
+ setVariableValue(name, e.target.value);
177
+ },
178
+ multiple: allowMultiple,
179
+ children: [
180
+ loading && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
181
+ value: "loading",
182
+ disabled: true,
183
+ children: "Loading"
184
+ }),
185
+ finalOptions.map((option)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
186
+ value: option.value,
187
+ children: option.label
188
+ }, option.value))
189
+ ]
190
+ }),
191
+ loading && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.LinearProgress, {})
192
+ ]
193
+ })
194
+ });
50
195
  }
51
- function TextVariable({ name }) {
52
- const { state } = (0, context_1.useTemplateVariable)(name);
53
- const s = (0, context_1.useTemplateVariableStore)();
196
+ function TextVariable({ name }) {
197
+ const { state } = (0, _context.useTemplateVariable)(name);
198
+ const s = (0, _context.useTemplateVariableStore)();
54
199
  const setVariableValue = s.setVariableValue;
55
- const ref = (0, react_1.useRef)(null);
56
- return ((0, jsx_runtime_1.jsx)(material_1.TextField, { ref: ref, defaultValue: state === null || state === void 0 ? void 0 : state.value, onBlur: (e) => setVariableValue(name, e.target.value), placeholder: name, label: name }));
200
+ const ref = (0, _react.useRef)(null);
201
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
202
+ ref: ref,
203
+ defaultValue: state === null || state === void 0 ? void 0 : state.value,
204
+ onBlur: (e)=>setVariableValue(name, e.target.value),
205
+ placeholder: name,
206
+ label: name
207
+ });
57
208
  }