1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-02 07:47:32 +00:00

Update sdoc struct (#6920)

* optimize code

* optimize code

* update sdoc-editor version
This commit is contained in:
杨顺强 2024-10-18 10:58:39 +08:00 committed by GitHub
parent b723b6436e
commit 058b95362e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 13 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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 };
};

View File

@ -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));