Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/last page operations #451

Merged
merged 12 commits into from
Nov 9, 2021
Merged
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