Implement Uppy uploader metadata editing and event handling#2288
Implement Uppy uploader metadata editing and event handling#2288corovcam wants to merge 4 commits intoinveniosoftware:masterfrom
Conversation
|
|
||
| Object.keys(files).forEach((fileID) => { | ||
| const file = files[fileID]; | ||
| file.meta["metadata"] = file.meta?.metadata || {}; |
There was a problem hiding this comment.
direct mutation of file.meta - should be immutable
There was a problem hiding this comment.
Well, originally file.meta is used by Uppy to update values from UI fields in metadata editor, but we also use file.meta to add additional info during multipart handling logic (e.g. parts). To distinguish between the Uppy and Multipart logic, I rather copied the Uppy fields into file.meta.metadata, and changed a bit Multipart uppy state updates to not override it.
| mapDispatchToProps | ||
| )(UppyUploaderComponent); | ||
|
|
||
| export { UPPY_EVENTS } from "./events"; |
There was a problem hiding this comment.
Only used internally, is there a reason to export for other parts of UI?
There was a problem hiding this comment.
To make available events a public enum. Not just a string literal. But it's optional ofc.
| onBeforeUpload: (files) => { | ||
| return activeAllowedMetaFields && activeAllowedMetaFields.length > 0 | ||
| ? onBeforeUploadProcessMetaFields(files, activeAllowedMetaFields) | ||
| : files; |
There was a problem hiding this comment.
Shadows variable from outer scope
|
This would require also a PR to InvenioRDM docs. Explaining, how instance admins could add certain metadata fields to certain file type: https://github.com/inveniosoftware/docs-invenio-rdm/blob/2a8d853626d756717e692c035b80ea24483143f2/docs/operate/customize/file-uploads/uploader.md?plain=1 |
Currently it is unclear how metadata fields could be passed to deposit form config, If, say, I want to annotate all |
| * @property {function(Object, Function): Object} [metaFields[].render] - Optional custom render function for advanced UI rendering of the field using Preact `h` function. If not provided, a standard text input will be rendered when `name` is set. See {@link https://uppy.io/docs/dashboard/#metafields|Uppy Dashboard metaFields documentation}. | ||
| * @property {function(Object): Boolean} [metaFields[].condition] - Optional function to conditionally attach or render the field based on the respective file properties (e.g. file.type). | ||
| */ | ||
| export const defaultAllowedMetaFields = [ |
There was a problem hiding this comment.
Commented out example doesn't work, remove or fix (input is not writeable):
Screen.Recording.2026-04-02.at.10.35.29.mov
There was a problem hiding this comment.
It does not work, because of inveniosoftware/invenio-app-rdm#3386. Both PRs need to be merged to make Uppy components display correctly.
| * @param {Object} uppyFiles - The Uppy files object dictionary. | ||
| * @param {Object} invenioFiles - The files object from Invenio. | ||
| * @param {Array<Object>} allowedMetaFields - Configuration for metadata fields. | ||
| * @returns {Object} Updated files dictionary. |
There was a problem hiding this comment.
Type inconsistency, the function returns updatedFiles but the docstring doesn’t fully explain when/why it’s needed. Could potentially return an empty object if there are no uppyFiles.
| * - The default implementation calls out to Companion’s S3 signing endpoints. | ||
| */ | ||
| async completeMultipartUpload(file) { | ||
| if (file.meta?.metadata && Object.keys(file.meta.metadata).length > 0 && this.opts.updateFileMetadata) { |
There was a problem hiding this comment.
If metadata update fails, the whole upload will fail without calling finalize, will it be properly cleaned up? I think finalize will handle cleanup properly if it fails
| uppy.setOptions({ | ||
| onBeforeUpload: (uppyFiles) => { | ||
| return activeAllowedMetaFields && activeAllowedMetaFields.length > 0 | ||
| ? onBeforeUploadProcessMetaFields(uppyFiles, files, activeAllowedMetaFields) |
There was a problem hiding this comment.
Files from closure not in deps, could get stale
|
Added docs for this: inveniosoftware/docs-invenio-rdm#926 |
Replaced: #2278
❤️ Thank you for your contribution!
Description
Implemented modular metadata editing support in the Uppy uploader and refactored event handling for better extensibility and maintainability.
Main changes:
Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Frontend
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: