Skip to content
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

Merged

Conversation

vsgoulart
Copy link
Contributor

Related to #1239

  • This PR adds a new form-js element or visually changes an existing component.

@vsgoulart vsgoulart requested a review from Skaiir August 25, 2024 18:31
@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Aug 25, 2024
@@ -168,9 +168,12 @@ export class Form {

const errors = this.validate();

const files = this.get('fileRegistry').getAllFiles();
Copy link
Contributor

@Skaiir Skaiir Aug 26, 2024

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).

Copy link
Contributor Author

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`;
Copy link
Contributor

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.

image

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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}
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Aug 26, 2024
@vsgoulart vsgoulart requested a review from Skaiir August 26, 2024 18:36
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Aug 26, 2024
@@ -2,256 +2,37 @@
"$schema": "../../../form-json-schema/resources/schema.json",
"components": [
{
"type": "expression",
Copy link
Contributor

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?

Copy link
Contributor Author

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 () => {
Copy link
Contributor

@Skaiir Skaiir Aug 27, 2024

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.

image

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`;
Copy link
Contributor

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.

@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Aug 27, 2024
@vsgoulart vsgoulart force-pushed the 1239-file-input-element branch from 68dea73 to 4397dd6 Compare September 2, 2024 12:40
@vsgoulart vsgoulart force-pushed the 1239-file-input-element-file-registry branch from 6ae8c2a to d78ecc5 Compare September 2, 2024 12:48
@vsgoulart vsgoulart requested a review from Skaiir September 3, 2024 18:41
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Sep 3, 2024

export const RepeatRenderModule = {
__init__: ['repeatRenderManager'],
repeatRenderManager: ['type', RepeatRenderManager],
fileRegistry: ['type', FileRegistry],
Copy link
Contributor

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.

@Skaiir Skaiir force-pushed the 1239-file-input-element-file-registry branch from d0f0455 to 33d404c Compare September 5, 2024 09:20
@Skaiir Skaiir force-pushed the 1239-file-input-element-file-registry branch from 33d404c to df63741 Compare September 5, 2024 09:23
@Skaiir Skaiir self-requested a review September 6, 2024 15:22
@vsgoulart vsgoulart force-pushed the 1239-file-input-element-file-registry branch from 0d63501 to 0bf66bf Compare September 9, 2024 08:41
@vsgoulart vsgoulart merged commit e4ff280 into 1239-file-input-element Sep 9, 2024
11 of 12 checks passed
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Sep 9, 2024
@vsgoulart vsgoulart deleted the 1239-file-input-element-file-registry branch September 9, 2024 08:48
vsgoulart added a commit that referenced this pull request Sep 9, 2024
* 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]>
vsgoulart added a commit that referenced this pull request Sep 13, 2024
* 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]>
vsgoulart added a commit that referenced this pull request Sep 23, 2024
* 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]>
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.

2 participants