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

Web: Files: fixed files upload #437

Merged
merged 21 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
93545f0
Web: Files: fixed files upload
gopienkonikita Oct 27, 2021
f923786
Web: Files: fixed upload
gopienkonikita Oct 27, 2021
ca52c40
Web: Files: fixed folders upload
gopienkonikita Oct 27, 2021
6d62e54
Web: Files: fixed files upload if filter is set
gopienkonikita Oct 28, 2021
dcb8f10
Web: Files: fixed Paging re-render
gopienkonikita Oct 28, 2021
a1d8a70
Web: Files: fixed Paging re-render
gopienkonikita Oct 28, 2021
b72ef82
Web: Files: fixed folder upload
gopienkonikita Oct 28, 2021
b30ae58
Web: Files: fixed upload folder hierarchy
gopienkonikita Oct 28, 2021
e6628c4
Merge branch 'hotfix/v1.0.1' into feature/files-upload
gopienkonikita Nov 1, 2021
fc93266
Web: Files: fixed folder update after upload
gopienkonikita Nov 2, 2021
93fae15
Web: Files: fixed files upload
gopienkonikita Nov 2, 2021
5ba3df9
Web: Files: fixed upload folder hierarchy
gopienkonikita Nov 2, 2021
fc28c97
Web: Files: fixed upload folder hierarchy
gopienkonikita Nov 2, 2021
96d12d3
Web: Files: fixed updating the folder tree after upload
gopienkonikita Nov 2, 2021
2141932
Web: Files: fixed updating the folder tree after upload
gopienkonikita Nov 2, 2021
49a0490
Web: Files: fixed updating the folder tree after upload
gopienkonikita Nov 3, 2021
bc765df
Web: Files: fixed upload convertFiles
gopienkonikita Nov 3, 2021
94fbdfa
Web: Files: fixed upload to tree menu
gopienkonikita Nov 3, 2021
daf7593
Web: Files: fixed upload folder
gopienkonikita Nov 3, 2021
ffddbbe
Web: Files: added tree menu update
gopienkonikita Nov 8, 2021
5c5db26
Web: Files: removed unused code
gopienkonikita Nov 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ const StyledSectionPaging = styled.div`
`;

class SectionPaging extends React.Component {
shouldComponentUpdate(nextProps) {
return !equal(this.props, nextProps);
}

render() {
return <StyledSectionPaging {...this.props} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const SectionPagingContent = ({
selectedCount,
selectedFolderId,
tReady,
totalPages,
}) => {
const { t } = useTranslation("Home");
const onNextClick = useCallback(
Expand Down Expand Up @@ -105,7 +106,6 @@ const SectionPagingContent = ({

const pageItems = useMemo(() => {
if (filter.total < filter.pageCount) return [];
const totalPages = Math.ceil(filter.total / filter.pageCount);
return [...Array(totalPages).keys()].map((item) => {
return {
key: item,
Expand All @@ -115,7 +115,7 @@ const SectionPagingContent = ({
}),
};
});
}, [filter.total, filter.pageCount, t]);
}, [filter.total, filter.pageCount, t, totalPages]);

const emptyPageSelection = {
key: 0,
Expand Down Expand Up @@ -168,11 +168,14 @@ const SectionPagingContent = ({
export default inject(({ filesStore, selectedFolderStore }) => {
const { files, folders, fetchFiles, filter, setIsLoading } = filesStore;

const totalPages = Math.ceil(filter.total / filter.pageCount);

return {
files,
folders,
selectedFolderId: selectedFolderStore.id,
filter,
totalPages,

setIsLoading,
fetchFiles,
Expand Down
27 changes: 26 additions & 1 deletion products/ASC.Files/Client/src/store/FilesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ class FilesStore {
const isRecycleBinFolder =
data.current.rootFolderType === FolderType.TRASH;

!isRecycleBinFolder && this.checkUpdateNode(data, folderId);

if (!isRecycleBinFolder && withSubfolders) {
const path = data.pathParts.slice(0);
const foldersCount = data.current.foldersCount;
Expand Down Expand Up @@ -340,7 +342,7 @@ class FilesStore {
const selectedFolder = {
selectedFolder: { ...this.selectedFolderStore },
};
this.createThumbnails();
this.viewAs === "tile" && this.createThumbnails();
return Promise.resolve(selectedFolder);
})
.catch((err) => {
Expand All @@ -363,6 +365,29 @@ class FilesStore {
return request();
};

checkUpdateNode = async (data, folderId) => {
const { treeFolders, getSubfolders } = this.treeFoldersStore;

const somePath = data.pathParts.slice(0);
const path = data.pathParts.slice(0);
let newItems = treeFolders;

while (somePath.length !== 1) {
newItems = newItems.find((x) => x.id === somePath[0])?.folders;
if (!newItems) {
return;
}

somePath.shift();
}

if (!newItems.find((x) => x.id == folderId)) {
path.splice(data.pathParts.length - 1, 1);
const subfolders = await getSubfolders(data.current.parentId);
loopTreeFolders(path, treeFolders, subfolders, 0);
}
};

isFileSelected = (fileId, parentId) => {
const item = this.selection.find(
(x) => x.id === fileId && x.parentId === parentId
Expand Down
158 changes: 120 additions & 38 deletions products/ASC.Files/Client/src/store/UploadDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { makeAutoObservable, runInAction } from "mobx";
import { TIMEOUT } from "../helpers/constants";
import { loopTreeFolders } from "../helpers/files-helpers";
import uniqueid from "lodash/uniqueId";
import throttle from "lodash/throttle";
import sumBy from "lodash/sumBy";
import { ConflictResolveType } from "@appserver/common/constants";
import {
getFolder,
getFileInfo,
getFolderInfo,
getProgress,
uploadFile,
convertFile,
Expand Down Expand Up @@ -317,7 +317,8 @@ class UploadDataStore {
file.inConversion = false;
}
});
this.refreshFiles(toFolderId, false);

//this.refreshFiles(toFolderId, false);
break;
}

Expand All @@ -335,7 +336,7 @@ class UploadDataStore {
}
});

this.refreshFiles(toFolderId, false);
this.refreshFiles(file);
const percent = this.getConversationPercent(index + 1);
this.setConversionPercent(percent, !!error);
}
Expand Down Expand Up @@ -450,46 +451,122 @@ class UploadDataStore {
}
};

refreshFiles = (folderId, needUpdateTree = true) => {
const { setTreeFolders } = this.treeFoldersStore;
if (
this.selectedFolderStore.id === folderId &&
window.location.pathname.indexOf("/history") === -1
) {
return this.filesStore.fetchFiles(
this.selectedFolderStore.id,
this.filesStore.filter.clone(),
false,
true
);
} else if (needUpdateTree) {
return getFolder(folderId, this.filesStore.filter.clone()).then(
(data) => {
const path = data.pathParts;
const newTreeFolders = this.treeFoldersStore.treeFolders;
const folders = data.folders;
const foldersCount = data.count;
loopTreeFolders(path, newTreeFolders, folders, foldersCount);
setTreeFolders(newTreeFolders);
refreshFiles = async (currentFile) => {
const {
files,
setFiles,
folders,
setFolders,
filter,
setFilter,
} = this.filesStore;
if (window.location.pathname.indexOf("/history") === -1) {
const newFiles = files;
const newFolders = folders;
const path = currentFile.path;

let folderInfo = null;
const index = path.findIndex((x) => x === this.selectedFolderStore.id);
const folderId = index !== -1 ? path[index + 1] : null;
if (folderId) folderInfo = await getFolderInfo(folderId);

const newPath = [];
if (folderInfo) {
let i = 0;
while (path[i] && path[i] !== folderId) {
newPath.push(path[i]);
i++;
}
);
}

if (newPath[newPath.length - 1] !== this.selectedFolderStore.id) {
return;
}

const addNewFile = () => {
if (folderInfo) {
const isFolderExist = newFolders.find((x) => x.id === folderInfo.id);
if (!isFolderExist && folderInfo) {
newFolders.unshift(folderInfo);
setFolders(newFolders);
const newFilter = filter;
newFilter.total = newFilter.total += 1;
setFilter(newFilter);
}
} else {
const isFileExist = newFiles.find(
(x) => x.id === currentFile.fileInfo.id
);

if (!isFileExist && currentFile && currentFile.fileInfo) {
newFiles.unshift(currentFile.fileInfo);
setFiles(newFiles);
const newFilter = filter;
newFilter.total = newFilter.total += 1;
setFilter(newFilter);
}
}
};

const isFiltered =
filter.filterType ||
filter.authorType ||
filter.search ||
filter.page !== 0;

if ((!currentFile && !folderInfo) || isFiltered) return;
if (folderInfo && this.selectedFolderStore.id === folderInfo.id) return;

if (folderInfo) {
const folderIndex = folders.findIndex((f) => f.id === folderInfo.id);
if (folderIndex !== -1) {
folders[folderIndex] = folderInfo;
return;
}
}

if (filter.total >= filter.pageCount) {
if (files.length) {
newFiles.pop();
addNewFile();
} else {
newFolders.pop();
addNewFile();
}
} else {
addNewFile();
}

if (!!folderInfo) {
const {
expandedKeys,
setExpandedKeys,
treeFolders,
} = this.treeFoldersStore;

const newExpandedKeys = expandedKeys.filter(
(x) => x !== newPath[newPath.length - 1] + ""
);

setExpandedKeys(newExpandedKeys);

loopTreeFolders(
newPath,
treeFolders,
this.filesStore.folders.length === 1 ? this.filesStore.folders : [],
this.filesStore.folders.length
);
}
}
};

throttleRefreshFiles = throttle((toFolderId) => {
return this.refreshFiles(toFolderId).catch((err) => {
console.log("RefreshFiles failed", err);
return Promise.resolve();
});
}, 1000);

uploadFileChunks = async (
location,
requestsDataArray,
fileSize,
indexOfFile,
file,
t
path
) => {
const length = requestsDataArray.length;
for (let index = 0; index < length; index++) {
Expand Down Expand Up @@ -543,8 +620,9 @@ class UploadDataStore {
// All chuncks are uploaded

const currentFile = this.files[indexOfFile];
currentFile.path = path;
if (!currentFile) return Promise.resolve();
const { toFolderId, needConvert } = currentFile;
const { needConvert } = currentFile;

if (needConvert) {
runInAction(() => (currentFile.action = "convert"));
Expand All @@ -556,7 +634,10 @@ class UploadDataStore {
}
return Promise.resolve();
} else {
return this.throttleRefreshFiles(toFolderId);
if (currentFile.action === "uploaded") {
this.refreshFiles(currentFile);
}
return Promise.resolve();
}
};

Expand Down Expand Up @@ -646,6 +727,7 @@ class UploadDataStore {
)
.then((res) => {
const location = res.data.location;
const path = res.data.path;

const requestsDataArray = [];

Expand All @@ -659,9 +741,9 @@ class UploadDataStore {
chunk++;
}

return { location, requestsDataArray, fileSize };
return { location, requestsDataArray, fileSize, path };
})
.then(({ location, requestsDataArray, fileSize }) => {
.then(({ location, requestsDataArray, fileSize, path }) => {
this.primaryProgressDataStore.setPrimaryProgressBarData({
icon: "upload",
visible: true,
Expand All @@ -678,7 +760,7 @@ class UploadDataStore {
fileSize,
indexOfFile,
file,
t
path
);
})
.catch((err) => {
Expand Down