Skip to content

Feature/kit location#1961

Merged
DonKoko merged 47 commits intoShelf-nu:mainfrom
rockingrohit9639:feature/kit-location
Sep 15, 2025
Merged

Feature/kit location#1961
DonKoko merged 47 commits intoShelf-nu:mainfrom
rockingrohit9639:feature/kit-location

Conversation

@rockingrohit9639
Copy link
Copy Markdown
Contributor

Closes #1947

@rockingrohit9639 rockingrohit9639 requested a review from DonKoko July 31, 2025 10:37
@rockingrohit9639 rockingrohit9639 self-assigned this Jul 31, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Jul 31, 2025

@rockingrohit9639 is attempting to deploy a commit to the Whaleagency Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel bot commented Aug 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
shelf-docs Ignored Ignored Preview Sep 15, 2025 9:12am

Copy link
Copy Markdown
Contributor

@DonKoko DonKoko left a comment

Choose a reason for hiding this comment

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

  • When you open edit of a kit, the current location of the kit is not loaded in the kit
  • The absolute actions of the kit edit page are not being fixed at the top. They are moving as you scroll
  • Kit location should be shown in the kit.overview not in the sidebar

Copy link
Copy Markdown
Contributor

@DonKoko DonKoko left a comment

Choose a reason for hiding this comment

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

Some things i missed in the previous review:

  • We need to add manage-kits route, same way it works with the booking so if you are on the location page you can add kits
  • update-location-drawer.tsx should be updated to handle kits
  • add-assets-to-location-drawer.tsx should be updated to handle kits.

This commit implements comprehensive kit location management with automatic cascading to contained assets, addressing all requirements from PR feedback:

Core Features:
- Kit location updates now cascade to all assets within the kit
- Consistent location management across individual, bulk, and manage-kits interfaces
- User warnings about cascade behavior in all relevant dialogs
- Location visibility improvements in manage-kits interface

Key Changes:
- Enhanced updateKitLocation() to cascade changes to kit assets using single location.update operations
- Added bulkUpdateKitLocation() cascade functionality with proper handling of location assignment and removal
- Fixed bulk location removal to handle empty string values correctly (locationId: null)
- Implemented cascade warnings in manage-kits interface with AlertDialog confirmation
- Added location column to manage-kits list for better user visibility
- Created getKitLocationUpdateNoteContent() function for consistent audit trail messaging
- Updated note messages to show "changed from X to Y" format instead of just "set to Y"
- Added cascade notice in individual kit location update modal
- Added warning message in bulk location update dialog

Technical Implementation:
- Uses efficient location.update with connect/disconnect operations instead of multiple asset.updateMany calls
- Creates individual audit notes for each affected asset with proper cascade attribution
- Maintains existing permission and validation patterns
- Preserves all existing functionality while adding new cascade behavior

Testing:
- Kit location assignment works with cascade to assets
- Kit location removal works with cascade to assets
- Bulk operations handle both assignment and removal correctly
- All warning dialogs display appropriate information
- Note creation works consistently across all update methods
@DonKoko
Copy link
Copy Markdown
Contributor

DonKoko commented Aug 26, 2025

@carlosvirreira there is one case we need to make a decision on how to handle.
What happens when a user tries to update an asset's location when that asset is part of a kit? Do we even allow it?

@carlosvirreira
Copy link
Copy Markdown
Contributor

@carlosvirreira there is one case we need to make a decision on how to handle. What happens when a user tries to update an asset's location when that asset is part of a kit? Do we even allow it?

What do you suggest? Next time you online please call me and share me the view so i can better judge it and not imagine it, the context in which this situation is being triggered is important. I am doubting on what to suggest based on your last question if this should be desirable or not.

This commit adds comprehensive location cascade when assets are added to kits, ensuring assets inherit their parent kit's location automatically.

Key Features:
- Assets added to kits automatically inherit the kit's location
- Assets added to kits without locations lose their current location
- User warnings inform about cascade behavior before actions
- Proper audit trail with notes explaining location changes via kit assignment

Implementation Details:
- Enhanced updateKitAssets() function with location cascade logic
- Added kit location data to manage-assets page loader
- Created location-aware warning dialogs for all asset-to-kit addition methods
- Fixed note creation order: kit assignment notes first, then location cascade notes

User Interface Changes:
- Added cascade warning in bulk-add-to-kit dialog
- Enhanced kit manage-assets AlertDialog with location-specific warnings
- Different warning messages based on whether kit has location or not
- Always show warning dialog (previously only shown for custody cases)

Coverage:
- Bulk add assets to kit from assets index ✓
- Add assets via kit manage-assets page ✓
- Add assets via scanner (scan-assets) ✓
- Proper note sequencing and audit trail ✓

Technical Notes:
- Uses efficient batch updates for asset locations
- Maintains existing permission and validation patterns
- Creates individual notes for each affected asset with proper attribution
- Follows same patterns as existing kit location cascade functionality
Implements comprehensive validation to prevent location updates on assets that belong to kits, enforcing consistent location management through parent kits.

Frontend Protection:
- Asset edit page: Location select disabled with HoverCard tooltip for kit assets
- Displays clear message directing users to update kit location instead
- Kit information added to asset edit loader for proper detection

Backend Validation:
- updateAsset: Added kit validation with descriptive error messages
- bulkUpdateAssetLocation: Added kit detection and batch validation
- Prevents circumvention of frontend restrictions with safety mechanisms

Error Handling:
- Individual updates: "This asset's location is managed by its parent kit '[Kit Name]'. Please update the kit's location instead."
- Bulk updates: "Cannot update location for assets that belong to kits: [Kit Names]. Update the kit locations instead."

Test Coverage:
- Added kit location cascade tests to verify asset-to-kit location inheritance
- Tests cover both kit-with-location and kit-without-location scenarios
- All existing tests continue to pass (27/27 tests passing)

Data Consistency:
- Enforces kit-based location management workflow
- Prevents conflicting location states between kits and their assets
- Maintains audit trail integrity with proper error reporting

This completes the comprehensive kit location management system ensuring all location updates flow through kit management with appropriate user guidance.
@DonKoko
Copy link
Copy Markdown
Contributor

DonKoko commented Sep 11, 2025

🧪 Kit Location Management Testing Plan

Overview

Complete testing checklist for the kit location management system with cascade
functionality and blocking validation.


  1. Kit → Asset Location Cascade (Kit Location Updates)

Individual Kit Location Updates (/kits/{kitId}/assets/update-location)

  • Kit with assets gets location assigned: Assets should inherit kit location + get cascade
    notes
  • Kit with assets gets location removed: Assets should lose location + get cascade notes
  • Kit without assets gets location changed: Should work without affecting any assets
  • Warning banner displays: Should show asset count and cascade notice before update
  • Note creation: Verify notes show "changed from X to Y via parent kit assignment/removal"

Bulk Kit Location Updates (/api/kits/bulk-actions - bulk-update-location)

  • Multiple kits assigned to location: All kit assets should inherit location + get cascade
    notes
  • Multiple kits location removed ("Without location"): All kit assets should lose location
  • get cascade notes
  • Warning dialog displays: Should show cascade notice before confirmation
  • Mixed kit selection: Some kits with assets, some without - all should work correctly
  • Error handling: Bulk removal with empty string should work (not throw foreign key error)

Location Manage-Kits Page (/locations/{locationId}/kits/manage-kits)

  • Adding kits to location: Kit assets should inherit location + show cascade warning
  • Removing kits from location: Kit assets should lose location + show cascade warning
  • Location column displays: Should show current kit locations in the list
  • Cascade warning dialog: Should show before changes with asset impact details
  • Kit links open in new tabs: Kit names should open kit pages in new tabs

  1. Asset → Kit Addition Cascade (Adding Assets to Kits)

Bulk Add Assets to Kit (/api/assets/bulk-add-to-kit)

  • Assets added to kit WITH location: Assets should inherit kit location + get cascade
    notes
  • Assets added to kit WITHOUT location: Assets should lose their current location + get
    cascade notes
  • Warning banner displays: Should show cascade notice in dialog
  • Mixed assets: Some with location, some without - should handle correctly
  • Note ordering: Kit assignment notes first, then location cascade notes

Kit Manage-Assets Page (/kits/{kitId}/assets/manage-assets)

  • Assets added to kit WITH location: Assets should inherit kit location + get cascade
    notes
  • Assets added to kit WITHOUT location: Assets should lose their current location + get
    cascade notes
  • Warning dialog displays: Should show different messages based on kit location status
  • Combined with custody warning: When kit is in custody, should show both warnings
  • Kit location data loads: Loader should include kit location information

Scanner Add Assets to Kit (/kits/{kitId}/scan-assets)

  • Scanned assets added to kit: Should use same cascade logic as manage-assets page
  • Location cascade works: Assets should inherit kit location automatically
  • Notes created: Should create proper cascade notes via scanning

  1. Asset Removal from Kits (Keep Current Location)

Asset Removal Behavior

  • Assets removed from kits: Should keep their current location (no automatic changes)
  • Custody handling: If kit in custody, removed assets get custody released but keep
    location
  • Booking updates: Assets disconnected from bookings but location unchanged
  • No location cascade: Verify no location updates happen during removal
  • Note creation: Only kit removal notes, no location notes

  1. Individual Asset Location Update Blocking

Asset Edit Page (/assets/{assetId}/edit)

  • Kit asset location select disabled: Should be disabled with HoverCard tooltip
  • Non-kit asset location select enabled: Should work normally with full functionality
  • Tooltip message accuracy: Should show kit name and guidance
  • Backend validation: If frontend bypassed, should throw descriptive error
  • Kit data loads: Asset edit loader should include kit information

Asset Overview Location Modal (/assets/{assetId}/overview/update-location)

  • Frontend button disabled: Location update button should be disabled for kit assets
  • Backend validation: Route should throw error if attempted (calls updateAsset)
  • Error message: Should explain kit management and suggest updating kit location
  • Non-kit assets: Should work normally for assets not in kits

Bulk Asset Location Updates (/api/assets/bulk-update-location)

  • Kit assets blocked: Should throw error listing affected kit names
  • Mixed selection: Some kit assets, some regular - should block entire operation
  • Error message clarity: Should guide to update kit locations instead
  • Non-kit assets: Should work normally when no kit assets selected
  • Empty selection: Should handle edge cases gracefully

  1. Note Creation and Audit Trail

Note Content Verification

  • Kit location change notes: "Location changed from X to Y via parent kit assignment"
  • Asset location change notes: "Location changed from X to Y via parent kit
    assignment/removal"
  • Proper user attribution: Notes should show correct user name
  • Note sequencing: Kit assignment notes before location cascade notes
  • Consistent messaging: Same note format across all update methods

Note Creation Scenarios

  • Adding assets to located kit: Creates both kit assignment + location cascade notes
  • Adding assets to non-located kit: Creates kit assignment + location removal notes
  • Kit location updates: Creates location notes for all kit assets
  • Bulk operations: Creates individual notes for each affected asset

  1. UI/UX and Error Handling

Warning Messages and UI

  • All warning dialogs display correctly: Blue info style, proper messaging
  • Warning messages are contextual: Different messages for different scenarios
  • Location visibility: Location columns show current states with visual indicators
  • Responsive design: Warnings and tooltips work on mobile/tablet views
  • Accessibility: Screen readers can access warning content

  1. Edge Cases and Boundary Conditions

Complex Scenarios

  • Empty kits: Operations on kits with no assets
  • Assets already in correct location: Handle redundant location assignments
  • Circular references: Edge cases with complex kit-asset relationships
  • Rapid successive updates: Multiple quick changes don't cause conflicts
  • Kit status changes: Location cascade works with kits in different statuses

Data Integrity

  • Orphaned relationships: No broken kit-asset references
  • Location consistency: Kit and asset locations stay synchronized
  • Audit trail completeness: All changes properly logged with notes

Priority Testing Order

🔥 Critical (Must Test First)

  • Basic kit location cascade (individual and bulk)
  • Asset-to-kit addition cascade
  • Individual asset location blocking
  • Note creation and ordering

🟡 High Priority

  • UI warnings and error messages
  • Edge cases and error handling
  • Bulk operations with mixed selections

🟢 Medium Priority

  • Integration scenarios
  • Accessibility and responsive design

@carlosvirreira this is ready for testing and deployed to our staging environment. I made a detailed test overview with everything that should be tested. It might seem like it is a lot, but usually you can test multiple of them with a singular action so its not that bad.

@carlosvirreira
Copy link
Copy Markdown
Contributor

Kit Location Management Testing Results Summary

Working Correctly

Kit Location Cascade:

  • Move kit with assets to new location → Assets inherit location + proper activity logs
  • Remove location from kit with assets → Assets lose location + proper activity logs
  • Activity log format: "updated/removed location via parent kit assignment/removal"

Asset Location Blocking:

  • Asset edit page → Location field disabled with proper tooltip message
  • Bulk asset location updates → Properly blocked with descriptive error listing kit names
  • Asset index bulk selection → Cannot update kit assets, clear error message

Asset-to-Kit Addition:

  • Add assets to located kit → Shows location update notice, assets inherit kit location
  • Add assets to non-located kit → Shows removal notice, assets lose current location

Issues Found - Medium Priority

Inconsistent UI Behavior:

  • Kit edit page vs Actions dropdown → Different behavior for location updates (needs investigation)
  • Kit location removal → Only possible via Actions dropdown, not available on kit edit page
  • Kit selector on asset index → No search functionality (UX improvement needed)

Backend/Frontend Mismatch:

  • Asset actions "Update Location" → No preemptive blocking, fails on backend with generic error
  • Should show same blocking message as edit page or disable the action entirely

Bugs Found - High Priority

Critical Bug:

Minor Issues:

  • Asset management filtering → Cannot filter by specific kit when viewing "in other kits"
  • Generic error message → "Oops! Something went wrong" instead of descriptive kit-related error

Recommendations

Immediate Action Required:

  1. Fix asset removal bug when adding filtered assets to kits
  2. Implement consistent location blocking across all asset update routes
  3. Add kit location removal option to kit edit page

UX Improvements:

  1. Add search to kit selector components
  2. Improve error messages consistency
  3. Consider unified location update behavior between edit and actions

Testing Status: Core functionality works as designed, but critical bug requires immediate attention before production deployment.

@carlosvirreira
Copy link
Copy Markdown
Contributor

Additional Request: Activity Log Language Improvements

I suggest reviewing the language used in our activity logs for better user clarity. The current technical phrasing may confuse users.

Suggested Changes:

Current Log Suggested Improvement
"updated the location of Pegasian Boots from Cerberus Lair to Chambers of Xeric via parent kit assignment" "Moved with kit 'Defense Equipment' from Cerberus Lair to Chambers of Xeric"
"removed Pegasian Boots from location Chambers of Xeric via parent kit removal" "Location cleared because kit 'Defense Equipment' was removed from its location"
"removed Spectral Spirit Shield from location Corporeal Beast Lair via parent kit removal" "Location cleared because it was added to kit 'Magic Equipment' (kit has no location)"

Benefits:

  • Clearer user understanding of automated actions
  • Always includes kit name for context
  • Uses plain language instead of technical terms
  • Reduces potential support confusion

Critical Bug Fixes:
- Fixed bulk-add-to-kit removing existing assets by adding addOnly parameter to updateKitAssets
- Fixed custody status reset bug when adding assets to kits in custody
- Fixed kit edit page not cascading location updates to kit assets

UX Improvements:
- Replaced basic Select with advanced searchable KitSelector component
- Added real-time search, keyboard navigation, and improved error handling
- Standardized kit selection across all interfaces

Data Integrity:
- Ensured consistent location management between kit edit page and actions dropdown
- Maintained backward compatibility while fixing asset removal logic
- Proper custody handling in bulk operations

Technical Changes:
- Created reusable KitSelector component based on CurrencySelector pattern
- Updated bulk-add-to-kit-dialog to use new selector component
- Modified updateKitAssets to support addOnly mode for bulk operations
- Enhanced kit edit action to use updateKitLocation for proper asset cascading
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 47 out of 47 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

app/routes/_layout+/locations.$locationId.scan-assets-kits.tsx:67

  • [nitpick] The title mentions 'Scan assets' but this route now handles both assets and kits. Consider updating to 'Scan assets and kits for location' to be more accurate.
    const title = `Scan assets for location | ${location.name}`;

app/components/kits/actions-dropdown.tsx:29

  • The function parameter destructuring is missing the type annotation. Consider adding the Props interface to maintain consistency with the other ActionsDropdown component in the codebase.
export default function ActionsDropdown({
  fullWidth,
}: {

Comment thread app/routes/_layout+/locations.$locationId.kits.tsx Outdated
Comment thread app/components/scanner/drawer/uses/update-location-drawer.tsx Outdated
Comment thread app/modules/asset/service.server.ts
@carlosvirreira
Copy link
Copy Markdown
Contributor

I have found no more issues here. This can be shipped. @DonKoko

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@DonKoko DonKoko merged commit 58b83e4 into Shelf-nu:main Sep 15, 2025
6 checks passed
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.

[Discussion request]: Kits locations

4 participants