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 d5e240b commit c494d4b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 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
6 changes: 5 additions & 1 deletion packages/components/file/src/js/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@
<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.type"
ng-bind="::$ctrl.translations.typeError">
</span>
</span>
<button class="oui-file-attachments__remove oui-icon oui-icon-close"
type="button"
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 @@ -12,6 +12,7 @@ export default class {
filesSelector: 'Select file(s)...',
maxsizeError: 'This file exceeds the size limit',
removeFile: 'Remove file from selector',
typeError: 'This file extension is not supported',
};

this.units = [
Expand Down

0 comments on commit c494d4b

Please sign in to comment.