Skip to content
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

Concept of the shopping lists' line item update actions. #614

Merged
merged 30 commits into from Nov 17, 2020

Conversation

ahmetoz
Copy link
Contributor

@ahmetoz ahmetoz commented Nov 5, 2020

  • Introduced ADR to document decisions.

Review Hint:
It would be better to check the file preview otherwise hard to understand because of the HTML source code in markdown.

@codecov-io
Copy link

codecov-io commented Nov 5, 2020

Codecov Report

Merging #614 (1ef3339) into shopping-lists-base-branch (9f7eb31) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@                      Coverage Diff                      @@
##             shopping-lists-base-branch     #614   +/-   ##
=============================================================
  Coverage                         99.35%   99.35%           
  Complexity                         2424     2424           
=============================================================
  Files                               194      194           
  Lines                              6084     6084           
  Branches                            377      377           
=============================================================
  Hits                               6045     6045           
  Misses                               20       20           
  Partials                             19       19           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f7eb31...6096a78. Read the comment docs.

…actions.md

Co-authored-by: King-Hin Leung <35692276+leungkinghin@users.noreply.github.com>
<!-- What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated. -->

- To ensure the order, we need to remove and add line items, which means a bigger payload, so performance overhead.
- [Add TextLineItem](https://docs.commercetools.com/api/projects/shoppingLists#add-textlineitem) is not checking the data is exists, so a user could add the
Copy link
Collaborator

@lojzatran lojzatran Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [Add TextLineItem](https://docs.commercetools.com/api/projects/shoppingLists#add-textlineitem) is not checking the data is exists, so a user could add the
- [Add TextLineItem](https://docs.commercetools.com/api/projects/shoppingLists#add-textlineitem) is not checking if the data exists. A user could add the

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand well this consequence. Can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of explanation? Update action JSON?

"addedAt": "2020-11-04T09:38:35.571Z"
},
{
"id": "24de3821-e27d-4ddb-bd0b-ecc99365285f",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it supposed to have different ID as LineItem SKU-1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<p> So we need to create an <a href="https://docs.commercetools.com/api/projects/shoppingLists#add-lineitem">AddLineItem</a> action
, a <a href="https://docs.commercetools.com/api/projects/shoppingLists#remove-lineitem">RemoveLineItem</a> action and
a <a href="https://docs.commercetools.com/api/projects/shoppingLists#change-lineitems-order">Change LineItems Order</a>
of the line items <b>SKU-1</b> and <b>SKU-3</b>, because when we add line item with <b>SKU-1</b>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand here.
In the drafts, the order is ['sku-1', 'sku-3']. Isn't it expected and no need to change the order?
I would understand ChangeLineitemOrder is required if the order in drafts is ['sku-3', 'sku-1']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like same, #614 (comment)

"lineItems": [
{
"sku": "SKU-1",
"quantity": 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is quantity supposed to update? I see the quantity of existing lineitem 'sku-1' is different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 282 to 299
{
"action": "removeLineItem",
"lineItemId": "24de3821-e27d-4ddb-bd0b-ecc99365285f"
},
{
"action": "addLineItem",
"sku": "SKU-3",
"quantity": 3,
"addedAt": "2020-11-05T10:00:10.101Z",
"custom": {
"type": {
"key": "custom-type-for-shoppinglists"
},
"fields": {
"textField": "text-3
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it is going to remove existing 'sku-2' line item.

These two updateActions are appropriate. I am just curious how we determine which updateActions are needed in UpdateActionUtil for each LineItem.

For example
existing line item : ['sku-4', 'sku-1', 'sku-2']
new line items : ['sku-3', 'sku-4', 'sku-1']

Besides adding 'sku-3' and removing 'sku-2', we have to remove 'sku-1', 'sku-4' from existing line items as well. Otherwise the order is not the same as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!, You are right, the scenario was the same as scenario 1. 97d4d15

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From your example, you checked sku-3 and sku-4 is different than to able to match the order, all actions need to be removed and added back because you need to ensure the order.

In scenario 1,

draft : [sku1,..., sku2]
target: [sku2...]

In scenario 2,

draft: [sku1,..., sku3, sku2]
target: [sku1,..., sku2]

sku1 is exactly the same until you find the first difference assume you have N same but a difference in the middle, you don't need to create actions for those N items, here how we will know the difference depends on the comparisons between draft and target objects, so it's like doing sequence comparisons with their order. During the implementation, I could find more examples and could add here.

@ahmetoz ahmetoz marked this pull request as ready for review November 5, 2020 17:39
@lojzatran
Copy link
Collaborator

lojzatran commented Nov 6, 2020

Can you add one more example - no new line item is added or removed, just order is different.
LineItemDrafts: L1 and L2
LineItems: L2 and L1

What is the solution here? [removeLineItem L1, removeLineItem L2, addLineItem L1, addLineItem L2]?

ahmetoz and others added 2 commits November 6, 2020 09:15
…actions.md

Co-authored-by: Lam Tran <lam.tran@commercetools.de>
@ahmetoz
Copy link
Contributor Author

ahmetoz commented Nov 6, 2020

Can you add one more example - no new line item is added or removed, just order is different.
LineItemDrafts: L1 and L2
LineItems: L2 and L1

What is the solution here? [removeLineItem L1, removeLineItem L2, addLineItem L1, addLineItem L2]?

d4f24e6 I don't know the exact algorithm yet, but could be done by removing and adding back.

@ahmetoz ahmetoz requested review from lojzatran and leungkinghin-ct and removed request for butenkor November 10, 2020 12:04
@ahmetoz ahmetoz mentioned this pull request Nov 11, 2020
6 tasks
@ahmetoz
Copy link
Contributor Author

ahmetoz commented Nov 17, 2020

@leungkinghin @lojzatran could you please re-check the latest updates: 1ef3339, 3902376, 6096a78

ahmetoz and others added 2 commits November 17, 2020 15:04
…actions.md

Co-authored-by: Lam Tran <lam.tran@commercetools.de>
</p>
<p>
First example seems reasonable but how you would sync a case like:
'[SKU-1, SKU-2, SKU-3]' to '[SKU-3, SKU-1, SKU-4, SKU-2]', so with a new algorithm it might be done with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'[SKU-1, SKU-2, SKU-3]' to '[SKU-3, SKU-1, SKU-4, SKU-2]', so with a new algorithm it might be done with
'[SKU-1, SKU-2, SKU-3]' to '[SKU-3, SKU-1, SKU-4, SKU-2]'? With a new algorithm it might be done with

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the new algorithm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is none: 98822a9

<p>
First example seems reasonable but how you would sync a case like:
'[SKU-1, SKU-2, SKU-3]' to '[SKU-3, SKU-1, SKU-4, SKU-2]', so with a new algorithm it might be done with
change order [line-item-id-3, line-item-id-1, line-item-id-2] then removeLineItem SKU-2, add back addLineItem SKU-4,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make those actions bold and also in the array [], so we know there are 3 of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in total 3 actions.
</p>
<p>
It looks like there are more different cases and that's why we decided to keep the idea of removing and adding back to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It looks like there are more different cases and that's why we decided to keep the idea of removing and adding back to
It looks like there are more different cases. That's why we decided to keep the idea of removing and adding back to

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the conclusion more dominant (bold, bigger font).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now better: 98822a9

@ahmetoz ahmetoz merged commit a834e77 into shopping-lists-base-branch Nov 17, 2020
@ahmetoz ahmetoz deleted the actions-line-items branch November 17, 2020 16:24
leungkinghin-ct pushed a commit that referenced this pull request Nov 24, 2020
* master:
  Bump commercetoolsJvmSdkVersion from 1.54.0 to 1.55.0
  Version updates and release notes of 3.0.0 (#620)
  610 -  Fix duration calculation for retry client. (+ refactor client creation logic) (#623)
  Add user guide for Shopping lists (#613)
  Cover shopping list line items in integration test scenarios (#626)
  Revert "Resolve ProductTypeSyncTest"
  wrapped <li> elements in <ul> tags (#616)
  Implement text line item actions (#625)
  Resolve ProductTypeSyncTest
  Implement LineItem actions (#618)
  Concept of the shopping lists' line item update actions. (#614)
  Bump assertj-core from 3.18.0 to 3.18.1
  Implement Shoppinglist Sync class with IT/UT (exclude LineItem and TextLineItem) (#615)
  Add shopping list update actions (without line items) (#611)
  Create shoppinglist sync utils and helper (#595)
  Add ShoppingList Reference Resolver helpers/utilities. (#602)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants