Fix DashboardBaseComponent position calculations to ensure new coordinates remain within bounds

This commit is contained in:
Simon Larsen 2024-11-01 14:32:21 +00:00
parent 90c0e42eb1
commit 3ae72726b8
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA

View File

@ -73,16 +73,16 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
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<ComponentProps> = (
widthOfTheComponentInDashboardUnits;
}
if(newTopInDashboardUnits < 0) {
newTopInDashboardUnits = 0;
}
if(newLeftInDashboardUnits < 0) {
newLeftInDashboardUnits = 0;
}
// update the component
const newComponentProps: DashboardBaseComponent = {
...props.component,