@perses-dev/dashboards 0.13.0 → 0.15.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/DashboardToolbar/DashboardToolbar.js +13 -14
- package/dist/cjs/{css/styles.js → components/GridLayout/GridContainer.js} +66 -39
- package/dist/cjs/components/GridLayout/GridLayout.js +51 -64
- package/dist/cjs/components/GridLayout/GridTitle.js +3 -2
- package/dist/cjs/components/Panel/PanelHeader.js +6 -6
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -2
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +7 -5
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +15 -54
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +25 -11
- package/dist/cjs/components/Variables/Variable.js +11 -4
- package/dist/cjs/components/Variables/VariableEditor.js +1 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -2
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +3 -3
- package/dist/cjs/components/Variables/VariableList.js +76 -17
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -1
- package/dist/cjs/context/DashboardProvider/common.js +3 -3
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +68 -39
- package/dist/cjs/context/{TimeRangeProvider.js → TimeRangeProvider/TimeRangeProvider.js} +4 -4
- package/dist/cjs/{utils → context/TimeRangeProvider}/index.js +2 -1
- package/dist/cjs/{utils/time-range-params.js → context/TimeRangeProvider/query-params.js} +11 -5
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/test/render.js +0 -1
- package/dist/cjs/test/testDashboard.js +1 -1
- package/dist/cjs/utils/component-ids.js +3 -3
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +3 -1
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +7 -7
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +13 -14
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridContainer.d.ts +6 -0
- package/dist/components/GridLayout/GridContainer.d.ts.map +1 -0
- package/dist/{css/styles.js → components/GridLayout/GridContainer.js} +65 -38
- package/dist/components/GridLayout/GridContainer.js.map +1 -0
- package/dist/components/GridLayout/GridLayout.d.ts +1 -2
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +53 -66
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +4 -3
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +6 -6
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +1 -2
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +8 -6
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +19 -58
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +25 -11
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/Variables/Variable.js +11 -4
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +1 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -2
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +3 -3
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts +5 -1
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +38 -18
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +2 -1
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +4 -4
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +70 -41
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/{TimeRangeProvider.d.ts → TimeRangeProvider/TimeRangeProvider.d.ts} +2 -2
- package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -0
- package/dist/context/{TimeRangeProvider.js → TimeRangeProvider/TimeRangeProvider.js} +4 -4
- package/dist/context/TimeRangeProvider/TimeRangeProvider.js.map +1 -0
- package/dist/context/TimeRangeProvider/index.d.ts +3 -0
- package/dist/context/TimeRangeProvider/index.d.ts.map +1 -0
- package/dist/{utils → context/TimeRangeProvider}/index.js +2 -1
- package/dist/context/TimeRangeProvider/index.js.map +1 -0
- package/dist/{utils/time-range-params.d.ts → context/TimeRangeProvider/query-params.d.ts} +3 -3
- package/dist/context/TimeRangeProvider/query-params.d.ts.map +1 -0
- package/dist/{utils/time-range-params.js → context/TimeRangeProvider/query-params.js} +13 -7
- package/dist/context/TimeRangeProvider/query-params.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/test/render.js +0 -1
- package/dist/test/render.js.map +1 -1
- package/dist/test/testDashboard.js +1 -1
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/component-ids.d.ts.map +1 -1
- package/dist/utils/component-ids.js +3 -3
- package/dist/utils/component-ids.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +3 -1
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -0
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +7 -7
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +5 -4
- package/dist/context/TimeRangeProvider.d.ts.map +0 -1
- package/dist/context/TimeRangeProvider.js.map +0 -1
- package/dist/css/styles.d.ts +0 -172
- package/dist/css/styles.d.ts.map +0 -1
- package/dist/css/styles.js.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/time-range-params.d.ts.map +0 -1
- package/dist/utils/time-range-params.js.map +0 -1
|
@@ -45,29 +45,43 @@ describe('TimeRangeControls', ()=>{
|
|
|
45
45
|
dashboardResource: _testDashboard.default
|
|
46
46
|
};
|
|
47
47
|
});
|
|
48
|
-
const renderTimeRangeControls = ()=>{
|
|
48
|
+
const renderTimeRangeControls = (testURLParams)=>{
|
|
49
49
|
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
|
|
50
50
|
initialState: initialState,
|
|
51
51
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
|
|
52
|
-
|
|
52
|
+
initialTimeRange: testDefaultTimeRange,
|
|
53
|
+
enabledURLParams: testURLParams,
|
|
53
54
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
|
|
54
55
|
})
|
|
55
56
|
}), undefined, history);
|
|
56
57
|
};
|
|
57
|
-
it('should
|
|
58
|
-
renderTimeRangeControls();
|
|
59
|
-
expect(_react.screen.getByText('Last
|
|
60
|
-
});
|
|
61
|
-
// TODO: fix setTimeRange no-op, test query params
|
|
62
|
-
it('should be able to select the first option', ()=>{
|
|
63
|
-
renderTimeRangeControls();
|
|
58
|
+
it('should default to dashboard duration and update selected time option when clicked', async ()=>{
|
|
59
|
+
renderTimeRangeControls(false);
|
|
60
|
+
expect(_react.screen.getByText('Last 30 minutes')).toBeInTheDocument();
|
|
64
61
|
const dateButton = _react.screen.getByRole('button');
|
|
65
62
|
_userEvent.default.click(dateButton);
|
|
66
|
-
const
|
|
63
|
+
const firstSelected = _react.screen.getByRole('option', {
|
|
67
64
|
name: 'Last 5 minutes'
|
|
68
65
|
});
|
|
69
|
-
_userEvent.default.click(
|
|
66
|
+
_userEvent.default.click(firstSelected);
|
|
70
67
|
expect(dateButton).toHaveTextContent(/5 minutes/i);
|
|
71
68
|
});
|
|
69
|
+
it('should update URL params with correct time range values', ()=>{
|
|
70
|
+
renderTimeRangeControls(true);
|
|
71
|
+
const dateButton = _react.screen.getByRole('button');
|
|
72
|
+
_userEvent.default.click(dateButton);
|
|
73
|
+
const firstSelected = _react.screen.getByRole('option', {
|
|
74
|
+
name: 'Last 5 minutes'
|
|
75
|
+
});
|
|
76
|
+
_userEvent.default.click(firstSelected);
|
|
77
|
+
expect(history.location.search).toEqual('?start=5m');
|
|
78
|
+
// pick another option from TimeRangeSelector dropdown
|
|
79
|
+
const secondSelected = _react.screen.getByText('Last 12 hours');
|
|
80
|
+
_userEvent.default.click(secondSelected);
|
|
81
|
+
expect(history.location.search).toEqual('?start=12h');
|
|
82
|
+
// back button should return to first option selected
|
|
83
|
+
history.back();
|
|
84
|
+
expect(history.location.search).toEqual('?start=5m');
|
|
85
|
+
});
|
|
72
86
|
// TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
|
|
73
87
|
});
|
|
@@ -57,16 +57,24 @@ function ListVariable({ name }) {
|
|
|
57
57
|
const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
|
|
58
58
|
const { setVariableValue , setVariableLoading , setVariableOptions } = (0, _context.useTemplateVariableActions)();
|
|
59
59
|
const datasourceStore = (0, _pluginSystem.useDatasourceStore)();
|
|
60
|
+
const allVariables = (0, _pluginSystem.useTemplateVariableValues)();
|
|
61
|
+
const { timeRange } = (0, _pluginSystem.useTimeRange)();
|
|
62
|
+
const variablePluginCtx = {
|
|
63
|
+
timeRange,
|
|
64
|
+
datasourceStore,
|
|
65
|
+
variables: allVariables
|
|
66
|
+
};
|
|
60
67
|
const spec = definition.spec.plugin.spec;
|
|
61
68
|
let dependsOnVariables;
|
|
62
69
|
if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
|
|
63
|
-
|
|
70
|
+
const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
|
|
71
|
+
dependsOnVariables = dependencies.variables;
|
|
64
72
|
}
|
|
65
73
|
const variables = (0, _pluginSystem.useTemplateVariableValues)(dependsOnVariables);
|
|
66
74
|
const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
|
|
67
75
|
const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
|
|
68
76
|
var ref4;
|
|
69
|
-
const
|
|
77
|
+
const title = (ref4 = (ref = definition === null || definition === void 0 ? void 0 : definition.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref4 !== void 0 ? ref4 : name;
|
|
70
78
|
let waitToLoad = false;
|
|
71
79
|
if (dependsOnVariables) {
|
|
72
80
|
waitToLoad = dependsOnVariables.some((v)=>{
|
|
@@ -75,7 +83,6 @@ function ListVariable({ name }) {
|
|
|
75
83
|
});
|
|
76
84
|
}
|
|
77
85
|
const variablesValueKey = getVariableValuesKey(variables);
|
|
78
|
-
const { timeRange } = (0, _pluginSystem.useTimeRange)();
|
|
79
86
|
const variablesOptionsQuery = (0, _reactQuery.useQuery)([
|
|
80
87
|
name,
|
|
81
88
|
definition,
|
|
@@ -165,7 +172,7 @@ function ListVariable({ name }) {
|
|
|
165
172
|
children: [
|
|
166
173
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
|
|
167
174
|
id: name,
|
|
168
|
-
children:
|
|
175
|
+
children: title
|
|
169
176
|
}),
|
|
170
177
|
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
|
|
171
178
|
sx: {
|
|
@@ -98,10 +98,10 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
|
|
|
98
98
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
99
99
|
fullWidth: true,
|
|
100
100
|
label: "Label",
|
|
101
|
-
value: state.
|
|
101
|
+
value: state.title,
|
|
102
102
|
onChange: (v)=>{
|
|
103
103
|
setState((draft)=>{
|
|
104
|
-
draft.
|
|
104
|
+
draft.title = v.target.value;
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
})
|
|
@@ -47,7 +47,7 @@ function getInitialState(initialVariableDefinition) {
|
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
49
49
|
name: initialVariableDefinition.spec.name,
|
|
50
|
-
|
|
50
|
+
title: (ref = initialVariableDefinition.spec.display) === null || ref === void 0 ? void 0 : ref.name,
|
|
51
51
|
kind: initialVariableDefinition.kind,
|
|
52
52
|
description: '',
|
|
53
53
|
listVariableFields,
|
|
@@ -55,11 +55,11 @@ function getInitialState(initialVariableDefinition) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
function getVariableDefinitionFromState(state) {
|
|
58
|
-
const { name ,
|
|
58
|
+
const { name , title , kind } = state;
|
|
59
59
|
const commonSpec = {
|
|
60
60
|
name,
|
|
61
61
|
display: {
|
|
62
|
-
|
|
62
|
+
name: title
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
if (kind === 'TextVariable') {
|
|
@@ -19,10 +19,12 @@ Object.defineProperty(exports, "TemplateVariableList", {
|
|
|
19
19
|
get: ()=>TemplateVariableList
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _react = require("react");
|
|
22
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
23
23
|
const _material = require("@mui/material");
|
|
24
24
|
const _eye = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Eye"));
|
|
25
25
|
const _pencil = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pencil"));
|
|
26
|
+
const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
|
|
27
|
+
const _pinOffOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOffOutline"));
|
|
26
28
|
const _context = require("../../context");
|
|
27
29
|
const _variable = require("./Variable");
|
|
28
30
|
const _variableEditor = require("./VariableEditor");
|
|
@@ -31,13 +33,57 @@ function _interopRequireDefault(obj) {
|
|
|
31
33
|
default: obj
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
|
-
function
|
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
37
|
+
if (typeof WeakMap !== "function") return null;
|
|
38
|
+
var cacheBabelInterop = new WeakMap();
|
|
39
|
+
var cacheNodeInterop = new WeakMap();
|
|
40
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
41
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
42
|
+
})(nodeInterop);
|
|
43
|
+
}
|
|
44
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
45
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
49
|
+
return {
|
|
50
|
+
default: obj
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
54
|
+
if (cache && cache.has(obj)) {
|
|
55
|
+
return cache.get(obj);
|
|
56
|
+
}
|
|
57
|
+
var newObj = {};
|
|
58
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
59
|
+
for(var key in obj){
|
|
60
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
61
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
62
|
+
if (desc && (desc.get || desc.set)) {
|
|
63
|
+
Object.defineProperty(newObj, key, desc);
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = obj[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
newObj.default = obj;
|
|
70
|
+
if (cache) {
|
|
71
|
+
cache.set(obj, newObj);
|
|
72
|
+
}
|
|
73
|
+
return newObj;
|
|
74
|
+
}
|
|
75
|
+
function TemplateVariableList(props) {
|
|
35
76
|
const [isEditing, setIsEditing] = (0, _react.useState)(false);
|
|
77
|
+
const [isPin, setIsPin] = (0, _react.useState)(props.initialVariableIsSticky);
|
|
36
78
|
const variableDefinitions = (0, _context.useTemplateVariableDefinitions)();
|
|
37
79
|
const { isEditMode } = (0, _context.useEditMode)();
|
|
38
80
|
const [showVariablesInEditMode, setShowVariablesInEditMode] = (0, _react.useState)(true);
|
|
39
81
|
const showVariables = isEditMode ? showVariablesInEditMode : true;
|
|
40
82
|
const { setVariableDefinitions } = (0, _context.useTemplateVariableActions)();
|
|
83
|
+
const scrollTrigger = (0, _material.useScrollTrigger)({
|
|
84
|
+
disableHysteresis: true
|
|
85
|
+
});
|
|
86
|
+
const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;
|
|
41
87
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
42
88
|
children: [
|
|
43
89
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Drawer, {
|
|
@@ -72,21 +118,34 @@ function TemplateVariableList() {
|
|
|
72
118
|
})
|
|
73
119
|
]
|
|
74
120
|
}),
|
|
75
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
121
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.AppBar, {
|
|
122
|
+
color: 'inherit',
|
|
123
|
+
position: isSticky ? 'fixed' : 'static',
|
|
124
|
+
elevation: isSticky ? 4 : 0,
|
|
125
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
126
|
+
display: 'flex',
|
|
127
|
+
justifyContent: "space-between",
|
|
128
|
+
my: isSticky ? 2 : 0,
|
|
129
|
+
ml: isSticky ? 2 : 0,
|
|
130
|
+
children: [
|
|
131
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
|
|
132
|
+
direction: 'row',
|
|
133
|
+
spacing: 2,
|
|
134
|
+
children: showVariables && variableDefinitions.map((v)=>{
|
|
135
|
+
var ref;
|
|
136
|
+
/*#__PURE__*/ return (0, _jsxRuntime.jsx)(_material.Box, {
|
|
137
|
+
display: ((ref = v.spec.display) === null || ref === void 0 ? void 0 : ref.hidden) ? 'none' : undefined,
|
|
138
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variable.TemplateVariable, {
|
|
139
|
+
name: v.spec.name
|
|
140
|
+
}, v.spec.name)
|
|
141
|
+
}, v.spec.name);
|
|
142
|
+
})
|
|
143
|
+
}),
|
|
144
|
+
props.initialVariableIsSticky && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
145
|
+
onClick: ()=>setIsPin(!isPin),
|
|
146
|
+
children: isPin ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOffOutline.default, {})
|
|
147
|
+
})
|
|
148
|
+
]
|
|
90
149
|
})
|
|
91
150
|
})
|
|
92
151
|
]
|
|
@@ -80,8 +80,9 @@ function initStore(props) {
|
|
|
80
80
|
setEditMode: (isEditMode)=>set({
|
|
81
81
|
isEditMode
|
|
82
82
|
}),
|
|
83
|
-
setDashboard: ({ spec: { panels , layouts } })=>{
|
|
83
|
+
setDashboard: ({ metadata , spec: { panels , layouts } })=>{
|
|
84
84
|
set((state)=>{
|
|
85
|
+
state.metadata = metadata;
|
|
85
86
|
const { panelGroups , panelGroupOrder } = (0, _panelGroupSlice.convertLayoutsToPanelGroups)(layouts);
|
|
86
87
|
state.panels = panels;
|
|
87
88
|
state.panelGroups = panelGroups;
|
|
@@ -20,9 +20,9 @@ Object.defineProperty(exports, "generateId", {
|
|
|
20
20
|
enumerable: true,
|
|
21
21
|
get: ()=>generateId
|
|
22
22
|
});
|
|
23
|
-
if (globalThis.dashboardStoreId === undefined) {
|
|
24
|
-
globalThis.dashboardStoreId = 0;
|
|
25
|
-
}
|
|
26
23
|
function generateId() {
|
|
24
|
+
if (globalThis.dashboardStoreId === undefined) {
|
|
25
|
+
globalThis.dashboardStoreId = 0;
|
|
26
|
+
}
|
|
27
27
|
return globalThis.dashboardStoreId++;
|
|
28
28
|
}
|
|
@@ -37,28 +37,34 @@ _export(exports, {
|
|
|
37
37
|
});
|
|
38
38
|
const _react = require("react");
|
|
39
39
|
const _dashboardProvider = require("./DashboardProvider");
|
|
40
|
+
const selectEditMode = ({ isEditMode , setEditMode })=>({
|
|
41
|
+
isEditMode,
|
|
42
|
+
setEditMode
|
|
43
|
+
});
|
|
40
44
|
function useEditMode() {
|
|
41
|
-
return (0, _dashboardProvider.useDashboardStore)(
|
|
42
|
-
isEditMode,
|
|
43
|
-
setEditMode
|
|
44
|
-
}));
|
|
45
|
+
return (0, _dashboardProvider.useDashboardStore)(selectEditMode);
|
|
45
46
|
}
|
|
47
|
+
const selectDashboardActions = ({ setDashboard , openAddPanelGroup , openAddPanel })=>({
|
|
48
|
+
setDashboard,
|
|
49
|
+
openAddPanelGroup,
|
|
50
|
+
openAddPanel
|
|
51
|
+
});
|
|
46
52
|
function useDashboardActions() {
|
|
47
|
-
const setDashboard = (0, _dashboardProvider.useDashboardStore)(
|
|
48
|
-
const openAddPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanelGroup);
|
|
49
|
-
const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
|
|
53
|
+
const { setDashboard , openAddPanelGroup , openAddPanel } = (0, _dashboardProvider.useDashboardStore)(selectDashboardActions);
|
|
50
54
|
return {
|
|
51
55
|
setDashboard,
|
|
52
|
-
openAddPanelGroup,
|
|
53
|
-
openAddPanel: ()=>openAddPanel(
|
|
56
|
+
openAddPanelGroup: ()=>openAddPanelGroup(),
|
|
57
|
+
openAddPanel: ()=>openAddPanel()
|
|
54
58
|
};
|
|
55
59
|
}
|
|
60
|
+
const selectPanelGroupOrder = (state)=>state.panelGroupOrder;
|
|
56
61
|
function usePanelGroupIds() {
|
|
57
|
-
return (0, _dashboardProvider.useDashboardStore)(
|
|
62
|
+
return (0, _dashboardProvider.useDashboardStore)(selectPanelGroupOrder);
|
|
58
63
|
}
|
|
64
|
+
const selectPanelGroups = (state)=>state.panelGroups;
|
|
59
65
|
function useListPanelGroups() {
|
|
60
66
|
const panelGroupIds = usePanelGroupIds();
|
|
61
|
-
const panelGroups = (0, _dashboardProvider.useDashboardStore)(
|
|
67
|
+
const panelGroups = (0, _dashboardProvider.useDashboardStore)(selectPanelGroups);
|
|
62
68
|
return (0, _react.useMemo)(()=>{
|
|
63
69
|
return panelGroupIds.map((id)=>{
|
|
64
70
|
const group = panelGroups[id];
|
|
@@ -73,18 +79,23 @@ function useListPanelGroups() {
|
|
|
73
79
|
]);
|
|
74
80
|
}
|
|
75
81
|
function usePanelGroup(panelGroupId) {
|
|
76
|
-
const panelGroup = (0, _dashboardProvider.useDashboardStore)((
|
|
82
|
+
const panelGroup = (0, _dashboardProvider.useDashboardStore)((0, _react.useCallback)((state)=>state.panelGroups[panelGroupId], [
|
|
83
|
+
panelGroupId
|
|
84
|
+
]));
|
|
77
85
|
if (panelGroup === undefined) {
|
|
78
86
|
throw new Error(`Panel group with Id ${panelGroupId} was not found`);
|
|
79
87
|
}
|
|
80
88
|
return panelGroup;
|
|
81
89
|
}
|
|
90
|
+
const selectPanelGroupActions = ({ openEditPanelGroup , deletePanelGroup , openAddPanel , updatePanelGroupLayouts })=>({
|
|
91
|
+
openEditPanelGroup,
|
|
92
|
+
deletePanelGroup,
|
|
93
|
+
openAddPanel,
|
|
94
|
+
updatePanelGroupLayouts
|
|
95
|
+
});
|
|
82
96
|
function usePanelGroupActions(panelGroupId) {
|
|
83
97
|
const { moveUp , moveDown } = useMovePanelGroup(panelGroupId);
|
|
84
|
-
const openEditPanelGroup = (0, _dashboardProvider.useDashboardStore)(
|
|
85
|
-
const deletePanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openDeletePanelGroupDialog);
|
|
86
|
-
const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
|
|
87
|
-
const updatePanelGroupLayouts = (0, _dashboardProvider.useDashboardStore)((store)=>store.updatePanelGroupLayouts);
|
|
98
|
+
const { openEditPanelGroup , deletePanelGroup , openAddPanel , updatePanelGroupLayouts } = (0, _dashboardProvider.useDashboardStore)(selectPanelGroupActions);
|
|
88
99
|
return {
|
|
89
100
|
openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
|
|
90
101
|
deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
|
|
@@ -94,13 +105,17 @@ function usePanelGroupActions(panelGroupId) {
|
|
|
94
105
|
updatePanelGroupLayouts: (itemLayouts)=>updatePanelGroupLayouts(panelGroupId, itemLayouts)
|
|
95
106
|
};
|
|
96
107
|
}
|
|
108
|
+
const selectSwapPanelGroups = (state)=>state.swapPanelGroups;
|
|
109
|
+
const selectPanelGroupsLength = (state)=>state.panelGroupOrder.length;
|
|
97
110
|
/**
|
|
98
111
|
* Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
|
|
99
112
|
* moved in that direction.
|
|
100
113
|
*/ function useMovePanelGroup(panelGroupId) {
|
|
101
|
-
const currentIndex = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId)
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
const currentIndex = (0, _dashboardProvider.useDashboardStore)((0, _react.useCallback)((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId), [
|
|
115
|
+
panelGroupId
|
|
116
|
+
]));
|
|
117
|
+
const panelGroupsLength = (0, _dashboardProvider.useDashboardStore)(selectPanelGroupsLength);
|
|
118
|
+
const swapPanelGroups = (0, _dashboardProvider.useDashboardStore)(selectSwapPanelGroups);
|
|
104
119
|
if (currentIndex < 0) {
|
|
105
120
|
throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
|
|
106
121
|
}
|
|
@@ -111,52 +126,66 @@ function usePanelGroupActions(panelGroupId) {
|
|
|
111
126
|
moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined
|
|
112
127
|
};
|
|
113
128
|
}
|
|
129
|
+
const selectPanelGroupEditor = (state)=>state.panelGroupEditor;
|
|
114
130
|
function usePanelGroupEditor() {
|
|
115
|
-
return (0, _dashboardProvider.useDashboardStore)(
|
|
131
|
+
return (0, _dashboardProvider.useDashboardStore)(selectPanelGroupEditor);
|
|
116
132
|
}
|
|
133
|
+
const selectDeletePanelGroupDialog = ({ deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup })=>({
|
|
134
|
+
deletePanelGroupDialog,
|
|
135
|
+
openDeletePanelGroupDialog,
|
|
136
|
+
closeDeletePanelGroupDialog,
|
|
137
|
+
deletePanelGroup
|
|
138
|
+
});
|
|
117
139
|
function useDeletePanelGroupDialog() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
140
|
+
const { deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup } = (0, _dashboardProvider.useDashboardStore)(selectDeletePanelGroupDialog);
|
|
141
|
+
return {
|
|
142
|
+
deletePanelGroupDialog,
|
|
143
|
+
deletePanelGroup,
|
|
144
|
+
openDeletePanelGroupDialog,
|
|
145
|
+
closeDeletePanelGroupDialog: ()=>closeDeletePanelGroupDialog()
|
|
146
|
+
};
|
|
124
147
|
}
|
|
125
148
|
function usePanel(panelGroupItemId) {
|
|
126
149
|
const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
|
|
127
|
-
const panel = (0, _dashboardProvider.useDashboardStore)((store)=>{
|
|
150
|
+
const panel = (0, _dashboardProvider.useDashboardStore)((0, _react.useCallback)((store)=>{
|
|
128
151
|
var ref;
|
|
129
152
|
const panelKey = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
|
|
130
153
|
if (panelKey === undefined) return;
|
|
131
154
|
return store.panels[panelKey];
|
|
132
|
-
}
|
|
155
|
+
}, [
|
|
156
|
+
panelGroupId,
|
|
157
|
+
panelGroupLayoutId
|
|
158
|
+
]));
|
|
133
159
|
if (panel === undefined) {
|
|
134
160
|
throw new Error(`Could not find panel for Id ${panelGroupItemId}`);
|
|
135
161
|
}
|
|
136
162
|
return panel;
|
|
137
163
|
}
|
|
164
|
+
const selectPanelActions = ({ openEditPanel , openDeletePanelDialog })=>({
|
|
165
|
+
openEditPanel,
|
|
166
|
+
openDeletePanelDialog
|
|
167
|
+
});
|
|
138
168
|
function usePanelActions(panelGroupItemId) {
|
|
139
|
-
const openEditPanel = (0, _dashboardProvider.useDashboardStore)(
|
|
140
|
-
const openDeletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.openDeletePanelDialog);
|
|
169
|
+
const { openEditPanel , openDeletePanelDialog } = (0, _dashboardProvider.useDashboardStore)(selectPanelActions);
|
|
141
170
|
return {
|
|
142
171
|
openEditPanel: ()=>openEditPanel(panelGroupItemId),
|
|
143
172
|
openDeletePanelDialog: ()=>openDeletePanelDialog(panelGroupItemId)
|
|
144
173
|
};
|
|
145
174
|
}
|
|
175
|
+
const selectPanelEditor = (state)=>state.panelEditor;
|
|
146
176
|
function usePanelEditor() {
|
|
147
|
-
return (0, _dashboardProvider.useDashboardStore)(
|
|
177
|
+
return (0, _dashboardProvider.useDashboardStore)(selectPanelEditor);
|
|
148
178
|
}
|
|
149
|
-
|
|
150
|
-
const deletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanelDialog);
|
|
151
|
-
// TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
|
|
152
|
-
const deletePanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanel);
|
|
153
|
-
const closeDeletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.closeDeletePanelDialog);
|
|
154
|
-
return {
|
|
179
|
+
const selectDeletePanelDialog = ({ deletePanelDialog , deletePanel , closeDeletePanelDialog })=>({
|
|
155
180
|
deletePanelDialog,
|
|
156
181
|
deletePanel,
|
|
157
182
|
closeDeletePanelDialog
|
|
158
|
-
};
|
|
183
|
+
});
|
|
184
|
+
function useDeletePanelDialog() {
|
|
185
|
+
// TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
|
|
186
|
+
return (0, _dashboardProvider.useDashboardStore)(selectDeletePanelDialog);
|
|
159
187
|
}
|
|
188
|
+
const selectDefaultTimeRange = (state)=>state.defaultTimeRange;
|
|
160
189
|
function useDefaultTimeRange() {
|
|
161
|
-
return (0, _dashboardProvider.useDashboardStore)(
|
|
190
|
+
return (0, _dashboardProvider.useDashboardStore)(selectDefaultTimeRange);
|
|
162
191
|
}
|
|
@@ -27,6 +27,7 @@ _export(exports, {
|
|
|
27
27
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
28
28
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
29
29
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
30
|
+
const _queryParams = require("./query-params");
|
|
30
31
|
function _getRequireWildcardCache(nodeInterop) {
|
|
31
32
|
if (typeof WeakMap !== "function") return null;
|
|
32
33
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -67,12 +68,11 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
67
68
|
return newObj;
|
|
68
69
|
}
|
|
69
70
|
function TimeRangeProvider(props) {
|
|
70
|
-
const {
|
|
71
|
-
|
|
71
|
+
const { initialTimeRange , enabledURLParams , children } = props;
|
|
72
|
+
const { timeRange , setTimeRange } = (0, _queryParams.useSetTimeRangeParams)(initialTimeRange, enabledURLParams);
|
|
72
73
|
const ctx = (0, _react.useMemo)(()=>({
|
|
73
74
|
timeRange,
|
|
74
|
-
setTimeRange
|
|
75
|
-
/* no-op */ }
|
|
75
|
+
setTimeRange
|
|
76
76
|
}), [
|
|
77
77
|
timeRange,
|
|
78
78
|
setTimeRange
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./
|
|
17
|
+
_exportStar(require("./TimeRangeProvider"), exports);
|
|
18
|
+
_exportStar(require("./query-params"), exports);
|
|
18
19
|
function _exportStar(from, to) {
|
|
19
20
|
Object.keys(from).forEach(function(k) {
|
|
20
21
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -106,23 +106,29 @@ function useInitialTimeRange(dashboardDuration) {
|
|
|
106
106
|
dashboardDuration
|
|
107
107
|
]);
|
|
108
108
|
}
|
|
109
|
-
function useSetTimeRangeParams(initialTimeRange,
|
|
109
|
+
function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
|
|
110
110
|
const [query, setQuery] = (0, _useQueryParams.useQueryParams)(timeRangeQueryConfig);
|
|
111
|
-
//
|
|
111
|
+
// determine whether initial param had previously been populated to fix back btn
|
|
112
|
+
const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
|
|
113
|
+
// optional fallback when app does not want query string as source of truth
|
|
114
|
+
// this occurs when enabledURLParams is set to false on TimeRangeProvider
|
|
112
115
|
const [timeRangeState, setTimeRangeState] = (0, _react.useState)(initialTimeRange);
|
|
113
116
|
const { start } = query;
|
|
114
117
|
(0, _react.useEffect)(()=>{
|
|
115
|
-
|
|
118
|
+
// when dashboard loaded with no params, default to dashboard duration
|
|
119
|
+
if (enabledURLParams && !paramsLoaded && !start) {
|
|
116
120
|
if ((0, _core.isRelativeTimeRange)(initialTimeRange)) {
|
|
117
121
|
setQuery({
|
|
118
122
|
start: initialTimeRange.pastDuration,
|
|
119
123
|
end: undefined
|
|
120
124
|
});
|
|
125
|
+
setParamsLoaded(true);
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
}, [
|
|
124
129
|
initialTimeRange,
|
|
125
|
-
|
|
130
|
+
enabledURLParams,
|
|
131
|
+
paramsLoaded,
|
|
126
132
|
start,
|
|
127
133
|
setQuery
|
|
128
134
|
]);
|
|
@@ -138,7 +144,7 @@ function useSetTimeRangeParams(initialTimeRange, paramsEnabled = true) {
|
|
|
138
144
|
}, [
|
|
139
145
|
setQuery
|
|
140
146
|
]);
|
|
141
|
-
if (!
|
|
147
|
+
if (!enabledURLParams) {
|
|
142
148
|
return {
|
|
143
149
|
timeRange: timeRangeState,
|
|
144
150
|
setTimeRange: setTimeRangeState
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,7 +16,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./components"), exports);
|
|
18
18
|
_exportStar(require("./context"), exports);
|
|
19
|
-
_exportStar(require("./utils"), exports);
|
|
20
19
|
_exportStar(require("./views"), exports);
|
|
21
20
|
function _exportStar(from, to) {
|
|
22
21
|
Object.keys(from).forEach(function(k) {
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -48,7 +48,6 @@ function renderWithContext(ui, options, history) {
|
|
|
48
48
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_useQueryParams.QueryParamProvider, {
|
|
49
49
|
adapter: _reactRouter6.ReactRouter6Adapter,
|
|
50
50
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ChartsThemeProvider, {
|
|
51
|
-
themeName: "perses",
|
|
52
51
|
chartsTheme: _components.testChartsTheme,
|
|
53
52
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginRegistry, {
|
|
54
53
|
...(0, _pluginSystem.mockPluginRegistry)(..._pluginRegistry.MOCK_PLUGINS),
|
|
@@ -19,10 +19,10 @@ Object.defineProperty(exports, "useId", {
|
|
|
19
19
|
get: ()=>useId
|
|
20
20
|
});
|
|
21
21
|
const _react = require("react");
|
|
22
|
-
if (globalThis.useIdValue === undefined) {
|
|
23
|
-
globalThis.useIdValue = 0;
|
|
24
|
-
}
|
|
25
22
|
function useId(prefix) {
|
|
23
|
+
if (globalThis.useIdValue === undefined) {
|
|
24
|
+
globalThis.useIdValue = 0;
|
|
25
|
+
}
|
|
26
26
|
const id = (0, _react.useRef)(undefined);
|
|
27
27
|
if (id.current === undefined) {
|
|
28
28
|
id.current = `${prefix}-${globalThis.useIdValue++}`;
|
|
@@ -25,7 +25,7 @@ const _components = require("@perses-dev/components");
|
|
|
25
25
|
const _components1 = require("../../components");
|
|
26
26
|
const _context = require("../../context");
|
|
27
27
|
const DashboardApp = (props)=>{
|
|
28
|
-
const { dashboardResource } = props;
|
|
28
|
+
const { dashboardResource , dashboardTitleComponent , initialVariableIsSticky } = props;
|
|
29
29
|
const { setEditMode } = (0, _context.useEditMode)();
|
|
30
30
|
const { dashboard , setDashboard } = (0, _context.useDashboard)();
|
|
31
31
|
const [originalDashboard, setOriginalDashboard] = (0, _react.useState)(undefined);
|
|
@@ -65,6 +65,8 @@ const DashboardApp = (props)=>{
|
|
|
65
65
|
children: [
|
|
66
66
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.DashboardToolbar, {
|
|
67
67
|
dashboardName: dashboardResource.metadata.name,
|
|
68
|
+
dashboardTitleComponent: dashboardTitleComponent,
|
|
69
|
+
initialVariableIsSticky: initialVariableIsSticky,
|
|
68
70
|
onEditButtonClick: onEditButtonClick,
|
|
69
71
|
onCancelButtonClick: onCancelButtonClick
|
|
70
72
|
}),
|