@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.
- package/dist/cjs/components/Dashboard.js +29 -14
- package/dist/cjs/components/DashboardToolbar.js +148 -20
- package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
- package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
- package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
- package/dist/cjs/components/GridLayout/index.js +18 -19
- package/dist/cjs/components/Panel/Panel.js +145 -55
- package/dist/cjs/components/Panel/Panel.test.js +50 -41
- package/dist/cjs/components/Panel/PanelContent.js +40 -12
- package/dist/cjs/components/Panel/index.js +16 -17
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
- package/dist/cjs/components/PanelDrawer/index.js +28 -0
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
- package/dist/cjs/components/TimeRangeControls/index.js +16 -17
- package/dist/cjs/components/Variables/Variable.js +186 -35
- package/dist/cjs/components/Variables/VariableList.js +100 -13
- package/dist/cjs/components/Variables/index.js +17 -18
- package/dist/cjs/components/index.js +21 -21
- package/dist/cjs/context/DashboardAppSlice.js +43 -31
- package/dist/cjs/context/DashboardProvider.js +88 -58
- package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
- package/dist/cjs/context/LayoutsSlice.js +40 -27
- package/dist/cjs/context/QueryStringProvider.js +69 -15
- package/dist/cjs/context/TemplateVariableProvider.js +128 -136
- package/dist/cjs/context/TimeRangeProvider.js +79 -30
- package/dist/cjs/context/index.js +22 -22
- package/dist/cjs/css/styles.js +43 -39
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/test/dashboard-provider.js +51 -0
- package/dist/cjs/test/index.js +18 -18
- package/dist/cjs/test/plugin-registry.js +52 -25
- package/dist/cjs/test/render.js +25 -22
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/cjs/test/testDashboard.js +193 -109
- package/dist/cjs/utils/functions.js +9 -5
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
- package/dist/cjs/views/ViewDashboard/index.js +28 -0
- package/dist/cjs/views/index.js +16 -17
- package/dist/components/Dashboard.js +38 -1
- package/dist/components/Dashboard.js.map +1 -0
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +154 -1
- package/dist/components/DashboardToolbar.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.js +35 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -0
- package/dist/components/GridLayout/GridLayout.js +99 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -0
- package/dist/components/GridLayout/GridTitle.js +77 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -0
- package/dist/components/GridLayout/index.js +16 -1
- package/dist/components/GridLayout/index.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +170 -1
- package/dist/components/Panel/Panel.js.map +1 -0
- package/dist/components/Panel/Panel.test.js +71 -1
- package/dist/components/Panel/Panel.test.js.map +1 -0
- package/dist/components/Panel/PanelContent.d.ts +2 -4
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +40 -1
- package/dist/components/Panel/PanelContent.js.map +1 -0
- package/dist/components/Panel/index.js +15 -1
- package/dist/components/Panel/index.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
- package/dist/components/PanelDrawer/index.d.ts +2 -0
- package/dist/components/PanelDrawer/index.d.ts.map +1 -0
- package/dist/components/PanelDrawer/index.js +15 -0
- package/dist/components/PanelDrawer/index.js.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
- package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
- package/dist/components/TimeRangeControls/index.js +15 -1
- package/dist/components/TimeRangeControls/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +202 -1
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableList.js +108 -1
- package/dist/components/Variables/VariableList.js.map +1 -0
- package/dist/components/Variables/index.js +16 -1
- package/dist/components/Variables/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +20 -1
- package/dist/components/index.js.map +1 -0
- package/dist/context/DashboardAppSlice.js +45 -1
- package/dist/context/DashboardAppSlice.js.map +1 -0
- package/dist/context/DashboardProvider.d.ts +4 -2
- package/dist/context/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider.js +107 -1
- package/dist/context/DashboardProvider.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +16 -0
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
- package/dist/context/DatasourceStoreProvider.js +64 -0
- package/dist/context/DatasourceStoreProvider.js.map +1 -0
- package/dist/context/LayoutsSlice.js +43 -1
- package/dist/context/LayoutsSlice.js.map +1 -0
- package/dist/context/QueryStringProvider.js +40 -1
- package/dist/context/QueryStringProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +6 -3
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +192 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TimeRangeProvider.js +72 -1
- package/dist/context/TimeRangeProvider.js.map +1 -0
- package/dist/context/index.d.ts +3 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +21 -1
- package/dist/context/index.js.map +1 -0
- package/dist/css/styles.js +186 -1
- package/dist/css/styles.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/test/dashboard-provider.d.ts +19 -0
- package/dist/test/dashboard-provider.d.ts.map +1 -0
- package/dist/test/dashboard-provider.js +40 -0
- package/dist/test/dashboard-provider.js.map +1 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +17 -1
- package/dist/test/index.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -3
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +74 -1
- package/dist/test/plugin-registry.js.map +1 -0
- package/dist/test/render.d.ts +1 -2
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +34 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.js +18 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +274 -1
- package/dist/test/testDashboard.js.map +1 -0
- package/dist/utils/functions.js +17 -1
- package/dist/utils/functions.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.js +56 -0
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
- package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
- package/dist/views/ViewDashboard/index.d.ts +2 -0
- package/dist/views/ViewDashboard/index.d.ts.map +1 -0
- package/dist/views/ViewDashboard/index.js +15 -0
- package/dist/views/ViewDashboard/index.js.map +1 -0
- package/dist/views/index.js +15 -1
- package/dist/views/index.js.map +1 -0
- package/package.json +13 -7
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
- package/dist/cjs/views/DashboardApp.js +0 -46
- package/dist/cjs/views/ViewDashboard.js +0 -43
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
- package/dist/views/DashboardApp.d.ts +0 -4
- package/dist/views/DashboardApp.d.ts.map +0 -1
- package/dist/views/DashboardApp.js +0 -1
- package/dist/views/ViewDashboard.d.ts.map +0 -1
- 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
37
|
-
const { dashboard
|
|
38
|
-
const { queryString
|
|
39
|
-
const defaultTimeRange = (0,
|
|
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,
|
|
42
|
-
const [showCustomDateSelector, setShowCustomDateSelector] = (0,
|
|
43
|
-
const anchorEl = (0,
|
|
44
|
-
return (
|
|
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
|
-
},
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
}
|
|
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
|
-
},
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
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:
|
|
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,
|
|
36
|
-
(0,
|
|
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(
|
|
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 =
|
|
45
|
-
|
|
46
|
-
const firstOption =
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Object.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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,
|
|
33
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(TextVariable, {
|
|
34
|
+
name: name
|
|
35
|
+
});
|
|
28
36
|
case 'ListVariable':
|
|
29
|
-
return (0,
|
|
37
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(ListVariable, {
|
|
38
|
+
name: name
|
|
39
|
+
});
|
|
30
40
|
}
|
|
31
|
-
return (0,
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 {
|
|
39
|
-
const
|
|
40
|
-
(0,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
53
|
-
const s = (0,
|
|
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,
|
|
56
|
-
return (
|
|
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
|
}
|