Skip to content

Commit

Permalink
fix(file): display error message for multiple files and code robustness
Browse files Browse the repository at this point in the history
ref: MANAGER-15044

Signed-off-by: Jacques Larique <[email protected]>
  • Loading branch information
Jacques Larique committed Sep 16, 2024
1 parent 843bf83 commit 3c10423
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/components/file/src/js/file.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export default class {
const hasTypeError = !acceptedTypes.some((acceptedType) => {
const [type, extension] = acceptedType.split('/');
if (extension) {
const isTypeValid = type === '*' || type.toLowerCase() === fileType.toLowerCase();
const isExtensionValid = extension === '*' || extension.toLowerCase() === fileExtension.toLowerCase();
const isTypeValid = type === '*' || type.toLowerCase() === fileType?.toLowerCase();
const isExtensionValid = extension === '*' || extension.toLowerCase() === fileExtension?.toLowerCase();
return isTypeValid && isExtensionValid;
}
return type === '*' || type.replace('.', '').toLowerCase() === fileExtension.toLowerCase();
return type === '*' || type.replace('.', '').toLowerCase() === fileExtension?.toLowerCase();
});
if (hasTypeError) {
file.errors.type = true;
Expand Down
8 changes: 6 additions & 2 deletions packages/components/file/src/js/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@
<span class="oui-file-ellipsis__size" ng-bind="file.infos.size"></span>
</span>
<span class="oui-file-attachments__error"
ng-if="file.errors && file.errors.maxsize"
ng-if="file.errors.maxsizeError"
ng-bind="::$ctrl.translations.maxsizeError">
</span>
<span class="oui-file-attachments__error"
ng-if="file.errors && file.errors.notSingle"
ng-if="file.errors.type"
ng-bind="::$ctrl.translations.typeError">
</span>
<span class="oui-file-attachments__error"
ng-if="file.errors.notSingle"
ng-bind="::$ctrl.translations.notSingleError">
</span>
</span>
Expand Down
1 change: 1 addition & 0 deletions packages/components/file/src/js/file.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class {
maxsizeError: 'This file exceeds the size limit',
notSingleError: 'You can only add one file',
removeFile: 'Remove file from selector',
typeError: 'This file extension is not supported',
};

this.units = [
Expand Down

0 comments on commit 3c10423

Please sign in to comment.