Open
Conversation
spartacus
|
||||||||||||||||||||||||||||||
| Project |
spartacus
|
| Branch Review |
fix/CXSPA-11929
|
| Run status |
|
| Run duration | 11m 59s |
| Commit |
|
| Committer | Roman |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
3
|
|
|
0
|
|
|
0
|
|
|
101
|
Upgrade your plan to view test results. | |
| View all changes introduced in this branch ↗︎ | |
uroslates
approved these changes
Mar 2, 2026
Contributor
uroslates
left a comment
There was a problem hiding this comment.
Looks good! 👍 Great job!
Added a comment with some neat-peek suggestions but not required, leave it to you to decide if they make sense in this case.
Would suggest we assign it to @KateChuen for QA!
Comment on lines
63
to
+78
| if (!userId) { | ||
| throw new Error('Must be logged in to reorder'); | ||
| } | ||
|
|
||
| if (cartId) { | ||
| this.multiCartFacade.deleteCart(cartId, userId); | ||
| // Wait for the cart entity to be fully removed from the store | ||
| // before proceeding with the reorder. | ||
| return this.multiCartFacade.getCartEntity(cartId).pipe( | ||
| filter((state) => !state.value && !state.loading), | ||
| take(1), | ||
| map(() => userId) | ||
| ); | ||
| } | ||
|
|
||
| return userId; | ||
| return of(userId); |
Contributor
There was a problem hiding this comment.
// ...
switchMap(([userId, cartId]) => {
if (!userId) {
return throwError(() => new Error('Must be logged in to reorder'));
}
if (cartId) {
return this.deleteCartAndWait(cartId, userId);
}
return of(userId);
})
);
// ...
protected deleteCartAndWait(cartId: string, userId: string): Observable<string> {
this.multiCartFacade.deleteCart(cartId, userId);
return this.multiCartFacade.getCartEntity(cartId).pipe(
filter((state) => !state.value && !state.loading || !!state.error),
take(1),
switchMap((state) => {
if (state.error) {
// Log W/O blocking reorder
console.warn('Cart deletion may have failed:', state.error);
}
return of(userId);
})
}
- [neat pick] Would add proper RxJs error propagation (
throwErrorinstead ofthrowfor consistency with reactive nature & better integration withcatchErrorandretry/... RxJs primitives) - [neat pick] For the sake of better readability and testability I would suggest extracting
deleteCartAndWaitinto separateprotectedmethod. - [neat pick] handle failed cases (
!state.value && !state.loading || !!state.error) - deletion failed but we continue - [neat pick]
this.multiCartFacade.getCartEntity->switchMapblock - we log error as warning and continue (not sure if necessary - leave it to you to decide)
I am not sure if in addition to above - in the context of returned deleteCartAndWait method observable - we should also handle adding rxjs timeout (for preventing indefinite hanging) and catchError (just logging and proceeding event if it times out). I guess it would be too much.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: https://jira.tools.sap/browse/CXSPA-11929
QA steps:
Can be reproduced locally with SPA from develop-next-major and backend 22.11jdk21. ("CX_BASE_URL": "https://spartacus-devci7677.eastus.cloudapp.azure.com:8443/")
Submit an order in B2B site. View order history and navigate to order details. Re-order
Message 'Products have been sucessfully added to the cart' appears.
Navigate to cart -> no cart entries visible.
Only when you hit F5 or add another product to the cart, cart becomes updated with the entry from re-order.