Skip to content

Commit

Permalink
fix: server validation error rendering (#604)
Browse files Browse the repository at this point in the history
Co-authored-by: nd0ut <[email protected]>
  • Loading branch information
nd0ut and nd0ut authored Feb 13, 2024
1 parent 3152640 commit 3e9835b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class UploaderBlock extends ActivityBlock {
if (!this.$['*uploadCollection']) {
let uploadCollection = new TypedCollection({
typedSchema: uploadEntrySchema,
watchList: ['uploadProgress', 'fileInfo', 'errors', 'cdnUrl', 'isUploading'],
watchList: ['uploadProgress', 'uploadError', 'fileInfo', 'errors', 'cdnUrl', 'isUploading'],
});
this.$['*uploadCollection'] = uploadCollection;
}
Expand Down Expand Up @@ -498,9 +498,6 @@ export class UploaderBlock extends ActivityBlock {
entry.setValue('errors', errors);
}

/** @private */
_debouncedRunFileValidators = debounce(this._runFileValidators.bind(this), 100);

/**
* @private
* @param {string[]} [entryIds]
Expand Down Expand Up @@ -626,16 +623,20 @@ export class UploaderBlock extends ActivityBlock {
this._flushOutputItems();

const uploadCollection = this.uploadCollection;
const updatedEntryIds = [
const entriesToRunValidation = [
...new Set(
Object.entries(changeMap)
.filter(([key]) => key !== 'errors')
.filter(([key]) => ['uploadError', 'fileInfo'].includes(key))
.map(([, ids]) => [...ids])
.flat(),
),
];

this._debouncedRunFileValidators(updatedEntryIds);
entriesToRunValidation.length > 0 &&
setTimeout(() => {
// We can't modify entry properties in the same tick, so we need to wait a bit
this._runFileValidators(entriesToRunValidation);
});

if (changeMap.uploadProgress) {
for (const entryId of changeMap.uploadProgress) {
Expand Down

0 comments on commit 3e9835b

Please sign in to comment.