From 3ae72726b8e19d80a2fd9293f390865b148b90b8 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 1 Nov 2024 14:32:21 +0000 Subject: [PATCH] Fix DashboardBaseComponent position calculations to ensure new coordinates remain within bounds --- .../Components/DashboardBaseComponent.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Dashboard/src/Components/Dashboard/Components/DashboardBaseComponent.tsx b/Dashboard/src/Components/Dashboard/Components/DashboardBaseComponent.tsx index bfb4d39e48..27b01eccbb 100644 --- a/Dashboard/src/Components/Dashboard/Components/DashboardBaseComponent.tsx +++ b/Dashboard/src/Components/Dashboard/Components/DashboardBaseComponent.tsx @@ -73,16 +73,16 @@ const DashboardBaseComponentElement: FunctionComponent = ( const newMoveToTop: number = mouseEvent.pageY; const newMoveToLeft: number = mouseEvent.pageX; - const oldTopDashboardUnits: number = props.component.topInDashboardUnits; - const oldLeftDashboardUnits: number = props.component.leftInDashboardUnits; + const oldTopDashboardUnits: number = props.component.topInDashboardUnits + 1; + const oldLeftDashboardUnits: number = props.component.leftInDashboardUnits + 1; // calculare new top and new left. let newTopInDashboardUnits: number = Math.floor( (newMoveToTop * oldTopDashboardUnits) / dashboardComponentOldTopInPx, - ); + ) - 1; let newLeftInDashboardUnits: number = Math.floor( (newMoveToLeft * oldLeftDashboardUnits) / dashboardComponentOldLeftInPx, - ); + ) - 1; // check if the new top and left are within the bounds of the dashboard @@ -117,6 +117,15 @@ const DashboardBaseComponentElement: FunctionComponent = ( widthOfTheComponentInDashboardUnits; } + + if(newTopInDashboardUnits < 0) { + newTopInDashboardUnits = 0; + } + + if(newLeftInDashboardUnits < 0) { + newLeftInDashboardUnits = 0; + } + // update the component const newComponentProps: DashboardBaseComponent = { ...props.component,