Skip to content

feat(content-uploader): allow host app to reset upload items state#4617

Open
olehrybak wants to merge 3 commits into
box:masterfrom
olehrybak:modernized-uploads-clear-state
Open

feat(content-uploader): allow host app to reset upload items state#4617
olehrybak wants to merge 3 commits into
box:masterfrom
olehrybak:modernized-uploads-clear-state

Conversation

@olehrybak

@olehrybak olehrybak commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Currently the state of the upload items is reset internally in the ContentUploader by calling resetUploadsManagerItemsWhenUploadsComplete method with a timer. This PR allows to register resetUploadsManagerItemsWhenUploadsComplete as a callback that can be used in the host application using setClearItemsCallback and disables internal state reset for modernized uploader. This change ensures that the modernized uploads experience is more flexible and can be adjusted to the requirements in the host applications.

Summary by CodeRabbit

  • Bug Fixes
    • Improved upload-item clearing so items are retained while the upload view/manager is active and are reliably cleared when uploads complete, including with the modernized uploads flow; added support for wiring an external “clear items after uploads complete” callback.
  • Tests
    • Added coverage for lifecycle and clearing behaviors to prevent regressions in upload cleanup logic.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8c249aa9-4b4a-41e1-a17f-35dc3c3851dc

📥 Commits

Reviewing files that changed from the base of the PR and between 5cdef38 and c0650f0.

📒 Files selected for processing (1)
  • src/elements/content-uploader/ContentUploader.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/elements/content-uploader/ContentUploader.tsx

Walkthrough

ContentUploader adds an optional setClearItemsCallback prop that parents can use; componentDidMount wires resetUploadsManagerItemsWhenUploadsComplete when provided. Clearing behavior now skips delayed clear when enableModernizedUploads is true and adjusts early-return logic to account for that flag and manager/view state.

Changes

Upload Item Clearing with Modernized Uploads

Layer / File(s) Summary
Callback contract and mount wiring
src/elements/content-uploader/ContentUploader.tsx
ContentUploaderProps adds an optional setClearItemsCallback prop. On mount, the component calls it with resetUploadsManagerItemsWhenUploadsComplete when provided; on unmount it registers a noop.
Clearing behavior for modernized uploads
src/elements/content-uploader/ContentUploader.tsx
checkClearUploadItems returns immediately when enableModernizedUploads is true (disabling delayed clear). resetUploadsManagerItemsWhenUploadsComplete updates its early-return logic to exclude the expanded-manager/items short-circuit when modernized uploads are enabled while keeping the VIEW_UPLOAD_IN_PROGRESS short-circuit.
Lifecycle and clearing behavior tests
src/elements/content-uploader/__tests__/ContentUploader.test.js
Adds tests: mount wiring for setClearItemsCallback, checkClearUploadItems scheduling behavior with fake timers for modernized vs legacy flows, and multiple resetUploadsManagerItemsWhenUploadsComplete scenarios covering manager expansion, useUploadsManager, view, and the feature flag.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • jpan-box
  • tjiang-box
  • reneshen0328

Poem

🐰 A tiny rabbit hops and gleams,
I wire a callback into streams,
When uploads finish, I softly sweep,
Clearing items while others sleep,
A tidy trail where data gleams.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: allowing host applications to reset upload items state through a callback mechanism.
Description check ✅ Passed The description clearly explains the purpose (registering a callback for host app control), the problem it solves (disabling internal timer-based reset for modernized uploads), and the benefits (flexibility for host applications).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@olehrybak olehrybak marked this pull request as ready for review June 10, 2026 09:27
@olehrybak olehrybak requested review from a team as code owners June 10, 2026 09:27

@Omfalos Omfalos left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lgtm

const { isUploadsManagerExpanded, view } = this.state;

// Do not reset items when upload manger is expanded or there're uploads in progress
// Do not reset items when upload manger is expanded (for non-modernized uploader) or there're uploads in progress

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo? manager instead of manger

uploadHost: string;
useUploadsManager?: boolean;
enableModernizedUploads?: boolean;
setClearItemsCallback?: (callback: () => void) => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Question] Does the host only calls this while the uploader is visibly mounted? If not perhaps it's safer to add this as a no-op into componentWillUnmount()?
Please correct me if I'm wrong but here's the concern:
The callback registered via setClearItemsCallback gives the host app a direct reference to this.resetUploadsManagerItemsWhenUploadsComplete. If ContentUploader unmounts while the host still holds that reference:

  • Host calls the function → this.setState(...) fires on an unmounted component (React will silently swallow it, but onCancel still fires against stale itemsRef data)
  • The host has no way to know the call was a no-op

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes sense, added setting of the clear callback to noop on unmount

reneshen0328
reneshen0328 previously approved these changes Jun 10, 2026

@reneshen0328 reneshen0328 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code logic makes sense to me, approved!

uploadHost: string;
useUploadsManager?: boolean;
enableModernizedUploads?: boolean;
setClearItemsCallback?: (callback: () => void) => void;

@tjuanitas tjuanitas Jun 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we follow the naming pattern of other props and call this something like onClear / onReset?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nvm I see what's happening here. why do you need to call the reset callback outside of ContentUploader?

Ideally, all the functionality should live within the UI Element (ContentUploader) and not within the host applications. The UI Elements (like ContentUploader, ContentSidebar, etc) are supposed to be self-contained, essentially "uncontrolled" components. We publish these elements for external customers to use in their own applications.

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.

4 participants