@perses-dev/dashboards 0.7.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Dashboard.js +1 -1
- package/dist/cjs/components/DashboardToolbar.js +3 -18
- package/dist/cjs/components/GridLayout/GridItemContent.js +3 -3
- package/dist/cjs/components/GridLayout/GridLayout.js +4 -7
- package/dist/cjs/components/GridLayout/GridTitle.js +15 -9
- package/dist/cjs/components/Panel/Panel.js +11 -6
- package/dist/cjs/components/Panel/Panel.test.js +17 -13
- package/dist/cjs/components/Panel/PanelContent.js +15 -0
- package/dist/cjs/components/Panel/index.js +29 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +124 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +111 -0
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +19 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +60 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -0
- package/dist/cjs/components/{TimeRangeControls.js → TimeRangeControls/TimeRangeControls.js} +20 -31
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +51 -0
- package/dist/cjs/components/TimeRangeControls/index.js +29 -0
- package/dist/cjs/components/Variables/Variable.js +57 -0
- package/dist/cjs/components/Variables/VariableList.js +27 -0
- package/dist/cjs/components/{VariableList → Variables}/index.js +1 -0
- package/dist/cjs/components/index.js +2 -3
- package/dist/cjs/context/DashboardAppSlice.js +45 -0
- package/dist/cjs/context/DashboardProvider.js +54 -36
- package/dist/cjs/context/LayoutsSlice.js +42 -0
- package/dist/cjs/context/QueryStringProvider.js +35 -0
- package/dist/cjs/context/TemplateVariableProvider.js +216 -0
- package/dist/cjs/context/TimeRangeProvider.js +66 -0
- package/dist/cjs/context/index.js +6 -3
- package/dist/cjs/css/styles.js +173 -169
- package/dist/cjs/test/plugin-registry.js +24 -17
- package/dist/cjs/test/render.js +11 -2
- package/dist/cjs/test/testDashboard.js +14 -37
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -0
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +52 -0
- package/dist/cjs/views/ViewDashboard/index.js +29 -0
- package/dist/cjs/views/index.js +1 -1
- package/dist/components/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard.js +1 -1
- package/dist/components/DashboardToolbar.d.ts +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +1 -0
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +1 -1
- package/dist/components/Panel/Panel.d.ts +2 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +1 -1
- package/dist/components/Panel/Panel.test.d.ts.map +1 -1
- package/dist/components/Panel/Panel.test.js +1 -1
- package/dist/components/Panel/PanelContent.d.ts +11 -0
- package/dist/components/Panel/PanelContent.d.ts.map +1 -0
- package/dist/components/Panel/PanelContent.js +1 -0
- package/dist/components/Panel/index.d.ts +2 -0
- package/dist/components/Panel/index.d.ts.map +1 -0
- package/dist/components/Panel/index.js +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.js +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +2 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +1 -0
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +9 -0
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +2 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -0
- package/dist/components/{TimeRangeControls.d.ts → TimeRangeControls/TimeRangeControls.d.ts} +0 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +2 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -0
- package/dist/components/TimeRangeControls/index.d.ts +2 -0
- package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
- package/dist/components/TimeRangeControls/index.js +1 -0
- package/dist/components/Variables/Variable.d.ts +8 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -0
- package/dist/components/Variables/Variable.js +1 -0
- package/dist/components/Variables/VariableList.d.ts +3 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -0
- package/dist/components/Variables/VariableList.js +1 -0
- package/dist/components/Variables/index.d.ts +3 -0
- package/dist/components/Variables/index.d.ts.map +1 -0
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/index.d.ts +2 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/context/DashboardAppSlice.d.ts +26 -0
- package/dist/context/DashboardAppSlice.d.ts.map +1 -0
- package/dist/context/DashboardAppSlice.js +1 -0
- package/dist/context/DashboardProvider.d.ts +8 -19
- package/dist/context/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider.js +1 -1
- package/dist/context/LayoutsSlice.d.ts +12 -0
- package/dist/context/LayoutsSlice.d.ts.map +1 -0
- package/dist/context/LayoutsSlice.js +1 -0
- package/dist/context/QueryStringProvider.d.ts +13 -0
- package/dist/context/QueryStringProvider.d.ts.map +1 -0
- package/dist/context/QueryStringProvider.js +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +25 -0
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider.js +1 -0
- package/dist/context/TimeRangeProvider.d.ts +12 -0
- package/dist/context/TimeRangeProvider.d.ts.map +1 -0
- package/dist/context/TimeRangeProvider.js +1 -0
- package/dist/context/index.d.ts +5 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/css/styles.d.ts +7 -7
- package/dist/css/styles.d.ts.map +1 -1
- package/dist/css/styles.js +1 -1
- package/dist/test/plugin-registry.d.ts +4 -2
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +1 -1
- package/dist/test/render.d.ts +2 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +1 -1
- 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 +1 -0
- package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.js +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 +1 -0
- package/package.json +9 -11
- package/dist/cjs/components/AddPanel/AddPanel.js +0 -75
- package/dist/cjs/components/VariableAutocomplete.js +0 -63
- package/dist/cjs/components/VariableList/VariableList.js +0 -42
- package/dist/cjs/components/VariableList/VariableList.test.js +0 -86
- package/dist/cjs/context/TemplateVariablesProvider.js +0 -142
- package/dist/cjs/context/TimeRangeStateProvider.js +0 -49
- package/dist/cjs/views/DashboardApp.js +0 -46
- package/dist/cjs/views/ViewDashboard.js +0 -15
- package/dist/components/AddPanel/AddPanel.d.ts +0 -8
- package/dist/components/AddPanel/AddPanel.d.ts.map +0 -1
- package/dist/components/AddPanel/AddPanel.js +0 -1
- package/dist/components/TimeRangeControls.d.ts.map +0 -1
- package/dist/components/TimeRangeControls.js +0 -1
- package/dist/components/VariableAutocomplete.d.ts +0 -21
- package/dist/components/VariableAutocomplete.d.ts.map +0 -1
- package/dist/components/VariableAutocomplete.js +0 -1
- package/dist/components/VariableList/VariableList.d.ts +0 -11
- package/dist/components/VariableList/VariableList.d.ts.map +0 -1
- package/dist/components/VariableList/VariableList.js +0 -1
- package/dist/components/VariableList/VariableList.test.d.ts +0 -2
- package/dist/components/VariableList/VariableList.test.d.ts.map +0 -1
- package/dist/components/VariableList/VariableList.test.js +0 -1
- package/dist/components/VariableList/index.d.ts +0 -2
- package/dist/components/VariableList/index.d.ts.map +0 -1
- package/dist/components/VariableList/index.js +0 -1
- package/dist/context/TemplateVariablesProvider.d.ts +0 -23
- package/dist/context/TemplateVariablesProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariablesProvider.js +0 -1
- package/dist/context/TimeRangeStateProvider.d.ts +0 -22
- package/dist/context/TimeRangeStateProvider.d.ts.map +0 -1
- package/dist/context/TimeRangeStateProvider.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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
+
const react_1 = require("@testing-library/react");
|
|
31
|
+
const user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
32
|
+
const immer_1 = __importDefault(require("immer"));
|
|
33
|
+
const dashboardAppSlice = __importStar(require("../../context/DashboardAppSlice"));
|
|
34
|
+
const layoutsSlice = __importStar(require("../../context/LayoutsSlice"));
|
|
35
|
+
const test_1 = require("../../test");
|
|
36
|
+
const testDashboard_1 = __importDefault(require("../../test/testDashboard"));
|
|
37
|
+
const PanelGroupDialog_1 = __importDefault(require("./PanelGroupDialog"));
|
|
38
|
+
const dashboardApp = {
|
|
39
|
+
panelDrawer: undefined,
|
|
40
|
+
openPanelDrawer: jest.fn(),
|
|
41
|
+
closePanelDrawer: jest.fn(),
|
|
42
|
+
panelGroupDialog: {
|
|
43
|
+
groupIndex: undefined,
|
|
44
|
+
},
|
|
45
|
+
openPanelGroupDialog: jest.fn(),
|
|
46
|
+
closePanelGroupDialog: jest.fn(),
|
|
47
|
+
};
|
|
48
|
+
const updateLayout = jest.fn();
|
|
49
|
+
jest.spyOn(layoutsSlice, 'useLayouts').mockReturnValue({
|
|
50
|
+
updateLayout,
|
|
51
|
+
addItemToLayout: jest.fn(),
|
|
52
|
+
layouts: testDashboard_1.default.spec.layouts,
|
|
53
|
+
});
|
|
54
|
+
describe('Add Panel Group', () => {
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
jest.clearAllMocks();
|
|
57
|
+
});
|
|
58
|
+
it('should add new panel group', () => {
|
|
59
|
+
jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);
|
|
60
|
+
(0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(PanelGroupDialog_1.default, {}));
|
|
61
|
+
const nameInput = react_1.screen.getByLabelText(/Name/);
|
|
62
|
+
user_event_1.default.type(nameInput, 'New Panel Group');
|
|
63
|
+
user_event_1.default.click(react_1.screen.getByText('Add'));
|
|
64
|
+
expect(updateLayout).toHaveBeenCalledWith({
|
|
65
|
+
kind: 'Grid',
|
|
66
|
+
spec: {
|
|
67
|
+
display: {
|
|
68
|
+
title: 'New Panel Group',
|
|
69
|
+
collapse: {
|
|
70
|
+
open: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
items: [],
|
|
74
|
+
},
|
|
75
|
+
}, undefined);
|
|
76
|
+
});
|
|
77
|
+
it('should edit existing panel group', () => {
|
|
78
|
+
jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue({
|
|
79
|
+
...dashboardApp,
|
|
80
|
+
panelGroupDialog: {
|
|
81
|
+
groupIndex: 0,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
(0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(PanelGroupDialog_1.default, {}));
|
|
85
|
+
const nameInput = react_1.screen.getByLabelText(/Name/);
|
|
86
|
+
user_event_1.default.type(nameInput, 'New Name');
|
|
87
|
+
user_event_1.default.click(react_1.screen.getByText('Apply'));
|
|
88
|
+
expect(updateLayout).toHaveBeenCalledWith((0, immer_1.default)(testDashboard_1.default.spec.layouts[0], (draftState) => {
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
90
|
+
draftState.spec.display.title += 'New Name';
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
92
|
+
draftState.spec.display.collapse = { open: false };
|
|
93
|
+
}), 0);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -16,11 +16,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
16
16
|
// limitations under the License.
|
|
17
17
|
const react_1 = require("react");
|
|
18
18
|
const material_1 = require("@mui/material");
|
|
19
|
-
const date_fns_1 = require("date-fns");
|
|
20
19
|
const components_1 = require("@perses-dev/components");
|
|
21
20
|
const core_1 = require("@perses-dev/core");
|
|
22
21
|
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
23
|
-
const
|
|
22
|
+
const context_1 = require("../../context");
|
|
24
23
|
// TODO: add time shortcut if one does not match duration
|
|
25
24
|
exports.TIME_OPTIONS = [
|
|
26
25
|
{ value: { pastDuration: '5m' }, display: 'Last 5 minutes' },
|
|
@@ -33,17 +32,13 @@ exports.TIME_OPTIONS = [
|
|
|
33
32
|
{ value: { pastDuration: '7d' }, display: 'Last 7 days' },
|
|
34
33
|
{ value: { pastDuration: '14d' }, display: 'Last 14 days' },
|
|
35
34
|
];
|
|
36
|
-
const FORM_CONTROL_LABEL = 'Time Range';
|
|
37
35
|
function TimeRangeControls() {
|
|
38
|
-
const { setTimeRange } = (0,
|
|
39
|
-
const {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const [
|
|
44
|
-
start: (0, date_fns_1.sub)(new Date(), { ...defaultStart }),
|
|
45
|
-
end: new Date(),
|
|
46
|
-
});
|
|
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);
|
|
40
|
+
// selected form value can be relative or absolute, timeRange from plugin-system is only absolute
|
|
41
|
+
const [selectedTimeRange, setSelectedTimeRange] = (0, react_1.useState)(defaultTimeRange);
|
|
47
42
|
const [showCustomDateSelector, setShowCustomDateSelector] = (0, react_1.useState)(false);
|
|
48
43
|
const anchorEl = (0, react_1.useRef)();
|
|
49
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: {
|
|
@@ -51,27 +46,21 @@ function TimeRangeControls() {
|
|
|
51
46
|
horizontal: 'center',
|
|
52
47
|
}, open: showCustomDateSelector, onClose: () => setShowCustomDateSelector(false), sx: (theme) => ({
|
|
53
48
|
padding: theme.spacing(2),
|
|
54
|
-
}), children: (0, jsx_runtime_1.jsx)(components_1.AbsoluteTimePicker, { initialTimeRange:
|
|
49
|
+
}), children: (0, jsx_runtime_1.jsx)(components_1.AbsoluteTimePicker, { initialTimeRange: timeRange, onChange: (timeRange) => {
|
|
55
50
|
setTimeRange(timeRange);
|
|
56
|
-
if (!(0, core_1.isRelativeValue)(timeRange)) {
|
|
57
|
-
setAbsoluteTime({ start: timeRange.start, end: timeRange.end });
|
|
58
|
-
}
|
|
59
51
|
setSelectedTimeRange(timeRange);
|
|
60
52
|
setShowCustomDateSelector(false);
|
|
61
|
-
} }) }), (0, jsx_runtime_1.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, onCustomClick: () => {
|
|
74
|
-
setShowCustomDateSelector(true);
|
|
75
|
-
} }) })] })] }));
|
|
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) => {
|
|
54
|
+
const duration = event.target.value;
|
|
55
|
+
const relativeTimeInput = {
|
|
56
|
+
pastDuration: duration,
|
|
57
|
+
end: new Date(),
|
|
58
|
+
};
|
|
59
|
+
setTimeRange(relativeTimeInput);
|
|
60
|
+
setSelectedTimeRange(relativeTimeInput);
|
|
61
|
+
setShowCustomDateSelector(false);
|
|
62
|
+
}, onCustomClick: () => {
|
|
63
|
+
setShowCustomDateSelector(true);
|
|
64
|
+
} }) }) })] }));
|
|
76
65
|
}
|
|
77
66
|
exports.TimeRangeControls = TimeRangeControls;
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
// Copyright 2022 The Perses Authors
|
|
8
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
// you may not use this file except in compliance with the License.
|
|
10
|
+
// You may obtain a copy of the License at
|
|
11
|
+
//
|
|
12
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
//
|
|
14
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
// See the License for the specific language governing permissions and
|
|
18
|
+
// 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', () => {
|
|
27
|
+
let initialState;
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
initialState = {
|
|
30
|
+
dashboardSpec: testDashboard_1.default.spec,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
const renderTimeRangeControls = () => {
|
|
34
|
+
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, {}) }) }) }));
|
|
37
|
+
};
|
|
38
|
+
it('should render correct initial relative time shortcut', async () => {
|
|
39
|
+
renderTimeRangeControls();
|
|
40
|
+
expect(react_1.screen.getByText('Last 1 day')).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
it('should be able to select the first option', () => {
|
|
43
|
+
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);
|
|
48
|
+
expect(dateButton).toHaveTextContent(/5 minutes/i);
|
|
49
|
+
});
|
|
50
|
+
// TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
|
|
51
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./TimeRangeControls"), exports);
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
// Copyright 2022 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const material_1 = require("@mui/material");
|
|
19
|
+
const 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) {
|
|
26
|
+
case 'TextVariable':
|
|
27
|
+
return (0, jsx_runtime_1.jsx)(TextVariable, { name: name });
|
|
28
|
+
case 'ListVariable':
|
|
29
|
+
return (0, jsx_runtime_1.jsx)(ListVariable, { name: name });
|
|
30
|
+
}
|
|
31
|
+
return (0, jsx_runtime_1.jsxs)("div", { children: ["Unsupported Variable Kind: $", kind] });
|
|
32
|
+
}
|
|
33
|
+
exports.TemplateVariable = TemplateVariable;
|
|
34
|
+
function ListVariable({ name }) {
|
|
35
|
+
var _a, _b, _c, _d;
|
|
36
|
+
const ctx = (0, context_1.useTemplateVariable)(name);
|
|
37
|
+
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;
|
|
44
|
+
if (allowMultiple && !Array.isArray(value)) {
|
|
45
|
+
value = [];
|
|
46
|
+
}
|
|
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, {}) })] }));
|
|
50
|
+
}
|
|
51
|
+
function TextVariable({ name }) {
|
|
52
|
+
const { state } = (0, context_1.useTemplateVariable)(name);
|
|
53
|
+
const s = (0, context_1.useTemplateVariableStore)();
|
|
54
|
+
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 }));
|
|
57
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplateVariableList = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2022 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const material_1 = require("@mui/material");
|
|
19
|
+
const context_1 = require("../../context");
|
|
20
|
+
const Variable_1 = require("./Variable");
|
|
21
|
+
function TemplateVariableList() {
|
|
22
|
+
const [isEditing, setIsEditing] = (0, react_1.useState)(false);
|
|
23
|
+
const variableDefinitions = (0, context_1.useTemplateVariableDefinitions)();
|
|
24
|
+
const { isEditMode } = (0, context_1.useEditMode)();
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { m: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Drawer, { anchor: 'right', open: isEditing, onClose: () => setIsEditing(false), children: (0, jsx_runtime_1.jsxs)(material_1.Box, { width: 900, p: 4, children: [(0, jsx_runtime_1.jsx)(material_1.TableContainer, { component: material_1.Paper, children: (0, jsx_runtime_1.jsxs)(material_1.Table, { sx: { minWidth: 650 }, "aria-label": "simple table", children: [(0, jsx_runtime_1.jsx)(material_1.TableHead, { children: (0, jsx_runtime_1.jsxs)(material_1.TableRow, { children: [(0, jsx_runtime_1.jsx)(material_1.TableCell, { children: "Variable Name" }), (0, jsx_runtime_1.jsx)(material_1.TableCell, { align: "right", children: "Type" })] }) }), (0, jsx_runtime_1.jsx)(material_1.TableBody, { children: variableDefinitions.map((v) => ((0, jsx_runtime_1.jsxs)(material_1.TableRow, { sx: { '&:last-child td, &:last-child th': { border: 0 } }, children: [(0, jsx_runtime_1.jsx)(material_1.TableCell, { component: "th", scope: "row", sx: { fontWeight: 'bold' }, children: v.name }), (0, jsx_runtime_1.jsx)(material_1.TableCell, { align: "right", children: v.kind })] }, v.name))) })] }) }), (0, jsx_runtime_1.jsx)("pre", { children: JSON.stringify(variableDefinitions, null, 2) })] }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { display: 'flex', justifyContent: "space-between", children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: 'row', spacing: 2, children: [variableDefinitions.map((v) => ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(Variable_1.TemplateVariable, { name: v.name }, v.name) }, v.name))), isEditMode && (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: () => setIsEditing(true), children: "Modify Variables" })] }) })] }));
|
|
26
|
+
}
|
|
27
|
+
exports.TemplateVariableList = TemplateVariableList;
|
|
@@ -26,4 +26,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./Variable"), exports);
|
|
29
30
|
__exportStar(require("./VariableList"), exports);
|
|
@@ -28,7 +28,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
__exportStar(require("./Dashboard"), exports);
|
|
30
30
|
__exportStar(require("./GridLayout"), exports);
|
|
31
|
-
__exportStar(require("./Panel
|
|
31
|
+
__exportStar(require("./Panel"), exports);
|
|
32
32
|
__exportStar(require("./TimeRangeControls"), exports);
|
|
33
|
-
__exportStar(require("./
|
|
34
|
-
__exportStar(require("./VariableList"), exports);
|
|
33
|
+
__exportStar(require("./Variables"), exports);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useDashboardApp = exports.createDashboardAppSlice = void 0;
|
|
16
|
+
const immer_1 = require("zustand/middleware/immer");
|
|
17
|
+
const DashboardProvider_1 = require("./DashboardProvider");
|
|
18
|
+
exports.createDashboardAppSlice = (0, immer_1.immer)((set) => ({
|
|
19
|
+
openPanelDrawer: ({ groupIndex, panelKey }) => set((state) => {
|
|
20
|
+
state.panelDrawer = {
|
|
21
|
+
groupIndex,
|
|
22
|
+
panelKey,
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
closePanelDrawer: () => set((state) => {
|
|
26
|
+
state.panelDrawer = undefined;
|
|
27
|
+
}),
|
|
28
|
+
openPanelGroupDialog: (groupIndex) => set((state) => {
|
|
29
|
+
state.panelGroupDialog = { groupIndex };
|
|
30
|
+
}),
|
|
31
|
+
closePanelGroupDialog: () => set((state) => {
|
|
32
|
+
state.panelGroupDialog = undefined;
|
|
33
|
+
}),
|
|
34
|
+
}));
|
|
35
|
+
function useDashboardApp() {
|
|
36
|
+
return (0, DashboardProvider_1.useDashboardStore)(({ panelDrawer, openPanelDrawer, closePanelDrawer, panelGroupDialog, openPanelGroupDialog, closePanelGroupDialog, }) => ({
|
|
37
|
+
panelDrawer,
|
|
38
|
+
openPanelDrawer,
|
|
39
|
+
closePanelDrawer,
|
|
40
|
+
panelGroupDialog,
|
|
41
|
+
openPanelGroupDialog,
|
|
42
|
+
closePanelGroupDialog,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
exports.useDashboardApp = useDashboardApp;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DashboardProvider = exports.
|
|
6
|
+
exports.DashboardProvider = exports.useDashboardStore = exports.useDashboard = exports.useEditMode = exports.usePanels = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
// Copyright 2022 The Perses Authors
|
|
9
9
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -17,64 +17,82 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
17
17
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
18
|
// See the License for the specific language governing permissions and
|
|
19
19
|
// limitations under the License.
|
|
20
|
-
const zustand_1 =
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
20
|
+
const zustand_1 = require("zustand");
|
|
21
|
+
const immer_1 = require("zustand/middleware/immer");
|
|
22
|
+
const shallow_1 = __importDefault(require("zustand/shallow"));
|
|
23
|
+
const react_1 = require("react");
|
|
24
|
+
const immer_2 = __importDefault(require("immer"));
|
|
25
|
+
const DashboardAppSlice_1 = require("./DashboardAppSlice");
|
|
26
|
+
const LayoutsSlice_1 = require("./LayoutsSlice");
|
|
24
27
|
function usePanels() {
|
|
25
|
-
|
|
26
|
-
return { panels, addPanel };
|
|
28
|
+
return useDashboardStore(({ panels, updatePanel }) => ({ panels, updatePanel }));
|
|
27
29
|
}
|
|
28
30
|
exports.usePanels = usePanels;
|
|
29
|
-
function useLayouts() {
|
|
30
|
-
const { layouts, setLayouts, addLayout, addItemToLayout } = useStore(({ layouts, setLayouts, addLayout, addItemToLayout }) => ({
|
|
31
|
-
layouts,
|
|
32
|
-
setLayouts,
|
|
33
|
-
addLayout,
|
|
34
|
-
addItemToLayout,
|
|
35
|
-
}));
|
|
36
|
-
return { layouts, setLayouts, addLayout, addItemToLayout };
|
|
37
|
-
}
|
|
38
|
-
exports.useLayouts = useLayouts;
|
|
39
31
|
function useEditMode() {
|
|
40
|
-
|
|
41
|
-
return { isEditMode, setEditMode };
|
|
32
|
+
return useDashboardStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));
|
|
42
33
|
}
|
|
43
34
|
exports.useEditMode = useEditMode;
|
|
44
35
|
function useDashboard() {
|
|
45
36
|
const selectDashboardSpec = (state) => {
|
|
46
|
-
return (0,
|
|
37
|
+
return (0, immer_2.default)(state.dashboard, (draftState) => {
|
|
47
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
39
|
draftState.panels = state.panels;
|
|
49
40
|
draftState.layouts = state.layouts;
|
|
50
41
|
});
|
|
51
42
|
};
|
|
52
|
-
const dashboard =
|
|
43
|
+
const dashboard = useDashboardStore(selectDashboardSpec);
|
|
53
44
|
return { dashboard };
|
|
54
45
|
}
|
|
55
46
|
exports.useDashboard = useDashboard;
|
|
47
|
+
const DashboardContext = (0, react_1.createContext)(undefined);
|
|
48
|
+
function useDashboardStore(selector) {
|
|
49
|
+
const store = (0, react_1.useContext)(DashboardContext);
|
|
50
|
+
if (store === undefined) {
|
|
51
|
+
throw new Error('No DashboardContext found. Did you forget a Provider?');
|
|
52
|
+
}
|
|
53
|
+
return (0, zustand_1.useStore)(store, selector, shallow_1.default);
|
|
54
|
+
}
|
|
55
|
+
exports.useDashboardStore = useDashboardStore;
|
|
56
56
|
function DashboardProvider(props) {
|
|
57
57
|
const { children, initialState: { dashboardSpec, isEditMode }, } = props;
|
|
58
58
|
const { layouts, panels } = dashboardSpec;
|
|
59
|
-
|
|
59
|
+
const dashboardStore = (0, zustand_1.createStore)()((0, immer_1.immer)((set, get, api) => {
|
|
60
|
+
return {
|
|
61
|
+
...(0, DashboardAppSlice_1.createDashboardAppSlice)(set, get, api, []),
|
|
62
|
+
...(0, LayoutsSlice_1.createLayoutsSlice)(set, get, api, []),
|
|
60
63
|
layouts,
|
|
61
64
|
panels,
|
|
62
65
|
dashboard: dashboardSpec,
|
|
66
|
+
updatePanel: (name, panel, groupIndex = 0) => set((state) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
// add new panel to layouts if panels[name] is undefined
|
|
69
|
+
if (state.panels[name] === undefined) {
|
|
70
|
+
// find maximum y so new panel is added to the end of the grid
|
|
71
|
+
let maxY = 0;
|
|
72
|
+
(_a = state.layouts[groupIndex]) === null || _a === void 0 ? void 0 : _a.spec.items.forEach((layout) => {
|
|
73
|
+
if (layout.y > maxY) {
|
|
74
|
+
maxY = layout.y;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const panelLayout = {
|
|
78
|
+
x: 0,
|
|
79
|
+
y: maxY + 1,
|
|
80
|
+
width: 12,
|
|
81
|
+
height: 6,
|
|
82
|
+
content: { $ref: `#/spec/panels/${name}` },
|
|
83
|
+
};
|
|
84
|
+
const layouts = state.layouts;
|
|
85
|
+
if (layouts && layouts[groupIndex]) {
|
|
86
|
+
(_b = layouts[groupIndex]) === null || _b === void 0 ? void 0 : _b.spec.items.push(panelLayout);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
|
+
state.panels[name] = panel;
|
|
91
|
+
}),
|
|
63
92
|
isEditMode: !!isEditMode,
|
|
64
93
|
setEditMode: (isEditMode) => set({ isEditMode }),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})),
|
|
69
|
-
addItemToLayout: (index, item) => set((0, immer_1.default)((state) => {
|
|
70
|
-
state.layouts[index].spec.items.push(item);
|
|
71
|
-
})),
|
|
72
|
-
setPanels: (panels) => set({ panels }),
|
|
73
|
-
addPanel: (name, panel) => {
|
|
74
|
-
set((0, immer_1.default)((state) => {
|
|
75
|
-
state.panels[name] = panel;
|
|
76
|
-
}, {}));
|
|
77
|
-
},
|
|
78
|
-
})), children: children }));
|
|
94
|
+
};
|
|
95
|
+
}));
|
|
96
|
+
return ((0, jsx_runtime_1.jsx)(DashboardContext.Provider, { value: dashboardStore, children: children }));
|
|
79
97
|
}
|
|
80
98
|
exports.DashboardProvider = DashboardProvider;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useLayouts = exports.createLayoutsSlice = void 0;
|
|
16
|
+
const immer_1 = require("zustand/middleware/immer");
|
|
17
|
+
const DashboardProvider_1 = require("./DashboardProvider");
|
|
18
|
+
exports.createLayoutsSlice = (0, immer_1.immer)((set) => ({
|
|
19
|
+
updateLayout: (layout, index) => set((state) => {
|
|
20
|
+
if (index === undefined) {
|
|
21
|
+
state.layouts.unshift(layout);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
state.layouts[index] = layout;
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
addItemToLayout: (index, item) => set((state) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const layouts = state.layouts;
|
|
30
|
+
if (layouts && layouts[index]) {
|
|
31
|
+
(_a = layouts[index]) === null || _a === void 0 ? void 0 : _a.spec.items.push(item);
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
}));
|
|
35
|
+
function useLayouts() {
|
|
36
|
+
return (0, DashboardProvider_1.useDashboardStore)(({ layouts, updateLayout, addItemToLayout }) => ({
|
|
37
|
+
layouts,
|
|
38
|
+
updateLayout,
|
|
39
|
+
addItemToLayout,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
exports.useLayouts = useLayouts;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useQueryString = exports.QueryStringProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2022 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
19
|
+
/**
|
|
20
|
+
* Allows apps to provide their own query string implementations
|
|
21
|
+
*/
|
|
22
|
+
function QueryStringProvider(props) {
|
|
23
|
+
const { queryString, setQueryString, children } = props;
|
|
24
|
+
const ctx = (0, react_1.useMemo)(() => ({ queryString, setQueryString }), [queryString, setQueryString]);
|
|
25
|
+
return (0, jsx_runtime_1.jsx)(plugin_system_1.QueryStringContext.Provider, { value: ctx, children: children });
|
|
26
|
+
}
|
|
27
|
+
exports.QueryStringProvider = QueryStringProvider;
|
|
28
|
+
function useQueryString() {
|
|
29
|
+
const ctx = (0, react_1.useContext)(plugin_system_1.QueryStringContext);
|
|
30
|
+
if (ctx === undefined) {
|
|
31
|
+
throw new Error('No QueryStringContext found. Did you forget a Provider?');
|
|
32
|
+
}
|
|
33
|
+
return ctx;
|
|
34
|
+
}
|
|
35
|
+
exports.useQueryString = useQueryString;
|