Skip to content

Commit

Permalink
destructure and coerce earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Sep 16, 2020
1 parent 41f2391 commit 531c36c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,49 @@ export default function getComponentWidthFromDrop({
return component.meta.width;
}

const draggingWidth = getDetailedComponentWidth({
const {
width: draggingWidth,
minimumWidth: minDraggingWidth,
} = getDetailedComponentWidth({
component,
components,
});

const destinationWidth = getDetailedComponentWidth({
const {
width: destinationWidth,
occupiedWidth: draggingOccupiedWidth,
} = getDetailedComponentWidth({
id: destination.id,
components,
});

let destinationCapacity =
destinationWidth.width - destinationWidth.occupiedWidth;
let destinationCapacity = Number(destinationWidth - draggingOccupiedWidth);

if (Number.isNaN(Number(destinationCapacity))) {
const grandparentWidth = getDetailedComponentWidth({
if (Number.isNaN(destinationCapacity)) {
const {
width: grandparentWidth,
occupiedWidth: grandparentOccupiedWidth,
} = getDetailedComponentWidth({
id: findParentId({
childId: destination.id,
layout: components,
}),
components,
});

destinationCapacity =
grandparentWidth.width - grandparentWidth.occupiedWidth;
destinationCapacity = Number(grandparentWidth - grandparentOccupiedWidth);
}

if (
Number.isNaN(Number(destinationCapacity)) ||
Number.isNaN(Number(draggingWidth.width))
Number.isNaN(destinationCapacity) ||
Number.isNaN(Number(draggingWidth))
) {
return draggingWidth.width;
return draggingWidth;
}
if (destinationCapacity >= draggingWidth.width) {
return draggingWidth.width;
if (destinationCapacity >= draggingWidth) {
return draggingWidth;
}
if (destinationCapacity >= draggingWidth.minimumWidth) {
if (destinationCapacity >= minDraggingWidth) {
return destinationCapacity;
}

Expand Down

0 comments on commit 531c36c

Please sign in to comment.