diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 0c1798c39f..336a979b7a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -16,7 +16,7 @@ "@gatsbyjs/reach-router": "1.3.9", "@seafile/react-image-lightbox": "3.0.1", "@seafile/resumablejs": "1.1.16", - "@seafile/sdoc-editor": "1.0.102", + "@seafile/sdoc-editor": "1.0.105", "@seafile/seafile-calendar": "0.0.28", "@seafile/seafile-editor": "^1.0.121", "@seafile/sf-metadata-ui-component": "^0.0.43", @@ -4784,9 +4784,9 @@ "integrity": "sha512-8rBbmAEuuwOAGHYGCtEzpx+bxAcGS+V30otMmhRe7bPAdh4E57RWgCa8x7pkzHGFlY1t5d+ILz1gojvPVMYQig==" }, "node_modules/@seafile/sdoc-editor": { - "version": "1.0.102", - "resolved": "https://registry.npmjs.org/@seafile/sdoc-editor/-/sdoc-editor-1.0.102.tgz", - "integrity": "sha512-FMuv26UWablfbsFr39LX4ApIBgJSU9q0x4p6CzW2tzDVIio+M1xvMUzS6NMiBrjhWjv9FEArNoNDvyEndcaG5w==", + "version": "1.0.105", + "resolved": "https://registry.npmjs.org/@seafile/sdoc-editor/-/sdoc-editor-1.0.105.tgz", + "integrity": "sha512-7njoR8JDGXpf8WbOiMCOpqDlYAt7UT3QVPit+9/9OnC6wok5iTdY7ZpaRkvGD1DkkfCk8lSTH5tLdxImaRrN7Q==", "dependencies": { "@seafile/print-js": "1.6.6", "@seafile/react-image-lightbox": "2.0.5", diff --git a/frontend/package.json b/frontend/package.json index b664cfdf12..8235ae7ac5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,7 +11,7 @@ "@gatsbyjs/reach-router": "1.3.9", "@seafile/react-image-lightbox": "3.0.1", "@seafile/resumablejs": "1.1.16", - "@seafile/sdoc-editor": "1.0.102", + "@seafile/sdoc-editor": "1.0.105", "@seafile/seafile-calendar": "0.0.28", "@seafile/seafile-editor": "^1.0.121", "@seafile/sf-metadata-ui-component": "^0.0.43", diff --git a/frontend/src/pages/sdoc/sdoc-file-history/helper.js b/frontend/src/pages/sdoc/sdoc-file-history/helper.js index 4b85fe6857..cc6d650aa4 100644 --- a/frontend/src/pages/sdoc/sdoc-file-history/helper.js +++ b/frontend/src/pages/sdoc/sdoc-file-history/helper.js @@ -28,3 +28,8 @@ export const getCurrentAndLastVersion = (path, historyGroups, isShowChanges) => const lastVersion = getLastVersion(path, isShowChanges, historyGroups); return [currentVersion, lastVersion]; }; + +export const formatHistoryContent = (content) => { + // patch new sdoc data struct + return { ...content, elements: content.elements || content.children }; +}; diff --git a/frontend/src/pages/sdoc/sdoc-file-history/index.js b/frontend/src/pages/sdoc/sdoc-file-history/index.js index dbcb67d9d6..afcfaa8cbd 100644 --- a/frontend/src/pages/sdoc/sdoc-file-history/index.js +++ b/frontend/src/pages/sdoc/sdoc-file-history/index.js @@ -14,7 +14,7 @@ import GoBack from '../../../components/common/go-back'; import SidePanel from './side-panel'; import { Utils, isMobile } from '../../../utils/utils'; import toaster from '../../../components/toast'; -import { getCurrentAndLastVersion } from './helper'; +import { formatHistoryContent, getCurrentAndLastVersion } from './helper'; import '../../../css/layout.css'; import './index.css'; @@ -70,7 +70,7 @@ class SdocFileHistory extends React.Component { if (firstChildren) { return { version: -1, - children: [ + elements: [ { id: firstChildren.id, type: 'title', @@ -91,7 +91,7 @@ class SdocFileHistory extends React.Component { const name = path ? path.split('/')?.pop()?.slice(0, -5) : ''; return { version: -1, - children: [ + elements: [ { id: '1', type: 'title', @@ -112,7 +112,7 @@ class SdocFileHistory extends React.Component { return; } if (lastVersion === 'init') { - const lastVersionContent = currentVersionContent ? this.getInitContent(currentVersionContent.children[0]) : this.getInitContentByPath(currentVersion.path); + const lastVersionContent = currentVersionContent ? this.getInitContent(currentVersionContent?.elements[0]) : this.getInitContentByPath(currentVersion.path); const validCurrentVersionContent = currentVersionContent || this.getInitContentByPath(currentVersion.path); this.setContent(validCurrentVersionContent, lastVersionContent); return; @@ -120,8 +120,8 @@ class SdocFileHistory extends React.Component { seafileAPI.getFileRevision(historyRepoID, lastVersion.commit_id, lastVersion.path).then(res => { return res.data ? seafileAPI.getFileContent(res.data) : { data: '' }; }).then(res => { - const lastVersionContent = res.data; - const firstChildren = currentVersionContent.children[0]; + const lastVersionContent = formatHistoryContent(res.data); + const firstChildren = currentVersionContent?.elements[0]; const validLastVersionContent = lastVersion && !lastVersionContent ? this.getInitContent(firstChildren) : lastVersionContent; this.setContent(currentVersionContent, validLastVersionContent); }).catch(error => { @@ -139,8 +139,9 @@ class SdocFileHistory extends React.Component { seafileAPI.getFileRevision(historyRepoID, currentVersion.commit_id, currentVersion.path).then(res => { return seafileAPI.getFileContent(res.data); }).then(res => { - const currentVersionContent = res.data; - this.updateLastVersionContent(currentVersionContent, currentVersion, lastVersion); + const currentVersionContent = formatHistoryContent(res.data); + const validCurrentVersionContent = currentVersionContent.elements ? currentVersionContent : this.getInitContentByPath(currentVersion.path); + this.updateLastVersionContent(validCurrentVersionContent, currentVersion, lastVersion); }).catch(error => { const errorMessage = Utils.getErrorMsg(error, true); toaster.danger(gettext(errorMessage));