Skip to content

♻️ refactor(line-items): deprecate LineItemsContainer, add LineItems standalone component#776

Open
acasazza wants to merge 6 commits into
v5.0.0from
feat/line-items-refactor
Open

♻️ refactor(line-items): deprecate LineItemsContainer, add LineItems standalone component#776
acasazza wants to merge 6 commits into
v5.0.0from
feat/line-items-refactor

Conversation

@acasazza
Copy link
Copy Markdown
Member

Summary

Refactors the line items components following the same pattern used by orders, prices, and SKU lists.

Changes

@commercelayer/core

  • line_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 flag
  • line_items/deleteLineItem.ts — deletes a line item

@commercelayer/hooks

  • useLineItems({ accessToken, orderId, interceptors? }) — SWR-based hook exposing lineItems, isLoading, error, updateLineItem, deleteLineItem, reload, mutate

@commercelayer/react-components

  • New LineItems standalone component — no OrderContext required
    • Props: accessToken, orderId, types? (filter by item_type), loader?, onUpdate?, onDelete?
    • Uses useLineItems internally; feeds LineItemContext privately so all child components work unchanged
  • LineItemsContainer marked @deprecated → migrate to <LineItems>
  • LineItemContext — added reload?() to context value type
  • LineItemsCount — fixed contextComponentName warning (LineItemsContainerLineItems)

Improvements over old container

LineItemsContainer LineItems
Requires OrderContext
types filter ❌ (defined, never used)
onUpdate / onDelete callbacks
reload() in context

Usage

<LineItems
  accessToken={token}
  orderId={id}
  types={["skus", "bundles"]}
  onDelete={(id) => toast(`Item ${id} removed`)}
>
  <LineItem>
    <LineItemName />
    <LineItemQuantity />
    <LineItemRemoveLink />
  </LineItem>
  <LineItemsCount />
  <LineItemsEmpty />
</LineItems>

Alessandro Casazza and others added 2 commits May 25, 2026 17:27
…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>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

npm i https://pkg.pr.new/@commercelayer/react-components@776

commit: 156b24d

@acasazza acasazza added refactor enhancement New feature or request core Core package labels May 25, 2026
@acasazza acasazza self-assigned this May 25, 2026
@acasazza acasazza added the components Components package label May 25, 2026
Alessandro Casazza and others added 4 commits May 25, 2026 17:45
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

components Components package core Core package enhancement New feature or request refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant