feat(file-picker): add reference selection mode - #4085
doubleface wants to merge 3 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
BundleMonFiles updated (3)
Unchanged files (15)
Total files change +192B +0.01% Groups updated (1)
Unchanged groups (2)
Final result: ✅ View report in BundleMon website ➡️ |
| disabled: true, | ||
| reasonKey: 'FilePicker.constraints.disabledReasons.fileNotAllowed' | ||
| } | ||
| } |
There was a problem hiding this comment.
Why can't we use the "allowedMimeTypes" parameters?
I don't understand the needs of allowFolder & onlyFolder .
There was a problem hiding this comment.
Mime type only apply to files and not folders then I think we will need a specific option anyway. Or should we create our own custom mime type for folders ? I don't think so
There was a problem hiding this comment.
This is the adaptation from another branch from @paultranvan who did not have all the context. That is why this PR is still in draft. There is still some work to make it more compliant with the spec. I actually think onlyFolder or equivalent should not be only in reference section.
There was a problem hiding this comment.
We can have : image/** why not folder/** or io.cozy.files:folder or things like that?
Bu we should not add more attributes.
There was a problem hiding this comment.
Instead of adding onlyFolder (and keeping allowFolder), I'd rather collapse the whole "what can be selected" constraint into a single field. file and folder become symmetric tokens, and mime globs narrow within files. Two options:
Option A - flat accept list
"accept": ["folder"] // folders only
"accept": ["file"] // any file
"accept": ["image/*", "application/pdf"] // images + PDF only
"accept": ["folder", "image/*"] // folders or images
Rule: a token without / matches the doctype (file/folder); a token with / is a mime glob (implies a file).
Option B - structured match list
"match": [{ "type": "folder" }, { "mime": "image/*" }]
More verbose, but self-documenting and extensible to other fields later (class, tags, size).
In both cases it's an OR across entries (item allowed if it matches any), and this replaces allowFolder + onlyFolder + allowedMimeTypes with one field. Absent = ["file", "folder"] (permissive).
@zatteo If we were only for stack, I would go for Option B. It's way more flexible & extensible. But with openburo in mind, maybe we should take Option A? What is your opinion? And in this case, it could still be acceptedMimeTypes
There was a problem hiding this comment.
It is a good point that:
- we don't have any mimetype for folders in cozy-stack
- but the client of the file picker don't care
class or tags or favorite are internal drive metadata. So indeed, to stay close to what openburo could look like, we should go to option A that does not expose any internal and stay simple.
For class or tags or favorite, it is maybe more a filter in the file picker itself that could help, like a "favorite" checkbox or tab in the file picker itself if we want to quickly see favorite. I don't see any usecase where we want to force the user to select a favorite.
About size, we have the max size for a file but also the max size for all files that is a mail requirement. The max size for all files would be complicated to insert in this match so we still need size management outside of this.
So I would go to A right now. In anycase I like the accept name that is explicit & generic.
There was a problem hiding this comment.
accept option avoid the confusion with mime type and is really clear. And since we have to avoid to expose any internal, option A looks good.
For
classortagsorfavorite, it is maybe more a filter in the file picker itself that could help, like a "favorite" checkbox or tab in the file picker itself if we want to quickly see favorite. I don't see any usecase where we want to force the user to select a favorite.
Since we will have a tab for recents for example, we could have a tab for favorites also. And those filters look more like something to help the user to find the files he wants to pick.
If we agree, I could update the spec
| "reference": { | ||
| "label": "Select", | ||
| "onlyFolder": true | ||
| } |
There was a problem hiding this comment.
what do you call reference? Only the io.cozy.files document?
I don't like the naming, but I've nothing yet to suggest.
There was a problem hiding this comment.
What we call a reference is "doctype + _id". Since the file picker will on return files or folder, I suppose we could remove the doctype part.
Maybe we could replace the reference with identifier ?
There was a problem hiding this comment.
I don't like identifier specially because I've that in mind: #4085 (comment)
There was a problem hiding this comment.
In this case, and if we want to return the full document, we could call it documents ?
There was a problem hiding this comment.
if it's identifier with type, it can be doc as everywhere in stack, json, data, obj if we want to return the whole json doc
| sharingLink?: string | ||
| downloadLink?: string | ||
| type?: string | ||
| doctype?: 'io.cozy.files' |
There was a problem hiding this comment.
why it's not the full FileDoctype Type from cozy-client?
There was a problem hiding this comment.
Good point. Then, if we return the full document, we could replace reference simply with documents (since we may return multiple documents) ?
| ...(downloadLink ? { downloadLink } : {}) | ||
| ...(downloadLink ? { downloadLink } : {}), | ||
| ...(reference ? { type: file.type, doctype: 'io.cozy.files' } : {}) | ||
| }) |
There was a problem hiding this comment.
if we ask a "reference" we should return the reference. So the complete io.cozy.files.
I'm wondering if we should not do the same for the other actions.
It should be caller responsibility to ask only specific fields.
There was a problem hiding this comment.
What we really want to achieve with reference is to not create a sharing or download link right @doubleface ?
There was a problem hiding this comment.
I'm wondering if we should not do the same for the other actions.
Good question, should we always return the full io.cozy.files and in some case "more" like a download link or a sharing link?
There was a problem hiding this comment.
I think yes. And if the caller do not need to handle the full io.cozy.files, then it can specified the desired attributes (because for exemple, a note is a big io.cozy.files...). No?
There was a problem hiding this comment.
What we really want to achieve with reference is to not create a sharing or download link right @doubleface ?
yes
There was a problem hiding this comment.
I'm wondering if we should not use this "reference" mode if there is any action set by the caller. Maybe it should be the default one.
There was a problem hiding this comment.
I'm wondering if we should not use this "reference" mode if there is any action set by the caller. Maybe it should be the default one.
Agree!
There was a problem hiding this comment.
I agree. The default action should be the one with no side effect
d37f96e to
3e05778
Compare
4384fbb to
5721916
Compare
5721916 to
fdf1d83
Compare
|
I like it a lot with this new specification. Even if sometimes the io.cozy.files document can return a lot of data, e.g. with a cozy-notes, I consider this as a feature for now. We will see in the future if sometimes we send too much data but there is no reason otherwise to not send the entire io.cozy.files document. |
| "sharingLink": { "label": "Share as link" }, | ||
| "doc": { | ||
| "label": "Select", | ||
| "accept": ["folder"] |
There was a problem hiding this comment.
I am skeptical about application/x-directory as it is non standard and we still need a custom value for "all files" so it does not solve entirely our problem.
Or maybe creating our own ones?
- application/vnd.twake.file => means all files
- application/vnd.twake.folder => means all folders
It fit in mimetype mental model and allow custom needs.
Allow PICK intents to return plain file references without generating sharing or download links. Keep the action opt-in, support folder-only constraints and multiple selection, and document the payload for callers.
Expose selected Cozy documents without mapping fields so callers receive cozy-client's complete file and folder shape. Rename the action to `documents` to reflect its array result.
87fd8fb to
22548d0
Compare
There was a problem hiding this comment.
Code Health Improved
(1 files improve in Code Health)
Our agent can fix these. Install it.
Gates Passed
3 Quality Gates Passed
View Improvements
| File | Code Health Impact | Categories Improved |
|---|---|---|
| FilePickerFooter.jsx | 9.69 → 10.00 | Excess Number of Function Arguments |
Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
Allow PICK intents to return plain file references without generating sharing or download links. Keep the action opt-in, support folder-only constraints and multiple selection, and document the payload for callers.