Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

When adding an item that already exists as packed, users need a way to track new unpacked items separately until they're physically packed.

Changes

  • BaggageCard.tsx - addItem: Check only for unpacked duplicates. If matching item exists but is packed, create new unpacked item instead of incrementing quantity.
  • BaggageCard.tsx - updateItem: When marking item as packed, detect and merge with existing packed item of same name, combining quantities.
  • ToastContext.tsx: Add mergeItems toast notification for merge feedback.
  • Tests: 4 new tests covering duplicate creation, quantity increment, merge behavior, and no-merge case.

Example Flow

  1. "Socks" (qty: 5, packed) exists
  2. Quick add "Socks" → new unpacked card (qty: 1)
  3. Pack the new item → merges into single card (qty: 6, packed)

Merged items

Original prompt

This section details on the original issue you should resolve

<issue_title>Handle adding duplicate items: allow separate item for unpacked, merge when packed</issue_title>
<issue_description>Originally issue #6 in dralan71/luggage-tracker

Overview

Currently, when adding a new item (via quick add or add item), if the item already exists, the quantity simply increases. However, to improve usability:

  • If the newly added item matches an existing item that is already packed, it should be added as a separate unpacked item.
  • When the new unpacked item is marked as packed, it should automatically merge with the existing packed item, updating the quantity accordingly and leaving only one packed item card.

Example:

  • You have "socks" (quantity: 5, packed) in your list.
  • You use quick add to add another "socks" item (quantity: 1, unpacked by default).
  • The new "socks" item appears as a separate unpacked card.
  • After physically packing the new socks and toggling them as packed in the app, the two "socks" items should merge into one card with quantity 6, packed.

Tasks

  • Update the item addition logic to allow duplicate items as separate cards if one is already packed.
  • Implement merging logic so that when an unpacked duplicate is marked as packed, it merges with the already packed item.
  • Ensure the UI reflects these changes clearly and intuitively.
  • Test for edge cases, such as bulk adds and rapid toggling between packed/unpacked.

Expected Outcome

Users can add more of an item even if it is already packed, and merging occurs automatically upon packing, streamlining item management.
</issue_description>

<agent_instructions>Make sure to run tsc and check for lint.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Summary by CodeRabbit

Release Notes

  • New Features

    • Intelligent item merging: duplicate items now seamlessly merge when packed, with confirmation notifications displayed.
  • Bug Fixes

    • Corrected display color formatting issue.
  • Documentation

    • Added comprehensive agent usage guidelines and development best practices.
  • Tests

    • Expanded test coverage for duplicate item handling scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

This change implements automatic merging of duplicate baggage items when unpacked items are marked as packed. When adding items, duplicates are kept separate if already packed; upon packing an unpacked duplicate, it merges with its packed counterpart. A new toast notification method and comprehensive test coverage support this functionality.

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md
New agent usage guidelines document covering output style, npm/vite commands, pre-commit checks, and pattern adherence practices.
Toast Enhancement
src/ToastContext.tsx
Added mergeItems(itemName: string, newQuantity: number) method to customToast for displaying merge notifications. Fixed color typo: '##222' → '#222' in toastConfig.success.
Core Logic
src/components/BaggageCard.tsx
Enhanced addItem to only merge with unpacked items; creates new unpacked item if duplicate is packed. Modified updateItem to detect unpacked-to-packed transitions and merge quantities with existing packed items, emitting merge toast on successful merge.
Test Coverage
src/test/BaggageCard.test.tsx
Added "Duplicate item handling" test suite with 4 test cases validating: packed duplicate creates separate unpacked item, unpacked duplicate increments quantity, unpacked-to-packed transition merges items, and no merge occurs when packed duplicate doesn't exist.

Sequence Diagram

sequenceDiagram
    participant User
    participant BaggageCard
    participant ToastContext

    User->>BaggageCard: Add duplicate item (packed variant exists)
    BaggageCard->>BaggageCard: Search unpacked items only
    BaggageCard->>BaggageCard: Create new unpacked item (qty: 1)
    BaggageCard->>User: Display separate unpacked card

    User->>BaggageCard: Mark unpacked duplicate as packed
    BaggageCard->>BaggageCard: Detect unpacked → packed transition
    BaggageCard->>BaggageCard: Find packed item with same name
    BaggageCard->>BaggageCard: Merge quantities & remove unpacked
    BaggageCard->>ToastContext: mergeItems(itemName, totalQty)
    ToastContext->>User: Show success toast with merge notification
    BaggageCard->>User: Display single packed card (merged qty)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PackTracker#10: Extends toast system with customToast.mergeItems method and emits merge notifications from BaggageCard when duplicate items are packed together—directly depends on the ToastContext enhancements introduced here.

Poem

🐰 A pair of socks, once split in two,
Now merge as one when packed anew—
Toast pops up with a joyful cheer,
"Combined they are, no duplicates here!"
Baggage organized, we rabbits say,
Hippity-hops the merge way! 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning AGENTS.md is documentation unrelated to issue #2 requirements; while not harmful, it falls outside the linked issue scope which concerns duplicate item handling logic. Remove AGENTS.md from this PR or document why it is necessary; keep the PR focused on duplicate item handling requirements from issue #2.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and clearly summarizes the main functionality change: handling duplicate items with separate unpacking and automatic merging when packed.
Linked Issues check ✅ Passed All primary coding requirements from issue #2 are met: addItem creates separate unpacked items for duplicates of packed items [#2], updateItem merges when unpacked duplicate is marked as packed [#2], mergeItems toast added [#2], and four test cases covering duplicate scenarios [#2].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…erge on pack

Co-authored-by: dralan71 <195392503+dralan71@users.noreply.github.com>
Copilot AI changed the title [WIP] Handle adding duplicate items for packed and unpacked Handle adding duplicate items: allow separate item for unpacked, merge when packed Jan 14, 2026
Copilot AI requested a review from dralan71 January 14, 2026 01:31
@dralan71 dralan71 marked this pull request as ready for review January 17, 2026 13:29
@dralan71
Copy link
Owner

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@dralan71 dralan71 added the enhancement New feature or request label Jan 17, 2026
@dralan71 dralan71 merged commit 1803581 into main Jan 17, 2026
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Feb 8, 2026
9 tasks
@dralan71 dralan71 deleted the copilot/handle-duplicate-items-issue branch February 9, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle adding duplicate items: allow separate item for unpacked, merge when packed

2 participants