Skip to content

Commit

Permalink
Merge pull request #451 from ONLYOFFICE/bugfix/last-page-operations
Browse files Browse the repository at this point in the history
Bugfix/last page operations
  • Loading branch information
gopienkonikita authored Nov 9, 2021
2 parents df09343 + 33944cc commit 6e854f8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
33 changes: 25 additions & 8 deletions products/ASC.Files/Client/src/store/FilesActionsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,30 @@ class FilesActionStore {
}
};

updateCurrentFolder = () => {
updateCurrentFolder = (selectionLength) => {
const {
clearSecondaryProgressData,
} = this.uploadDataStore.secondaryProgressDataStore;

const { filter, fetchFiles } = this.filesStore;
fetchFiles(this.selectedFolderStore.id, filter, true, true).finally(() =>
setTimeout(() => clearSecondaryProgressData(), TIMEOUT)
);
const {
filter,
fetchFiles,
isEmptyLastPageAfterOperation,
resetFilterPage,
} = this.filesStore;

let newFilter;

if (selectionLength && isEmptyLastPageAfterOperation(selectionLength)) {
newFilter = resetFilterPage();
}

fetchFiles(
this.selectedFolderStore.id,
newFilter ? newFilter : filter,
true,
true
).finally(() => setTimeout(() => clearSecondaryProgressData(), TIMEOUT));
};

deleteAction = async (translations, newSelection = null) => {
Expand Down Expand Up @@ -113,7 +128,7 @@ class FilesActionStore {
label: translations.deleteOperation,
};
await this.uploadDataStore.loopFilesOperations(data, pbData);
this.updateCurrentFolder();
this.updateCurrentFolder(selection.length);
}
);
} catch (err) {
Expand Down Expand Up @@ -332,21 +347,23 @@ class FilesActionStore {
label: translations.deleteOperation,
};

const selectionFilesLength = 1;

if (isFile) {
this.isMediaOpen();
return deleteFile(itemId)
.then(async (res) => {
const data = res[0] ? res[0] : null;
await this.uploadDataStore.loopFilesOperations(data, pbData);
this.updateCurrentFolder();
this.updateCurrentFolder(selectionFilesLength);
})
.then(() => toastr.success(translations.successRemoveFile));
} else {
return deleteFolder(itemId)
.then(async (res) => {
const data = res[0] ? res[0] : null;
await this.uploadDataStore.loopFilesOperations(data, pbData);
this.updateCurrentFolder();
this.updateCurrentFolder(selectionFilesLength);
})
.then(() => toastr.success(translations.successRemoveFolder));
}
Expand Down
20 changes: 20 additions & 0 deletions products/ASC.Files/Client/src/store/FilesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,26 @@ class FilesStore {
);
};

isEmptyLastPageAfterOperation = (newSelection) => {
const selection =
newSelection || this.selection?.length || [this.bufferSelection].length;

return (
selection &&
this.filter.page > 0 &&
!this.filter.hasNext() &&
selection === this.files.length + this.folders.length
);
};

resetFilterPage = () => {
let newFilter;
newFilter = this.filter.clone();
newFilter.page--;

return newFilter;
};

fetchFiles = (
folderId,
filter,
Expand Down
27 changes: 21 additions & 6 deletions products/ASC.Files/Client/src/store/UploadDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,13 @@ class UploadDataStore {

moveToCopyTo = (destFolderId, pbData, isCopy) => {
const { treeFolders, setTreeFolders } = this.treeFoldersStore;
const { fetchFiles, filter } = this.filesStore;
const {
fetchFiles,
filter,
isEmptyLastPageAfterOperation,
resetFilterPage,
} = this.filesStore;

const {
clearSecondaryProgressData,
setSecondaryProgressBarData,
Expand All @@ -994,11 +1000,20 @@ class UploadDataStore {
loopTreeFolders(path, newTreeFolders, folders, foldersCount);

if (!isCopy || destFolderId === this.selectedFolderStore.id) {
fetchFiles(this.selectedFolderStore.id, filter, true, true).finally(
() => {
setTimeout(() => clearSecondaryProgressData(), TIMEOUT);
}
);
let newFilter;

if (isEmptyLastPageAfterOperation()) {
newFilter = resetFilterPage();
}

fetchFiles(
this.selectedFolderStore.id,
newFilter ? newFilter : filter,
true,
true
).finally(() => {
setTimeout(() => clearSecondaryProgressData(), TIMEOUT);
});
} else {
setSecondaryProgressBarData({
icon: pbData.icon,
Expand Down

0 comments on commit 6e854f8

Please sign in to comment.