From 0a5a0d8408c8af7fb3346e187b220dde379f1327 Mon Sep 17 00:00:00 2001 From: Shenoy Pratik Date: Fri, 12 Nov 2021 10:22:26 -0800 Subject: [PATCH] moved loading viz after panel update (#232) Signed-off-by: Shenoy Pratik --- .../custom_panels/custom_panel_view.tsx | 35 ++++++------- .../custom_panels/helpers/utils.tsx | 1 + .../panel_modules/panel_grid/panel_grid.tsx | 49 ++++++++++++------- .../visualization_container.tsx | 2 +- 4 files changed, 52 insertions(+), 35 deletions(-) diff --git a/dashboards-observability/public/components/custom_panels/custom_panel_view.tsx b/dashboards-observability/public/components/custom_panels/custom_panel_view.tsx index 900bd9c9b..dddd0a820 100644 --- a/dashboards-observability/public/components/custom_panels/custom_panel_view.tsx +++ b/dashboards-observability/public/components/custom_panels/custom_panel_view.tsx @@ -593,28 +593,29 @@ export const CustomPanelView = ({ - {panelVisualizations.length === 0 && ( + {panelVisualizations.length > 0 ? ( + + ) : ( )} - diff --git a/dashboards-observability/public/components/custom_panels/helpers/utils.tsx b/dashboards-observability/public/components/custom_panels/helpers/utils.tsx index be8615968..c401c332e 100644 --- a/dashboards-observability/public/components/custom_panels/helpers/utils.tsx +++ b/dashboards-observability/public/components/custom_panels/helpers/utils.tsx @@ -320,3 +320,4 @@ export const displayVisualization = (data: any, type: string, editMode?: boolean } return vizComponent; }; + diff --git a/dashboards-observability/public/components/custom_panels/panel_modules/panel_grid/panel_grid.tsx b/dashboards-observability/public/components/custom_panels/panel_modules/panel_grid/panel_grid.tsx index 7ffbe22db..2246cb820 100644 --- a/dashboards-observability/public/components/custom_panels/panel_modules/panel_grid/panel_grid.tsx +++ b/dashboards-observability/public/components/custom_panels/panel_modules/panel_grid/panel_grid.tsx @@ -73,6 +73,7 @@ export const PanelGrid = ({ }: Props) => { const [currentLayout, setCurrentLayout] = useState([]); const [postEditLayout, setPostEditLayout] = useState([]); + const [gridData, setGridData] = useState(panelVisualizations.map(() => <>)); const isLocked = useObservable(chrome.getIsNavDrawerLocked$()); // Reset Size of Visualizations when layout is changed @@ -81,6 +82,29 @@ export const PanelGrid = ({ setPostEditLayout(currentLayout); }; + const loadVizComponents = () => { + const gridDataComps = panelVisualizations.map( + (panelVisualization: VisualizationType, index) => ( + + ) + ); + setGridData(gridDataComps); + }; + // Reload the Layout const reloadLayout = () => { const tempLayout: Layout[] = panelVisualizations.map((panelVisualization) => { @@ -125,6 +149,7 @@ export const PanelGrid = ({ useEffect(() => { if (editMode) { reloadLayout(); + loadVizComponents(); } else { if (editActionType === 'save') { const visualizationParams = postEditLayout.map((layout) => @@ -138,6 +163,7 @@ export const PanelGrid = ({ // Update layout whenever visualizations are updated useEffect(() => { reloadLayout(); + loadVizComponents(); }, [panelVisualizations]); // Reset Size of Panel Grid when Nav Dock is Locked @@ -147,6 +173,10 @@ export const PanelGrid = ({ }, 300); }, [isLocked]); + useEffect(() => { + loadVizComponents(); + }, []); + return ( - {panelVisualizations.map((panelVisualization: VisualizationType) => ( -
- -
+ {panelVisualizations.map((panelVisualization: VisualizationType, index) => ( +
{gridData[index]}
))}
); diff --git a/dashboards-observability/public/components/custom_panels/panel_modules/visualization_container/visualization_container.tsx b/dashboards-observability/public/components/custom_panels/panel_modules/visualization_container/visualization_container.tsx index 2400f9781..d9ab33c83 100644 --- a/dashboards-observability/public/components/custom_panels/panel_modules/visualization_container/visualization_container.tsx +++ b/dashboards-observability/public/components/custom_panels/panel_modules/visualization_container/visualization_container.tsx @@ -139,7 +139,7 @@ export const VisualizationContainer = ({
- +

{isError}