Web: Editor: Moved the functionality of converting history and getting the current version into separate functions.

This commit is contained in:
Tatiana Lopaeva 2021-09-23 10:23:25 +03:00
parent 944591cd4d
commit 1983d60e55

View File

@ -495,17 +495,10 @@ const Editor = () => {
document.location.reload(); document.location.reload();
}; };
const onSDKRequestHistory = async () => { const getDocumentHistory = (fileHistory) => {
try { let result = [];
let fileHistory = await getEditHistory(fileId);
let newArr = [];
console.log("fileHistory", fileHistory); console.log("fileHistory", fileHistory);
const historyLength = fileHistory.length; const historyLength = fileHistory.length;
const currentVersion =
url.indexOf("&version=") !== -1
? +url.split("&version=")[1]
: fileHistory[historyLength - 1].version;
for (let i = 0; i < historyLength; i++) { for (let i = 0; i < historyLength; i++) {
const changes = fileHistory[i].changes; const changes = fileHistory[i].changes;
@ -528,12 +521,24 @@ const Editor = () => {
versionGroup, versionGroup,
}; };
newArr.push(obj); result.push(obj);
} }
console.log("newArr", newArr); console.log("newArr", result);
return result;
};
const currentDocumentVersion = (fileHistory) => {
const historyLength = fileHistory.length;
return url.indexOf("&version=") !== -1
? +url.split("&version=")[1]
: fileHistory[historyLength - 1].version;
};
const onSDKRequestHistory = async () => {
try {
let fileHistory = await getEditHistory(fileId);
docEditor.refreshHistory({ docEditor.refreshHistory({
currentVersion, currentVersion: currentDocumentVersion(fileHistory),
history: newArr, history: getDocumentHistory(fileHistory),
}); });
} catch (e) { } catch (e) {
docEditor.refreshHistory({ docEditor.refreshHistory({