diff --git a/frontend/webapp/containers/main/overview/overview-actions-menu/index.tsx b/frontend/webapp/containers/main/overview/overview-actions-menu/index.tsx index 82b50f53a9..8afd90ac46 100644 --- a/frontend/webapp/containers/main/overview/overview-actions-menu/index.tsx +++ b/frontend/webapp/containers/main/overview/overview-actions-menu/index.tsx @@ -9,6 +9,7 @@ const MenuContainer = styled.div` display: flex; align-items: center; margin: 20px 0; + padding: 0 16px; gap: 16px; `; diff --git a/frontend/webapp/containers/main/overview/overview-data-flow/index.tsx b/frontend/webapp/containers/main/overview/overview-data-flow/index.tsx index 88a2e85db1..9e76c004ff 100644 --- a/frontend/webapp/containers/main/overview/overview-data-flow/index.tsx +++ b/frontend/webapp/containers/main/overview/overview-data-flow/index.tsx @@ -6,7 +6,7 @@ import { ToastList } from '@/components'; import MultiSourceControl from '../multi-source-control'; import { OverviewActionMenuContainer } from '../overview-actions-menu'; import { buildNodesAndEdges, NodeBaseDataFlow } from '@/reuseable-components'; -import { useMetrics, useContainerWidth, useNodeDataFlowHandlers, useSourceCRUD, useDestinationCRUD, useInstrumentationRuleCRUD, useActionCRUD } from '@/hooks'; +import { useMetrics, useContainerSize, useNodeDataFlowHandlers, useSourceCRUD, useDestinationCRUD, useInstrumentationRuleCRUD, useActionCRUD } from '@/hooks'; const AllDrawers = dynamic(() => import('../all-drawers'), { ssr: false, @@ -17,7 +17,7 @@ const AllModals = dynamic(() => import('../all-modals'), { }); export const OverviewDataFlowWrapper = styled.div` - width: calc(100% - 64px); + width: 100%; height: calc(100vh - 176px); position: relative; `; @@ -31,7 +31,8 @@ export default function OverviewDataFlowContainer() { const { actions } = useActionCRUD(); const { destinations } = useDestinationCRUD(); const { instrumentationRules } = useInstrumentationRuleCRUD(); - const { containerRef, containerWidth } = useContainerWidth(); + const { containerRef, containerWidth, containerHeight } = useContainerSize(); + const { handleNodeClick } = useNodeDataFlowHandlers({ rules: instrumentationRules, sources, @@ -48,10 +49,11 @@ export default function OverviewDataFlowContainer() { destinations, metrics, containerWidth, + containerHeight, nodeWidth: NODE_WIDTH, nodeHeight: NODE_HEIGHT, }); - }, [instrumentationRules, sources, actions, destinations, metrics, containerWidth]); + }, [instrumentationRules, sources, actions, destinations, metrics, containerWidth, containerHeight]); return ( diff --git a/frontend/webapp/hooks/common/index.ts b/frontend/webapp/hooks/common/index.ts index 138bf57115..c5ab3a396d 100644 --- a/frontend/webapp/hooks/common/index.ts +++ b/frontend/webapp/hooks/common/index.ts @@ -1,4 +1,4 @@ -export * from './useContainerWidth'; +export * from './useContainerSize'; export * from './useOnClickOutside'; export * from './useKeyDown'; export * from './useTimeAgo'; diff --git a/frontend/webapp/hooks/common/useContainerSize.ts b/frontend/webapp/hooks/common/useContainerSize.ts new file mode 100644 index 0000000000..2c8dac8a6c --- /dev/null +++ b/frontend/webapp/hooks/common/useContainerSize.ts @@ -0,0 +1,25 @@ +import { useEffect, useState, useRef } from 'react'; + +export function useContainerSize() { + const containerRef = useRef(null); + const [containerWidth, setContainerWidth] = useState(0); + const [containerHeight, setContainerHeight] = useState(0); + + useEffect(() => { + const resize = () => { + if (containerRef.current) { + const { width, height } = containerRef.current.getBoundingClientRect(); + + setContainerWidth(width); + setContainerHeight(height); + } + }; + + resize(); + + window.addEventListener('resize', resize); + return () => window.removeEventListener('resize', resize); + }, []); + + return { containerRef, containerWidth, containerHeight }; +} diff --git a/frontend/webapp/hooks/common/useContainerWidth.ts b/frontend/webapp/hooks/common/useContainerWidth.ts deleted file mode 100644 index 9ea9c601bd..0000000000 --- a/frontend/webapp/hooks/common/useContainerWidth.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useEffect, useState, useRef } from 'react'; - -export function useContainerWidth() { - const containerRef = useRef(null); - const [containerWidth, setContainerWidth] = useState(0); - - useEffect(() => { - const updateWidth = () => { - if (containerRef.current) { - setContainerWidth( - containerRef.current.getBoundingClientRect().width - 64 - ); - } - }; - - updateWidth(); - - window.addEventListener('resize', updateWidth); - return () => window.removeEventListener('resize', updateWidth); - }, []); - - return { containerRef, containerWidth }; -} diff --git a/frontend/webapp/reuseable-components/nodes-data-flow/builder.ts b/frontend/webapp/reuseable-components/nodes-data-flow/builder.ts index e22a3766f0..3fa6de27af 100644 --- a/frontend/webapp/reuseable-components/nodes-data-flow/builder.ts +++ b/frontend/webapp/reuseable-components/nodes-data-flow/builder.ts @@ -55,6 +55,7 @@ export const buildNodesAndEdges = ({ destinations, metrics, containerWidth, + containerHeight, nodeWidth, nodeHeight, }: { @@ -64,6 +65,7 @@ export const buildNodesAndEdges = ({ destinations: ActualDestination[]; metrics?: OverviewMetricsResponse; containerWidth: number; + containerHeight: number; nodeWidth: number; nodeHeight: number; }) => { @@ -77,33 +79,32 @@ export const buildNodesAndEdges = ({ }; } - // Calculate positions for each node - const startX = 0; - const endX = (containerWidth <= 1500 ? 1500 : containerWidth) - nodeWidth; + const startX = 24; + const endX = (containerWidth <= 1500 ? 1500 : containerWidth) - nodeWidth - 40 - startX; + const getY = (idx?: number) => nodeHeight * ((idx || 0) + 1); + const postions = { rules: { x: startX, - y: (idx?: number) => nodeHeight * ((idx || 0) + 1), + y: getY, }, sources: { x: getValueForRange(containerWidth, [ - [0, 1500, endX / 3.5], - [1500, 1600, endX / 4], - [1600, null, endX / 4.5], + [0, 1600, endX / 3.5], + [1600, null, endX / 4], ]), - y: (idx?: number) => nodeHeight * ((idx || 0) + 1), + y: getY, }, actions: { x: getValueForRange(containerWidth, [ - [0, 1500, endX / 1.55], - [1500, 1600, endX / 1.6], - [1600, null, endX / 1.65], + [0, 1600, endX / 1.55], + [1600, null, endX / 1.6], ]), - y: (idx?: number) => nodeHeight * ((idx || 0) + 1), + y: getY, }, destinations: { x: endX, - y: (idx?: number) => nodeHeight * ((idx || 0) + 1), + y: getY, }, }; @@ -331,6 +332,22 @@ export const buildNodesAndEdges = ({ }); } + tempNodes['rules'].push( + createNode( + 'hidden', + 'hidden', + postions['rules']['x'], + containerHeight, + {}, + { + width: 1, + height: 1, + opacity: 0, + pointerEvents: 'none', + }, + ), + ); + Object.values(tempNodes).forEach((arr) => nodes.push(...arr)); return { nodes, edges }; diff --git a/frontend/webapp/reuseable-components/nodes-data-flow/index.tsx b/frontend/webapp/reuseable-components/nodes-data-flow/index.tsx index 544c2454fa..8c36574cca 100644 --- a/frontend/webapp/reuseable-components/nodes-data-flow/index.tsx +++ b/frontend/webapp/reuseable-components/nodes-data-flow/index.tsx @@ -61,7 +61,18 @@ export function NodeBaseDataFlow({ nodes, edges, onNodeClick, nodeWidth }: NodeB - +