CB-3600 support files aggregation (#1813)

* CB-3600 support files aggregation

* CB-3600 notify about duplicates

---------

Co-authored-by: dariamarutkina <125263541+dariamarutkina@users.noreply.github.com>
This commit is contained in:
alex
2023-07-14 15:15:34 +03:00
committed by GitHub
co-authored by dariamarutkina
parent 872c226522
commit ba0cd2d3fa
5 changed files with 32 additions and 0 deletions
@@ -56,6 +56,8 @@ type BaseProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' |
mod?: 'surface';
ref?: React.Ref<HTMLInputElement>;
style?: ComponentStyle;
aggregate?: boolean;
onDuplicate?: (files: File[]) => void;
};
type ControlledProps = BaseProps & {
@@ -101,7 +103,9 @@ export const InputFiles: InputFilesType = observer(
large,
tiny,
autoHide,
aggregate,
onChange,
onDuplicate,
...rest
}: ControlledProps | ObjectProps<any, any>,
refInherit: React.Ref<HTMLInputElement>,
@@ -120,6 +124,30 @@ export const InputFiles: InputFilesType = observer(
}
function setValue(value: FileList | null) {
if (aggregate) {
if (value) {
const currentFiles = Array.from(innerState || []);
const newFiles = Array.from(value);
const existingFiles = new Set();
const aggregation = new DataTransfer();
for (const file of [...currentFiles, ...newFiles]) {
if (!existingFiles.has(file.name)) {
aggregation.items.add(file);
existingFiles.add(file.name);
}
}
const duplication = newFiles.filter(n => currentFiles.some(c => c.name === n.name));
if (duplication.length > 0) {
onDuplicate?.(duplication);
}
value = aggregation.files;
}
}
setInnerState(value);
if (state) {
state[name] = value;
@@ -97,6 +97,7 @@ export default [
['ui_file_size_exceeds', 'Max file size exceeds. File size: {arg:size}. Max file size: {arg:maxSize}'],
['ui_upload_file', 'Upload file'],
['ui_upload_files', 'Upload files'],
['ui_upload_files_duplicate_error', 'Files with the same name already exist'],
['root_permission_denied', "You don't have permissions"],
['root_permission_no_permission', "You don't have permission for this action"],
@@ -81,6 +81,7 @@ export default [
['ui_file_size_exceeds', 'Max file size exceeds. File size: {arg:size}. Max file size: {arg:maxSize}'],
['ui_upload_file', 'Upload file'],
['ui_upload_files', 'Upload files'],
['ui_upload_files_duplicate_error', 'Files with the same name already exist'],
['root_permission_denied', 'Non hai i permessi'],
['app_root_session_expire_warning_title', 'La sessione sta per scadere'],
@@ -93,6 +93,7 @@ export default [
['ui_file_size_exceeds', 'Максимальный размер файла превышен. Размер файла: {arg:size}. Максимальный размер: {arg:maxSize}'],
['ui_upload_file', 'Загрузить файл'],
['ui_upload_files', 'Загрузить файлы'],
['ui_upload_files_duplicate_error', 'Файлы с такими именами уже существуют'],
['root_permission_denied', 'Отказано в доступе'],
['root_permission_no_permission', 'У вас нет разрешения на это действие'],
@@ -94,6 +94,7 @@ export default [
['ui_file_size_exceeds', 'Max file size exceeds. File size: {arg:size}. Max file size: {arg:maxSize}'],
['ui_upload_file', 'Upload file'],
['ui_upload_files', 'Upload files'],
['ui_upload_files_duplicate_error', 'Files with the same name already exist'],
['root_permission_denied', '您没有权限'],
['root_permission_no_permission', '您没有权限执行此操作'],