Skip to content

Conversation

@jfox-box
Copy link
Contributor

@jfox-box jfox-box commented Sep 4, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Selection now stays in sync with visible items when the file list changes (e.g., after item updates or metadata queries), preventing selections of items no longer present.
    • Eliminates stale or mismatched selection states so badges and bulk actions accurately reflect the current collection.
    • Improves consistency when switching collections or updating metadata, reducing user confusion and unintended actions.

@jfox-box jfox-box requested a review from a team as a code owner September 4, 2025 21:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

I pity the fool who loses selection—this change adds an internal method to validate and reconcile selectedItemIds with the currently loaded items, and calls it after collection or metadata updates to keep selection state consistent (short-circuits for all or empty selections).

Changes

Cohort / File(s) Summary
ContentExplorer selection validation
src/elements/content-explorer/ContentExplorer.tsx
Added validateSelectedItemIds(items: BoxItem[]): void; imported lodash/isEqual; invoke validation after building/updating currentCollection.items in updateItemInCollection, and after metadata-update flows in updateMetadataSuccessCallback and showMetadataQueryResultsSuccessCallback to sync selectedItemIds with current items.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User / External Trigger
  participant CE as ContentExplorer
  participant V as validateSelectedItemIds

  rect rgb(245,248,255)
    note over CE: Collection / metadata update flow
    U->>CE: Trigger item update or metadata query
    CE->>CE: Update currentCollection.items (newCollection/items)
    CE->>V: validateSelectedItemIds(items)
    alt selection = 'all' or empty
      V-->>CE: short-circuit (no change)
    else
      V-->>CE: compute intersection, update selectedItemIds if different
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • greg-in-a-box
  • tjiang-box

Poem

I pity the fool with broken picks,
IDs scatterin' like busted bricks.
New validator marches in with flair,
Syncin' selections with stern glare.
Now content stands tidy, clean as new—oooh!


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP (Model Context Protocol) integration is disabled
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 217e5a4 and 78df0f9.

📒 Files selected for processing (1)
  • src/elements/content-explorer/ContentExplorer.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/elements/content-explorer/ContentExplorer.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Rule: Automatic merge queue (queue)
  • GitHub Check: lint_test_build
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Queue: Embarked in merge queue
  • GitHub Check: Summary
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch validate-selected-item-ids

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/elements/content-explorer/ContentExplorer.tsx (1)

1075-1083: Don’t use as const on newCollection when you mutate it, fool.

as const makes props effectively readonly and can cause TS errors when assigning newCollection.items = …. Remove it.

-        const newCollection = { ...currentCollection } as const;
+        const newCollection = { ...currentCollection };
 
         newCollection.items = items.map(item => (item.id === newItem.id ? newItem : item));
 
         this.validateSelectedItemIds(newCollection.items);
🧹 Nitpick comments (1)
src/elements/content-explorer/ContentExplorer.tsx (1)

8-8: Drop the extra baggage, fool — consider ditching lodash/isEqual for Set equality.

A tiny helper to compare two Sets saves bytes and avoids another import. Not blocking.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP (Model Context Protocol) integration is disabled
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1ba15df and 217e5a4.

📒 Files selected for processing (1)
  • src/elements/content-explorer/ContentExplorer.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint_test_build
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Summary
🔇 Additional comments (2)
src/elements/content-explorer/ContentExplorer.tsx (2)

428-429: Right call to validate after metadata query results.

Keeps selection honest with the latest items. I like it.


1739-1739: Nice: revalidating selection after metadata edits.

Prevents stale IDs hanging around. That’s tight.

@mergify mergify bot merged commit baaaa83 into master Sep 4, 2025
11 checks passed
@mergify mergify bot deleted the validate-selected-item-ids branch September 4, 2025 22:59
bfoxx1906 pushed a commit to bfoxx1906/box-ui-elements that referenced this pull request Sep 6, 2025
…ox#4268)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants