@perses-dev/dashboards 0.0.0-snapshot-color-palette-gen-test-bc1b508 → 0.0.0-snapshot-tooltip-highlight-c995fc8
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/EditJsonDialog/EditJsonDialog.js +5 -0
- package/dist/cjs/components/GridLayout/GridItemContent.js +22 -4
- package/dist/cjs/components/GridLayout/GridLayout.js +31 -2
- package/dist/cjs/components/Panel/Panel.js +2 -2
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +41 -34
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +32 -18
- package/dist/cjs/components/PanelDrawer/usePanelEditor.js +87 -0
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +5 -5
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -8
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +7 -8
- package/dist/cjs/context/DashboardProvider/common.js +26 -6
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +4 -4
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +8 -32
- package/dist/cjs/context/useDashboard.js +4 -4
- package/dist/cjs/stories/decorators/WithDatasourceStore.js +2 -47
- package/dist/cjs/stories/decorators/index.js +0 -4
- package/dist/cjs/test/datasource-provider.js +70 -0
- package/dist/cjs/test/index.js +1 -0
- package/dist/cjs/test/plugin-registry.js +11 -5
- package/dist/cjs/test/testDashboard.js +79 -79
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/{stories/decorators/WithQueryClient.js → utils/time.js} +9 -11
- package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -1
- package/dist/components/EditJsonDialog/EditJsonDialog.js +5 -0
- package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +22 -4
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +31 -2
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +3 -3
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +42 -35
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +32 -18
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelDrawer/usePanelEditor.d.ts +15 -0
- package/dist/components/PanelDrawer/usePanelEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/usePanelEditor.js +84 -0
- package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +6 -6
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -8
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -2
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +7 -8
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +2 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +17 -2
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +3 -3
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +3 -6
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +9 -33
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +4 -4
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/stories/decorators/WithDatasourceStore.js +1 -46
- package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
- package/dist/stories/decorators/index.js +0 -4
- package/dist/stories/decorators/index.js.map +1 -1
- package/dist/test/datasource-provider.d.ts +6 -0
- package/dist/test/datasource-provider.d.ts.map +1 -0
- package/dist/test/datasource-provider.js +60 -0
- package/dist/test/datasource-provider.js.map +1 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +1 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +11 -5
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/testDashboard.js +79 -79
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/time.d.ts +5 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/{stories/decorators/WithQueryClient.js → utils/time.js} +10 -10
- package/dist/utils/time.js.map +1 -0
- package/package.json +6 -6
- package/dist/cjs/stories/decorators/WithPluginRegistry.js +0 -91
- package/dist/cjs/stories/decorators/WithQueryParams.js +0 -29
- package/dist/cjs/stories/decorators/WithTimeRange.js +0 -38
- package/dist/stories/decorators/WithPluginRegistry.js +0 -46
- package/dist/stories/decorators/WithPluginRegistry.js.map +0 -1
- package/dist/stories/decorators/WithQueryClient.js.map +0 -1
- package/dist/stories/decorators/WithQueryParams.js +0 -23
- package/dist/stories/decorators/WithQueryParams.js.map +0 -1
- package/dist/stories/decorators/WithTimeRange.js +0 -32
- package/dist/stories/decorators/WithTimeRange.js.map +0 -1
|
@@ -11,13 +11,16 @@
|
|
|
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 { DataQueriesProvider } from '@perses-dev/plugin-system';
|
|
14
15
|
import { useEditMode, usePanel, usePanelActions } from '../../context';
|
|
16
|
+
import { useSuggestedStepMs } from '../../utils';
|
|
15
17
|
import { Panel } from '../Panel/Panel';
|
|
16
18
|
/**
|
|
17
19
|
* Resolves the reference to panel content in a GridItemDefinition and renders the panel.
|
|
18
20
|
*/ export function GridItemContent(props) {
|
|
19
|
-
const { panelGroupItemId } = props;
|
|
21
|
+
const { panelGroupItemId , width } = props;
|
|
20
22
|
const panelDefinition = usePanel(panelGroupItemId);
|
|
23
|
+
const { spec: { queries } , } = panelDefinition;
|
|
21
24
|
const { isEditMode } = useEditMode();
|
|
22
25
|
const { openEditPanel , openDeletePanelDialog , duplicatePanel } = usePanelActions(panelGroupItemId);
|
|
23
26
|
// Provide actions to the panel when in edit mode
|
|
@@ -29,9 +32,24 @@ import { Panel } from '../Panel/Panel';
|
|
|
29
32
|
onDeletePanelClick: openDeletePanelDialog
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
// map TimeSeriesQueryDefinition to Definition<UnknownSpec>
|
|
36
|
+
const suggestedStepMs = useSuggestedStepMs(width);
|
|
37
|
+
const queryDefinitions = queries !== null && queries !== void 0 ? queries : [];
|
|
38
|
+
const definitions = queryDefinitions.map((query)=>{
|
|
39
|
+
return {
|
|
40
|
+
kind: query.spec.plugin.kind,
|
|
41
|
+
spec: query.spec.plugin.spec
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
return /*#__PURE__*/ _jsx(DataQueriesProvider, {
|
|
45
|
+
definitions: definitions,
|
|
46
|
+
options: {
|
|
47
|
+
suggestedStepMs
|
|
48
|
+
},
|
|
49
|
+
children: /*#__PURE__*/ _jsx(Panel, {
|
|
50
|
+
definition: panelDefinition,
|
|
51
|
+
editHandlers: editHandlers
|
|
52
|
+
})
|
|
35
53
|
});
|
|
36
54
|
}
|
|
37
55
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/GridLayout/GridItemContent.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 { PanelGroupItemId, useEditMode, usePanel, usePanelActions } from '../../context';\nimport { Panel, PanelProps } from '../Panel/Panel';\n\nexport interface GridItemContentProps {\n panelGroupItemId: PanelGroupItemId;\n}\n\n/**\n * Resolves the reference to panel content in a GridItemDefinition and renders the panel.\n */\nexport function GridItemContent(props: GridItemContentProps) {\n const { panelGroupItemId } = props;\n const panelDefinition = usePanel(panelGroupItemId);\n const { isEditMode } = useEditMode();\n const { openEditPanel, openDeletePanelDialog, duplicatePanel } = usePanelActions(panelGroupItemId);\n\n // Provide actions to the panel when in edit mode\n let editHandlers: PanelProps['editHandlers'] = undefined;\n if (isEditMode) {\n editHandlers = {\n onEditPanelClick: openEditPanel,\n onDuplicatePanelClick: duplicatePanel,\n onDeletePanelClick: openDeletePanelDialog,\n };\n }\n\n return <Panel definition={panelDefinition} editHandlers={editHandlers}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/GridItemContent.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 { QueryDefinition } from '@perses-dev/core';\nimport { DataQueriesProvider } from '@perses-dev/plugin-system';\nimport { PanelGroupItemId, useEditMode, usePanel, usePanelActions } from '../../context';\nimport { useSuggestedStepMs } from '../../utils';\nimport { Panel, PanelProps } from '../Panel/Panel';\n\nexport interface GridItemContentProps {\n panelGroupItemId: PanelGroupItemId;\n width: number; // necessary for determining the suggested step ms\n}\n\n/**\n * Resolves the reference to panel content in a GridItemDefinition and renders the panel.\n */\nexport function GridItemContent(props: GridItemContentProps) {\n const { panelGroupItemId, width } = props;\n const panelDefinition = usePanel(panelGroupItemId);\n const {\n spec: { queries },\n } = panelDefinition;\n const { isEditMode } = useEditMode();\n const { openEditPanel, openDeletePanelDialog, duplicatePanel } = usePanelActions(panelGroupItemId);\n\n // Provide actions to the panel when in edit mode\n let editHandlers: PanelProps['editHandlers'] = undefined;\n if (isEditMode) {\n editHandlers = {\n onEditPanelClick: openEditPanel,\n onDuplicatePanelClick: duplicatePanel,\n onDeletePanelClick: openDeletePanelDialog,\n };\n }\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const suggestedStepMs = useSuggestedStepMs(width);\n const queryDefinitions = queries ?? [];\n const definitions = queryDefinitions.map((query: QueryDefinition) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n });\n\n return (\n <DataQueriesProvider definitions={definitions} options={{ suggestedStepMs }}>\n <Panel definition={panelDefinition} editHandlers={editHandlers} />\n </DataQueriesProvider>\n );\n}\n"],"names":["DataQueriesProvider","useEditMode","usePanel","usePanelActions","useSuggestedStepMs","Panel","GridItemContent","props","panelGroupItemId","width","panelDefinition","spec","queries","isEditMode","openEditPanel","openDeletePanelDialog","duplicatePanel","editHandlers","undefined","onEditPanelClick","onDuplicatePanelClick","onDeletePanelClick","suggestedStepMs","queryDefinitions","definitions","map","query","kind","plugin","options","definition"],"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;AACA,SAASA,mBAAmB,QAAQ,2BAA2B,CAAC;AAChE,SAA2BC,WAAW,EAAEC,QAAQ,EAAEC,eAAe,QAAQ,eAAe,CAAC;AACzF,SAASC,kBAAkB,QAAQ,aAAa,CAAC;AACjD,SAASC,KAAK,QAAoB,gBAAgB,CAAC;AAOnD;;CAEC,GACD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,EAAEC,gBAAgB,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAC1C,MAAMG,eAAe,GAAGR,QAAQ,CAACM,gBAAgB,CAAC,AAAC;IACnD,MAAM,EACJG,IAAI,EAAE,EAAEC,OAAO,CAAA,EAAE,CAAA,IAClB,GAAGF,eAAe,AAAC;IACpB,MAAM,EAAEG,UAAU,CAAA,EAAE,GAAGZ,WAAW,EAAE,AAAC;IACrC,MAAM,EAAEa,aAAa,CAAA,EAAEC,qBAAqB,CAAA,EAAEC,cAAc,CAAA,EAAE,GAAGb,eAAe,CAACK,gBAAgB,CAAC,AAAC;IAEnG,iDAAiD;IACjD,IAAIS,YAAY,GAA+BC,SAAS,AAAC;IACzD,IAAIL,UAAU,EAAE;QACdI,YAAY,GAAG;YACbE,gBAAgB,EAAEL,aAAa;YAC/BM,qBAAqB,EAAEJ,cAAc;YACrCK,kBAAkB,EAAEN,qBAAqB;SAC1C,CAAC;IACJ,CAAC;IAED,2DAA2D;IAC3D,MAAMO,eAAe,GAAGlB,kBAAkB,CAACK,KAAK,CAAC,AAAC;IAClD,MAAMc,gBAAgB,GAAGX,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,EAAE,AAAC;IACvC,MAAMY,WAAW,GAAGD,gBAAgB,CAACE,GAAG,CAAC,CAACC,KAAsB,GAAK;QACnE,OAAO;YACLC,IAAI,EAAED,KAAK,CAACf,IAAI,CAACiB,MAAM,CAACD,IAAI;YAC5BhB,IAAI,EAAEe,KAAK,CAACf,IAAI,CAACiB,MAAM,CAACjB,IAAI;SAC7B,CAAC;IACJ,CAAC,CAAC,AAAC;IAEH,qBACE,KAACX,mBAAmB;QAACwB,WAAW,EAAEA,WAAW;QAAEK,OAAO,EAAE;YAAEP,eAAe;SAAE;kBACzE,cAAA,KAACjB,KAAK;YAACyB,UAAU,EAAEpB,eAAe;YAAEO,YAAY,EAAEA,YAAY;UAAI;MAC9C,CACtB;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAoD,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAoD,YAAY,EAAE,MAAM,eAAe,CAAC;AAS/F,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAkFhD"}
|
|
@@ -20,6 +20,7 @@ import { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants'
|
|
|
20
20
|
import { GridTitle } from './GridTitle';
|
|
21
21
|
import { GridItemContent } from './GridItemContent';
|
|
22
22
|
import { GridContainer } from './GridContainer';
|
|
23
|
+
const DEFAULT_MARGIN = 10;
|
|
23
24
|
const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
24
25
|
/**
|
|
25
26
|
* Layout component that arranges children in a Grid based on the definition.
|
|
@@ -31,6 +32,7 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
|
31
32
|
var ref;
|
|
32
33
|
const [isOpen, setIsOpen] = useState((ref = !groupDefinition.isCollapsed) !== null && ref !== void 0 ? ref : true);
|
|
33
34
|
const { isEditMode } = useEditMode();
|
|
35
|
+
const [gridColWidth, setGridColWidth] = useState(0);
|
|
34
36
|
const handleLayoutChange = (currentLayout, allLayouts)=>{
|
|
35
37
|
// Using the value from `allLayouts` instead of `currentLayout` because of
|
|
36
38
|
// a bug in react-layout-grid where `currentLayout` does not adjust properly
|
|
@@ -41,6 +43,16 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
|
41
43
|
updatePanelGroupLayouts(smallLayout);
|
|
42
44
|
}
|
|
43
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Calculate the column width so we can determine the width of each panel for suggested step ms
|
|
48
|
+
* https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35
|
|
49
|
+
*/ const handleWidthChange = (containerWidth, margin, cols, containerPadding)=>{
|
|
50
|
+
const marginX = margin[0];
|
|
51
|
+
const marginWidth = marginX * (cols - 1);
|
|
52
|
+
const containerPaddingWidth = containerPadding[0] * 2;
|
|
53
|
+
// exclude margin and padding from total width
|
|
54
|
+
setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);
|
|
55
|
+
};
|
|
44
56
|
return /*#__PURE__*/ _jsxs(GridContainer, {
|
|
45
57
|
children: [
|
|
46
58
|
groupDefinition.title !== undefined && /*#__PURE__*/ _jsx(GridTitle, {
|
|
@@ -70,6 +82,10 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
|
70
82
|
],
|
|
71
83
|
isDraggable: isEditMode,
|
|
72
84
|
isResizable: isEditMode,
|
|
85
|
+
margin: [
|
|
86
|
+
DEFAULT_MARGIN,
|
|
87
|
+
DEFAULT_MARGIN
|
|
88
|
+
],
|
|
73
89
|
containerPadding: [
|
|
74
90
|
0,
|
|
75
91
|
10
|
|
@@ -78,14 +94,16 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
|
78
94
|
[GRID_LAYOUT_SMALL_BREAKPOINT]: groupDefinition.itemLayouts
|
|
79
95
|
},
|
|
80
96
|
onLayoutChange: handleLayoutChange,
|
|
81
|
-
|
|
97
|
+
onWidthChange: handleWidthChange,
|
|
98
|
+
children: groupDefinition.itemLayouts.map(({ i , w })=>/*#__PURE__*/ _jsx("div", {
|
|
82
99
|
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
83
100
|
FallbackComponent: ErrorAlert,
|
|
84
101
|
children: /*#__PURE__*/ _jsx(GridItemContent, {
|
|
85
102
|
panelGroupItemId: {
|
|
86
103
|
panelGroupId,
|
|
87
104
|
panelGroupItemLayoutId: i
|
|
88
|
-
}
|
|
105
|
+
},
|
|
106
|
+
width: calculateGridItemWidth(w, gridColWidth)
|
|
89
107
|
})
|
|
90
108
|
})
|
|
91
109
|
}, i))
|
|
@@ -94,5 +112,16 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
|
94
112
|
]
|
|
95
113
|
});
|
|
96
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Calculates grid item width
|
|
117
|
+
* @param w number of columns the grid item spans
|
|
118
|
+
* @param colWidth the width of each column in px
|
|
119
|
+
* @returns grid item's width in px
|
|
120
|
+
* https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35
|
|
121
|
+
*/ const calculateGridItemWidth = (w, colWidth)=>{
|
|
122
|
+
// 0 * Infinity === NaN, which causes problems with resize contraints
|
|
123
|
+
if (!Number.isFinite(w)) return w;
|
|
124
|
+
return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);
|
|
125
|
+
};
|
|
97
126
|
|
|
98
127
|
//# sourceMappingURL=GridLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/GridLayout/GridLayout.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.\nimport { useState } from 'react';\nimport { Responsive, WidthProvider, Layouts, Layout } from 'react-grid-layout';\nimport { Collapse, useTheme } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { useEditMode, usePanelGroup, usePanelGroupActions, PanelGroupId } from '../../context';\nimport { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { GridTitle } from './GridTitle';\nimport { GridItemContent } from './GridItemContent';\nimport { GridContainer } from './GridContainer';\n\nconst ResponsiveGridLayout = WidthProvider(Responsive);\n\nexport interface GridLayoutProps {\n panelGroupId: PanelGroupId;\n}\n\n/**\n * Layout component that arranges children in a Grid based on the definition.\n */\nexport function GridLayout(props: GridLayoutProps) {\n const { panelGroupId /*...others */ } = props;\n const theme = useTheme();\n const groupDefinition = usePanelGroup(panelGroupId);\n const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);\n\n const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed ?? true);\n const { isEditMode } = useEditMode();\n\n const handleLayoutChange = (currentLayout: Layout[], allLayouts: Layouts) => {\n // Using the value from `allLayouts` instead of `currentLayout` because of\n // a bug in react-layout-grid where `currentLayout` does not adjust properly\n // when going to a smaller breakpoint and then back to a larger breakpoint.\n // https://github.com/react-grid-layout/react-grid-layout/issues/1663\n const smallLayout = allLayouts[GRID_LAYOUT_SMALL_BREAKPOINT];\n if (smallLayout) {\n updatePanelGroupLayouts(smallLayout);\n }\n };\n\n return (\n <GridContainer>\n {groupDefinition.title !== undefined && (\n <GridTitle\n panelGroupId={panelGroupId}\n title={groupDefinition.title}\n collapse={\n groupDefinition.isCollapsed === undefined\n ? undefined\n : { isOpen, onToggleOpen: () => setIsOpen((current) => !current) }\n }\n />\n )}\n <Collapse in={isOpen} unmountOnExit appear={false} data-testid=\"panel-group-content\">\n <ResponsiveGridLayout\n className=\"layout\"\n breakpoints={{ sm: theme.breakpoints.values.sm, xxs: 0 }}\n cols={GRID_LAYOUT_COLS}\n rowHeight={30}\n draggableHandle={'.drag-handle'}\n resizeHandles={['se']}\n isDraggable={isEditMode}\n isResizable={isEditMode}\n containerPadding={[0, 10]}\n layouts={{ [GRID_LAYOUT_SMALL_BREAKPOINT]: groupDefinition.itemLayouts }}\n onLayoutChange={handleLayoutChange}\n >\n {groupDefinition.itemLayouts.map(({ i }) => (\n <div key={i}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <GridItemContent
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/GridLayout.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.\nimport { useState } from 'react';\nimport { Responsive, WidthProvider, Layouts, Layout } from 'react-grid-layout';\nimport { Collapse, useTheme } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { useEditMode, usePanelGroup, usePanelGroupActions, PanelGroupId } from '../../context';\nimport { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { GridTitle } from './GridTitle';\nimport { GridItemContent } from './GridItemContent';\nimport { GridContainer } from './GridContainer';\n\nconst DEFAULT_MARGIN = 10;\nconst ResponsiveGridLayout = WidthProvider(Responsive);\n\nexport interface GridLayoutProps {\n panelGroupId: PanelGroupId;\n}\n\n/**\n * Layout component that arranges children in a Grid based on the definition.\n */\nexport function GridLayout(props: GridLayoutProps) {\n const { panelGroupId /*...others */ } = props;\n const theme = useTheme();\n const groupDefinition = usePanelGroup(panelGroupId);\n const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);\n\n const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed ?? true);\n const { isEditMode } = useEditMode();\n\n const [gridColWidth, setGridColWidth] = useState(0);\n\n const handleLayoutChange = (currentLayout: Layout[], allLayouts: Layouts) => {\n // Using the value from `allLayouts` instead of `currentLayout` because of\n // a bug in react-layout-grid where `currentLayout` does not adjust properly\n // when going to a smaller breakpoint and then back to a larger breakpoint.\n // https://github.com/react-grid-layout/react-grid-layout/issues/1663\n const smallLayout = allLayouts[GRID_LAYOUT_SMALL_BREAKPOINT];\n if (smallLayout) {\n updatePanelGroupLayouts(smallLayout);\n }\n };\n\n /**\n * Calculate the column width so we can determine the width of each panel for suggested step ms\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\n const handleWidthChange = (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ) => {\n const marginX = margin[0];\n const marginWidth = marginX * (cols - 1);\n const containerPaddingWidth = containerPadding[0] * 2;\n // exclude margin and padding from total width\n setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);\n };\n\n return (\n <GridContainer>\n {groupDefinition.title !== undefined && (\n <GridTitle\n panelGroupId={panelGroupId}\n title={groupDefinition.title}\n collapse={\n groupDefinition.isCollapsed === undefined\n ? undefined\n : { isOpen, onToggleOpen: () => setIsOpen((current) => !current) }\n }\n />\n )}\n <Collapse in={isOpen} unmountOnExit appear={false} data-testid=\"panel-group-content\">\n <ResponsiveGridLayout\n className=\"layout\"\n breakpoints={{ sm: theme.breakpoints.values.sm, xxs: 0 }}\n cols={GRID_LAYOUT_COLS}\n rowHeight={30}\n draggableHandle={'.drag-handle'}\n resizeHandles={['se']}\n isDraggable={isEditMode}\n isResizable={isEditMode}\n margin={[DEFAULT_MARGIN, DEFAULT_MARGIN]}\n containerPadding={[0, 10]}\n layouts={{ [GRID_LAYOUT_SMALL_BREAKPOINT]: groupDefinition.itemLayouts }}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n >\n {groupDefinition.itemLayouts.map(({ i, w }) => (\n <div key={i}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <GridItemContent\n panelGroupItemId={{ panelGroupId, panelGroupItemLayoutId: i }}\n width={calculateGridItemWidth(w, gridColWidth)}\n />\n </ErrorBoundary>\n </div>\n ))}\n </ResponsiveGridLayout>\n </Collapse>\n </GridContainer>\n );\n}\n\n/**\n * Calculates grid item width\n * @param w number of columns the grid item spans\n * @param colWidth the width of each column in px\n * @returns grid item's width in px\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\nconst calculateGridItemWidth = (w: number, colWidth: number) => {\n // 0 * Infinity === NaN, which causes problems with resize contraints\n if (!Number.isFinite(w)) return w;\n return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);\n};\n"],"names":["useState","Responsive","WidthProvider","Collapse","useTheme","ErrorAlert","ErrorBoundary","useEditMode","usePanelGroup","usePanelGroupActions","GRID_LAYOUT_COLS","GRID_LAYOUT_SMALL_BREAKPOINT","GridTitle","GridItemContent","GridContainer","DEFAULT_MARGIN","ResponsiveGridLayout","GridLayout","props","panelGroupId","theme","groupDefinition","updatePanelGroupLayouts","isOpen","setIsOpen","isCollapsed","isEditMode","gridColWidth","setGridColWidth","handleLayoutChange","currentLayout","allLayouts","smallLayout","handleWidthChange","containerWidth","margin","cols","containerPadding","marginX","marginWidth","containerPaddingWidth","title","undefined","collapse","onToggleOpen","current","in","unmountOnExit","appear","data-testid","className","breakpoints","sm","values","xxs","rowHeight","draggableHandle","resizeHandles","isDraggable","isResizable","layouts","itemLayouts","onLayoutChange","onWidthChange","map","i","w","div","FallbackComponent","panelGroupItemId","panelGroupItemLayoutId","width","calculateGridItemWidth","colWidth","Number","isFinite","Math","round","max"],"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;AACjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,UAAU,EAAEC,aAAa,QAAyB,mBAAmB,CAAC;AAC/E,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,eAAe,CAAC;AACnD,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAwB,CAAC;AACnE,SAASC,WAAW,EAAEC,aAAa,EAAEC,oBAAoB,QAAsB,eAAe,CAAC;AAC/F,SAASC,gBAAgB,EAAEC,4BAA4B,QAAQ,iBAAiB,CAAC;AACjF,SAASC,SAAS,QAAQ,aAAa,CAAC;AACxC,SAASC,eAAe,QAAQ,mBAAmB,CAAC;AACpD,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAEhD,MAAMC,cAAc,GAAG,EAAE,AAAC;AA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xEC,cAAc,EAAEjC,kBAAkB;oBAClCkC,aAAa,EAAE9B,iBAAiB;8BAE/BZ,eAAe,CAACwC,WAAW,CAACG,GAAG,CAAC,CAAC,EAAEC,CAAC,CAAA,EAAEC,CAAC,CAAA,EAAE,iBACxC,KAACC,KAAG;sCACF,cAAA,KAAC7D,aAAa;gCAAC8D,iBAAiB,EAAE/D,UAAU;0CAC1C,cAAA,KAACQ,eAAe;oCACdwD,gBAAgB,EAAE;wCAAElD,YAAY;wCAAEmD,sBAAsB,EAAEL,CAAC;qCAAE;oCAC7DM,KAAK,EAAEC,sBAAsB,CAACN,CAAC,EAAEvC,YAAY,CAAC;kCAC9C;8BACY;2BANRsC,CAAC,CAOL,AACP,CAAC;kBACmB;cACd;;MACG,CAChB;AACJ,CAAC;AAED;;;;;;CAMC,GACD,MAAMO,sBAAsB,GAAG,CAACN,CAAS,EAAEO,QAAgB,GAAK;IAC9D,qEAAqE;IACrE,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACT,CAAC,CAAC,EAAE,OAAOA,CAAC,CAAC;IAClC,OAAOU,IAAI,CAACC,KAAK,CAACJ,QAAQ,GAAGP,CAAC,GAAGU,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEZ,CAAC,GAAG,CAAC,CAAC,GAAGnD,cAAc,CAAC,CAAC;AACxE,CAAC,AAAC"}
|
|
@@ -9,5 +9,5 @@ export interface PanelProps extends CardProps<'section'> {
|
|
|
9
9
|
/**
|
|
10
10
|
* Renders a PanelDefinition's content inside of a Card.
|
|
11
11
|
*/
|
|
12
|
-
export declare
|
|
12
|
+
export declare const Panel: import("react").NamedExoticComponent<PanelProps>;
|
|
13
13
|
//# sourceMappingURL=Panel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAQ,SAAS,EAAe,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,WAAW,UAAW,SAAQ,SAAS,CAAC,SAAS,CAAC;IACtD,UAAU,EAAE,eAAe,CAAC;IAC5B,YAAY,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAQ,SAAS,EAAe,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,WAAW,UAAW,SAAQ,SAAS,CAAC,SAAS,CAAC;IACtD,UAAU,EAAE,eAAe,CAAC;IAC5B,YAAY,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,kDAuFhB,CAAC"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { useState, useMemo } from 'react';
|
|
14
|
+
import { useState, useMemo, memo } from 'react';
|
|
15
15
|
import useResizeObserver from 'use-resize-observer';
|
|
16
16
|
import { useInView } from 'react-intersection-observer';
|
|
17
17
|
import { ErrorBoundary, ErrorAlert, combineSx, useId, useChartsTheme } from '@perses-dev/components';
|
|
@@ -20,7 +20,7 @@ import { PanelHeader } from './PanelHeader';
|
|
|
20
20
|
import { PanelContent } from './PanelContent';
|
|
21
21
|
/**
|
|
22
22
|
* Renders a PanelDefinition's content inside of a Card.
|
|
23
|
-
*/ export function Panel(props) {
|
|
23
|
+
*/ export const Panel = /*#__PURE__*/ memo(function Panel(props) {
|
|
24
24
|
const { definition , editHandlers , onMouseEnter , onMouseLeave , sx , ...others } = props;
|
|
25
25
|
// Make sure we have an ID we can use for aria attributes
|
|
26
26
|
const generatedPanelId = useId('Panel');
|
|
@@ -105,6 +105,6 @@ import { PanelContent } from './PanelContent';
|
|
|
105
105
|
})
|
|
106
106
|
]
|
|
107
107
|
});
|
|
108
|
-
}
|
|
108
|
+
});
|
|
109
109
|
|
|
110
110
|
//# sourceMappingURL=Panel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Panel/Panel.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 { useState, useMemo } from 'react';\nimport useResizeObserver from 'use-resize-observer';\nimport { useInView } from 'react-intersection-observer';\nimport { ErrorBoundary, ErrorAlert, combineSx, useId, useChartsTheme } from '@perses-dev/components';\nimport { PanelDefinition } from '@perses-dev/core';\nimport { Card, CardProps, CardContent } from '@mui/material';\nimport { PanelHeader, PanelHeaderProps } from './PanelHeader';\nimport { PanelContent } from './PanelContent';\n\nexport interface PanelProps extends CardProps<'section'> {\n definition: PanelDefinition;\n editHandlers?: PanelHeaderProps['editHandlers'];\n}\n\n/**\n * Renders a PanelDefinition's content inside of a Card.\n */\nexport function Panel(props: PanelProps) {\n const { definition, editHandlers, onMouseEnter, onMouseLeave, sx, ...others } = props;\n\n // Make sure we have an ID we can use for aria attributes\n const generatedPanelId = useId('Panel');\n const headerId = `${generatedPanelId}-header`;\n\n const [contentElement, setContentElement] = useState<HTMLElement | null>(null);\n\n const { width, height } = useResizeObserver({ ref: contentElement });\n\n const contentDimensions = useMemo(() => {\n if (width === undefined || height === undefined) return undefined;\n return { width, height };\n }, [width, height]);\n\n const { ref, inView } = useInView({\n threshold: 0.3,\n initialInView: false,\n triggerOnce: true,\n });\n\n const chartsTheme = useChartsTheme();\n\n const handleMouseEnter: CardProps['onMouseEnter'] = (e) => {\n onMouseEnter?.(e);\n };\n\n const handleMouseLeave: CardProps['onMouseLeave'] = (e) => {\n onMouseLeave?.(e);\n };\n\n return (\n <Card\n ref={ref}\n component=\"section\"\n sx={combineSx(\n {\n width: '100%',\n height: '100%',\n display: 'flex',\n flexFlow: 'column nowrap',\n },\n sx\n )}\n variant=\"outlined\"\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n aria-labelledby={headerId}\n aria-describedby={headerId}\n data-testid=\"panel\"\n {...others}\n >\n <PanelHeader\n id={headerId}\n title={definition.spec.display.name}\n description={definition.spec.display.description}\n editHandlers={editHandlers}\n sx={{ paddingX: `${chartsTheme.container.padding.default}px` }}\n />\n <CardContent\n component=\"figure\"\n sx={{\n position: 'relative',\n overflow: 'hidden',\n flexGrow: 1,\n margin: 0,\n padding: 0,\n // Override MUI default style for last-child\n ':last-child': {\n padding: 0,\n },\n }}\n ref={setContentElement}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert} resetKeys={[definition.spec.plugin.spec]}>\n {inView === true && (\n <PanelContent\n panelPluginKind={definition.spec.plugin.kind}\n spec={definition.spec.plugin.spec}\n contentDimensions={contentDimensions}\n />\n )}\n </ErrorBoundary>\n </CardContent>\n </Card>\n );\n}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Panel/Panel.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 { useState, useMemo, memo } from 'react';\nimport useResizeObserver from 'use-resize-observer';\nimport { useInView } from 'react-intersection-observer';\nimport { ErrorBoundary, ErrorAlert, combineSx, useId, useChartsTheme } from '@perses-dev/components';\nimport { PanelDefinition } from '@perses-dev/core';\nimport { Card, CardProps, CardContent } from '@mui/material';\nimport { PanelHeader, PanelHeaderProps } from './PanelHeader';\nimport { PanelContent } from './PanelContent';\n\nexport interface PanelProps extends CardProps<'section'> {\n definition: PanelDefinition;\n editHandlers?: PanelHeaderProps['editHandlers'];\n}\n\n/**\n * Renders a PanelDefinition's content inside of a Card.\n */\nexport const Panel = memo(function Panel(props: PanelProps) {\n const { definition, editHandlers, onMouseEnter, onMouseLeave, sx, ...others } = props;\n\n // Make sure we have an ID we can use for aria attributes\n const generatedPanelId = useId('Panel');\n const headerId = `${generatedPanelId}-header`;\n\n const [contentElement, setContentElement] = useState<HTMLElement | null>(null);\n\n const { width, height } = useResizeObserver({ ref: contentElement });\n\n const contentDimensions = useMemo(() => {\n if (width === undefined || height === undefined) return undefined;\n return { width, height };\n }, [width, height]);\n\n const { ref, inView } = useInView({\n threshold: 0.3,\n initialInView: false,\n triggerOnce: true,\n });\n\n const chartsTheme = useChartsTheme();\n\n const handleMouseEnter: CardProps['onMouseEnter'] = (e) => {\n onMouseEnter?.(e);\n };\n\n const handleMouseLeave: CardProps['onMouseLeave'] = (e) => {\n onMouseLeave?.(e);\n };\n\n return (\n <Card\n ref={ref}\n component=\"section\"\n sx={combineSx(\n {\n width: '100%',\n height: '100%',\n display: 'flex',\n flexFlow: 'column nowrap',\n },\n sx\n )}\n variant=\"outlined\"\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n aria-labelledby={headerId}\n aria-describedby={headerId}\n data-testid=\"panel\"\n {...others}\n >\n <PanelHeader\n id={headerId}\n title={definition.spec.display.name}\n description={definition.spec.display.description}\n editHandlers={editHandlers}\n sx={{ paddingX: `${chartsTheme.container.padding.default}px` }}\n />\n <CardContent\n component=\"figure\"\n sx={{\n position: 'relative',\n overflow: 'hidden',\n flexGrow: 1,\n margin: 0,\n padding: 0,\n // Override MUI default style for last-child\n ':last-child': {\n padding: 0,\n },\n }}\n ref={setContentElement}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert} resetKeys={[definition.spec.plugin.spec]}>\n {inView === true && (\n <PanelContent\n panelPluginKind={definition.spec.plugin.kind}\n spec={definition.spec.plugin.spec}\n contentDimensions={contentDimensions}\n />\n )}\n </ErrorBoundary>\n </CardContent>\n </Card>\n );\n});\n"],"names":["useState","useMemo","memo","useResizeObserver","useInView","ErrorBoundary","ErrorAlert","combineSx","useId","useChartsTheme","Card","CardContent","PanelHeader","PanelContent","Panel","props","definition","editHandlers","onMouseEnter","onMouseLeave","sx","others","generatedPanelId","headerId","contentElement","setContentElement","width","height","ref","contentDimensions","undefined","inView","threshold","initialInView","triggerOnce","chartsTheme","handleMouseEnter","e","handleMouseLeave","component","display","flexFlow","variant","aria-labelledby","aria-describedby","data-testid","id","title","spec","name","description","paddingX","container","padding","default","position","overflow","flexGrow","margin","FallbackComponent","resetKeys","plugin","panelPluginKind","kind"],"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,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,OAAO,CAAC;AAChD,OAAOC,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,SAASC,SAAS,QAAQ,6BAA6B,CAAC;AACxD,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,KAAK,EAAEC,cAAc,QAAQ,wBAAwB,CAAC;AAErG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AAM,EAAE,CAAC;oBACTL,OAAO,EAAE,CAAC;oBACV,4CAA4C;oBAC5C,aAAa,EAAE;wBACbA,OAAO,EAAE,CAAC;qBACX;iBACF;gBACDzB,GAAG,EAAEH,iBAAiB;0BAEtB,cAAA,KAACpB,aAAa;oBAACsD,iBAAiB,EAAErD,UAAU;oBAAEsD,SAAS,EAAE;wBAAC5C,UAAU,CAACgC,IAAI,CAACa,MAAM,CAACb,IAAI;qBAAC;8BACnFjB,MAAM,KAAK,IAAI,kBACd,KAAClB,YAAY;wBACXiD,eAAe,EAAE9C,UAAU,CAACgC,IAAI,CAACa,MAAM,CAACE,IAAI;wBAC5Cf,IAAI,EAAEhC,UAAU,CAACgC,IAAI,CAACa,MAAM,CAACb,IAAI;wBACjCnB,iBAAiB,EAAEA,iBAAiB;sBACpC,AACH;kBACa;cACJ;;MACT,CACP;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PanelEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"names":[],"mappings":";AA8BA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAIvF,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC/C;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAqI1D;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
|
|
@@ -14,28 +14,29 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import { useEffect, useState } from 'react';
|
|
15
15
|
import { Box, FormControl, FormHelperText, Grid, InputLabel, MenuItem, Select, TextField, Typography } from '@mui/material';
|
|
16
16
|
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
17
|
-
import { PluginKindSelect,
|
|
17
|
+
import { PluginKindSelect, usePluginEditor, PanelSpecEditor } from '@perses-dev/plugin-system';
|
|
18
18
|
import { useListPanelGroups } from '../../context';
|
|
19
19
|
import { PanelPreview } from './PanelPreview';
|
|
20
|
+
import { usePanelEditor } from './usePanelEditor';
|
|
20
21
|
export function PanelEditorForm(props) {
|
|
21
22
|
var ref;
|
|
22
|
-
const { initialValues , onChange } = props;
|
|
23
|
+
const { initialValues: { panelDefinition: initialPanelDef , groupId: initialGroupId } , onChange , } = props;
|
|
23
24
|
const panelGroups = useListPanelGroups();
|
|
24
|
-
const [
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const [kind, setKind] = useState(initialValues.kind);
|
|
28
|
-
const [spec, setSpec] = useState(initialValues.spec);
|
|
25
|
+
const [groupId, setGroupId] = useState(initialGroupId);
|
|
26
|
+
const { panelDefinition , setName , setDescription , setQueries , setPlugin , setPanelDefinition } = usePanelEditor(initialPanelDef);
|
|
27
|
+
const { plugin } = panelDefinition.spec;
|
|
29
28
|
// Use common plugin editor logic even though we've split the inputs up in this form
|
|
30
29
|
const pluginEditor = usePluginEditor({
|
|
31
30
|
pluginType: 'Panel',
|
|
32
31
|
value: {
|
|
33
|
-
kind,
|
|
34
|
-
spec
|
|
32
|
+
kind: plugin.kind,
|
|
33
|
+
spec: plugin.spec
|
|
35
34
|
},
|
|
36
35
|
onChange: (plugin)=>{
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
setPlugin(plugin);
|
|
37
|
+
},
|
|
38
|
+
onHideQueryEditorChange: (isHidden)=>{
|
|
39
|
+
setQueries(undefined, isHidden);
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
// Ignore string values (which would be an "empty" value from the Select) since we don't allow them to unset it
|
|
@@ -46,24 +47,26 @@ export function PanelEditorForm(props) {
|
|
|
46
47
|
}
|
|
47
48
|
setGroupId(value);
|
|
48
49
|
};
|
|
50
|
+
const handlePanelDefinitionChange = (nextPanelDef)=>{
|
|
51
|
+
const { kind: pluginKind , spec: pluginSpec } = nextPanelDef.spec.plugin;
|
|
52
|
+
// if panel plugin kind and spec are modified, then need to save current spec
|
|
53
|
+
if (panelDefinition.spec.plugin.kind !== pluginKind && JSON.stringify(panelDefinition.spec.plugin.spec) !== JSON.stringify(pluginSpec)) {
|
|
54
|
+
pluginEditor.rememberCurrentSpecState();
|
|
55
|
+
}
|
|
56
|
+
setPanelDefinition(nextPanelDef);
|
|
57
|
+
};
|
|
49
58
|
useEffect(()=>{
|
|
50
59
|
const values = {
|
|
51
|
-
name,
|
|
52
|
-
description,
|
|
53
60
|
groupId,
|
|
54
|
-
|
|
55
|
-
spec
|
|
61
|
+
panelDefinition
|
|
56
62
|
};
|
|
57
63
|
onChange(values);
|
|
58
64
|
}, [
|
|
59
|
-
name,
|
|
60
|
-
description,
|
|
61
65
|
groupId,
|
|
62
|
-
|
|
63
|
-
spec,
|
|
66
|
+
panelDefinition,
|
|
64
67
|
onChange
|
|
65
68
|
]);
|
|
66
|
-
var _title, ref1;
|
|
69
|
+
var _name, _title, _description, ref1;
|
|
67
70
|
return(// Grid maxHeight allows user to scroll inside Drawer to see all content
|
|
68
71
|
/*#__PURE__*/ _jsx(Box, {
|
|
69
72
|
component: "form",
|
|
@@ -84,9 +87,11 @@ export function PanelEditorForm(props) {
|
|
|
84
87
|
required: true,
|
|
85
88
|
fullWidth: true,
|
|
86
89
|
label: "Name",
|
|
87
|
-
value: name,
|
|
90
|
+
value: (_name = panelDefinition.spec.display.name) !== null && _name !== void 0 ? _name : '',
|
|
88
91
|
variant: "outlined",
|
|
89
|
-
onChange: (e)=>
|
|
92
|
+
onChange: (e)=>{
|
|
93
|
+
setName(e.target.value);
|
|
94
|
+
}
|
|
90
95
|
})
|
|
91
96
|
}),
|
|
92
97
|
/*#__PURE__*/ _jsx(Grid, {
|
|
@@ -119,9 +124,11 @@ export function PanelEditorForm(props) {
|
|
|
119
124
|
children: /*#__PURE__*/ _jsx(TextField, {
|
|
120
125
|
fullWidth: true,
|
|
121
126
|
label: "Description",
|
|
122
|
-
value: description,
|
|
127
|
+
value: (_description = panelDefinition.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
123
128
|
variant: "outlined",
|
|
124
|
-
onChange: (e)=>
|
|
129
|
+
onChange: (e)=>{
|
|
130
|
+
setDescription(e.target.value);
|
|
131
|
+
}
|
|
125
132
|
})
|
|
126
133
|
}),
|
|
127
134
|
/*#__PURE__*/ _jsxs(Grid, {
|
|
@@ -142,7 +149,7 @@ export function PanelEditorForm(props) {
|
|
|
142
149
|
required: true,
|
|
143
150
|
labelId: "panel-type-label",
|
|
144
151
|
label: "Type",
|
|
145
|
-
value: pluginEditor.pendingKind ? pluginEditor.pendingKind : kind,
|
|
152
|
+
value: pluginEditor.pendingKind ? pluginEditor.pendingKind : plugin.kind,
|
|
146
153
|
onChange: pluginEditor.onKindChange
|
|
147
154
|
})
|
|
148
155
|
]
|
|
@@ -164,11 +171,7 @@ export function PanelEditorForm(props) {
|
|
|
164
171
|
/*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
165
172
|
FallbackComponent: ErrorAlert,
|
|
166
173
|
children: /*#__PURE__*/ _jsx(PanelPreview, {
|
|
167
|
-
|
|
168
|
-
name: name,
|
|
169
|
-
description: description,
|
|
170
|
-
spec: spec,
|
|
171
|
-
groupId: groupId
|
|
174
|
+
panelDefinition: panelDefinition
|
|
172
175
|
})
|
|
173
176
|
})
|
|
174
177
|
]
|
|
@@ -178,11 +181,15 @@ export function PanelEditorForm(props) {
|
|
|
178
181
|
xs: 12,
|
|
179
182
|
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
180
183
|
FallbackComponent: ErrorAlert,
|
|
181
|
-
children: /*#__PURE__*/ _jsx(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
children: /*#__PURE__*/ _jsx(PanelSpecEditor, {
|
|
185
|
+
panelDefinition: panelDefinition,
|
|
186
|
+
onJSONChange: handlePanelDefinitionChange,
|
|
187
|
+
onQueriesChange: (queries)=>{
|
|
188
|
+
setQueries(queries);
|
|
189
|
+
},
|
|
190
|
+
onPluginSpecChange: (spec)=>{
|
|
191
|
+
pluginEditor.onSpecChange(spec);
|
|
192
|
+
}
|
|
186
193
|
})
|
|
187
194
|
})
|
|
188
195
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelEditorForm.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 { useEffect, useState } from 'react';\nimport {\n Box,\n FormControl,\n FormHelperText,\n Grid,\n InputLabel,\n MenuItem,\n Select,\n SelectProps,\n TextField,\n Typography,\n} from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { PluginKindSelect, PluginSpecEditor, usePluginEditor } from '@perses-dev/plugin-system';\nimport { useListPanelGroups } from '../../context';\nimport { PanelEditorValues } from '../../context/DashboardProvider/panel-editor-slice';\nimport { PanelPreview } from './PanelPreview';\n\nexport interface PanelEditorFormProps {\n initialValues: PanelEditorValues;\n onChange: (values: PanelEditorValues) => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps) {\n const { initialValues, onChange } = props;\n\n const panelGroups = useListPanelGroups();\n\n const [name, setName] = useState(initialValues.name);\n const [description, setDescription] = useState(initialValues.description);\n const [groupId, setGroupId] = useState(initialValues.groupId);\n const [kind, setKind] = useState(initialValues.kind);\n const [spec, setSpec] = useState(initialValues.spec);\n\n // Use common plugin editor logic even though we've split the inputs up in this form\n const pluginEditor = usePluginEditor({\n pluginType: 'Panel',\n value: { kind, spec },\n onChange: (plugin) => {\n setKind(plugin.kind);\n setSpec(plugin.spec);\n },\n });\n\n // Ignore string values (which would be an \"empty\" value from the Select) since we don't allow them to unset it\n const handleGroupChange: SelectProps<number>['onChange'] = (e) => {\n const { value } = e.target;\n if (typeof value === 'string') {\n return;\n }\n setGroupId(value);\n };\n\n useEffect(() => {\n const values: PanelEditorValues = { name, description, groupId, kind, spec };\n onChange(values);\n }, [name, description, groupId, kind, spec, onChange]);\n\n return (\n // Grid maxHeight allows user to scroll inside Drawer to see all content\n <Box\n component=\"form\"\n id={panelEditorFormId}\n sx={{ flex: 1, overflowY: 'scroll', padding: (theme) => theme.spacing(2) }}\n >\n <Grid container spacing={2}>\n <Grid item xs={8}>\n <TextField\n required\n fullWidth\n label=\"Name\"\n value={name}\n variant=\"outlined\"\n onChange={(e) => setName(e.target.value)}\n />\n </Grid>\n <Grid item xs={4}>\n <FormControl fullWidth>\n <InputLabel id=\"select-group\">Group</InputLabel>\n <Select required labelId=\"select-group\" label=\"Group\" value={groupId} onChange={handleGroupChange}>\n {panelGroups.map((panelGroup, index) => (\n <MenuItem key={panelGroup.id} value={panelGroup.id}>\n {panelGroup.title ?? `Group ${index + 1}`}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n <Grid item xs={8}>\n <TextField\n fullWidth\n label=\"Description\"\n value={description}\n variant=\"outlined\"\n onChange={(e) => setDescription(e.target.value)}\n />\n </Grid>\n <Grid item xs={4}>\n <FormControl fullWidth disabled={pluginEditor.isLoading} error={pluginEditor.error !== null}>\n <InputLabel id=\"panel-type-label\">Type</InputLabel>\n <PluginKindSelect\n pluginType=\"Panel\"\n required\n labelId=\"panel-type-label\"\n label=\"Type\"\n value={pluginEditor.pendingKind ? pluginEditor.pendingKind : kind}\n onChange={pluginEditor.onKindChange}\n />\n </FormControl>\n <FormHelperText>{pluginEditor.error?.message ?? ''}</FormHelperText>\n </Grid>\n <Grid item xs={12}>\n <Typography variant=\"h4\" marginBottom={1}>\n Preview\n </Typography>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PanelPreview kind={kind} name={name} description={description} spec={spec} groupId={groupId} />\n </ErrorBoundary>\n </Grid>\n <Grid item xs={12}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PluginSpecEditor pluginType=\"Panel\" pluginKind={kind} value={spec} onChange={pluginEditor.onSpecChange} />\n </ErrorBoundary>\n </Grid>\n </Grid>\n </Box>\n );\n}\n\n/**\n * The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.\n */\nexport const panelEditorFormId = 'panel-editor-form';\n"],"names":["useEffect","useState","Box","FormControl","FormHelperText","Grid","InputLabel","MenuItem","Select","TextField","Typography","ErrorAlert","ErrorBoundary","PluginKindSelect","PluginSpecEditor","usePluginEditor","useListPanelGroups","PanelPreview","PanelEditorForm","props","pluginEditor","initialValues","onChange","panelGroups","name","setName","description","setDescription","groupId","setGroupId","kind","setKind","spec","setSpec","pluginType","value","plugin","handleGroupChange","e","target","values","panelGroup","component","id","panelEditorFormId","sx","flex","overflowY","padding","theme","spacing","container","item","xs","required","fullWidth","label","variant","labelId","map","index","title","disabled","isLoading","error","pendingKind","onKindChange","message","marginBottom","FallbackComponent","pluginKind","onSpecChange"],"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,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAC5C,SACEC,GAAG,EACHC,WAAW,EACXC,cAAc,EACdC,IAAI,EACJC,UAAU,EACVC,QAAQ,EACRC,MAAM,EAENC,SAAS,E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er/PanelEditorForm.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 { useEffect, useState } from 'react';\nimport {\n Box,\n FormControl,\n FormHelperText,\n Grid,\n InputLabel,\n MenuItem,\n Select,\n SelectProps,\n TextField,\n Typography,\n} from '@mui/material';\nimport { PanelDefinition } from '@perses-dev/core';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { PluginKindSelect, usePluginEditor, PanelSpecEditor } from '@perses-dev/plugin-system';\nimport { useListPanelGroups } from '../../context';\nimport { PanelEditorValues } from '../../context/DashboardProvider/panel-editor-slice';\nimport { PanelPreview } from './PanelPreview';\nimport { usePanelEditor } from './usePanelEditor';\n\nexport interface PanelEditorFormProps {\n initialValues: PanelEditorValues;\n onChange: (values: PanelEditorValues) => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps) {\n const {\n initialValues: { panelDefinition: initialPanelDef, groupId: initialGroupId },\n onChange,\n } = props;\n\n const panelGroups = useListPanelGroups();\n const [groupId, setGroupId] = useState(initialGroupId);\n const { panelDefinition, setName, setDescription, setQueries, setPlugin, setPanelDefinition } =\n usePanelEditor(initialPanelDef);\n const { plugin } = panelDefinition.spec;\n\n // Use common plugin editor logic even though we've split the inputs up in this form\n const pluginEditor = usePluginEditor({\n pluginType: 'Panel',\n value: { kind: plugin.kind, spec: plugin.spec },\n onChange: (plugin) => {\n setPlugin(plugin);\n },\n onHideQueryEditorChange: (isHidden) => {\n setQueries(undefined, isHidden);\n },\n });\n\n // Ignore string values (which would be an \"empty\" value from the Select) since we don't allow them to unset it\n const handleGroupChange: SelectProps<number>['onChange'] = (e) => {\n const { value } = e.target;\n if (typeof value === 'string') {\n return;\n }\n setGroupId(value);\n };\n\n const handlePanelDefinitionChange = (nextPanelDef: PanelDefinition) => {\n const { kind: pluginKind, spec: pluginSpec } = nextPanelDef.spec.plugin;\n // if panel plugin kind and spec are modified, then need to save current spec\n if (\n panelDefinition.spec.plugin.kind !== pluginKind &&\n JSON.stringify(panelDefinition.spec.plugin.spec) !== JSON.stringify(pluginSpec)\n ) {\n pluginEditor.rememberCurrentSpecState();\n }\n\n setPanelDefinition(nextPanelDef);\n };\n\n useEffect(() => {\n const values: PanelEditorValues = { groupId, panelDefinition };\n onChange(values);\n }, [groupId, panelDefinition, onChange]);\n\n return (\n // Grid maxHeight allows user to scroll inside Drawer to see all content\n <Box\n component=\"form\"\n id={panelEditorFormId}\n sx={{ flex: 1, overflowY: 'scroll', padding: (theme) => theme.spacing(2) }}\n >\n <Grid container spacing={2}>\n <Grid item xs={8}>\n <TextField\n required\n fullWidth\n label=\"Name\"\n value={panelDefinition.spec.display.name ?? ''}\n variant=\"outlined\"\n onChange={(e) => {\n setName(e.target.value);\n }}\n />\n </Grid>\n <Grid item xs={4}>\n <FormControl fullWidth>\n <InputLabel id=\"select-group\">Group</InputLabel>\n <Select required labelId=\"select-group\" label=\"Group\" value={groupId} onChange={handleGroupChange}>\n {panelGroups.map((panelGroup, index) => (\n <MenuItem key={panelGroup.id} value={panelGroup.id}>\n {panelGroup.title ?? `Group ${index + 1}`}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n <Grid item xs={8}>\n <TextField\n fullWidth\n label=\"Description\"\n value={panelDefinition.spec.display.description ?? ''}\n variant=\"outlined\"\n onChange={(e) => {\n setDescription(e.target.value);\n }}\n />\n </Grid>\n <Grid item xs={4}>\n <FormControl fullWidth disabled={pluginEditor.isLoading} error={pluginEditor.error !== null}>\n <InputLabel id=\"panel-type-label\">Type</InputLabel>\n <PluginKindSelect\n pluginType=\"Panel\"\n required\n labelId=\"panel-type-label\"\n label=\"Type\"\n value={pluginEditor.pendingKind ? pluginEditor.pendingKind : plugin.kind}\n onChange={pluginEditor.onKindChange}\n />\n </FormControl>\n <FormHelperText>{pluginEditor.error?.message ?? ''}</FormHelperText>\n </Grid>\n <Grid item xs={12}>\n <Typography variant=\"h4\" marginBottom={1}>\n Preview\n </Typography>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PanelPreview panelDefinition={panelDefinition} />\n </ErrorBoundary>\n </Grid>\n <Grid item xs={12}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PanelSpecEditor\n panelDefinition={panelDefinition}\n onJSONChange={handlePanelDefinitionChange}\n onQueriesChange={(queries) => {\n setQueries(queries);\n }}\n onPluginSpecChange={(spec) => {\n pluginEditor.onSpecChange(spec);\n }}\n />\n </ErrorBoundary>\n </Grid>\n </Grid>\n </Box>\n );\n}\n\n/**\n * The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.\n */\nexport const panelEditorFormId = 'panel-editor-form';\n"],"names":["useEffect","useState","Box","FormControl","FormHelperText","Grid","InputLabel","MenuItem","Select","TextField","Typography","ErrorAlert","ErrorBoundary","PluginKindSelect","usePluginEditor","PanelSpecEditor","useListPanelGroups","PanelPreview","usePanelEditor","PanelEditorForm","props","pluginEditor","initialValues","panelDefinition","initialPanelDef","groupId","initialGroupId","onChange","panelGroups","setGroupId","setName","setDescription","setQueries","setPlugin","setPanelDefinition","plugin","spec","pluginType","value","kind","onHideQueryEditorChange","isHidden","undefined","handleGroupChange","e","target","handlePanelDefinitionChange","nextPanelDef","pluginKind","pluginSpec","JSON","stringify","rememberCurrentSpecState","values","panelGroup","component","id","panelEditorFormId","sx","flex","overflowY","padding","theme","spacing","container","item","xs","required","fullWidth","label","display","name","variant","labelId","map","index","title","description","disabled","isLoading","error","pendingKind","onKindChange","message","marginBottom","FallbackComponent","onJSONChange","onQueriesChange","queries","onPluginSpecChange","onSpecChange"],"mappings":"AAAA,oCAAoC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AAI;oCACxEZ,QAAQ,EAAEN,YAAY,CAAC6D,YAAY;kCACnC;;0BACU;sCACd,KAAC9E,cAAc;sCAAEiB,CAAAA,IAA2B,GAA3BA,CAAAA,GAAkB,GAAlBA,YAAY,CAAC2D,KAAK,cAAlB3D,GAAkB,WAAS,GAA3BA,KAAAA,CAA2B,GAA3BA,GAAkB,CAAE8D,OAAO,cAA3B9D,IAA2B,cAA3BA,IAA2B,GAAI,EAAE;0BAAkB;;kBAC/D;8BACP,MAAChB,IAAI;oBAAC4D,IAAI;oBAACC,EAAE,EAAE,EAAE;;sCACf,KAACxD,UAAU;4BAAC8D,OAAO,EAAC,IAAI;4BAACY,YAAY,EAAE,CAAC;sCAAE,SAE1C;0BAAa;sCACb,KAACxE,aAAa;4BAACyE,iBAAiB,EAAE1E,UAAU;sCAC1C,cAAA,KAACM,YAAY;gCAACM,eAAe,EAAEA,eAAe;8BAAI;0BACpC;;kBACX;8BACP,KAAClB,IAAI;oBAAC4D,IAAI;oBAACC,EAAE,EAAE,EAAE;8BACf,cAAA,KAACtD,aAAa;wBAACyE,iBAAiB,EAAE1E,UAAU;kCAC1C,cAAA,KAACI,eAAe;4BACdQ,eAAe,EAAEA,eAAe;4BAChC+D,YAAY,EAAExC,2BAA2B;4BACzCyC,eAAe,EAAE,CAACC,OAAO,GAAK;gCAC5BxD,UAAU,CAACwD,OAAO,CAAC,CAAC;4BACtB,CAAC;4BACDC,kBAAkB,EAAE,CAACrD,IAAI,GAAK;gCAC5Bf,YAAY,CAACqE,YAAY,CAACtD,IAAI,CAAC,CAAC;4BAClC,CAAC;0BACD;sBACY;kBACX;;UACF;MACH,EACN;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,MAAMqB,iBAAiB,GAAG,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PanelEditorValues } from '../../context';
|
|
3
|
-
export declare function PanelPreview({
|
|
3
|
+
export declare function PanelPreview({ panelDefinition }: Pick<PanelEditorValues, 'panelDefinition'>): JSX.Element | null;
|
|
4
4
|
//# sourceMappingURL=PanelPreview.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelPreview.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelPreview.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PanelPreview.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelPreview.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOlD,wBAAgB,YAAY,CAAC,EAAE,eAAe,EAAE,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,sBA+B3F"}
|
|
@@ -11,29 +11,43 @@
|
|
|
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 { useRef } from 'react';
|
|
14
15
|
import { Box } from '@mui/material';
|
|
16
|
+
import { DataQueriesProvider } from '@perses-dev/plugin-system';
|
|
15
17
|
import { Panel } from '../Panel';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
if (kind === '') {
|
|
18
|
+
import { useSuggestedStepMs } from '../../utils';
|
|
19
|
+
const PANEL_PREVIEW_HEIGHT = 300;
|
|
20
|
+
const PANEL_PREVIEW_DEFAULT_WIDTH = 840;
|
|
21
|
+
export function PanelPreview({ panelDefinition }) {
|
|
22
|
+
const boxRef = useRef(null);
|
|
23
|
+
let width = PANEL_PREVIEW_DEFAULT_WIDTH;
|
|
24
|
+
if (boxRef.current !== null) {
|
|
25
|
+
width = boxRef.current.getBoundingClientRect().width;
|
|
26
|
+
}
|
|
27
|
+
const suggestedStepMs = useSuggestedStepMs(width);
|
|
28
|
+
if (panelDefinition.spec.plugin.kind === '') {
|
|
31
29
|
return null;
|
|
32
30
|
}
|
|
31
|
+
var _queries;
|
|
32
|
+
const queries = (_queries = panelDefinition.spec.queries) !== null && _queries !== void 0 ? _queries : [];
|
|
33
|
+
// map TimeSeriesQueryDefinition to Definition<UnknownSpec>
|
|
34
|
+
const definitions = queries.length ? queries.map((query)=>{
|
|
35
|
+
return {
|
|
36
|
+
kind: query.spec.plugin.kind,
|
|
37
|
+
spec: query.spec.plugin.spec
|
|
38
|
+
};
|
|
39
|
+
}) : [];
|
|
33
40
|
return /*#__PURE__*/ _jsx(Box, {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
ref: boxRef,
|
|
42
|
+
height: PANEL_PREVIEW_HEIGHT,
|
|
43
|
+
children: /*#__PURE__*/ _jsx(DataQueriesProvider, {
|
|
44
|
+
definitions: definitions,
|
|
45
|
+
options: {
|
|
46
|
+
suggestedStepMs
|
|
47
|
+
},
|
|
48
|
+
children: /*#__PURE__*/ _jsx(Panel, {
|
|
49
|
+
definition: panelDefinition
|
|
50
|
+
})
|
|
37
51
|
})
|
|
38
52
|
});
|
|
39
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelPreview.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 { Box } from '@mui/material';\nimport { PanelEditorValues } from '../../context';\nimport { Panel
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelPreview.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 { useRef } from 'react';\nimport { Box } from '@mui/material';\nimport { QueryDefinition } from '@perses-dev/core';\nimport { DataQueriesProvider } from '@perses-dev/plugin-system';\nimport { PanelEditorValues } from '../../context';\nimport { Panel } from '../Panel';\nimport { useSuggestedStepMs } from '../../utils';\n\nconst PANEL_PREVIEW_HEIGHT = 300;\nconst PANEL_PREVIEW_DEFAULT_WIDTH = 840;\n\nexport function PanelPreview({ panelDefinition }: Pick<PanelEditorValues, 'panelDefinition'>) {\n const boxRef = useRef<HTMLDivElement>(null);\n let width = PANEL_PREVIEW_DEFAULT_WIDTH;\n if (boxRef.current !== null) {\n width = boxRef.current.getBoundingClientRect().width;\n }\n const suggestedStepMs = useSuggestedStepMs(width);\n\n if (panelDefinition.spec.plugin.kind === '') {\n return null;\n }\n\n const queries = panelDefinition.spec.queries ?? [];\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.length\n ? queries.map((query: QueryDefinition) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n })\n : [];\n\n return (\n <Box ref={boxRef} height={PANEL_PREVIEW_HEIGHT}>\n <DataQueriesProvider definitions={definitions} options={{ suggestedStepMs }}>\n <Panel definition={panelDefinition} />\n </DataQueriesProvider>\n </Box>\n );\n}\n"],"names":["useRef","Box","DataQueriesProvider","Panel","useSuggestedStepMs","PANEL_PREVIEW_HEIGHT","PANEL_PREVIEW_DEFAULT_WIDTH","PanelPreview","panelDefinition","boxRef","width","current","getBoundingClientRect","suggestedStepMs","spec","plugin","kind","queries","definitions","length","map","query","ref","height","options","definition"],"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,OAAO,CAAC;AAC/B,SAASC,GAAG,QAAQ,eAAe,CAAC;AAEpC,SAASC,mBAAmB,QAAQ,2BAA2B,CAAC;AAEhE,SAASC,KAAK,QAAQ,UAAU,CAAC;AACjC,SAASC,kBAAkB,QAAQ,aAAa,CAAC;AAEjD,MAAMC,oBAAoB,GAAG,GAAG,AAAC;AACjC,MAAMC,2BAA2B,GAAG,GAAG,AAAC;AAExC,OAAO,SAASC,YAAY,CAAC,EAAEC,eAAe,CAAA,EAA8C,EAAE;IAC5F,MAAMC,MAAM,GAAGT,MAAM,CAAiB,IAAI,CAAC,AAAC;IAC5C,IAAIU,KAAK,GAAGJ,2BAA2B,AAAC;IACxC,IAAIG,MAAM,CAACE,OAAO,KAAK,IAAI,EAAE;QAC3BD,KAAK,GAAGD,MAAM,CAACE,OAAO,CAACC,qBAAqB,EAAE,CAACF,KAAK,CAAC;IACvD,CAAC;IACD,MAAMG,eAAe,GAAGT,kBAAkB,CAACM,KAAK,CAAC,AAAC;IAElD,IAAIF,eAAe,CAACM,IAAI,CAACC,MAAM,CAACC,IAAI,KAAK,EAAE,EAAE;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;QAEeR,QAA4B;IAA5C,MAAMS,OAAO,GAAGT,CAAAA,QAA4B,GAA5BA,eAAe,CAACM,IAAI,CAACG,OAAO,cAA5BT,QAA4B,cAA5BA,QAA4B,GAAI,EAAE,AAAC;IAEnD,2DAA2D;IAC3D,MAAMU,WAAW,GAAGD,OAAO,CAACE,MAAM,GAC9BF,OAAO,CAACG,GA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