mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 23:29:49 +00:00
fix wiki page when delete middle page (#7955)
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"no-class-assign": "warn",
|
||||
"no-unused-vars": "warn",
|
||||
"no-useless-escape": "off",
|
||||
"no-inner-declarations": "off",
|
||||
"no-irregular-whitespace": "warn",
|
||||
"no-trailing-spaces": "warn",
|
||||
"react/jsx-indent": ["warn", 2],
|
||||
|
@@ -8,7 +8,7 @@ import Loading from '../../components/loading';
|
||||
import WikiNav from './wiki-nav/index';
|
||||
import PageUtils from './wiki-nav/page-utils';
|
||||
import Page from './models/page';
|
||||
import { isObjectNotEmpty } from './utils';
|
||||
import { isObjectNotEmpty, isPageInSubtree } from './utils';
|
||||
import wikiAPI from '../../utils/wiki-api';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import WikiExternalOperations from './wiki-external-operations';
|
||||
@@ -46,7 +46,7 @@ class SidePanel extends PureComponent {
|
||||
|
||||
onDeletePage = (pageId) => {
|
||||
const config = deepCopy(this.props.config);
|
||||
const { pages } = config;
|
||||
const { pages, navigation } = config;
|
||||
const index = PageUtils.getPageIndexById(pageId, pages);
|
||||
const deletePageName = pages[index].name;
|
||||
config.pages.splice(index, 1);
|
||||
@@ -64,7 +64,8 @@ class SidePanel extends PureComponent {
|
||||
let errMessage = Utils.getErrorMsg(error);
|
||||
toaster.danger(errMessage);
|
||||
});
|
||||
if (this.props.getCurrentPageId() === pageId) {
|
||||
const currentPageId = this.props.getCurrentPageId();
|
||||
if (currentPageId === pageId || isPageInSubtree(navigation, pageId, currentPageId)) {
|
||||
const newPageId = config.pages.length > 0 ? config.pages[0].id : '';
|
||||
this.props.setCurrentPage(newPageId);
|
||||
}
|
||||
|
@@ -108,7 +108,14 @@ const getPaths = (navigation, currentPageId, pages, isGetPathStr) => {
|
||||
paths: pathStr,
|
||||
curNode
|
||||
};
|
||||
return pathStr.split('-').map(id => idPageMap[id]);
|
||||
const pathIds = pathStr.split('-');
|
||||
const result = [];
|
||||
for (const id of pathIds) {
|
||||
const page = idPageMap[id];
|
||||
if (!page) return result;
|
||||
result.push(page);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const getNamePaths = (config, pageId) => {
|
||||
@@ -134,6 +141,33 @@ const getNamePaths = (config, pageId) => {
|
||||
};
|
||||
};
|
||||
|
||||
const isPageInSubtree = (navigation, targetPageId, currentPageId) => {
|
||||
let found = false;
|
||||
function traverse(node) {
|
||||
if (node.id === targetPageId) {
|
||||
function checkSubtree(subNode) {
|
||||
if (subNode.id === currentPageId) {
|
||||
found = true;
|
||||
return;
|
||||
}
|
||||
if (subNode.children) {
|
||||
subNode.children.forEach(child => {
|
||||
if (child) checkSubtree(child);
|
||||
});
|
||||
}
|
||||
}
|
||||
checkSubtree(node);
|
||||
return;
|
||||
}
|
||||
if (node.children) {
|
||||
node.children.forEach(child => {
|
||||
if (child) traverse(child);
|
||||
});
|
||||
}
|
||||
}
|
||||
navigation.forEach(item => traverse(item));
|
||||
return found;
|
||||
};
|
||||
|
||||
export {
|
||||
generatorBase64Code,
|
||||
@@ -144,5 +178,6 @@ export {
|
||||
getWikPageLink,
|
||||
throttle,
|
||||
getPaths,
|
||||
getNamePaths
|
||||
getNamePaths,
|
||||
isPageInSubtree
|
||||
};
|
||||
|
Reference in New Issue
Block a user