@perses-dev/dashboards 0.23.0 → 0.24.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/TimeRangeControls/TimeRangeControls.js +7 -3
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -7
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +8 -4
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/package.json +7 -6
- package/dist/cjs/components/Panel/Panel.test.js +0 -137
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +0 -131
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +0 -87
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +0 -95
- package/dist/cjs/components/Variables/variable-model.test.js +0 -106
- package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +0 -82
- package/dist/cjs/utils/panelUtils.test.js +0 -195
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +0 -110
- package/dist/components/Panel/Panel.test.d.ts +0 -2
- package/dist/components/Panel/Panel.test.d.ts.map +0 -1
- package/dist/components/Panel/Panel.test.js +0 -130
- package/dist/components/Panel/Panel.test.js.map +0 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +0 -2
- package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +0 -124
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +0 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +0 -2
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +0 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +0 -80
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +0 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +0 -2
- package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +0 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +0 -88
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +0 -1
- package/dist/components/Variables/variable-model.test.d.ts +0 -2
- package/dist/components/Variables/variable-model.test.d.ts.map +0 -1
- package/dist/components/Variables/variable-model.test.js +0 -104
- package/dist/components/Variables/variable-model.test.js.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts +0 -2
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.test.js +0 -80
- package/dist/context/TemplateVariableProvider/query-params.test.js.map +0 -1
- package/dist/utils/panelUtils.test.d.ts +0 -2
- package/dist/utils/panelUtils.test.d.ts.map +0 -1
- package/dist/utils/panelUtils.test.js +0 -193
- package/dist/utils/panelUtils.test.js.map +0 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +0 -2
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +0 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +0 -103
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +0 -1
|
@@ -26,6 +26,7 @@ _export(exports, {
|
|
|
26
26
|
});
|
|
27
27
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
28
28
|
const _refresh = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Refresh"));
|
|
29
|
+
const _material = require("@mui/material");
|
|
29
30
|
const _components = require("@perses-dev/components");
|
|
30
31
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
31
32
|
const _core = require("@perses-dev/core");
|
|
@@ -94,8 +95,9 @@ const TIME_OPTIONS = [
|
|
|
94
95
|
}
|
|
95
96
|
];
|
|
96
97
|
const DEFAULT_HEIGHT = '34px';
|
|
97
|
-
function TimeRangeControls({ heightPx }) {
|
|
98
|
+
function TimeRangeControls({ heightPx , showRefresh =true }) {
|
|
98
99
|
const { timeRange , setTimeRange , refresh } = (0, _pluginSystem.useTimeRange)();
|
|
100
|
+
// TODO: Remove this since it couples to the dashboard context
|
|
99
101
|
const defaultTimeRange = (0, _context.useDefaultTimeRange)();
|
|
100
102
|
// Convert height to a string, then use the string for styling
|
|
101
103
|
const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;
|
|
@@ -110,7 +112,9 @@ function TimeRangeControls({ heightPx }) {
|
|
|
110
112
|
});
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(
|
|
115
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
116
|
+
direction: "row",
|
|
117
|
+
spacing: 1,
|
|
114
118
|
children: [
|
|
115
119
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.DateTimeRangePicker, {
|
|
116
120
|
timeOptions: TIME_OPTIONS,
|
|
@@ -118,7 +122,7 @@ function TimeRangeControls({ heightPx }) {
|
|
|
118
122
|
onChange: setTimeRange,
|
|
119
123
|
height: height
|
|
120
124
|
}),
|
|
121
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
|
|
125
|
+
showRefresh && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
|
|
122
126
|
description: _constants.TOOLTIP_TEXT.refreshDashboard,
|
|
123
127
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_toolbarIconButton.ToolbarIconButton, {
|
|
124
128
|
"aria-label": _constants.TOOLTIP_TEXT.refreshDashboard,
|
|
@@ -29,7 +29,7 @@ const _jsxRuntime = require("react/jsx-runtime");
|
|
|
29
29
|
const _zustand = require("zustand");
|
|
30
30
|
const _middleware = require("zustand/middleware");
|
|
31
31
|
const _immer = require("zustand/middleware/immer");
|
|
32
|
-
const _shallow =
|
|
32
|
+
const _shallow = require("zustand/shallow");
|
|
33
33
|
const _react = require("react");
|
|
34
34
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
35
35
|
const _panelGroupEditorSlice = require("./panel-group-editor-slice");
|
|
@@ -40,18 +40,13 @@ const _deletePanelGroupSlice = require("./delete-panel-group-slice");
|
|
|
40
40
|
const _deletePanelSlice = require("./delete-panel-slice");
|
|
41
41
|
const _discardChangesDialogSlice = require("./discard-changes-dialog-slice");
|
|
42
42
|
const _duplicatePanelSlice = require("./duplicate-panel-slice");
|
|
43
|
-
function _interopRequireDefault(obj) {
|
|
44
|
-
return obj && obj.__esModule ? obj : {
|
|
45
|
-
default: obj
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
43
|
const DashboardContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
|
|
49
44
|
function useDashboardStore(selector) {
|
|
50
45
|
const store = (0, _react.useContext)(DashboardContext);
|
|
51
46
|
if (store === undefined) {
|
|
52
47
|
throw new Error('No DashboardContext found. Did you forget a Provider?');
|
|
53
48
|
}
|
|
54
|
-
return (0, _zustand.useStore)(store, selector, _shallow.
|
|
49
|
+
return (0, _zustand.useStore)(store, selector, _shallow.shallow);
|
|
55
50
|
}
|
|
56
51
|
function DashboardProvider(props) {
|
|
57
52
|
const createDashboardStore = (0, _react.useCallback)(initStore, [
|
|
@@ -3,7 +3,8 @@ import { TimeOption } from '@perses-dev/components';
|
|
|
3
3
|
export declare const TIME_OPTIONS: TimeOption[];
|
|
4
4
|
interface TimeRangeControlsProps {
|
|
5
5
|
heightPx?: number;
|
|
6
|
+
showRefresh?: boolean;
|
|
6
7
|
}
|
|
7
|
-
export declare function TimeRangeControls({ heightPx }: TimeRangeControlsProps): JSX.Element;
|
|
8
|
+
export declare function TimeRangeControls({ heightPx, showRefresh }: TimeRangeControlsProps): JSX.Element;
|
|
8
9
|
export {};
|
|
9
10
|
//# sourceMappingURL=TimeRangeControls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAoC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOtF,eAAO,MAAM,YAAY,EAAE,UAAU,EAUpC,CAAC;AAIF,UAAU,sBAAsB;IAE9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,WAAkB,EAAE,EAAE,sBAAsB,eA8BzF"}
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import RefreshIcon from 'mdi-material-ui/Refresh';
|
|
15
|
+
import { Stack } from '@mui/material';
|
|
15
16
|
import { DateTimeRangePicker, InfoTooltip } from '@perses-dev/components';
|
|
16
17
|
import { useTimeRange } from '@perses-dev/plugin-system';
|
|
17
18
|
import { isDurationString } from '@perses-dev/core';
|
|
@@ -75,8 +76,9 @@ export const TIME_OPTIONS = [
|
|
|
75
76
|
}
|
|
76
77
|
];
|
|
77
78
|
const DEFAULT_HEIGHT = '34px';
|
|
78
|
-
export function TimeRangeControls({ heightPx }) {
|
|
79
|
+
export function TimeRangeControls({ heightPx , showRefresh =true }) {
|
|
79
80
|
const { timeRange , setTimeRange , refresh } = useTimeRange();
|
|
81
|
+
// TODO: Remove this since it couples to the dashboard context
|
|
80
82
|
const defaultTimeRange = useDefaultTimeRange();
|
|
81
83
|
// Convert height to a string, then use the string for styling
|
|
82
84
|
const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;
|
|
@@ -91,7 +93,9 @@ export function TimeRangeControls({ heightPx }) {
|
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
|
-
return /*#__PURE__*/ _jsxs(
|
|
96
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
97
|
+
direction: "row",
|
|
98
|
+
spacing: 1,
|
|
95
99
|
children: [
|
|
96
100
|
/*#__PURE__*/ _jsx(DateTimeRangePicker, {
|
|
97
101
|
timeOptions: TIME_OPTIONS,
|
|
@@ -99,7 +103,7 @@ export function TimeRangeControls({ heightPx }) {
|
|
|
99
103
|
onChange: setTimeRange,
|
|
100
104
|
height: height
|
|
101
105
|
}),
|
|
102
|
-
/*#__PURE__*/ _jsx(InfoTooltip, {
|
|
106
|
+
showRefresh && /*#__PURE__*/ _jsx(InfoTooltip, {
|
|
103
107
|
description: TOOLTIP_TEXT.refreshDashboard,
|
|
104
108
|
children: /*#__PURE__*/ _jsx(ToolbarIconButton, {
|
|
105
109
|
"aria-label": TOOLTIP_TEXT.refreshDashboard,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport RefreshIcon from 'mdi-material-ui/Refresh';\nimport { DateTimeRangePicker, InfoTooltip, TimeOption } from '@perses-dev/components';\nimport { useTimeRange } from '@perses-dev/plugin-system';\nimport { isDurationString } from '@perses-dev/core';\nimport { TOOLTIP_TEXT } from '../../constants';\nimport { useDefaultTimeRange } from '../../context';\nimport { ToolbarIconButton } from '../ToolbarIconButton';\n\nexport const TIME_OPTIONS: TimeOption[] = [\n { value: { pastDuration: '5m' }, display: 'Last 5 minutes' },\n { value: { pastDuration: '15m' }, display: 'Last 15 minutes' },\n { value: { pastDuration: '30m' }, display: 'Last 30 minutes' },\n { value: { pastDuration: '1h' }, display: 'Last 1 hour' },\n { value: { pastDuration: '6h' }, display: 'Last 6 hours' },\n { value: { pastDuration: '12h' }, display: 'Last 12 hours' },\n { value: { pastDuration: '24h' }, display: 'Last 1 day' },\n { value: { pastDuration: '7d' }, display: 'Last 7 days' },\n { value: { pastDuration: '14d' }, display: 'Last 14 days' },\n];\n\nconst DEFAULT_HEIGHT = '34px';\n\ninterface TimeRangeControlsProps {\n // The controls look best at heights >= 28 pixels\n heightPx?: number;\n}\n\nexport function TimeRangeControls({ heightPx }: TimeRangeControlsProps) {\n const { timeRange, setTimeRange, refresh } = useTimeRange();\n const defaultTimeRange = useDefaultTimeRange();\n\n // Convert height to a string, then use the string for styling\n const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;\n\n // add time shortcut if one does not match duration from dashboard JSON\n if (!TIME_OPTIONS.some((option) => option.value.pastDuration === defaultTimeRange.pastDuration)) {\n if (isDurationString(defaultTimeRange.pastDuration)) {\n TIME_OPTIONS.push({\n value: { pastDuration: defaultTimeRange.pastDuration },\n display: `Last ${defaultTimeRange.pastDuration}`,\n });\n }\n }\n\n return (\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport RefreshIcon from 'mdi-material-ui/Refresh';\nimport { Stack } from '@mui/material';\nimport { DateTimeRangePicker, InfoTooltip, TimeOption } from '@perses-dev/components';\nimport { useTimeRange } from '@perses-dev/plugin-system';\nimport { isDurationString } from '@perses-dev/core';\nimport { TOOLTIP_TEXT } from '../../constants';\nimport { useDefaultTimeRange } from '../../context';\nimport { ToolbarIconButton } from '../ToolbarIconButton';\n\nexport const TIME_OPTIONS: TimeOption[] = [\n { value: { pastDuration: '5m' }, display: 'Last 5 minutes' },\n { value: { pastDuration: '15m' }, display: 'Last 15 minutes' },\n { value: { pastDuration: '30m' }, display: 'Last 30 minutes' },\n { value: { pastDuration: '1h' }, display: 'Last 1 hour' },\n { value: { pastDuration: '6h' }, display: 'Last 6 hours' },\n { value: { pastDuration: '12h' }, display: 'Last 12 hours' },\n { value: { pastDuration: '24h' }, display: 'Last 1 day' },\n { value: { pastDuration: '7d' }, display: 'Last 7 days' },\n { value: { pastDuration: '14d' }, display: 'Last 14 days' },\n];\n\nconst DEFAULT_HEIGHT = '34px';\n\ninterface TimeRangeControlsProps {\n // The controls look best at heights >= 28 pixels\n heightPx?: number;\n\n // Whether to show the refresh button or not\n showRefresh?: boolean;\n}\n\nexport function TimeRangeControls({ heightPx, showRefresh = true }: TimeRangeControlsProps) {\n const { timeRange, setTimeRange, refresh } = useTimeRange();\n // TODO: Remove this since it couples to the dashboard context\n const defaultTimeRange = useDefaultTimeRange();\n\n // Convert height to a string, then use the string for styling\n const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;\n\n // add time shortcut if one does not match duration from dashboard JSON\n if (!TIME_OPTIONS.some((option) => option.value.pastDuration === defaultTimeRange.pastDuration)) {\n if (isDurationString(defaultTimeRange.pastDuration)) {\n TIME_OPTIONS.push({\n value: { pastDuration: defaultTimeRange.pastDuration },\n display: `Last ${defaultTimeRange.pastDuration}`,\n });\n }\n }\n\n return (\n <Stack direction=\"row\" spacing={1}>\n <DateTimeRangePicker timeOptions={TIME_OPTIONS} value={timeRange} onChange={setTimeRange} height={height} />\n {showRefresh && (\n <InfoTooltip description={TOOLTIP_TEXT.refreshDashboard}>\n <ToolbarIconButton aria-label={TOOLTIP_TEXT.refreshDashboard} onClick={refresh} sx={{ height }}>\n <RefreshIcon />\n </ToolbarIconButton>\n </InfoTooltip>\n )}\n </Stack>\n );\n}\n"],"names":["RefreshIcon","Stack","DateTimeRangePicker","InfoTooltip","useTimeRange","isDurationString","TOOLTIP_TEXT","useDefaultTimeRange","ToolbarIconButton","TIME_OPTIONS","value","pastDuration","display","DEFAULT_HEIGHT","TimeRangeControls","heightPx","showRefresh","timeRange","setTimeRange","refresh","defaultTimeRange","height","undefined","some","option","push","direction","spacing","timeOptions","onChange","description","refreshDashboard","aria-label","onClick","sx"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,WAAW,MAAM,yBAAyB,CAAC;AAClD,SAASC,KAAK,QAAQ,eAAe,CAAC;AACtC,SAASC,mBAAmB,EAAEC,WAAW,QAAoB,wBAAwB,CAAC;AACtF,SAASC,YAAY,QAAQ,2BAA2B,CAAC;AACzD,SAASC,gBAAgB,QAAQ,kBAAkB,CAAC;AACpD,SAASC,YAAY,QAAQ,iBAAiB,CAAC;AAC/C,SAASC,mBAAmB,QAAQ,eAAe,CAAC;AACpD,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;AAEzD,OAAO,MAAMC,YAAY,GAAiB;IACxC;QAAEC,KAAK,EAAE;YAAEC,YAAY,EAAE,IAAI;SAAE;QAAEC,OAAO,EAA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C,CAACC,MAAM,GAAKA,MAAM,CAACd,KAAK,CAACC,YAAY,KAAKS,gBAAgB,CAACT,YAAY,CAAC,EAAE;QAC/F,IAAIN,gBAAgB,CAACe,gBAAgB,CAACT,YAAY,CAAC,EAAE;YACnDF,YAAY,CAACgB,IAAI,CAAC;gBAChBf,KAAK,EAAE;oBAAEC,YAAY,EAAES,gBAAgB,CAACT,YAAY;iBAAE;gBACtDC,OAAO,EAAE,CAAC,KAAK,EAAEQ,gBAAgB,CAACT,YAAY,CAAC,CAAC;aACjD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,qBACE,MAACV,KAAK;QAACyB,SAAS,EAAC,KAAK;QAACC,OAAO,EAAE,CAAC;;0BAC/B,KAACzB,mBAAmB;gBAAC0B,WAAW,EAAEnB,YAAY;gBAAEC,KAAK,EAAEO,SAAS;gBAAEY,QAAQ,EAAEX,YAAY;gBAAEG,MAAM,EAAEA,MAAM;cAAI;YAC3GL,WAAW,kBACV,KAACb,WAAW;gBAAC2B,WAAW,EAAExB,YAAY,CAACyB,gBAAgB;0BACrD,cAAA,KAACvB,iBAAiB;oBAACwB,YAAU,EAAE1B,YAAY,CAACyB,gBAAgB;oBAAEE,OAAO,EAAEd,OAAO;oBAAEe,EAAE,EAAE;wBAAEb,MAAM;qBAAE;8BAC5F,cAAA,KAACrB,WAAW,KAAG;kBACG;cACR,AACf;;MACK,CACR;AACJ,CAAC"}
|
|
@@ -14,7 +14,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
14
14
|
import { createStore, useStore } from 'zustand';
|
|
15
15
|
import { devtools } from 'zustand/middleware';
|
|
16
16
|
import { immer } from 'zustand/middleware/immer';
|
|
17
|
-
import shallow from 'zustand/shallow';
|
|
17
|
+
import { shallow } from 'zustand/shallow';
|
|
18
18
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
19
19
|
import { usePlugin, usePluginRegistry } from '@perses-dev/plugin-system';
|
|
20
20
|
import { createPanelGroupEditorSlice } from './panel-group-editor-slice';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createStore, useStore } from 'zustand';\nimport type { StoreApi } from 'zustand';\nimport { devtools } from 'zustand/middleware';\nimport { immer } from 'zustand/middleware/immer';\nimport shallow from 'zustand/shallow';\nimport { createContext, ReactNode, useCallback, useContext, useEffect, useState } from 'react';\nimport { DashboardResource, Display, ProjectMetadata, RelativeTimeRange } from '@perses-dev/core';\nimport { usePlugin, usePluginRegistry } from '@perses-dev/plugin-system';\nimport { createPanelGroupEditorSlice, PanelGroupEditorSlice } from './panel-group-editor-slice';\nimport { convertLayoutsToPanelGroups, createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editor-slice';\nimport { createPanelSlice, PanelSlice } from './panel-slice';\nimport { createDeletePanelGroupSlice, DeletePanelGroupSlice } from './delete-panel-group-slice';\nimport { createDeletePanelSlice, DeletePanelSlice } from './delete-panel-slice';\nimport { createDiscardChangesDialogSlice, DiscardChangesConfirmationDialogSlice } from './discard-changes-dialog-slice';\nimport { createDuplicatePanelSlice, DuplicatePanelSlice } from './duplicate-panel-slice';\n\nexport interface DashboardStoreState\n extends PanelGroupSlice,\n PanelSlice,\n PanelGroupEditorSlice,\n DeletePanelGroupSlice,\n PanelEditorSlice,\n DeletePanelSlice,\n DiscardChangesConfirmationDialogSlice,\n DuplicatePanelSlice {\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n defaultTimeRange: RelativeTimeRange;\n setDashboard: (dashboard: DashboardResource) => void;\n metadata: ProjectMetadata;\n display?: Display;\n}\n\nexport interface DashboardStoreProps {\n dashboardResource: DashboardResource;\n isEditMode?: boolean;\n}\n\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: ReactNode;\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T) {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStore(store, selector, shallow);\n}\n\nexport function DashboardProvider(props: DashboardProviderProps) {\n const createDashboardStore = useCallback(initStore, [props]);\n\n // load plugin to retrieve initial spec if default panel kind is defined\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPanelKind = defaultPluginKinds?.['Panel'] ?? '';\n const { data: plugin } = usePlugin('Panel', defaultPanelKind);\n\n const [store] = useState(createDashboardStore(props)); // prevent calling createDashboardStore every time it rerenders\n\n useEffect(() => {\n if (plugin === undefined) return;\n const spec = plugin.createInitialOptions();\n // set default panel kind and spec for add panel editor\n store.setState({ initialValues: { kind: defaultPanelKind, spec } });\n }, [plugin, store, defaultPanelKind]);\n\n return (\n <DashboardContext.Provider value={store as StoreApi<DashboardStoreState>}>\n {props.children}\n </DashboardContext.Provider>\n );\n}\n\nfunction initStore(props: DashboardProviderProps) {\n const {\n initialState: { dashboardResource, isEditMode },\n } = props;\n\n const {\n spec: { display, layouts, panels, duration },\n metadata,\n } = dashboardResource;\n const store = createStore<DashboardStoreState>()(\n immer(\n devtools((...args) => {\n const [set] = args;\n return {\n ...createPanelGroupSlice(layouts)(...args),\n ...createPanelSlice(panels)(...args),\n ...createPanelGroupEditorSlice(...args),\n ...createDeletePanelGroupSlice(...args),\n ...createPanelEditorSlice()(...args),\n ...createDeletePanelSlice()(...args),\n ...createDiscardChangesDialogSlice(...args),\n ...createDuplicatePanelSlice()(...args),\n metadata,\n display,\n defaultTimeRange: { pastDuration: duration },\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean) => set({ isEditMode }),\n setDashboard: ({ metadata, spec: { display, panels, layouts } }) => {\n set((state) => {\n state.metadata = metadata;\n state.display = display;\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n state.panels = panels;\n state.panelGroups = panelGroups;\n state.panelGroupOrder = panelGroupOrder;\n });\n },\n };\n })\n )\n );\n\n return store;\n}\n"],"names":["createStore","useStore","devtools","immer","shallow","createContext","useCallback","useContext","useEffect","useState","usePlugin","usePluginRegistry","createPanelGroupEditorSlice","convertLayoutsToPanelGroups","createPanelGroupSlice","createPanelEditorSlice","createPanelSlice","createDeletePanelGroupSlice","createDeletePanelSlice","createDiscardChangesDialogSlice","createDuplicatePanelSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","createDashboardStore","initStore","defaultPluginKinds","defaultPanelKind","data","plugin","spec","createInitialOptions","setState","initialValues","kind","Provider","value","children","initialState","dashboardResource","isEditMode","display","layouts","panels","duration","metadata","args","set","defaultTimeRange","pastDuration","setEditMode","setDashboard","state","panelGroups","panelGroupOrder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,SAAS,CAAC;AAEhD,SAASC,QAAQ,QAAQ,oBAAoB,CAAC;AAC9C,SAASC,KAAK,QAAQ,0BAA0B,CAAC;AACjD,
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createStore, useStore } from 'zustand';\nimport type { StoreApi } from 'zustand';\nimport { devtools } from 'zustand/middleware';\nimport { immer } from 'zustand/middleware/immer';\nimport { shallow } from 'zustand/shallow';\nimport { createContext, ReactNode, useCallback, useContext, useEffect, useState } from 'react';\nimport { DashboardResource, Display, ProjectMetadata, RelativeTimeRange } from '@perses-dev/core';\nimport { usePlugin, usePluginRegistry } from '@perses-dev/plugin-system';\nimport { createPanelGroupEditorSlice, PanelGroupEditorSlice } from './panel-group-editor-slice';\nimport { convertLayoutsToPanelGroups, createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editor-slice';\nimport { createPanelSlice, PanelSlice } from './panel-slice';\nimport { createDeletePanelGroupSlice, DeletePanelGroupSlice } from './delete-panel-group-slice';\nimport { createDeletePanelSlice, DeletePanelSlice } from './delete-panel-slice';\nimport { createDiscardChangesDialogSlice, DiscardChangesConfirmationDialogSlice } from './discard-changes-dialog-slice';\nimport { createDuplicatePanelSlice, DuplicatePanelSlice } from './duplicate-panel-slice';\n\nexport interface DashboardStoreState\n extends PanelGroupSlice,\n PanelSlice,\n PanelGroupEditorSlice,\n DeletePanelGroupSlice,\n PanelEditorSlice,\n DeletePanelSlice,\n DiscardChangesConfirmationDialogSlice,\n DuplicatePanelSlice {\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n defaultTimeRange: RelativeTimeRange;\n setDashboard: (dashboard: DashboardResource) => void;\n metadata: ProjectMetadata;\n display?: Display;\n}\n\nexport interface DashboardStoreProps {\n dashboardResource: DashboardResource;\n isEditMode?: boolean;\n}\n\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: ReactNode;\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T) {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStore(store, selector, shallow);\n}\n\nexport function DashboardProvider(props: DashboardProviderProps) {\n const createDashboardStore = useCallback(initStore, [props]);\n\n // load plugin to retrieve initial spec if default panel kind is defined\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPanelKind = defaultPluginKinds?.['Panel'] ?? '';\n const { data: plugin } = usePlugin('Panel', defaultPanelKind);\n\n const [store] = useState(createDashboardStore(props)); // prevent calling createDashboardStore every time it rerenders\n\n useEffect(() => {\n if (plugin === undefined) return;\n const spec = plugin.createInitialOptions();\n // set default panel kind and spec for add panel editor\n store.setState({ initialValues: { kind: defaultPanelKind, spec } });\n }, [plugin, store, defaultPanelKind]);\n\n return (\n <DashboardContext.Provider value={store as StoreApi<DashboardStoreState>}>\n {props.children}\n </DashboardContext.Provider>\n );\n}\n\nfunction initStore(props: DashboardProviderProps) {\n const {\n initialState: { dashboardResource, isEditMode },\n } = props;\n\n const {\n spec: { display, layouts, panels, duration },\n metadata,\n } = dashboardResource;\n const store = createStore<DashboardStoreState>()(\n immer(\n devtools((...args) => {\n const [set] = args;\n return {\n ...createPanelGroupSlice(layouts)(...args),\n ...createPanelSlice(panels)(...args),\n ...createPanelGroupEditorSlice(...args),\n ...createDeletePanelGroupSlice(...args),\n ...createPanelEditorSlice()(...args),\n ...createDeletePanelSlice()(...args),\n ...createDiscardChangesDialogSlice(...args),\n ...createDuplicatePanelSlice()(...args),\n metadata,\n display,\n defaultTimeRange: { pastDuration: duration },\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean) => set({ isEditMode }),\n setDashboard: ({ metadata, spec: { display, panels, layouts } }) => {\n set((state) => {\n state.metadata = metadata;\n state.display = display;\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n state.panels = panels;\n state.panelGroups = panelGroups;\n state.panelGroupOrder = panelGroupOrder;\n });\n },\n };\n })\n )\n );\n\n return store;\n}\n"],"names":["createStore","useStore","devtools","immer","shallow","createContext","useCallback","useContext","useEffect","useState","usePlugin","usePluginRegistry","createPanelGroupEditorSlice","convertLayoutsToPanelGroups","createPanelGroupSlice","createPanelEditorSlice","createPanelSlice","createDeletePanelGroupSlice","createDeletePanelSlice","createDiscardChangesDialogSlice","createDuplicatePanelSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","createDashboardStore","initStore","defaultPluginKinds","defaultPanelKind","data","plugin","spec","createInitialOptions","setState","initialValues","kind","Provider","value","children","initialState","dashboardResource","isEditMode","display","layouts","panels","duration","metadata","args","set","defaultTimeRange","pastDuration","setEditMode","setDashboard","state","panelGroups","panelGroupOrder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,SAAS,CAAC;AAEhD,SAASC,QAAQ,QAAQ,oBAAoB,CAAC;AAC9C,SAASC,KAAK,QAAQ,0BAA0B,CAAC;AACjD,SAASC,OAAO,QAAQ,iBAAiB,CAAC;AAC1C,SAASC,aAAa,EAAaC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAE/F,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,2BAA2B,CAAC;AACzE,SAASC,2BAA2B,QAA+B,4BAA4B,CAAC;AAChG,SAASC,2BAA2B,EAAEC,qBAAqB,QAAyB,qBAAqB,CAAC;AAC1G,SAASC,sBAAsB,QAA0B,sBAAsB,CAAC;AAChF,SAASC,gBAAg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GAAGhC,+BAA+B,IAAIgC,IAAI,CAAC;YAC3C,GAAG/B,yBAAyB,EAAE,IAAI+B,IAAI,CAAC;YACvCD,QAAQ;YACRJ,OAAO;YACPO,gBAAgB,EAAE;gBAAEC,YAAY,EAAEL,QAAQ;aAAE;YAC5CJ,UAAU,EAAE,CAAC,CAACA,UAAU;YACxBU,WAAW,EAAE,CAACV,UAAmB,GAAKO,GAAG,CAAC;oBAAEP,UAAU;iBAAE,CAAC;YACzDW,YAAY,EAAE,CAAC,EAAEN,QAAQ,CAAA,EAAEf,IAAI,EAAE,EAAEW,OAAO,CAAA,EAAEE,MAAM,CAAA,EAAED,OAAO,CAAA,EAAE,CAAA,EAAE,GAAK;gBAClEK,GAAG,CAAC,CAACK,KAAK,GAAK;oBACbA,KAAK,CAACP,QAAQ,GAAGA,QAAQ,CAAC;oBAC1BO,KAAK,CAACX,OAAO,GAAGA,OAAO,CAAC;oBACxB,MAAM,EAAEY,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAE,GAAG9C,2BAA2B,CAACkC,OAAO,CAAC,AAAC;oBAC9EU,KAAK,CAACT,MAAM,GAAGA,MAAM,CAAC;oBACtBS,KAAK,CAACC,WAAW,GAAGA,WAAW,CAAC;oBAChCD,KAAK,CAACE,eAAe,GAAGA,eAAe,CAAC;gBAC1C,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CACF,AAAC;IAEF,OAAOlC,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/dashboards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "The dashboards feature in Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"build": "concurrently \"npm:build:*\"",
|
|
21
21
|
"build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
|
|
22
22
|
"build:esm": "swc ./src -d dist --config-file ../.swcrc",
|
|
23
|
-
"build:types": "tsc --
|
|
23
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
24
25
|
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
25
26
|
"test": "TZ=UTC jest",
|
|
26
27
|
"test:watch": "npm run test -- --watch",
|
|
@@ -28,9 +29,9 @@
|
|
|
28
29
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@perses-dev/components": "0.
|
|
32
|
-
"@perses-dev/core": "0.
|
|
33
|
-
"@perses-dev/plugin-system": "0.
|
|
32
|
+
"@perses-dev/components": "0.24.0",
|
|
33
|
+
"@perses-dev/core": "0.24.0",
|
|
34
|
+
"@perses-dev/plugin-system": "0.24.0",
|
|
34
35
|
"@types/react-grid-layout": "^1.3.2",
|
|
35
36
|
"date-fns": "^2.28.0",
|
|
36
37
|
"immer": "^9.0.15",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"use-immer": "^0.7.0",
|
|
41
42
|
"use-query-params": "^2.1.1",
|
|
42
43
|
"use-resize-observer": "^9.0.0",
|
|
43
|
-
"zustand": "^4.
|
|
44
|
+
"zustand": "^4.3.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"intersection-observer": "^0.12.2"
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _test = require("../../test");
|
|
21
|
-
const _panel = require("./Panel");
|
|
22
|
-
function _interopRequireDefault(obj) {
|
|
23
|
-
return obj && obj.__esModule ? obj : {
|
|
24
|
-
default: obj
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
describe('Panel', ()=>{
|
|
28
|
-
const createTestPanel = ()=>({
|
|
29
|
-
kind: 'Panel',
|
|
30
|
-
spec: {
|
|
31
|
-
display: {
|
|
32
|
-
name: 'Fake Panel Title',
|
|
33
|
-
description: 'This is a fake panel'
|
|
34
|
-
},
|
|
35
|
-
plugin: {
|
|
36
|
-
kind: 'TimeSeriesChart',
|
|
37
|
-
spec: {}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
// Helper to render the panel with some context set
|
|
42
|
-
const renderPanel = (definition, editHandlers)=>{
|
|
43
|
-
definition !== null && definition !== void 0 ? definition : definition = createTestPanel();
|
|
44
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panel.Panel, {
|
|
45
|
-
definition: definition,
|
|
46
|
-
editHandlers: editHandlers
|
|
47
|
-
}));
|
|
48
|
-
};
|
|
49
|
-
// Helper to get the panel once rendered
|
|
50
|
-
const getPanel = ()=>_react.screen.getByRole('region', {
|
|
51
|
-
name: 'Fake Panel Title'
|
|
52
|
-
});
|
|
53
|
-
it('should render panel', async ()=>{
|
|
54
|
-
renderPanel();
|
|
55
|
-
const panel = getPanel();
|
|
56
|
-
expect(panel).toBeInTheDocument();
|
|
57
|
-
// Should diplay header with panel's title
|
|
58
|
-
const header = _react.screen.getByRole('banner');
|
|
59
|
-
expect(header).toHaveTextContent('Fake Panel Title');
|
|
60
|
-
// Should display chart's content from the fake panel plugin
|
|
61
|
-
const content = _react.screen.getByRole('figure');
|
|
62
|
-
await (0, _react.waitFor)(()=>{
|
|
63
|
-
expect(content).toHaveTextContent('TimeSeriesChart panel');
|
|
64
|
-
});
|
|
65
|
-
expect(content);
|
|
66
|
-
});
|
|
67
|
-
it('shows panel description', async ()=>{
|
|
68
|
-
renderPanel();
|
|
69
|
-
const panel = getPanel();
|
|
70
|
-
// Description button should not be visible until hover on panel
|
|
71
|
-
const missingButton = _react.screen.queryByRole('button', {
|
|
72
|
-
name: /description/i
|
|
73
|
-
});
|
|
74
|
-
expect(missingButton).not.toBeInTheDocument();
|
|
75
|
-
_userEvent.default.hover(panel);
|
|
76
|
-
const descriptionButton = _react.screen.getByRole('button', {
|
|
77
|
-
name: /description/i
|
|
78
|
-
});
|
|
79
|
-
expect(descriptionButton).toBeInTheDocument();
|
|
80
|
-
// Can hover to see panel description in tooltip
|
|
81
|
-
_userEvent.default.hover(descriptionButton);
|
|
82
|
-
const tooltip = await _react.screen.findByRole('tooltip');
|
|
83
|
-
expect(tooltip).toHaveTextContent('This is a fake panel');
|
|
84
|
-
});
|
|
85
|
-
it('does not show description when panel does not have one', ()=>{
|
|
86
|
-
// Render a panel without a description set
|
|
87
|
-
const withoutDescription = createTestPanel();
|
|
88
|
-
withoutDescription.spec.display.description = undefined;
|
|
89
|
-
renderPanel(withoutDescription);
|
|
90
|
-
const panel = getPanel();
|
|
91
|
-
_userEvent.default.hover(panel);
|
|
92
|
-
const descriptionButton = _react.screen.queryByRole('button', {
|
|
93
|
-
name: /description/i
|
|
94
|
-
});
|
|
95
|
-
expect(descriptionButton).not.toBeInTheDocument();
|
|
96
|
-
});
|
|
97
|
-
it('does not show description in edit mode', ()=>{
|
|
98
|
-
renderPanel(undefined, {
|
|
99
|
-
onEditPanelClick: jest.fn(),
|
|
100
|
-
onDeletePanelClick: jest.fn(),
|
|
101
|
-
onDuplicatePanelClick: jest.fn()
|
|
102
|
-
});
|
|
103
|
-
const panel = getPanel();
|
|
104
|
-
_userEvent.default.hover(panel);
|
|
105
|
-
const descriptionButton = _react.screen.queryByRole('button', {
|
|
106
|
-
name: /description/i
|
|
107
|
-
});
|
|
108
|
-
expect(descriptionButton).not.toBeInTheDocument();
|
|
109
|
-
});
|
|
110
|
-
it('can trigger panel actions in edit mode', ()=>{
|
|
111
|
-
const onEditPanelClick = jest.fn();
|
|
112
|
-
const onDeletePanelClick = jest.fn();
|
|
113
|
-
const onDuplicatePanelClick = jest.fn();
|
|
114
|
-
renderPanel(undefined, {
|
|
115
|
-
onEditPanelClick,
|
|
116
|
-
onDeletePanelClick,
|
|
117
|
-
onDuplicatePanelClick
|
|
118
|
-
});
|
|
119
|
-
const panel = getPanel();
|
|
120
|
-
_userEvent.default.hover(panel);
|
|
121
|
-
const editButton = _react.screen.getByRole('button', {
|
|
122
|
-
name: /edit/i
|
|
123
|
-
});
|
|
124
|
-
_userEvent.default.click(editButton);
|
|
125
|
-
const deleteButton = _react.screen.getByRole('button', {
|
|
126
|
-
name: /delete/i
|
|
127
|
-
});
|
|
128
|
-
_userEvent.default.click(deleteButton);
|
|
129
|
-
const duplicateButton = _react.screen.getByRole('button', {
|
|
130
|
-
name: /duplicate/i
|
|
131
|
-
});
|
|
132
|
-
_userEvent.default.click(duplicateButton);
|
|
133
|
-
expect(onEditPanelClick).toHaveBeenCalledTimes(1);
|
|
134
|
-
expect(onDeletePanelClick).toHaveBeenCalledTimes(1);
|
|
135
|
-
expect(onDuplicatePanelClick).toHaveBeenCalledTimes(1);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _testUtils = require("react-dom/test-utils");
|
|
21
|
-
const _test = require("../../test");
|
|
22
|
-
const _dashboardProvider = require("../../context/DashboardProvider");
|
|
23
|
-
const _panelDrawer = require("./PanelDrawer");
|
|
24
|
-
function _interopRequireDefault(obj) {
|
|
25
|
-
return obj && obj.__esModule ? obj : {
|
|
26
|
-
default: obj
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
describe('Panel Drawer', ()=>{
|
|
30
|
-
const renderPanelDrawer = ()=>{
|
|
31
|
-
const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
|
|
32
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_dashboardProvider.DashboardProvider, {
|
|
33
|
-
initialState: {
|
|
34
|
-
dashboardResource: (0, _test.getTestDashboard)(),
|
|
35
|
-
isEditMode: true
|
|
36
|
-
},
|
|
37
|
-
children: [
|
|
38
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
|
|
39
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
|
|
40
|
-
]
|
|
41
|
-
}));
|
|
42
|
-
const { value: storeApi } = store;
|
|
43
|
-
if (storeApi === undefined) {
|
|
44
|
-
throw new Error('Expected dashboard store to be set after initial render');
|
|
45
|
-
}
|
|
46
|
-
return storeApi;
|
|
47
|
-
};
|
|
48
|
-
it('should add new panel', async ()=>{
|
|
49
|
-
const storeApi = renderPanelDrawer();
|
|
50
|
-
// Open the drawer for a new panel
|
|
51
|
-
(0, _testUtils.act)(()=>storeApi.getState().openAddPanel());
|
|
52
|
-
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
53
|
-
_userEvent.default.type(nameInput, 'New Panel');
|
|
54
|
-
_userEvent.default.click(_react.screen.getByText('Add'));
|
|
55
|
-
// TODO: Assert drawer is closed?
|
|
56
|
-
const panels = storeApi.getState().panels;
|
|
57
|
-
expect(panels).toMatchObject({
|
|
58
|
-
// Should have the new panel in the store
|
|
59
|
-
NewPanel: {
|
|
60
|
-
kind: 'Panel',
|
|
61
|
-
spec: {
|
|
62
|
-
display: {
|
|
63
|
-
name: 'New Panel'
|
|
64
|
-
},
|
|
65
|
-
plugin: {
|
|
66
|
-
kind: '',
|
|
67
|
-
spec: {}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
it('should add panel with duplicate panel name', async ()=>{
|
|
74
|
-
const storeApi = renderPanelDrawer();
|
|
75
|
-
(0, _testUtils.act)(()=>storeApi.getState().openAddPanel());
|
|
76
|
-
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
77
|
-
_userEvent.default.type(nameInput, 'cpu');
|
|
78
|
-
_userEvent.default.click(_react.screen.getByText('Add'));
|
|
79
|
-
const panels = storeApi.getState().panels;
|
|
80
|
-
expect(panels).toMatchObject({
|
|
81
|
-
// make sure we don't have duplicate panel key by appending "-1"
|
|
82
|
-
'cpu-1': {
|
|
83
|
-
kind: 'Panel',
|
|
84
|
-
spec: {
|
|
85
|
-
display: {
|
|
86
|
-
name: 'cpu'
|
|
87
|
-
},
|
|
88
|
-
plugin: {
|
|
89
|
-
kind: '',
|
|
90
|
-
spec: {}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it('should edit an existing panel', async ()=>{
|
|
97
|
-
const storeApi = renderPanelDrawer();
|
|
98
|
-
// Open the drawer for an existing panel
|
|
99
|
-
const group = Object.values(storeApi.getState().panelGroups).find((group)=>group.title === 'CPU Stats');
|
|
100
|
-
if (group === undefined) {
|
|
101
|
-
throw new Error('Test group not found');
|
|
102
|
-
}
|
|
103
|
-
const layout = Object.entries(group.itemPanelKeys).find(([, panelKey])=>panelKey === 'cpu');
|
|
104
|
-
if (layout === undefined) {
|
|
105
|
-
throw new Error('Test panel not found');
|
|
106
|
-
}
|
|
107
|
-
(0, _testUtils.act)(()=>storeApi.getState().openEditPanel({
|
|
108
|
-
panelGroupId: group.id,
|
|
109
|
-
panelGroupItemLayoutId: layout[0]
|
|
110
|
-
}));
|
|
111
|
-
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
112
|
-
_userEvent.default.clear(nameInput);
|
|
113
|
-
_userEvent.default.type(nameInput, 'cpu usage');
|
|
114
|
-
_userEvent.default.click(_react.screen.getByText('Apply'));
|
|
115
|
-
const panels = storeApi.getState().panels;
|
|
116
|
-
expect(panels).toMatchObject({
|
|
117
|
-
cpu: {
|
|
118
|
-
kind: 'Panel',
|
|
119
|
-
spec: {
|
|
120
|
-
display: {
|
|
121
|
-
name: 'cpu usage'
|
|
122
|
-
},
|
|
123
|
-
plugin: {
|
|
124
|
-
kind: 'TimeSeriesChart',
|
|
125
|
-
spec: {}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _testUtils = require("react-dom/test-utils");
|
|
21
|
-
const _context = require("../../context");
|
|
22
|
-
const _test = require("../../test");
|
|
23
|
-
const _panelGroupDialog = require("./PanelGroupDialog");
|
|
24
|
-
function _interopRequireDefault(obj) {
|
|
25
|
-
return obj && obj.__esModule ? obj : {
|
|
26
|
-
default: obj
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
describe('Add Panel Group', ()=>{
|
|
30
|
-
const renderDialog = ()=>{
|
|
31
|
-
const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
|
|
32
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_context.DashboardProvider, {
|
|
33
|
-
initialState: {
|
|
34
|
-
dashboardResource: (0, _test.getTestDashboard)(),
|
|
35
|
-
isEditMode: true
|
|
36
|
-
},
|
|
37
|
-
children: [
|
|
38
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
|
|
39
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelGroupDialog.PanelGroupDialog, {})
|
|
40
|
-
]
|
|
41
|
-
}));
|
|
42
|
-
const { value: storeApi } = store;
|
|
43
|
-
if (storeApi === undefined) {
|
|
44
|
-
throw new Error('Expected dashboard store to be set after initial render');
|
|
45
|
-
}
|
|
46
|
-
return storeApi;
|
|
47
|
-
};
|
|
48
|
-
it('should add new panel group', async ()=>{
|
|
49
|
-
const storeApi = renderDialog();
|
|
50
|
-
// Open the dialog for a new panel group
|
|
51
|
-
(0, _testUtils.act)(()=>storeApi.getState().openAddPanelGroup());
|
|
52
|
-
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
53
|
-
_userEvent.default.type(nameInput, 'New Panel Group');
|
|
54
|
-
_userEvent.default.click(_react.screen.getByText('Add'));
|
|
55
|
-
// TODO: Figure out how to test this without coupling to the store state
|
|
56
|
-
const panelGroups = Object.values(storeApi.getState().panelGroups);
|
|
57
|
-
expect(panelGroups).toContainEqual({
|
|
58
|
-
id: expect.any(Number),
|
|
59
|
-
title: 'New Panel Group',
|
|
60
|
-
isCollapsed: false,
|
|
61
|
-
itemLayouts: expect.any(Array),
|
|
62
|
-
itemPanelKeys: expect.any(Object)
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it('should edit existing panel group', async ()=>{
|
|
66
|
-
const storeApi = renderDialog();
|
|
67
|
-
// Open the dialog for an existing panel group
|
|
68
|
-
const group = Object.values(storeApi.getState().panelGroups).find((group)=>group.title === 'CPU Stats');
|
|
69
|
-
if (group === undefined) {
|
|
70
|
-
throw new Error('Missing test group');
|
|
71
|
-
}
|
|
72
|
-
(0, _testUtils.act)(()=>storeApi.getState().openEditPanelGroup(group.id));
|
|
73
|
-
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
74
|
-
_userEvent.default.clear(nameInput);
|
|
75
|
-
_userEvent.default.type(nameInput, 'New Name');
|
|
76
|
-
_userEvent.default.click(_react.screen.getByText('Apply'));
|
|
77
|
-
// TODO: Figure out how to test this without coupling to the store state
|
|
78
|
-
const panelGroups = storeApi.getState().panelGroups;
|
|
79
|
-
expect(panelGroups).toMatchObject({
|
|
80
|
-
[group.id]: {
|
|
81
|
-
id: group.id,
|
|
82
|
-
title: 'New Name',
|
|
83
|
-
isCollapsed: false
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|