From d863c2781a1a5139e7709c7b9af312f05da26006 Mon Sep 17 00:00:00 2001 From: palash-signoz Date: Thu, 26 May 2022 15:09:59 +0530 Subject: [PATCH] feat: dashboard layout is updated from widgets (#1207) --- .../src/container/GridGraphLayout/index.tsx | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/frontend/src/container/GridGraphLayout/index.tsx b/frontend/src/container/GridGraphLayout/index.tsx index 444c976999..0927197bd0 100644 --- a/frontend/src/container/GridGraphLayout/index.tsx +++ b/frontend/src/container/GridGraphLayout/index.tsx @@ -74,24 +74,31 @@ function GridGraph(): JSX.Element { }; }); } - return data.layout - .filter((_, index) => widgets[index]) - .map((e, index) => ({ - ...e, - Component: (): JSX.Element => { - if (widgets[index]) { - return ( - - ); - } - return
; - }, - })); + + return widgets.map((widget, index) => { + const allLayouts = data?.layout; + const lastLayout = (data?.layout || [])[(allLayouts?.length || 0) - 1]; + + const currentLayout = (allLayouts || [])[index] || { + h: lastLayout.h, + i: (lastLayout.i + 1).toString(), + w: lastLayout.w, + x: (lastLayout.x % 2) * 6, + y: lastLayout.y, + }; + + return { + ...currentLayout, + Component: (): JSX.Element => ( + + ), + }; + }); }, [widgets, data.layout]); useEffect(() => { @@ -217,6 +224,8 @@ function GridGraph(): JSX.Element { return ; } + console.log({ layouts }); + return ( <> {saveLayout && ( @@ -255,7 +264,7 @@ function GridGraph(): JSX.Element {