Skip to content

Commit

Permalink
fix: server validation error rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Feb 12, 2024
1 parent 3152640 commit 9a5d510
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 9a5d510

Please sign in to comment.