@perses-dev/dashboards 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Dashboard.js +4 -5
- package/dist/cjs/components/DashboardToolbar.js +11 -5
- package/dist/cjs/components/GridLayout/GridItemContent.js +3 -11
- package/dist/cjs/components/GridLayout/GridLayout.js +8 -6
- package/dist/cjs/components/GridLayout/GridTitle.js +9 -11
- package/dist/cjs/components/Panel/DeletePanelDialog.js +12 -8
- package/dist/cjs/components/Panel/Panel.js +4 -13
- package/dist/cjs/components/Panel/Panel.test.js +4 -3
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -1
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +3 -3
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +21 -15
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +9 -3
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +70 -111
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +22 -16
- package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +92 -0
- package/dist/cjs/components/PanelGroupDialog/index.js +29 -0
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +8 -11
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +20 -13
- package/dist/cjs/components/Variables/Variable.js +1 -0
- package/dist/cjs/components/Variables/VariableEditor.js +33 -0
- package/dist/cjs/components/Variables/VariableList.js +0 -1
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +20 -8
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +122 -29
- package/dist/cjs/context/DashboardProvider/{panel-editing-slice.js → panel-editor-slice.js} +32 -13
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +102 -0
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +187 -17
- package/dist/cjs/context/TimeRangeProvider.js +20 -44
- package/dist/cjs/context/index.js +1 -1
- package/dist/cjs/context/useDashboardSpec.js +61 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/test/render.js +25 -5
- package/dist/cjs/test/setup-tests.js +4 -1
- package/dist/cjs/test/testDashboard.js +11 -10
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/utils/time-range-params.js +145 -0
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -4
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +42 -93
- package/dist/components/Dashboard.js +5 -6
- package/dist/components/Dashboard.js.map +1 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +13 -7
- package/dist/components/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -4
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +4 -12
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -3
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +9 -7
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +2 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +10 -12
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.js +13 -9
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +2 -2
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +5 -14
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.d.ts +1 -1
- package/dist/components/Panel/Panel.test.d.ts.map +1 -1
- package/dist/components/Panel/Panel.test.js +4 -3
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +2 -2
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +3 -3
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +22 -16
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +9 -3
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +1 -2
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -2
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +73 -112
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +21 -15
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +12 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +82 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -0
- package/dist/components/PanelGroupDialog/index.d.ts +3 -0
- package/dist/components/PanelGroupDialog/index.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/index.js +16 -0
- package/dist/components/PanelGroupDialog/index.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +11 -14
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +21 -14
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/Variables/Variable.js +1 -0
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +33 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.js +0 -1
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +7 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +19 -7
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +64 -22
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +133 -26
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +2 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/{panel-editing-slice.d.ts → panel-editor-slice.d.ts} +28 -13
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/{panel-editing-slice.js → panel-editor-slice.js} +33 -14
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +40 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +96 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +75 -10
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +189 -17
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/TimeRangeProvider.d.ts +9 -2
- package/dist/context/TimeRangeProvider.d.ts.map +1 -1
- package/dist/context/TimeRangeProvider.js +15 -43
- package/dist/context/TimeRangeProvider.js.map +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboardSpec.d.ts +3 -0
- package/dist/context/useDashboardSpec.d.ts.map +1 -0
- package/dist/context/useDashboardSpec.js +55 -0
- package/dist/context/useDashboardSpec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/test/render.d.ts +2 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +25 -5
- package/dist/test/render.js.map +1 -1
- package/dist/test/setup-tests.d.ts.map +1 -1
- package/dist/test/setup-tests.js +4 -0
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +11 -10
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/time-range-params.d.ts +25 -0
- package/dist/utils/time-range-params.d.ts.map +1 -0
- package/dist/utils/time-range-params.js +137 -0
- package/dist/utils/time-range-params.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +1 -3
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +45 -96
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +5 -4
- package/dist/cjs/context/DashboardProvider/layout-slice.js +0 -200
- package/dist/cjs/context/QueryStringProvider.js +0 -89
- package/dist/context/DashboardProvider/layout-slice.d.ts +0 -57
- package/dist/context/DashboardProvider/layout-slice.d.ts.map +0 -1
- package/dist/context/DashboardProvider/layout-slice.js +0 -196
- package/dist/context/DashboardProvider/layout-slice.js.map +0 -1
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +0 -1
- package/dist/context/DashboardProvider/panel-editing-slice.js.map +0 -1
- package/dist/context/QueryStringProvider.d.ts +0 -13
- package/dist/context/QueryStringProvider.d.ts.map +0 -1
- package/dist/context/QueryStringProvider.js +0 -40
- package/dist/context/QueryStringProvider.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAIL,4BAA4B,EAE7B,MAAM,eAAe,CAAC;AAIvB,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;IACpE,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,4BAA4B,CAAC,eAAe,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,eAkCtD"}
|
|
@@ -11,38 +11,20 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { useEffect } from 'react';
|
|
15
14
|
import { Box } from '@mui/material';
|
|
16
|
-
import { getDefaultTimeRange } from '@perses-dev/core';
|
|
17
|
-
import { useQueryString } from '@perses-dev/plugin-system';
|
|
18
15
|
import { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';
|
|
19
16
|
import { TimeRangeProvider, TemplateVariableProvider, DashboardProvider, DatasourceStoreProvider } from '../../context';
|
|
17
|
+
import { useInitialTimeRange, useSetTimeRangeParams } from '../../utils';
|
|
20
18
|
import { DashboardApp } from './DashboardApp';
|
|
21
19
|
/**
|
|
22
20
|
* The View for displaying a Dashboard, along with the UI for selecting variable values.
|
|
23
21
|
*/ export function ViewDashboard(props) {
|
|
24
22
|
const { dashboardResource , datasourceApi , sx , ...others } = props;
|
|
25
23
|
const { spec } = dashboardResource;
|
|
26
|
-
const { queryString , setQueryString } = useQueryString();
|
|
27
24
|
var _duration;
|
|
28
25
|
const dashboardDuration = (_duration = spec.duration) !== null && _duration !== void 0 ? _duration : '1h';
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
useEffect(()=>{
|
|
32
|
-
const currentParams = Object.fromEntries([
|
|
33
|
-
...queryString
|
|
34
|
-
]);
|
|
35
|
-
// if app does not provide query string implementation, setTimeRange is used instead
|
|
36
|
-
if (!currentParams.start && setQueryString) {
|
|
37
|
-
// default to duration in dashboard definition if start param is not already set
|
|
38
|
-
queryString.set('start', dashboardDuration);
|
|
39
|
-
setQueryString(queryString);
|
|
40
|
-
}
|
|
41
|
-
}, [
|
|
42
|
-
dashboardDuration,
|
|
43
|
-
queryString,
|
|
44
|
-
setQueryString
|
|
45
|
-
]);
|
|
26
|
+
const initialTimeRange = useInitialTimeRange(dashboardDuration);
|
|
27
|
+
const { timeRange , setTimeRange } = useSetTimeRangeParams(initialTimeRange, true);
|
|
46
28
|
return /*#__PURE__*/ _jsx(DatasourceStoreProvider, {
|
|
47
29
|
dashboardResource: dashboardResource,
|
|
48
30
|
datasourceApi: datasourceApi,
|
|
@@ -51,7 +33,8 @@ import { DashboardApp } from './DashboardApp';
|
|
|
51
33
|
dashboardSpec: spec
|
|
52
34
|
},
|
|
53
35
|
children: /*#__PURE__*/ _jsx(TimeRangeProvider, {
|
|
54
|
-
|
|
36
|
+
timeRange: timeRange,
|
|
37
|
+
setTimeRange: setTimeRange,
|
|
55
38
|
children: /*#__PURE__*/ _jsx(TemplateVariableProvider, {
|
|
56
39
|
initialVariableDefinitions: spec.variables,
|
|
57
40
|
children: /*#__PURE__*/ _jsx(Box, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"sourcesContent":["// Copyright 2022 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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"sourcesContent":["// Copyright 2022 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 { Box, BoxProps } from '@mui/material';\nimport { DashboardResource } from '@perses-dev/core';\nimport { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';\nimport {\n TimeRangeProvider,\n TemplateVariableProvider,\n DashboardProvider,\n DatasourceStoreProviderProps,\n DatasourceStoreProvider,\n} from '../../context';\nimport { useInitialTimeRange, useSetTimeRangeParams } from '../../utils';\nimport { DashboardApp } from './DashboardApp';\n\nexport interface ViewDashboardProps extends Omit<BoxProps, 'children'> {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceStoreProviderProps['datasourceApi'];\n}\n\n/**\n * The View for displaying a Dashboard, along with the UI for selecting variable values.\n */\nexport function ViewDashboard(props: ViewDashboardProps) {\n const { dashboardResource, datasourceApi, sx, ...others } = props;\n const { spec } = dashboardResource;\n const dashboardDuration = spec.duration ?? '1h';\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n const { timeRange, setTimeRange } = useSetTimeRangeParams(initialTimeRange, true);\n\n return (\n <DatasourceStoreProvider dashboardResource={dashboardResource} datasourceApi={datasourceApi}>\n <DashboardProvider initialState={{ dashboardSpec: spec }}>\n <TimeRangeProvider timeRange={timeRange} setTimeRange={setTimeRange}>\n <TemplateVariableProvider initialVariableDefinitions={spec.variables}>\n <Box\n sx={combineSx(\n {\n display: 'flex',\n width: '100%',\n height: '100%',\n position: 'relative',\n overflow: 'hidden',\n },\n sx\n )}\n {...others}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardApp dashboardResource={dashboardResource} />\n </ErrorBoundary>\n </Box>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n </DashboardProvider>\n </DatasourceStoreProvider>\n );\n}\n"],"names":["Box","ErrorBoundary","ErrorAlert","combineSx","TimeRangeProvider","TemplateVariableProvider","DashboardProvider","DatasourceStoreProvider","useInitialTimeRange","useSetTimeRangeParams","DashboardApp","ViewDashboard","props","dashboardResource","datasourceApi","sx","others","spec","dashboardDuration","duration","initialTimeRange","timeRange","setTimeRange","initialState","dashboardSpec","initialVariableDefinitions","variables","display","width","height","position","overflow","FallbackComponent"],"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,GAAG,QAAkB,eAAe,CAAC;AAE9C,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,QAAQ,wBAAwB,CAAC;AAC9E,SACEC,iBAAiB,EACjBC,wBAAwB,EACxBC,iBAAiB,EAEjBC,uBAAuB,QAClB,eAAe,CAAC;AACvB,SAASC,mBAAmB,EAAEC,qBAAqB,QAAQ,aAAa,CAAC;AACzE,SAASC,YAAY,QAAQ,gBAAgB,CAAC;AAO9C;;CAEC,GACD,OAAO,SAASC,aAAa,CAACC,KAAyB,EAAE;IACvD,MAAM,EAAEC,iBAAiB,CAAA,EAAEC,aAAa,CAAA,EAAEC,EAAE,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGJ,KAAK,AAAC;IAClE,MAAM,EAAEK,IAAI,CAAA,EAAE,GAAGJ,iBAAiB,AAAC;QACTI,SAAa;IAAvC,MAAMC,iBAAiB,GAAGD,CAAAA,SAAa,GAAbA,IAAI,CAACE,QAAQ,cAAbF,SAAa,cAAbA,SAAa,GAAI,IAAI,AAAC;IAChD,MAAMG,gBAAgB,GAAGZ,mBAAmB,CAACU,iBAAiB,CAAC,AAAC;IAChE,MAAM,EAAEG,SAAS,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGb,qBAAqB,CAACW,gBAAgB,EAAE,IAAI,CAAC,AAAC;IAElF,qBACE,KAACb,uBAAuB;QAACM,iBAAiB,EAAEA,iBAAiB;QAAEC,aAAa,EAAEA,aAAa;kBACzF,cAAA,KAACR,iBAAiB;YAACiB,YAAY,EAAE;gBAAEC,aAAa,EAAEP,IAAI;aAAE;sBACtD,cAAA,KAACb,iBAAiB;gBAACiB,SAAS,EAAEA,SAAS;gBAAEC,YAAY,EAAEA,YAAY;0BACjE,cAAA,KAACjB,wBAAwB;oBAACoB,0BAA0B,EAAER,IAAI,CAACS,SAAS;8BAClE,cAAA,KAAC1B,GAAG;wBACFe,EAAE,EAAEZ,SAAS,CACX;4BACEwB,OAAO,EAAE,MAAM;4BACfC,KAAK,EAAE,MAAM;4BACbC,MAAM,EAAE,MAAM;4BACdC,QAAQ,EAAE,UAAU;4BACpBC,QAAQ,EAAE,QAAQ;yBACnB,EACDhB,EAAE,CACH;wBACA,GAAGC,MAAM;kCAEV,cAAA,KAACf,aAAa;4BAAC+B,iBAAiB,EAAE9B,UAAU;sCAC1C,cAAA,KAACQ,YAAY;gCAACG,iBAAiB,EAAEA,iBAAiB;8BAAI;0BACxC;sBACZ;kBACmB;cACT;UACF;MACI,CAC1B;AACJ,CAAC"}
|
|
@@ -10,56 +10,33 @@
|
|
|
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
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { screen } from '@testing-library/react';
|
|
15
15
|
import userEvent from '@testing-library/user-event';
|
|
16
|
-
import { DashboardProvider,
|
|
17
|
-
import {
|
|
18
|
-
import testDashboard from '../../../test/testDashboard';
|
|
16
|
+
import { DashboardProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';
|
|
17
|
+
import { getTestDashboard, renderWithContext } from '../../../test';
|
|
19
18
|
import { DashboardApp } from '../DashboardApp';
|
|
20
19
|
describe('Panel Groups', ()=>{
|
|
21
20
|
const renderDashboard = ()=>{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
children: [
|
|
36
|
-
/*#__PURE__*/ _jsx(DashboardProviderSpy, {}),
|
|
37
|
-
/*#__PURE__*/ _jsx(DashboardApp, {
|
|
38
|
-
dashboardResource: getTestDashboard()
|
|
39
|
-
})
|
|
40
|
-
]
|
|
21
|
+
renderWithContext(/*#__PURE__*/ _jsx(TimeRangeProvider, {
|
|
22
|
+
timeRange: {
|
|
23
|
+
pastDuration: '30m'
|
|
24
|
+
},
|
|
25
|
+
children: /*#__PURE__*/ _jsx(TemplateVariableProvider, {
|
|
26
|
+
children: /*#__PURE__*/ _jsx(DashboardProvider, {
|
|
27
|
+
initialState: {
|
|
28
|
+
dashboardSpec: getTestDashboard().spec,
|
|
29
|
+
isEditMode: true
|
|
30
|
+
},
|
|
31
|
+
children: /*#__PURE__*/ _jsx(DashboardApp, {
|
|
32
|
+
dashboardResource: getTestDashboard()
|
|
41
33
|
})
|
|
42
34
|
})
|
|
43
35
|
})
|
|
44
36
|
}));
|
|
45
|
-
const { value: storeApi } = store;
|
|
46
|
-
if (storeApi === undefined) {
|
|
47
|
-
throw new Error('Expected dashboard store to be set after initial render');
|
|
48
|
-
}
|
|
49
|
-
return storeApi;
|
|
50
37
|
};
|
|
51
|
-
beforeEach(()=>{
|
|
52
|
-
const mockIntersectionObserver = jest.fn();
|
|
53
|
-
mockIntersectionObserver.mockReturnValue({
|
|
54
|
-
observe: ()=>null,
|
|
55
|
-
unobserve: ()=>null,
|
|
56
|
-
disconnect: ()=>null
|
|
57
|
-
});
|
|
58
|
-
window.IntersectionObserver = mockIntersectionObserver;
|
|
59
|
-
});
|
|
60
38
|
it('should delete panel', ()=>{
|
|
61
|
-
|
|
62
|
-
const storeApi = renderDashboard();
|
|
39
|
+
renderDashboard();
|
|
63
40
|
const panel = screen.getByText('CPU');
|
|
64
41
|
userEvent.hover(panel);
|
|
65
42
|
const deletePanelButton = screen.getByLabelText('delete panel');
|
|
@@ -67,37 +44,28 @@ describe('Panel Groups', ()=>{
|
|
|
67
44
|
screen.getByText('Delete Panel');
|
|
68
45
|
const deleteButton = screen.getByText('Delete');
|
|
69
46
|
userEvent.click(deleteButton);
|
|
70
|
-
|
|
71
|
-
const deletedPanel =
|
|
72
|
-
expect(
|
|
73
|
-
const panels = storeApi.getState().panels;
|
|
74
|
-
// should remove cpu from state.panels since it's not used anymore
|
|
75
|
-
expect(panels).toEqual(expect.not.objectContaining({
|
|
76
|
-
cpu: testDashboard.spec.panels['cpu']
|
|
77
|
-
}));
|
|
47
|
+
// The panel should disappear
|
|
48
|
+
const deletedPanel = screen.queryByText('CPU');
|
|
49
|
+
expect(deletedPanel).not.toBeInTheDocument();
|
|
78
50
|
});
|
|
79
|
-
it('should only delete panel from panel group if panel is referenced more than once', ()=>{
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
51
|
+
it('should only delete panel from panel group if panel is not referenced more than once', ()=>{
|
|
52
|
+
renderDashboard();
|
|
53
|
+
const panels = screen.getAllByText('Disk I/O Utilization');
|
|
54
|
+
expect(panels).toHaveLength(2);
|
|
55
|
+
const panel = panels[0];
|
|
56
|
+
if (panel === undefined) throw new Error('Missing panel');
|
|
83
57
|
userEvent.hover(panel);
|
|
84
58
|
const deletePanelButton = screen.getByLabelText('delete panel');
|
|
85
59
|
userEvent.click(deletePanelButton);
|
|
86
60
|
screen.getByText('Delete Panel');
|
|
87
61
|
const deleteButton = screen.getByText('Delete');
|
|
88
62
|
userEvent.click(deleteButton);
|
|
89
|
-
|
|
90
|
-
const deletedPanel =
|
|
91
|
-
expect(
|
|
92
|
-
const panels = storeApi.getState().panels;
|
|
93
|
-
// should NOT remove diskIO from state.panels since it's used in another panel group
|
|
94
|
-
expect(panels).toEqual(expect.objectContaining({
|
|
95
|
-
diskIO: testDashboard.spec.panels['diskIO']
|
|
96
|
-
}));
|
|
63
|
+
// The deleted panel should still be on screen in the other group
|
|
64
|
+
const deletedPanel = screen.queryByText('Disk I/O Utilization');
|
|
65
|
+
expect(deletedPanel).toBeInTheDocument();
|
|
97
66
|
});
|
|
98
67
|
it('should swap panels', ()=>{
|
|
99
|
-
|
|
100
|
-
const storeApi = renderDashboard();
|
|
68
|
+
renderDashboard();
|
|
101
69
|
// should move panel down
|
|
102
70
|
const group1 = screen.getByText('CPU Stats');
|
|
103
71
|
userEvent.hover(group1);
|
|
@@ -109,13 +77,14 @@ describe('Panel Groups', ()=>{
|
|
|
109
77
|
userEvent.hover(group2);
|
|
110
78
|
const moveGroupUpBtn = screen.getByLabelText('move group up');
|
|
111
79
|
userEvent.click(moveGroupUpBtn);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
80
|
+
/* TODO: Figure out how to test this visually without coupling to the store
|
|
81
|
+
const layouts = storeApi.getState().layouts;
|
|
82
|
+
expect(layouts[0]?.title).toBe(undefined);
|
|
83
|
+
expect(layouts[1]?.title).toBe('Disk Stats');
|
|
84
|
+
expect(layouts[2]?.title).toBe('CPU Stats');
|
|
85
|
+
*/ });
|
|
117
86
|
it('should delete a panel group', ()=>{
|
|
118
|
-
|
|
87
|
+
renderDashboard();
|
|
119
88
|
const group = screen.getByText('CPU Stats');
|
|
120
89
|
userEvent.hover(group);
|
|
121
90
|
const deleteGroupIcon = screen.getByLabelText('delete group');
|
|
@@ -123,35 +92,15 @@ describe('Panel Groups', ()=>{
|
|
|
123
92
|
screen.getByText('Delete Panel Group');
|
|
124
93
|
const deleteButton = screen.getByText('Delete');
|
|
125
94
|
userEvent.click(deleteButton);
|
|
126
|
-
// should remove group
|
|
127
|
-
const
|
|
128
|
-
expect(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
x: 0,
|
|
136
|
-
y: 0,
|
|
137
|
-
width: 12,
|
|
138
|
-
height: 4,
|
|
139
|
-
content: {
|
|
140
|
-
$ref: '#/spec/panels/cpu'
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
|
-
};
|
|
145
|
-
expect(layouts).toEqual(expect.not.objectContaining(deletedLayout));
|
|
146
|
-
const panels = storeApi.getState().panels;
|
|
147
|
-
// should remove cpu from state.panels since it's not used anymore
|
|
148
|
-
expect(panels).toEqual(expect.not.objectContaining({
|
|
149
|
-
cpu: testDashboard.spec.panels['cpu']
|
|
150
|
-
}));
|
|
151
|
-
// should not remove diskIO from state.panels since it's still used in another group
|
|
152
|
-
expect(panels).toEqual(expect.objectContaining({
|
|
153
|
-
diskIO: testDashboard.spec.panels['diskIO']
|
|
154
|
-
}));
|
|
95
|
+
// should remove group
|
|
96
|
+
const deletedGroup = screen.queryByText('CPU Stats');
|
|
97
|
+
expect(deletedGroup).not.toBeInTheDocument();
|
|
98
|
+
// CPU panel should be completely gone since it wasn't in any other group
|
|
99
|
+
let panel = screen.queryByText('CPU');
|
|
100
|
+
expect(panel).not.toBeInTheDocument();
|
|
101
|
+
// A DiskIO panel should still be present in the other group that wasn't deleted
|
|
102
|
+
panel = screen.queryByText('Disk I/O Utilization');
|
|
103
|
+
expect(panel).toBeInTheDocument();
|
|
155
104
|
});
|
|
156
105
|
});
|
|
157
106
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/ViewDashboard/tests/panelGroups.test.tsx"],"sourcesContent":["// Copyright 2022 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 { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { DashboardProvider, QueryStringProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';\nimport { PanelGroupDefinition } from '../../../context/DashboardProvider/layout-slice';\nimport { createDashboardProviderSpy, getTestDashboard, renderWithContext } from '../../../test';\nimport testDashboard from '../../../test/testDashboard';\nimport { DashboardApp } from '../DashboardApp';\n\ndescribe('Panel Groups', () => {\n const renderDashboard = () => {\n const { store, DashboardProviderSpy } = createDashboardProviderSpy();\n renderWithContext(\n <QueryStringProvider queryString={new URLSearchParams('https://localhost:3000/')}>\n <TimeRangeProvider initialTimeRange={{ pastDuration: '30m' }}>\n <TemplateVariableProvider>\n <DashboardProvider initialState={{ dashboardSpec: getTestDashboard().spec, isEditMode: true }}>\n <DashboardProviderSpy />\n <DashboardApp dashboardResource={getTestDashboard()} />\n </DashboardProvider>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n </QueryStringProvider>\n );\n\n const { value: storeApi } = store;\n if (storeApi === undefined) {\n throw new Error('Expected dashboard store to be set after initial render');\n }\n\n return storeApi;\n };\n\n beforeEach(() => {\n const mockIntersectionObserver = jest.fn();\n mockIntersectionObserver.mockReturnValue({\n observe: () => null,\n unobserve: () => null,\n disconnect: () => null,\n });\n window.IntersectionObserver = mockIntersectionObserver;\n });\n\n it('should delete panel', () => {\n const storeApi = renderDashboard();\n const panel = screen.getByText('CPU');\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n const layouts = storeApi.getState().layouts;\n const deletedPanel = testDashboard.spec.panels['cpu'];\n expect(layouts[0]?.items).toEqual(expect.not.objectContaining(deletedPanel));\n\n const panels = storeApi.getState().panels;\n // should remove cpu from state.panels since it's not used anymore\n expect(panels).toEqual(expect.not.objectContaining({ cpu: testDashboard.spec.panels['cpu'] }));\n });\n\n it('should only delete panel from panel group if panel is referenced more than once', () => {\n const storeApi = renderDashboard();\n const panel = screen.getByText('Disk I/O Utilization');\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n const layouts = storeApi.getState().layouts;\n const deletedPanel = testDashboard.spec.panels['diskIO'];\n expect(layouts[0]?.items).toEqual(expect.not.objectContaining(deletedPanel));\n\n const panels = storeApi.getState().panels;\n // should NOT remove diskIO from state.panels since it's used in another panel group\n expect(panels).toEqual(expect.objectContaining({ diskIO: testDashboard.spec.panels['diskIO'] }));\n });\n\n it('should swap panels', () => {\n const storeApi = renderDashboard();\n // should move panel down\n const group1 = screen.getByText('CPU Stats');\n userEvent.hover(group1);\n const moveGroupDownBtn = screen.getByLabelText('move group down');\n userEvent.click(moveGroupDownBtn);\n userEvent.unhover(moveGroupDownBtn);\n // should move panel up\n const group2 = screen.getByText('Disk Stats');\n userEvent.hover(group2);\n const moveGroupUpBtn = screen.getByLabelText('move group up');\n userEvent.click(moveGroupUpBtn);\n\n const layouts = storeApi.getState().layouts;\n expect(layouts[0]?.title).toBe(undefined);\n expect(layouts[1]?.title).toBe('Disk Stats');\n expect(layouts[2]?.title).toBe('CPU Stats');\n });\n\n it('should delete a panel group', () => {\n const storeApi = renderDashboard();\n const group = screen.getByText('CPU Stats');\n userEvent.hover(group);\n const deleteGroupIcon = screen.getByLabelText('delete group');\n userEvent.click(deleteGroupIcon);\n screen.getByText('Delete Panel Group');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // should remove group from state.layouts\n const layouts = storeApi.getState().layouts;\n expect(layouts).toHaveLength(2);\n const deletedLayout: PanelGroupDefinition = {\n id: 0,\n title: 'CPU Stats',\n isCollapsed: false,\n items: [\n {\n x: 0,\n y: 0,\n width: 12,\n height: 4,\n content: { $ref: '#/spec/panels/cpu' },\n },\n ],\n };\n expect(layouts).toEqual(expect.not.objectContaining(deletedLayout));\n\n const panels = storeApi.getState().panels;\n // should remove cpu from state.panels since it's not used anymore\n expect(panels).toEqual(expect.not.objectContaining({ cpu: testDashboard.spec.panels['cpu'] }));\n // should not remove diskIO from state.panels since it's still used in another group\n expect(panels).toEqual(expect.objectContaining({ diskIO: testDashboard.spec.panels['diskIO'] }));\n });\n});\n"],"names":["screen","userEvent","DashboardProvider","QueryStringProvider","TemplateVariableProvider","TimeRangeProvider","createDashboardProviderSpy","getTestDashboard","renderWithContext","testDashboard","DashboardApp","describe","renderDashboard","store","DashboardProviderSpy","queryString","URLSearchParams","initialTimeRange","pastDuration","initialState","dashboardSpec","spec","isEditMode","dashboardResource","value","storeApi","undefined","Error","beforeEach","mockIntersectionObserver","jest","fn","mockReturnValue","observe","unobserve","disconnect","window","IntersectionObserver","it","layouts","panel","getByText","hover","deletePanelButton","getByLabelText","click","deleteButton","getState","deletedPanel","panels","expect","items","toEqual","not","objectContaining","cpu","diskIO","group1","moveGroupDownBtn","unhover","group2","moveGroupUpBtn","title","toBe","group","deleteGroupIcon","toHaveLength","deletedLayout","id","isCollapsed","x","y","width","height","content","$ref"],"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,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,iBAAiB,EAAEC,mBAAmB,EAAEC,wBAAwB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;A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AC;QAEpE,MAAMlB,MAAM,GAAGxB,QAAQ,CAACsB,QAAQ,EAAE,CAACE,MAAM,AAAC;QAC1C,kEAAkE;QAClEC,MAAM,CAACD,MAAM,CAAC,CAACG,OAAO,CAACF,MAAM,CAACG,GAAG,CAACC,gBAAgB,CAAC;YAAEC,GAAG,EAAE9C,aAAa,CAACY,IAAI,CAAC4B,MAAM,CAAC,KAAK,CAAC;SAAE,CAAC,CAAC,CAAC;QAC/F,oFAAoF;QACpFC,MAAM,CAACD,MAAM,CAAC,CAACG,OAAO,CAACF,MAAM,CAACI,gBAAgB,CAAC;YAAEE,MAAM,EAAE/C,aAAa,CAACY,IAAI,CAAC4B,MAAM,CAAC,QAAQ,CAAC;SAAE,CAAC,CAAC,CAAC;IACnG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/ViewDashboard/tests/panelGroups.test.tsx"],"sourcesContent":["// Copyright 2022 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 { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { DashboardProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';\nimport { getTestDashboard, renderWithContext } from '../../../test';\nimport { DashboardApp } from '../DashboardApp';\n\ndescribe('Panel Groups', () => {\n const renderDashboard = () => {\n renderWithContext(\n <TimeRangeProvider timeRange={{ pastDuration: '30m' }}>\n <TemplateVariableProvider>\n <DashboardProvider initialState={{ dashboardSpec: getTestDashboard().spec, isEditMode: true }}>\n <DashboardApp dashboardResource={getTestDashboard()} />\n </DashboardProvider>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n );\n };\n it('should delete panel', () => {\n renderDashboard();\n const panel = screen.getByText('CPU');\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The panel should disappear\n const deletedPanel = screen.queryByText('CPU');\n expect(deletedPanel).not.toBeInTheDocument();\n });\n\n it('should only delete panel from panel group if panel is not referenced more than once', () => {\n renderDashboard();\n\n const panels = screen.getAllByText('Disk I/O Utilization');\n expect(panels).toHaveLength(2);\n\n const panel = panels[0];\n if (panel === undefined) throw new Error('Missing panel');\n\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The deleted panel should still be on screen in the other group\n const deletedPanel = screen.queryByText('Disk I/O Utilization');\n expect(deletedPanel).toBeInTheDocument();\n });\n\n it('should swap panels', () => {\n renderDashboard();\n\n // should move panel down\n const group1 = screen.getByText('CPU Stats');\n userEvent.hover(group1);\n const moveGroupDownBtn = screen.getByLabelText('move group down');\n userEvent.click(moveGroupDownBtn);\n userEvent.unhover(moveGroupDownBtn);\n\n // should move panel up\n const group2 = screen.getByText('Disk Stats');\n userEvent.hover(group2);\n const moveGroupUpBtn = screen.getByLabelText('move group up');\n userEvent.click(moveGroupUpBtn);\n\n /* TODO: Figure out how to test this visually without coupling to the store\n const layouts = storeApi.getState().layouts;\n expect(layouts[0]?.title).toBe(undefined);\n expect(layouts[1]?.title).toBe('Disk Stats');\n expect(layouts[2]?.title).toBe('CPU Stats');\n */\n });\n\n it('should delete a panel group', () => {\n renderDashboard();\n const group = screen.getByText('CPU Stats');\n userEvent.hover(group);\n const deleteGroupIcon = screen.getByLabelText('delete group');\n userEvent.click(deleteGroupIcon);\n screen.getByText('Delete Panel Group');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // should remove group\n const deletedGroup = screen.queryByText('CPU Stats');\n expect(deletedGroup).not.toBeInTheDocument();\n\n // CPU panel should be completely gone since it wasn't in any other group\n let panel = screen.queryByText('CPU');\n expect(panel).not.toBeInTheDocument();\n\n // A DiskIO panel should still be present in the other group that wasn't deleted\n panel = screen.queryByText('Disk I/O Utilization');\n expect(panel).toBeInTheDocument();\n });\n});\n"],"names":["screen","userEvent","DashboardProvider","TemplateVariableProvider","TimeRangeProvider","getTestDashboard","renderWithContext","DashboardApp","describe","renderDashboard","timeRange","pastDuration","initialState","dashboardSpec","spec","isEditMode","dashboardResource","it","panel","getByText","hover","deletePanelButton","getByLabelText","click","deleteButton","deletedPanel","queryByText","expect","not","toBeInTheDocument","panels","getAllByText","toHaveLength","undefined","Error","group1","moveGroupDownBtn","unhover","group2","moveGroupUpBtn","group","deleteGroupIcon","deletedGroup"],"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,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,iBAAiB,EAAEC,wBAAwB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AAClG,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,eAAe,CAAC;AACpE,SAASC,YAAY,QAAQ,iBAAiB,CAAC;AAE/CC,QAAQ,CAAC,cAAc,EAAE,IAAM;IAC7B,MAAMC,eAAe,GAAG,IAAM;QAC5BH,iBAAiB,eACf,KAACF,iBAAiB;YAACM,SAAS,EAAE;gBAAEC,YAAY,EAAE,KAAK;aAAE;sBACnD,cAAA,KAACR,wBAAwB;0BACvB,cAAA,KAACD,iBAAiB;oBAACU,YAA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B,EAAE,CAAC,6BAA6B,EAAE,IAAM;QACtCR,eAAe,EAAE,CAAC;QAClB,MAAM+B,KAAK,GAAGxC,MAAM,CAACmB,SAAS,CAAC,WAAW,CAAC,AAAC;QAC5ClB,SAAS,CAACmB,KAAK,CAACoB,KAAK,CAAC,CAAC;QACvB,MAAMC,eAAe,GAAGzC,MAAM,CAACsB,cAAc,CAAC,cAAc,CAAC,AAAC;QAC9DrB,SAAS,CAACsB,KAAK,CAACkB,eAAe,CAAC,CAAC;QACjCzC,MAAM,CAACmB,SAAS,CAAC,oBAAoB,CAAC,CAAC;QACvC,MAAMK,YAAY,GAAGxB,MAAM,CAACmB,SAAS,CAAC,QAAQ,CAAC,AAAC;QAChDlB,SAAS,CAACsB,KAAK,CAACC,YAAY,CAAC,CAAC;QAE9B,sBAAsB;QACtB,MAAMkB,YAAY,GAAG1C,MAAM,CAAC0B,WAAW,CAAC,WAAW,CAAC,AAAC;QACrDC,MAAM,CAACe,YAAY,CAAC,CAACd,GAAG,CAACC,iBAAiB,EAAE,CAAC;QAE7C,yEAAyE;QACzE,IAAIX,KAAK,GAAGlB,MAAM,CAAC0B,WAAW,CAAC,KAAK,CAAC,AAAC;QACtCC,MAAM,CAACT,KAAK,CAAC,CAACU,GAAG,CAACC,iBAAiB,EAAE,CAAC;QAEtC,gFAAgF;QAChFX,KAAK,GAAGlB,MAAM,CAAC0B,WAAW,CAAC,sBAAsB,CAAC,CAAC;QACnDC,MAAM,CAACT,KAAK,CAAC,CAACW,iBAAiB,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/dashboards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@perses-dev/components": "^0.
|
|
31
|
-
"@perses-dev/core": "^0.
|
|
32
|
-
"@perses-dev/plugin-system": "^0.
|
|
30
|
+
"@perses-dev/components": "^0.11.0",
|
|
31
|
+
"@perses-dev/core": "^0.11.0",
|
|
32
|
+
"@perses-dev/plugin-system": "^0.11.0",
|
|
33
33
|
"@types/react-grid-layout": "^1.3.2",
|
|
34
34
|
"date-fns": "^2.28.0",
|
|
35
35
|
"immer": "^9.0.15",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"react-grid-layout": "^1.3.4",
|
|
38
38
|
"react-intersection-observer": "^9.4.0",
|
|
39
39
|
"use-immer": "^0.7.0",
|
|
40
|
+
"use-query-params": "^2.1.1",
|
|
40
41
|
"use-resize-observer": "^9.0.0",
|
|
41
42
|
"zustand": "^4.1.1"
|
|
42
43
|
},
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 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
|
-
Object.defineProperty(exports, "createLayoutSlice", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: ()=>createLayoutSlice
|
|
20
|
-
});
|
|
21
|
-
const _core = require("@perses-dev/core");
|
|
22
|
-
function createLayoutSlice(layouts) {
|
|
23
|
-
// Return the state creator function for Zustand that uses the layouts provided as initial state
|
|
24
|
-
let id = -1;
|
|
25
|
-
function createPanelGroupId() {
|
|
26
|
-
id++;
|
|
27
|
-
return id;
|
|
28
|
-
}
|
|
29
|
-
var ref;
|
|
30
|
-
return (set, get)=>{
|
|
31
|
-
return {
|
|
32
|
-
layouts: layouts.map((layout)=>{
|
|
33
|
-
var ref1, ref2, ref3;
|
|
34
|
-
return {
|
|
35
|
-
...layout,
|
|
36
|
-
id: createPanelGroupId(),
|
|
37
|
-
title: (ref1 = layout.spec.display) === null || ref1 === void 0 ? void 0 : ref1.title,
|
|
38
|
-
isCollapsed: (ref = !((ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.collapse) === null || ref3 === void 0 ? void 0 : ref3.open)) !== null && ref !== void 0 ? ref : false,
|
|
39
|
-
items: layout.spec.items
|
|
40
|
-
};
|
|
41
|
-
}),
|
|
42
|
-
getPanelKey ({ groupIndex , itemIndex }) {
|
|
43
|
-
const { layouts } = get();
|
|
44
|
-
const group = findGroup(layouts, groupIndex);
|
|
45
|
-
const item = findItem(group, itemIndex);
|
|
46
|
-
return (0, _core.getPanelKeyFromRef)(item.content);
|
|
47
|
-
},
|
|
48
|
-
addPanelToGroup (panelKey, groupIndex) {
|
|
49
|
-
const { layouts } = get();
|
|
50
|
-
const group = findGroup(layouts, groupIndex);
|
|
51
|
-
const gridItem = {
|
|
52
|
-
x: 0,
|
|
53
|
-
y: getYForNewRow(group),
|
|
54
|
-
width: 12,
|
|
55
|
-
height: 6,
|
|
56
|
-
content: (0, _core.createPanelRef)(panelKey)
|
|
57
|
-
};
|
|
58
|
-
set((state)=>{
|
|
59
|
-
var ref;
|
|
60
|
-
(ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
movePanelToGroup ({ groupIndex , itemIndex }, newGroupIndex) {
|
|
64
|
-
const { layouts } = get();
|
|
65
|
-
// Find the existing item to make sure it exists
|
|
66
|
-
const group = findGroup(layouts, groupIndex);
|
|
67
|
-
const item = findItem(group, itemIndex);
|
|
68
|
-
// Find the new group and figure out where a new row should go
|
|
69
|
-
const newGroup = findGroup(layouts, newGroupIndex);
|
|
70
|
-
const newGroupY = getYForNewRow(newGroup);
|
|
71
|
-
set((state)=>{
|
|
72
|
-
var // Remove the item from its current group
|
|
73
|
-
ref, // Add a new item to the new group
|
|
74
|
-
ref1;
|
|
75
|
-
(ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
|
|
76
|
-
(ref1 = state.layouts[newGroupIndex]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
|
|
77
|
-
x: 0,
|
|
78
|
-
y: newGroupY,
|
|
79
|
-
width: item.width,
|
|
80
|
-
height: item.height,
|
|
81
|
-
content: item.content
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
// TODO: Maybe combine this into some kind of groupEditor state
|
|
86
|
-
updatePanelGroup (next, groupIndex) {
|
|
87
|
-
set((state)=>{
|
|
88
|
-
if (groupIndex === undefined) {
|
|
89
|
-
state.layouts.unshift({
|
|
90
|
-
...next,
|
|
91
|
-
id: createPanelGroupId()
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
const layout = state.layouts[groupIndex];
|
|
95
|
-
if (layout === undefined) {
|
|
96
|
-
throw new Error(`No layout at index ${groupIndex}`);
|
|
97
|
-
}
|
|
98
|
-
state.layouts[groupIndex] = {
|
|
99
|
-
...next,
|
|
100
|
-
id: layout.id
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
swapPanelGroups (x, y) {
|
|
106
|
-
set((state)=>{
|
|
107
|
-
if (x < 0 || x >= state.layouts.length || y < 0 || y >= state.layouts.length) {
|
|
108
|
-
throw new Error('index out of bound');
|
|
109
|
-
}
|
|
110
|
-
const xPanelGroup = state.layouts[x];
|
|
111
|
-
const yPanelGroup = state.layouts[y];
|
|
112
|
-
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
113
|
-
throw new Error('panel group is undefined');
|
|
114
|
-
}
|
|
115
|
-
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
116
|
-
[state.layouts[x], state.layouts[y]] = [
|
|
117
|
-
yPanelGroup,
|
|
118
|
-
xPanelGroup
|
|
119
|
-
];
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
deletePanelInPanelGroup ({ groupIndex , itemIndex }) {
|
|
123
|
-
set((state)=>{
|
|
124
|
-
const group = state.layouts[groupIndex];
|
|
125
|
-
if (group === undefined) {
|
|
126
|
-
throw new Error(`No panel group found: ${groupIndex}`);
|
|
127
|
-
}
|
|
128
|
-
// remove panel from panel group
|
|
129
|
-
group.items.splice(itemIndex, 1);
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
deletePanelGroup (groupIndex) {
|
|
133
|
-
const { layouts , deletePanels } = get();
|
|
134
|
-
const group = layouts[groupIndex];
|
|
135
|
-
if (group === undefined) {
|
|
136
|
-
throw new Error(`No panel group found: ${groupIndex}`);
|
|
137
|
-
}
|
|
138
|
-
// remove panels from group first
|
|
139
|
-
const panelsToBeDeleted = [];
|
|
140
|
-
for(let i = 0; i < group.items.length; i++){
|
|
141
|
-
panelsToBeDeleted.push({
|
|
142
|
-
groupIndex,
|
|
143
|
-
itemIndex: i
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
deletePanels(panelsToBeDeleted);
|
|
147
|
-
// remove group from state.layouts
|
|
148
|
-
set((state)=>{
|
|
149
|
-
state.layouts.splice(groupIndex, 1);
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
// Return an object that maps each panel to the groups it belongs
|
|
153
|
-
mapPanelToPanelGroups () {
|
|
154
|
-
const map = {}; // { panel key: [group ids] }
|
|
155
|
-
get().layouts.forEach((group)=>{
|
|
156
|
-
// for each panel in a group, add the group id to map[panelKey]
|
|
157
|
-
group.items.forEach((panel)=>{
|
|
158
|
-
const panelKey = (0, _core.getPanelKeyFromRef)(panel.content);
|
|
159
|
-
if (map[panelKey]) {
|
|
160
|
-
var ref;
|
|
161
|
-
(ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
|
|
162
|
-
} else {
|
|
163
|
-
map[panelKey] = [
|
|
164
|
-
group.id
|
|
165
|
-
];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
return map;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
// Helper to find a group and throw if not found
|
|
175
|
-
function findGroup(layouts, groupIndex) {
|
|
176
|
-
const group = layouts[groupIndex];
|
|
177
|
-
if (group === undefined) {
|
|
178
|
-
throw new Error(`No layout at index ${groupIndex}`);
|
|
179
|
-
}
|
|
180
|
-
return group;
|
|
181
|
-
}
|
|
182
|
-
// Helper to get an item in a group and throw if not found
|
|
183
|
-
function findItem(group, itemIndex) {
|
|
184
|
-
const item = group.items[itemIndex];
|
|
185
|
-
if (item === undefined) {
|
|
186
|
-
throw new Error(`No grid item found at position ${itemIndex}`);
|
|
187
|
-
}
|
|
188
|
-
return item;
|
|
189
|
-
}
|
|
190
|
-
// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
|
|
191
|
-
function getYForNewRow(group) {
|
|
192
|
-
let newRowY = 0;
|
|
193
|
-
for (const item of group.items){
|
|
194
|
-
const itemMaxY = item.y + item.height;
|
|
195
|
-
if (itemMaxY > newRowY) {
|
|
196
|
-
newRowY = itemMaxY;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return newRowY;
|
|
200
|
-
}
|