1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-25 06:33:48 +00:00

fix: sdoc history diff toggle bug

This commit is contained in:
er-pai-r
2023-12-11 18:17:15 +08:00
parent 7efe677798
commit 6435074e92
2 changed files with 56 additions and 38 deletions

View File

@@ -88,34 +88,38 @@ class SdocFileHistory extends React.Component {
}; };
}; };
updateLastVersionContent = (currentVersionContent, currentVersion, lastVersion) => {
if (!lastVersion) {
this.setContent(currentVersionContent, '');
return;
}
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;
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));
this.setContent(currentVersionContent, '');
});
};
onSelectHistoryVersion = (currentVersion, lastVersion) => { onSelectHistoryVersion = (currentVersion, lastVersion) => {
this.setState({ isLoading: true, currentVersion }); this.setState({ isLoading: true, currentVersion });
seafileAPI.getFileRevision(historyRepoID, currentVersion.commit_id, currentVersion.path).then(res => { seafileAPI.getFileRevision(historyRepoID, currentVersion.commit_id, currentVersion.path).then(res => {
return seafileAPI.getFileContent(res.data); return seafileAPI.getFileContent(res.data);
}).then(res => { }).then(res => {
const currentVersionContent = res.data; const currentVersionContent = res.data;
if (lastVersion) { this.updateLastVersionContent(currentVersionContent, currentVersion, 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;
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));
this.setContent(currentVersionContent, '');
});
} else {
this.setContent(currentVersionContent, '');
}
}).catch(error => { }).catch(error => {
const errorMessage = Utils.getErrorMsg(error, true); const errorMessage = Utils.getErrorMsg(error, true);
toaster.danger(gettext(errorMessage)); toaster.danger(gettext(errorMessage));
@@ -127,21 +131,12 @@ class SdocFileHistory extends React.Component {
this.setState({ currentVersionContent, lastVersionContent, isLoading: false, changes: [], currentDiffIndex: 0 }); this.setState({ currentVersionContent, lastVersionContent, isLoading: false, changes: [], currentDiffIndex: 0 });
}; };
onShowChanges = (isShowChanges) => { onShowChanges = (isShowChanges, lastVersion) => {
if (isShowChanges) { if (isShowChanges) {
const { currentVersionContent, currentVersion } = this.state; const { currentVersionContent, currentVersion } = this.state;
this.setState({ isLoading: true, isShowChanges }, () => { this.setState({ isLoading: true, isShowChanges }, () => {
localStorage.setItem('seahub-sdoc-history-show-changes', isShowChanges + ''); localStorage.setItem('seahub-sdoc-history-show-changes', isShowChanges + '');
seafileAPI.getNextFileRevision(historyRepoID, currentVersion.id, currentVersion.path).then(res => { this.updateLastVersionContent(currentVersionContent, currentVersion, lastVersion);
return res.data ? seafileAPI.getFileContent(res.data) : { data: '' };
}).then(res => {
const lastVersionContent = res.data;
this.setContent(currentVersionContent, lastVersionContent);
}).catch(error => {
const errorMessage = Utils.getErrorMsg(error, true);
toaster.danger(gettext(errorMessage));
this.setContent(currentVersionContent, '');
});
}); });
return; return;
} }

View File

@@ -142,13 +142,11 @@ class SidePanel extends Component {
}); });
}; };
onSelectHistoryVersion = (path) => { getLastVersion = (path, isShowChanges) => {
const { isShowChanges } = this.props;
const { historyGroups } = this.state; const { historyGroups } = this.state;
const [monthIndex, dayIndex, dailyIndex] = path; const [monthIndex, dayIndex, dailyIndex] = path;
const monthHistoryGroup = historyGroups[monthIndex]; const monthHistoryGroup = historyGroups[monthIndex];
const dayHistoryGroup = monthHistoryGroup.children[dayIndex]; const dayHistoryGroup = monthHistoryGroup.children[dayIndex];
const currentVersion = dayHistoryGroup.children[dailyIndex];
let lastVersion = ''; let lastVersion = '';
if (isShowChanges) { if (isShowChanges) {
if (dayHistoryGroup.showDaily) { if (dayHistoryGroup.showDaily) {
@@ -164,6 +162,17 @@ class SidePanel extends Component {
lastVersion = 'init'; lastVersion = 'init';
} }
} }
return lastVersion;
};
onSelectHistoryVersion = (path) => {
const { historyGroups } = this.state;
const { isShowChanges } = this.props;
const [monthIndex, dayIndex, dailyIndex] = path;
const monthHistoryGroup = historyGroups[monthIndex];
const dayHistoryGroup = monthHistoryGroup.children[dayIndex];
const currentVersion = dayHistoryGroup.children[dailyIndex];
const lastVersion = this.getLastVersion(path, isShowChanges);
this.props.onSelectHistoryVersion(currentVersion, lastVersion); this.props.onSelectHistoryVersion(currentVersion, lastVersion);
}; };
@@ -275,8 +284,22 @@ class SidePanel extends Component {
}; };
onShowChanges = () => { onShowChanges = () => {
const { isShowChanges } = this.props; const { isShowChanges, currentVersion } = this.props;
this.props.onShowChanges(!isShowChanges); const { historyGroups } = this.state;
const nextShowChanges = !isShowChanges;
let lastVersion;
if (nextShowChanges) {
const { date } = currentVersion;
const momentDate = moment(date);
const month = momentDate.format('YYYY-MM');
const day = momentDate.format('YYYY-MM-DD');
const monthIndex = historyGroups.findIndex(item => item.month === month);
const dayIndex = historyGroups[monthIndex].children.findIndex(item => item.day === day);
const dailyIndex = historyGroups[monthIndex].children[dayIndex].children.findIndex(item => item.date === date);
const path = [monthIndex, dayIndex, dailyIndex];
lastVersion = this.getLastVersion(path, nextShowChanges);
}
this.props.onShowChanges(nextShowChanges, lastVersion);
}; };
render() { render() {