-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement file registry on filepicker #1246
feat: implement file registry on filepicker #1246
Conversation
@@ -168,9 +168,12 @@ export class Form { | |||
|
|||
const errors = this.validate(); | |||
|
|||
const files = this.get('fileRegistry').getAllFiles(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be filtered based on the available instances. Otherwise it'll submit hidden files as well.
Lazy pseudocode:
const validFileRefs = instances
.filter(instance => instance.type === 'filepicker')
.map(instance => instance.value);
const filteredFiles = files.filter(file => validFileRefs.includes(file.value));
But first there's the issue of how these files are keyed (see other comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted the files when the component unmounts, this the logic is encapsulated on the component
const { field, onChange, domId, errors = [], disabled, readonly, required } = props; | ||
const { label, multiple = '', accept = '', id } = field; | ||
const evaluatedAccept = useSingleLineTemplateEvaluation(accept); | ||
const evaluatedMultiple = | ||
useSingleLineTemplateEvaluation(typeof multiple === 'string' ? multiple : multiple.toString()) === 'true'; | ||
const errorMessageId = `${domId}-error-message`; | ||
const filesKey = `${id}_value_key`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keying needs to be done differently. It needs to include the full path otherwise dynamic list keys will overwrite eachother. The id is unique only at the design level. The true id of an element at the render level is the full path / key of the element.
My prefered fileKey would be something like fileRef::${simpleHash(fullPath)}
. Hashing is optional but it's more about the fact that it's mental overhead for the users for it to be actually readable. Also I know some people will try to reverse engineer the path from it which is not something I'd like to encourage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't do the hashing, I'm not sure if I agree with the mental overhead point.
Anyway, this can be easily fixed tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess on this one we can defer to @volodymyr-melnykc for a decision.
setSelectedFiles(files); | ||
}} | ||
/> | ||
<div className="fjs-filepicker-container"> | ||
<button | ||
type="button" | ||
disabled={disabled} | ||
disabled={disabled || readonly || fileRegistry === null} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, at the moment it's still possible to submit a file in the editor. I guess you're planning on adding a custom editor renderer for this anyways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, needs fixing for sure. I don't know if it's related to the label or something but when I click around on it in the editor, it opens the window, which can lead to an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned through Slack I couldn't reproduce it, maybe we can check it together tomorrow
@@ -2,256 +2,37 @@ | |||
"$schema": "../../../form-json-schema/resources/schema.json", | |||
"components": [ | |||
{ | |||
"type": "expression", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main start:playground schema, probably committed by error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
|
||
useEffect(() => { | ||
const reset = () => { | ||
return () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is that by design, hiding operations are not destructive, so that if someone hides something by accident they don't lose their progress. So I think we'll have to go the route I initially suggested as otherwise we orphan file references and have different behavior for the file picker and regular components.
This is what happened when I hide and show something again.
const { field, onChange, domId, errors = [], disabled, readonly, required } = props; | ||
const { label, multiple = '', accept = '', id } = field; | ||
const evaluatedAccept = useSingleLineTemplateEvaluation(accept); | ||
const evaluatedMultiple = | ||
useSingleLineTemplateEvaluation(typeof multiple === 'string' ? multiple : multiple.toString()) === 'true'; | ||
const errorMessageId = `${domId}-error-message`; | ||
const filesKey = `${id}_value_key`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess on this one we can defer to @volodymyr-melnykc for a decision.
68dea73
to
4397dd6
Compare
6ae8c2a
to
d78ecc5
Compare
|
||
export const RepeatRenderModule = { | ||
__init__: ['repeatRenderManager'], | ||
repeatRenderManager: ['type', RepeatRenderManager], | ||
fileRegistry: ['type', FileRegistry], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for future reference, we're registering this twice which I guess was due to a timing issue, but the modules access eachother. So probably here you needed either a __depends__
or to re-order some things.
d0f0455
to
33d404c
Compare
Related to #1239
33d404c
to
df63741
Compare
0d63501
to
0bf66bf
Compare
* feat: implement file registry on filepicker * fix: fix file registry key * fix: delete file when dynamic list item is deleted * test: fix filepicker tests * chore: revert unnecessary change * fix: properly handle dynamic lists deletion * fix: set input file value after expanding dynamic list items * test: fix tests * fix: trim all files from a dynamic list subtree * fix: refactor form field instance registry * chore: added `useBooleanExpressionEvaluation` hook * fix: improve file picker reliability Related to #1239 * chore: changed filepicker prefix to `files::` Related to #1239 * fix: ensure the hidden filepicker gets disabled as well Related to #1239 * chore: adjust filepicker tests * chore: cleanup formFieldInstanceRegistry tests Related to #1239 * refactor: Improve typing * refactor: Improve variable naming * fix: fix dynamic list expand button label * fix: prevent collapsed dynamic list items from unmounting * refactor: Remove unnecessary method, improve types and delete files on hide if events * test: remove duplicated test * fix: clear file references to deleted files Related to #1239 --------- Co-authored-by: Skaiir <[email protected]>
* feat: implement file registry on filepicker * fix: fix file registry key * fix: delete file when dynamic list item is deleted * test: fix filepicker tests * chore: revert unnecessary change * fix: properly handle dynamic lists deletion * fix: set input file value after expanding dynamic list items * test: fix tests * fix: trim all files from a dynamic list subtree * fix: refactor form field instance registry * chore: added `useBooleanExpressionEvaluation` hook * fix: improve file picker reliability Related to #1239 * chore: changed filepicker prefix to `files::` Related to #1239 * fix: ensure the hidden filepicker gets disabled as well Related to #1239 * chore: adjust filepicker tests * chore: cleanup formFieldInstanceRegistry tests Related to #1239 * refactor: Improve typing * refactor: Improve variable naming * fix: fix dynamic list expand button label * fix: prevent collapsed dynamic list items from unmounting * refactor: Remove unnecessary method, improve types and delete files on hide if events * test: remove duplicated test * fix: clear file references to deleted files Related to #1239 --------- Co-authored-by: Skaiir <[email protected]>
* feat: implement file registry on filepicker * fix: fix file registry key * fix: delete file when dynamic list item is deleted * test: fix filepicker tests * chore: revert unnecessary change * fix: properly handle dynamic lists deletion * fix: set input file value after expanding dynamic list items * test: fix tests * fix: trim all files from a dynamic list subtree * fix: refactor form field instance registry * chore: added `useBooleanExpressionEvaluation` hook * fix: improve file picker reliability Related to #1239 * chore: changed filepicker prefix to `files::` Related to #1239 * fix: ensure the hidden filepicker gets disabled as well Related to #1239 * chore: adjust filepicker tests * chore: cleanup formFieldInstanceRegistry tests Related to #1239 * refactor: Improve typing * refactor: Improve variable naming * fix: fix dynamic list expand button label * fix: prevent collapsed dynamic list items from unmounting * refactor: Remove unnecessary method, improve types and delete files on hide if events * test: remove duplicated test * fix: clear file references to deleted files Related to #1239 --------- Co-authored-by: Skaiir <[email protected]>
Related to #1239
form-js
element or visually changes an existing component.