-
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
Merged
vsgoulart
merged 23 commits into
1239-file-input-element
from
1239-file-input-element-file-registry
Sep 9, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
29b2ab4
feat: implement file registry on filepicker
vsgoulart 9adcef4
fix: fix file registry key
vsgoulart d8856b6
fix: delete file when dynamic list item is deleted
vsgoulart d78ecc5
test: fix filepicker tests
vsgoulart 47df9ab
chore: revert unnecessary change
vsgoulart 4ce9952
fix: properly handle dynamic lists deletion
vsgoulart ae551a7
fix: set input file value after expanding dynamic list items
vsgoulart e815aa2
test: fix tests
vsgoulart 093c725
fix: trim all files from a dynamic list subtree
vsgoulart ff19c18
fix: refactor form field instance registry
Skaiir 596aff5
chore: added `useBooleanExpressionEvaluation` hook
Skaiir c4bdaac
fix: improve file picker reliability
Skaiir df63741
chore: changed filepicker prefix to `files::`
Skaiir 8b36418
fix: ensure the hidden filepicker gets disabled as well
Skaiir 66fcf4f
chore: adjust filepicker tests
Skaiir 53c0b51
chore: cleanup formFieldInstanceRegistry tests
Skaiir 59549dc
refactor: Improve typing
vsgoulart 62dd997
refactor: Improve variable naming
vsgoulart 5899ff6
fix: fix dynamic list expand button label
vsgoulart f8c8137
fix: prevent collapsed dynamic list items from unmounting
vsgoulart 99efb59
refactor: Remove unnecessary method, improve types and delete files o…
vsgoulart 17a535f
test: remove duplicated test
vsgoulart 0bf66bf
fix: clear file references to deleted files
Skaiir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { extractFileReferencesFromRemovedData } from '../util/extractFileReferencesFromRemovedData'; | ||
|
||
const fileRegistry = Symbol('fileRegistry'); | ||
const eventBusSymbol = Symbol('eventBus'); | ||
const formFieldRegistrySymbol = Symbol('formFieldRegistry'); | ||
const formFieldInstanceRegistrySymbol = Symbol('formFieldInstanceRegistry'); | ||
const EMPTY_ARRAY = []; | ||
|
||
class FileRegistry { | ||
/** | ||
* @param {import('../core/EventBus').EventBus} eventBus | ||
* @param {import('../core/FormFieldRegistry').FormFieldRegistry} formFieldRegistry | ||
* @param {import('../core/FormFieldInstanceRegistry').FormFieldInstanceRegistry} formFieldInstanceRegistry | ||
*/ | ||
constructor(eventBus, formFieldRegistry, formFieldInstanceRegistry) { | ||
/** @type {Map<string, File[]>} */ | ||
this[fileRegistry] = new Map(); | ||
/** @type {import('../core/EventBus').EventBus} */ | ||
this[eventBusSymbol] = eventBus; | ||
/** @type {import('../core/FormFieldRegistry').FormFieldRegistry} */ | ||
this[formFieldRegistrySymbol] = formFieldRegistry; | ||
/** @type {import('../core/FormFieldInstanceRegistry').FormFieldInstanceRegistry} */ | ||
this[formFieldInstanceRegistrySymbol] = formFieldInstanceRegistry; | ||
|
||
const removeFileHandler = ({ item }) => { | ||
const fileReferences = extractFileReferencesFromRemovedData(item); | ||
|
||
// Remove all file references from the registry | ||
fileReferences.forEach((fileReference) => { | ||
this.deleteFiles(fileReference); | ||
}); | ||
}; | ||
|
||
eventBus.on('form.clear', () => this.clear()); | ||
eventBus.on('conditionChecker.remove', removeFileHandler); | ||
eventBus.on('repeatRenderManager.remove', removeFileHandler); | ||
} | ||
|
||
/** | ||
* @param {string} id | ||
* @param {File[]} files | ||
*/ | ||
setFiles(id, files) { | ||
this[fileRegistry].set(id, files); | ||
} | ||
|
||
/** | ||
* @param {string} id | ||
* @returns {File[]} | ||
*/ | ||
getFiles(id) { | ||
return this[fileRegistry].get(id) || EMPTY_ARRAY; | ||
} | ||
|
||
/** | ||
* @returns {string[]} | ||
*/ | ||
getKeys() { | ||
return Array.from(this[fileRegistry].keys()); | ||
} | ||
|
||
/** | ||
* @param {string} id | ||
* @returns {boolean} | ||
*/ | ||
hasKey(id) { | ||
return this[fileRegistry].has(id); | ||
} | ||
|
||
/** | ||
* @param {string} id | ||
*/ | ||
deleteFiles(id) { | ||
this[fileRegistry].delete(id); | ||
} | ||
|
||
/** | ||
* @returns {Map<string, File[]>} | ||
*/ | ||
getAllFiles() { | ||
return new Map(this[fileRegistry]); | ||
} | ||
|
||
clear() { | ||
this[fileRegistry].clear(); | ||
} | ||
} | ||
|
||
FileRegistry.$inject = ['eventBus', 'formFieldRegistry', 'formFieldInstanceRegistry']; | ||
|
||
export { FileRegistry }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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