mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-24 21:07:17 +00:00
fix: init content
This commit is contained in:
@@ -48,6 +48,46 @@ class SdocFileHistory extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
getInitContent = (firstChildren) => {
|
||||
if (firstChildren) {
|
||||
return {
|
||||
version: -1,
|
||||
children: [
|
||||
{
|
||||
id: firstChildren.id,
|
||||
type: 'title',
|
||||
children: [
|
||||
{
|
||||
id: firstChildren.children[0].id,
|
||||
text: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
return this.getInitContentByPath();
|
||||
};
|
||||
|
||||
getInitContentByPath = (path) => {
|
||||
const name = path ? path.split('/')?.pop()?.slice(0, -5) : '';
|
||||
return {
|
||||
version: -1,
|
||||
children: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'title',
|
||||
children: [
|
||||
{
|
||||
id: '2',
|
||||
text: name
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
onSelectHistoryVersion = (currentVersion, lastVersion) => {
|
||||
this.setState({ isLoading: true, currentVersion });
|
||||
seafileAPI.getFileRevision(historyRepoID, currentVersion.commit_id, currentVersion.path).then(res => {
|
||||
@@ -55,11 +95,19 @@ class SdocFileHistory extends React.Component {
|
||||
}).then(res => {
|
||||
const currentVersionContent = res.data;
|
||||
if (lastVersion) {
|
||||
if (lastVersion === 'init') {
|
||||
const lastVersionContent = currentVersionContent ? this.getInitContent(currentVersionContent.children[0]) : this.getInitContentByPath(currentVersion.path);
|
||||
const validCurrentVersionContent = currentVersionContent || this.getInitContentByPath(currentVersion.path);
|
||||
this.setContent(validCurrentVersionContent, lastVersionContent);
|
||||
return;
|
||||
}
|
||||
seafileAPI.getFileRevision(historyRepoID, lastVersion.commit_id, lastVersion.path).then(res => {
|
||||
return res.data ? seafileAPI.getFileContent(res.data) : { data: '' };
|
||||
}).then(res => {
|
||||
const lastVersionContent = res.data;
|
||||
this.setContent(currentVersionContent, lastVersionContent);
|
||||
const firstChildren = currentVersionContent.children[0];
|
||||
const validLastVersionContent = lastVersion && !lastVersionContent ? this.getInitContent(firstChildren) : lastVersionContent;
|
||||
this.setContent(currentVersionContent, validLastVersionContent);
|
||||
}).catch(error => {
|
||||
const errorMessage = Utils.getErrorMsg(error, true);
|
||||
toaster.danger(gettext(errorMessage));
|
||||
|
@@ -24,7 +24,6 @@ class SidePanel extends Component {
|
||||
historyGroups: [],
|
||||
errorMessage: '',
|
||||
hasMore: false,
|
||||
fileOwner: '',
|
||||
isReloadingData: false,
|
||||
};
|
||||
this.currentPage = 1;
|
||||
@@ -41,15 +40,16 @@ class SidePanel extends Component {
|
||||
seafileAPI.listSdocHistory(docUuid, this.currentPage, PER_PAGE).then(res => {
|
||||
const result = res.data;
|
||||
const resultCount = result.histories.length;
|
||||
const historyGroups = this.formatHistories(result.histories);
|
||||
this.setState({
|
||||
historyGroups: this.formatHistories(result.histories),
|
||||
hasMore: resultCount >= PER_PAGE,
|
||||
isLoading: false,
|
||||
fileOwner: result.histories[0]?.creator_email,
|
||||
}, () => {
|
||||
if (historyGroups.length > 0) {
|
||||
this.onSelectHistoryVersion([0, 0, 0]);
|
||||
}
|
||||
});
|
||||
if (result.histories[0]) {
|
||||
this.props.onSelectHistoryVersion(result.histories[0], result.histories[1]);
|
||||
}
|
||||
}).catch((error) => {
|
||||
this.setState({isLoading: false});
|
||||
throw Error('there has an error in server');
|
||||
@@ -85,7 +85,6 @@ class SidePanel extends Component {
|
||||
historyGroups: this.formatHistories(result.histories),
|
||||
hasMore: resultCount >= PER_PAGE,
|
||||
isLoading: false,
|
||||
fileOwner: result.histories[0].creator_email,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,6 +160,9 @@ class SidePanel extends Component {
|
||||
if (!lastVersion) {
|
||||
lastVersion = historyGroups[monthIndex + 1]?.children[0]?.children[0];
|
||||
}
|
||||
if (monthIndex === 0 && !lastVersion) {
|
||||
lastVersion = 'init';
|
||||
}
|
||||
}
|
||||
this.props.onSelectHistoryVersion(currentVersion, lastVersion);
|
||||
};
|
||||
|
Reference in New Issue
Block a user