Skip to content

Commit

Permalink
moved loading viz after panel update (#232)
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <[email protected]>
  • Loading branch information
ps48 authored Nov 12, 2021
1 parent fb42e78 commit 0a5a0d8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,28 +593,29 @@ export const CustomPanelView = ({
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />
{panelVisualizations.length === 0 && (
{panelVisualizations.length > 0 ? (
<PanelGrid
http={http}
panelId={panelId}
chrome={chrome}
panelVisualizations={panelVisualizations}
setPanelVisualizations={setPanelVisualizations}
editMode={editMode}
pplService={pplService}
startTime={start}
endTime={end}
onRefresh={onRefresh}
cloneVisualization={cloneVisualization}
pplFilterValue={pplFilterValue}
showFlyout={showFlyout}
editActionType={editActionType}
/>
) : (
<EmptyPanelView
addVizDisabled={addVizDisabled}
getVizContextPanels={getVizContextPanels}
/>
)}
<PanelGrid
http={http}
panelId={panelId}
chrome={chrome}
panelVisualizations={panelVisualizations}
setPanelVisualizations={setPanelVisualizations}
editMode={editMode}
pplService={pplService}
startTime={start}
endTime={end}
onRefresh={onRefresh}
cloneVisualization={cloneVisualization}
pplFilterValue={pplFilterValue}
showFlyout={showFlyout}
editActionType={editActionType}
/>
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,4 @@ export const displayVisualization = (data: any, type: string, editMode?: boolean
}
return vizComponent;
};

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const PanelGrid = ({
}: Props) => {
const [currentLayout, setCurrentLayout] = useState<Layout[]>([]);
const [postEditLayout, setPostEditLayout] = useState<Layout[]>([]);
const [gridData, setGridData] = useState(panelVisualizations.map(() => <></>));
const isLocked = useObservable(chrome.getIsNavDrawerLocked$());

// Reset Size of Visualizations when layout is changed
Expand All @@ -81,6 +82,29 @@ export const PanelGrid = ({
setPostEditLayout(currentLayout);
};

const loadVizComponents = () => {
const gridDataComps = panelVisualizations.map(
(panelVisualization: VisualizationType, index) => (
<VisualizationContainer
key={panelVisualization.id}
http={http}
editMode={editMode}
visualizationId={panelVisualization.id}
savedVisualizationId={panelVisualization.savedVisualizationId}
pplService={pplService}
fromTime={startTime}
toTime={endTime}
onRefresh={onRefresh}
cloneVisualization={cloneVisualization}
pplFilterValue={pplFilterValue}
showFlyout={showFlyout}
removeVisualization={removeVisualization}
/>
)
);
setGridData(gridDataComps);
};

// Reload the Layout
const reloadLayout = () => {
const tempLayout: Layout[] = panelVisualizations.map((panelVisualization) => {
Expand Down Expand Up @@ -125,6 +149,7 @@ export const PanelGrid = ({
useEffect(() => {
if (editMode) {
reloadLayout();
loadVizComponents();
} else {
if (editActionType === 'save') {
const visualizationParams = postEditLayout.map((layout) =>
Expand All @@ -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
Expand All @@ -147,6 +173,10 @@ export const PanelGrid = ({
}, 300);
}, [isLocked]);

useEffect(() => {
loadVizComponents();
}, []);

return (
<ResponsiveGridLayout
layouts={{ lg: currentLayout, md: currentLayout, sm: currentLayout }}
Expand All @@ -155,23 +185,8 @@ export const PanelGrid = ({
cols={{ lg: 12, md: 12, sm: 12, xs: 1, xxs: 1 }}
onLayoutChange={layoutChanged}
>
{panelVisualizations.map((panelVisualization: VisualizationType) => (
<div key={panelVisualization.id}>
<VisualizationContainer
http={http}
editMode={editMode}
visualizationId={panelVisualization.id}
savedVisualizationId={panelVisualization.savedVisualizationId}
pplService={pplService}
fromTime={startTime}
toTime={endTime}
onRefresh={onRefresh}
cloneVisualization={cloneVisualization}
pplFilterValue={pplFilterValue}
showFlyout={showFlyout}
removeVisualization={removeVisualization}
/>
</div>
{panelVisualizations.map((panelVisualization: VisualizationType, index) => (
<div key={panelVisualization.id}>{gridData[index]}</div>
))}
</ResponsiveGridLayout>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const VisualizationContainer = ({
<div className="visualization-error-div">
<EuiIcon type="alert" color="danger" size="s" />
<EuiSpacer size="s" />
<EuiText size='s'>
<EuiText size="s">
<p>{isError}</p>
</EuiText>
</div>
Expand Down

0 comments on commit 0a5a0d8

Please sign in to comment.