From 09e583c9df5c2ab4e728bf33aa7dd795bc2cad59 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Tue, 15 Sep 2020 15:38:39 -0700 Subject: [PATCH 1/3] fix test config --- .github/workflows/superset-frontend.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/superset-frontend.yml b/.github/workflows/superset-frontend.yml index 8ddaa3b70f71e..86d0e533cd84a 100644 --- a/.github/workflows/superset-frontend.yml +++ b/.github/workflows/superset-frontend.yml @@ -33,7 +33,6 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Install dependencies - - name: npm install working-directory: ./superset-frontend run: | npm install From 41f2391d8203a71c644d2f666bf234bf6b52854c Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Tue, 15 Sep 2020 15:59:52 -0700 Subject: [PATCH 2/3] fix tests --- .../src/dashboard/util/getComponentWidthFromDrop.js | 7 +++++-- .../src/explore/components/controls/BoundsControl.jsx | 4 ++-- .../explore/components/controls/FilterBoxItemControl.jsx | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js b/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js index 01d283644cbea..7dc1522dcb0f0 100644 --- a/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js +++ b/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js @@ -50,7 +50,7 @@ export default function getComponentWidthFromDrop({ let destinationCapacity = destinationWidth.width - destinationWidth.occupiedWidth; - if (Number.isNaN(destinationCapacity)) { + if (Number.isNaN(Number(destinationCapacity))) { const grandparentWidth = getDetailedComponentWidth({ id: findParentId({ childId: destination.id, @@ -63,7 +63,10 @@ export default function getComponentWidthFromDrop({ grandparentWidth.width - grandparentWidth.occupiedWidth; } - if (Number.isNaN(destinationCapacity) || Number.isNaN(draggingWidth.width)) { + if ( + Number.isNaN(Number(destinationCapacity)) || + Number.isNaN(Number(draggingWidth.width)) + ) { return draggingWidth.width; } if (destinationCapacity >= draggingWidth.width) { diff --git a/superset-frontend/src/explore/components/controls/BoundsControl.jsx b/superset-frontend/src/explore/components/controls/BoundsControl.jsx index f52f430558b57..5c7c567f33fbb 100644 --- a/superset-frontend/src/explore/components/controls/BoundsControl.jsx +++ b/superset-frontend/src/explore/components/controls/BoundsControl.jsx @@ -67,10 +67,10 @@ export default class BoundsControl extends React.Component { onChange() { const mm = this.state.minMax; const errors = []; - if (mm[0] && Number.isNaN(mm[0])) { + if (mm[0] && Number.isNaN(Number(mm[0]))) { errors.push(t('`Min` value should be numeric or empty')); } - if (mm[1] && Number.isNaN(mm[1])) { + if (mm[1] && Number.isNaN(Number(mm[1]))) { errors.push(t('`Max` value should be numeric or empty')); } if (errors.length === 0) { diff --git a/superset-frontend/src/explore/components/controls/FilterBoxItemControl.jsx b/superset-frontend/src/explore/components/controls/FilterBoxItemControl.jsx index 237174ced4fb6..9802174849732 100644 --- a/superset-frontend/src/explore/components/controls/FilterBoxItemControl.jsx +++ b/superset-frontend/src/explore/components/controls/FilterBoxItemControl.jsx @@ -116,9 +116,9 @@ export default class FilterBoxItemControl extends React.Component { if (type === 'BOOLEAN') { typedValue = value === 'true'; } else if (INTEGRAL_TYPES.has(type)) { - typedValue = Number.isNaN(value) ? null : parseInt(value, 10); + typedValue = Number.isNaN(Number(value)) ? null : parseInt(value, 10); } else if (DECIMAL_TYPES.has(type)) { - typedValue = Number.isNaN(value) ? null : parseFloat(value); + typedValue = Number.isNaN(Number(value)) ? null : parseFloat(value); } } } From 531c36c6dd2b97477bce5bd140a17ca8d82bef36 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Tue, 15 Sep 2020 16:40:57 -0700 Subject: [PATCH 3/3] destructure and coerce earlier --- .../util/getComponentWidthFromDrop.js | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js b/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js index 7dc1522dcb0f0..766df531bf1a8 100644 --- a/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js +++ b/superset-frontend/src/dashboard/util/getComponentWidthFromDrop.js @@ -37,21 +37,29 @@ 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, @@ -59,20 +67,19 @@ export default function getComponentWidthFromDrop({ 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; }