feat(content-uploader): allow host app to reset upload items state#4617
feat(content-uploader): allow host app to reset upload items state#4617olehrybak wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughContentUploader adds an optional ChangesUpload Item Clearing with Modernized Uploads
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
| 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 |
There was a problem hiding this comment.
Typo? manager instead of manger
| uploadHost: string; | ||
| useUploadsManager?: boolean; | ||
| enableModernizedUploads?: boolean; | ||
| setClearItemsCallback?: (callback: () => void) => void; |
There was a problem hiding this comment.
[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
There was a problem hiding this comment.
Yeah, makes sense, added setting of the clear callback to noop on unmount
reneshen0328
left a comment
There was a problem hiding this comment.
Code logic makes sense to me, approved!
| uploadHost: string; | ||
| useUploadsManager?: boolean; | ||
| enableModernizedUploads?: boolean; | ||
| setClearItemsCallback?: (callback: () => void) => void; |
There was a problem hiding this comment.
can we follow the naming pattern of other props and call this something like onClear / onReset?
There was a problem hiding this comment.
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.
Summary
Currently the state of the upload items is reset internally in the
ContentUploaderby callingresetUploadsManagerItemsWhenUploadsCompletemethod with a timer. This PR allows to registerresetUploadsManagerItemsWhenUploadsCompleteas a callback that can be used in the host application usingsetClearItemsCallbackand 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