-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Distance - Start and Stop labels do not change when dragging one over another. #44748
Changes from 2 commits
00d5b26
717e2ec
0f16a6c
82fc097
33a04fc
e166e19
826e52f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,15 @@ function IOURequestStepDistance({ | |
const {translate} = useLocalize(); | ||
|
||
const [optimisticWaypoints, setOptimisticWaypoints] = useState<WaypointCollection | null>(null); | ||
const waypoints = useMemo(() => optimisticWaypoints ?? transaction?.comment?.waypoints ?? {waypoint0: {}, waypoint1: {}}, [optimisticWaypoints, transaction]); | ||
const waypoints = useMemo( | ||
() => | ||
optimisticWaypoints ?? | ||
transaction?.comment?.waypoints ?? { | ||
waypoint0: {keyForList: 'start_waypoint'}, | ||
waypoint1: {keyForList: 'stop_waypoint'}, | ||
}, | ||
[optimisticWaypoints, transaction], | ||
); | ||
const waypointsList = Object.keys(waypoints); | ||
const previousWaypoints = usePrevious(waypoints); | ||
const numberOfWaypoints = Object.keys(waypoints).length; | ||
|
@@ -92,7 +100,14 @@ function IOURequestStepDistance({ | |
const isRouteAbsentWithoutErrors = !hasRoute && !hasRouteError; | ||
const shouldFetchRoute = (isRouteAbsentWithoutErrors || haveValidatedWaypointsChanged) && !isLoadingRoute && Object.keys(validatedWaypoints).length > 1; | ||
const [shouldShowAtLeastTwoDifferentWaypointsError, setShouldShowAtLeastTwoDifferentWaypointsError] = useState(false); | ||
const nonEmptyWaypointsCount = useMemo(() => Object.keys(waypoints).filter((key) => !isEmpty(waypoints[key])).length, [waypoints]); | ||
const nonEmptyWaypointsCount = useMemo( | ||
() => | ||
Object.keys(waypoints).filter((key) => { | ||
const {keyForList, ...waypointWithoutKey} = waypoints[key]; | ||
return !isEmpty(waypointWithoutKey); | ||
}).length, | ||
[waypoints], | ||
); | ||
const duplicateWaypointsError = useMemo( | ||
() => nonEmptyWaypointsCount >= 2 && Object.keys(validatedWaypoints).length !== nonEmptyWaypointsCount, | ||
[nonEmptyWaypointsCount, validatedWaypoints], | ||
|
@@ -346,7 +361,9 @@ function IOURequestStepDistance({ | |
data.forEach((waypoint, index) => { | ||
newWaypoints[`waypoint${index}`] = waypoints[waypoint] ?? {}; | ||
// Find waypoint that BECOMES empty after dragging | ||
if (isEmpty(newWaypoints[`waypoint${index}`]) && !isEmpty(waypoints[`waypoint${index}`] ?? {})) { | ||
const {keyForList, ...newWaypointsWithoutKey} = newWaypoints[`waypoint${index}`]; | ||
const {keyForList: waypointKey, ...waypointWithoutKey} = waypoints[`waypoint${index}`]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible if waypoints[ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry for delay, I will confirm this today. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hoangzinh, I think there won't be any case when |
||
if (isEmpty(newWaypointsWithoutKey) && !isEmpty(waypointWithoutKey ?? {})) { | ||
emptyWaypointIndex = index; | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can split it into a shareable method, that can be used in the below changes as well. A method like
isEmptyWaypoint
? (we should handle null/undefined inside that method as well)And
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check this in few hours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoangzinh, suggestion looks good to me, code updated.