♻️ refactor(line-items): deprecate LineItemsContainer, add LineItems standalone component#776
Open
acasazza wants to merge 6 commits into
Open
♻️ refactor(line-items): deprecate LineItemsContainer, add LineItems standalone component#776acasazza wants to merge 6 commits into
acasazza wants to merge 6 commits into
Conversation
…standalone component - Add core functions: getLineItems, updateLineItem, deleteLineItem - Add useLineItems hook (SWR-based) to @commercelayer/hooks - Add LineItems standalone component (no OrderContext required) - supports types prop for item_type filtering - supports onUpdate/onDelete callbacks - exposes reload() via LineItemContext - Deprecate LineItemsContainer in favour of LineItems - Fix LineItemsCount contextComponentName warning (LineItemsContainer → LineItems) - Add reload to LineItemContext Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nd LineItems component Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
…context - accessToken falls back to CommerceLayerContext when not provided as prop - orderId falls back to OrderContext when not provided as prop - prop values always take precedence over context values - Added 4 tests covering all fallback and precedence combinations Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- UseLineItemsParams.accessToken is now optional (swrKey already guards fetch) - Added accessToken guard in SWR fetcher, updateLineItem, and deleteLineItem - Fixed definite assignment assertion in test to satisfy strict TS check Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…neItems Both values are now read exclusively from context: - accessToken from CommerceLayerContext - orderId from OrderContext Updated tests to use Providers wrapper instead of direct props. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove dead guards from SWR fetcher (swrKey already prevents unreachable paths) - Add tests: returns empty when accessToken is undefined - Add tests: updateLineItem and deleteLineItem throw when accessToken is missing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Refactors the line items components following the same pattern used by orders, prices, and SKU lists.
Changes
@commercelayer/coreline_items/getLineItems.ts— fetches an order's line items with full includes (line_item_options.sku_option,item)line_items/updateLineItem.ts— updates quantity / external price flagline_items/deleteLineItem.ts— deletes a line item@commercelayer/hooksuseLineItems({ accessToken, orderId, interceptors? })— SWR-based hook exposinglineItems,isLoading,error,updateLineItem,deleteLineItem,reload,mutate@commercelayer/react-componentsLineItemsstandalone component — noOrderContextrequiredaccessToken,orderId,types?(filter by item_type),loader?,onUpdate?,onDelete?useLineItemsinternally; feedsLineItemContextprivately so all child components work unchangedLineItemsContainermarked@deprecated→ migrate to<LineItems>LineItemContext— addedreload?()to context value typeLineItemsCount— fixedcontextComponentNamewarning (LineItemsContainer→LineItems)Improvements over old container
LineItemsContainerLineItemsOrderContexttypesfilteronUpdate/onDeletecallbacksreload()in contextUsage