Merge pull request #565 from ONLYOFFICE/bugfix/65023

Fix Bug 65023 - Files. Added confirmation dialog when copying/moving …
This commit is contained in:
Alexey Safronov 2024-08-02 17:08:11 +04:00 committed by GitHub
commit c5fa8b9258
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 134 additions and 28 deletions

View File

@ -52,7 +52,7 @@ export interface ConflictResolveDialogProps {
visible: boolean;
setConflictResolveDialogVisible: (value: boolean) => void;
conflictResolveDialogData: TConflictResolveDialogData;
items: (TFile | TFolder)[];
items: (TFile & TFolder)[];
itemOperationToFolder: (data: {
destFolderId: number;
folderIds: number[];
@ -69,6 +69,7 @@ export interface ConflictResolveDialogProps {
setActiveFiles: (items: TActiveItem[]) => void;
setActiveFolders: (items: TActiveItem[]) => void;
updateActiveFiles: (items: TActiveItem[]) => void;
updateActiveFolders: (items: TActiveItem[]) => void;
setSelected: (value: string) => void;
setMoveToPanelVisible: (value: boolean) => void;
setRestorePanelVisible: (value: boolean) => void;
@ -90,4 +91,8 @@ export interface ConflictResolveDialogProps {
t: TTranslation,
create: boolean,
) => void;
isFileDialog: boolean;
isFolderDialog: boolean;
files: TFile[];
folders: TFolder[];
}

View File

@ -50,6 +50,7 @@ const ConflictResolveDialog = (props: ConflictResolveDialogProps) => {
setActiveFiles,
setActiveFolders,
updateActiveFiles,
updateActiveFolders,
setSelected,
setMoveToPanelVisible,
setRestorePanelVisible,
@ -59,6 +60,10 @@ const ConflictResolveDialog = (props: ConflictResolveDialogProps) => {
handleFilesUpload,
setShareCollectSelector,
openFileAction,
isFileDialog,
isFolderDialog,
files,
folders,
} = props;
const { t, ready } = useTranslation(["Common"]);
@ -68,7 +73,6 @@ const ConflictResolveDialog = (props: ConflictResolveDialogProps) => {
folderIds,
fileIds,
deleteAfter,
folderTitle,
isCopy,
translations,
isUploadConflict,
@ -115,16 +119,23 @@ const ConflictResolveDialog = (props: ConflictResolveDialogProps) => {
const onAcceptType = async (conflictResolveType: ConflictResolveType) => {
let newFileIds = fileIds;
let newFolderIds = folderIds;
let newActiveFiles = activeFiles;
let newActiveFolders = activeFolders;
if (conflictResolveType === ConflictResolveType.Skip) {
items.forEach((item) => {
newFileIds = newFileIds.filter((x) => x !== item.id);
newActiveFiles = newActiveFiles.filter((f) => f.id !== item.id);
files.forEach((file) => {
newFileIds = newFileIds.filter((x) => x !== file.id);
newActiveFiles = newActiveFiles.filter((f) => f.id !== file.id);
});
folders.forEach((folder) => {
newFolderIds = newFolderIds.filter((x) => x !== folder.id);
newActiveFolders = newActiveFolders.filter((f) => f.id !== folder.id);
});
}
updateActiveFiles(newActiveFiles);
if (!folderIds.length && !newFileIds.length) {
updateActiveFolders(newActiveFiles);
if (!newFolderIds.length && !newFileIds.length) {
setSelected("none");
onClosePanels();
return;
@ -199,29 +210,87 @@ const ConflictResolveDialog = (props: ConflictResolveDialogProps) => {
}
};
const messageText =
items.length === 1 ? (
const getMessageText = () => {
const singleFileMessage = (
<Trans
t={t}
ns="Common"
i18nKey="ConflictResolveDescription"
values={{ file: items[0].title, folder: folderTitle }}
components={{ 1: <span className="bold" /> }}
/>
) : (
<Trans
t={t}
ns="Common"
i18nKey="ConflictResolveDescriptionFiles"
values={{ filesCount: items.length, folder: folderTitle }}
i18nKey="FileActionRequired"
values={{ fileName: items[0].title }}
components={{ 1: <span className="bold" /> }}
/>
);
const singleFolderMessage = (
<Trans
t={t}
ns="Common"
i18nKey="FolderActionRequired"
values={{ folderName: items[0].title }}
components={{ 1: <span className="bold" /> }}
/>
);
return isFileDialog
? items.length === 1
? singleFileMessage
: t("Common:FilesAlreadyContains")
: isFolderDialog
? items.length === 1
? singleFolderMessage
: t("Common:FoldersAlreadyContains")
: t("Common:FilesAndFoldersAlreadyContains");
};
const getOverwriteTitle = () => {
return isFileDialog
? t("Common:OverwriteTitle")
: isFolderDialog
? t("Common:MergeFolders")
: t("Common:MergeAndOverwrite");
};
const getOverwriteDescription = () => {
return isFileDialog
? t("Common:OverwriteDescription")
: isFolderDialog
? t("Common:MergeFoldersDescription")
: t("Common:MultiplyOverwrite");
};
const getDuplicateTitle = () => {
return isFileDialog
? t("Common:CreateFileCopy")
: isFolderDialog
? t("Common:CopyAndKeepBothFolders")
: t("Common:CopyAndKeepAll");
};
const getDuplicateDescription = () => {
return isFileDialog
? t("Common:CreateDescription")
: isFolderDialog
? t("Common:CreateFolderDescription")
: t("Common:FoldersAndFilesWillBeCopied");
};
const getSkipDescription = () => {
return isFileDialog
? t("Common:SkipDescription")
: isFolderDialog
? t("Common:SkipFolderDescription")
: t("Common:FilesAndFolderWillNotBeCopied");
};
const messageText = getMessageText();
const overwriteTitle = getOverwriteTitle();
const overwriteDescription = getOverwriteDescription();
const duplicateTitle = getDuplicateTitle();
const duplicateDescription = getDuplicateDescription();
const skipDescription = getSkipDescription();
return (
<ConflictResolve
visible={visible}
headerLabel={t("Common:ConflictResolveTitle")}
headerLabel={t("Common:ActionRequired")}
isLoading={!ready}
onSubmit={isUploadConflict ? onAcceptUploadType : onAcceptType}
onClose={onCloseDialog}
@ -229,12 +298,12 @@ const ConflictResolveDialog = (props: ConflictResolveDialogProps) => {
submitButtonLabel={t("Common:OKButton")}
messageText={messageText}
selectActionText={t("Common:ConflictResolveSelectAction")}
overwriteTitle={t("Common:OverwriteTitle")}
overwriteDescription={t("Common:OverwriteDescription")}
duplicateTitle={t("Common:CreateFileCopy")}
duplicateDescription={t("Common:CreateDescription")}
overwriteTitle={overwriteTitle}
overwriteDescription={overwriteDescription}
duplicateTitle={duplicateTitle}
duplicateDescription={duplicateDescription}
skipTitle={t("Common:SkipTitle")}
skipDescription={t("Common:SkipDescription")}
skipDescription={skipDescription}
/>
);
};
@ -263,9 +332,17 @@ export default inject<TStore>(
setActiveFiles,
setActiveFolders,
updateActiveFiles,
updateActiveFolders,
setSelected,
} = filesStore;
const files = items
? items.filter((f) => (f.fileExst || f.contentLength) && f)
: [];
const folders = items
? items.filter((f) => !f.fileExst && !f.contentLength && f)
: [];
return {
items,
visible,
@ -277,6 +354,7 @@ export default inject<TStore>(
setActiveFiles,
setActiveFolders,
updateActiveFiles,
updateActiveFolders,
setSelected,
setMoveToPanelVisible,
setRestorePanelVisible,
@ -286,6 +364,10 @@ export default inject<TStore>(
handleFilesUpload,
setShareCollectSelector,
openFileAction,
files,
folders,
isFileDialog: !folders.length,
isFolderDialog: !files.length,
};
},
)(observer(ConflictResolveDialog));

View File

@ -820,6 +820,10 @@ class FilesStore {
this.activeFiles = items;
};
updateActiveFolders = (items) => {
this.activeFolders = items;
};
clearFiles = () => {
this.setFolders([]);
this.setFiles([]);

View File

@ -37,7 +37,6 @@ function ConflictResolveDialog({
reject,
resolve,
fileName,
folderName,
}: ConflictResolveProps) {
const { t } = useTranslation(["Common"]);
@ -53,8 +52,8 @@ function ConflictResolveDialog({
<Trans
t={t}
ns="Common"
i18nKey="ConflictResolveDescription"
values={{ file: fileName, folder: folderName }}
i18nKey="FileActionRequired"
values={{ fileName }}
components={{ 1: <strong className="bold" /> }}
/>
}
@ -65,7 +64,7 @@ function ConflictResolveDialog({
duplicateDescription={t("CreateDescription")}
skipTitle={t("SkipTitle")}
skipDescription={t("SkipDescription")}
headerLabel={t("ConflictResolveTitle")}
headerLabel={t("ActionRequired")}
/>
);
}

View File

@ -58,6 +58,12 @@
"ConflictResolveDescriptionFiles": "{{filesCount}} documents with the same name already exist in the folder <1>{{folder}}</1>.",
"ConflictResolveSelectAction": "Please select the action:",
"ConflictResolveTitle": "Overwrite confirmation",
"ActionRequired": "Action required",
"FileActionRequired": "The destination already contains a file named «<1>{{fileName}}</1>».",
"FolderActionRequired": "The destination already contains a folder named «<1>{{folderName}}</1>».",
"FilesAlreadyContains": "The destination already contains files with the same name.",
"FoldersAlreadyContains": "The destination already contains folders with the same name.",
"FilesAndFoldersAlreadyContains": "The destination already contains files and folders with the same name.",
"Connect": "Connect",
"Content": "Content",
"Context": "Context",
@ -72,7 +78,11 @@
"CreateAndCopy": "Create and copy",
"CreateCopy": "Create copy",
"CreateDescription": "There will be two different files in the folder.",
"CreateFolderDescription": "There will be two different folders in the destination",
"FoldersAndFilesWillBeCopied": "Folders and files will be copied in the destination",
"CreateFileCopy": "Create file copy",
"CopyAndKeepBothFolders": "Copy and keep both folders",
"CopyAndKeepAll": "Copy and keep all",
"CreateFormFillingRoom": "Create Form filling room",
"CreateMasterFormFromFile": "Create Form Template from file",
"CreatePDFForm": "Create PDF Form",
@ -306,6 +316,10 @@
"OtherOperations": "Other operations",
"OverwriteDescription": "The new file will replace the existing one as a new version.",
"OverwriteTitle": "Overwrite with version update",
"MergeFolders": "Merge folders",
"MergeFoldersDescription": "Two folders will be merged into one with all the contents",
"MergeAndOverwrite": "Merge and overwrite",
"MultiplyOverwrite": "Several folders will be merged into one, files will be overwritten with the version update",
"Owner": "Owner",
"PageOfTotalPage": "{{page}} of {{totalPage}}",
"Paid": "Paid",
@ -437,6 +451,8 @@
"Size": "Size",
"SizeImageLarge": "The image size is too large, please select another image.",
"SkipDescription": "No file will be copied. The original file will be retained in the destination folder.",
"SkipFolderDescription": "No folder will be copied",
"FilesAndFolderWillNotBeCopied": "Files and folder will not be copied",
"SkipTitle": "Skip",
"SomethingWentWrong": "Something went wrong.",
"SortBy": "Sort by",