Skip to content

Commit

Permalink
Merge pull request #36405 from Expensify/revert-34869-fix/33919
Browse files Browse the repository at this point in the history
[CP Staging] Revert "Fix: Duplicated waypoints after dragging"
  • Loading branch information
MonilBhavsar authored Feb 13, 2024
2 parents d534a9e + 6ed3706 commit 35ab989
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
10 changes: 3 additions & 7 deletions src/components/DistanceRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,17 @@ function DistanceRequest({transactionID, report, transaction, route, isEditingRe
}

const newWaypoints = {};
let emptyWaypointIndex = -1;
_.each(data, (waypoint, index) => {
newWaypoints[`waypoint${index}`] = lodashGet(waypoints, waypoint, {});
// Find waypoint that BECOMES empty after dragging
if (_.isEmpty(newWaypoints[`waypoint${index}`]) && !_.isEmpty(lodashGet(waypoints, `waypoint${index}`, {}))) {
emptyWaypointIndex = index;
}
});

setOptimisticWaypoints(newWaypoints);
Promise.all([Transaction.removeWaypoint(transaction, emptyWaypointIndex.toString(), true), Transaction.updateWaypoints(transactionID, newWaypoints, true)]).then(() => {
// eslint-disable-next-line rulesdir/no-thenable-actions-in-views
Transaction.updateWaypoints(transactionID, newWaypoints).then(() => {
setOptimisticWaypoints(null);
});
},
[transactionID, transaction, waypoints, waypointsList],
[transactionID, waypoints, waypointsList],
);

const submitWaypoints = useCallback(() => {
Expand Down
9 changes: 5 additions & 4 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp
}
}

function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft: boolean): Promise<void> {
function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft: boolean) {
// Index comes from the route params and is a string
const index = Number(currentIndex);
const existingWaypoints = transaction?.comment?.waypoints ?? {};
Expand All @@ -115,7 +115,7 @@ function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft:
const waypointValues = Object.values(existingWaypoints);
const removed = waypointValues.splice(index, 1);
if (removed.length === 0) {
return Promise.resolve();
return;
}

const isRemovedWaypointEmpty = removed.length > 0 && !TransactionUtils.waypointHasValidAddress(removed[0] ?? {});
Expand Down Expand Up @@ -164,9 +164,10 @@ function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft:
};
}
if (isDraft) {
return Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, newTransaction);
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, newTransaction);
return;
}
return Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, newTransaction);
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, newTransaction);
}

function getOnyxDataForRouteRequest(transactionID: string, isDraft = false): OnyxData {
Expand Down
10 changes: 3 additions & 7 deletions src/pages/iou/request/step/IOURequestStepDistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,17 @@ function IOURequestStepDistance({
}

const newWaypoints = {};
let emptyWaypointIndex = -1;
_.each(data, (waypoint, index) => {
newWaypoints[`waypoint${index}`] = lodashGet(waypoints, waypoint, {});
// Find waypoint that BECOMES empty after dragging
if (_.isEmpty(newWaypoints[`waypoint${index}`]) && !_.isEmpty(lodashGet(waypoints, `waypoint${index}`, {}))) {
emptyWaypointIndex = index;
}
});

setOptimisticWaypoints(newWaypoints);
Promise.all([Transaction.removeWaypoint(transaction, emptyWaypointIndex.toString(), true), Transaction.updateWaypoints(transactionID, newWaypoints, true)]).then(() => {
// eslint-disable-next-line rulesdir/no-thenable-actions-in-views
Transaction.updateWaypoints(transactionID, newWaypoints, true).then(() => {
setOptimisticWaypoints(null);
});
},
[transactionID, transaction, waypoints, waypointsList],
[transactionID, waypoints, waypointsList],
);

const submitWaypoints = useCallback(() => {
Expand Down

0 comments on commit 35ab989

Please sign in to comment.