mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 22:01:06 +00:00
fix wiki config error (#6087)
This commit is contained in:
@@ -4,7 +4,7 @@ import MediaQuery from 'react-responsive';
|
|||||||
import { Modal } from 'reactstrap';
|
import { Modal } from 'reactstrap';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
import wikiAPI from '../../utils/wiki-api';
|
import wikiAPI from '../../utils/wiki-api';
|
||||||
import { slug, wikiId, siteRoot, initialPath, isDir, sharedToken, hasIndex, lang, isEditWiki } from '../../utils/constants';
|
import { slug, wikiId, siteRoot, initialPath, isDir, sharedToken, hasIndex, lang, isEditWiki, gettext } from '../../utils/constants';
|
||||||
import Dirent from '../../models/dirent';
|
import Dirent from '../../models/dirent';
|
||||||
import WikiConfig from './models/wiki-config';
|
import WikiConfig from './models/wiki-config';
|
||||||
import TreeNode from '../../components/tree-view/tree-node';
|
import TreeNode from '../../components/tree-view/tree-node';
|
||||||
@@ -44,7 +44,7 @@ class Wiki extends Component {
|
|||||||
indexNode: null,
|
indexNode: null,
|
||||||
indexContent: '',
|
indexContent: '',
|
||||||
currentPageId: '',
|
currentPageId: '',
|
||||||
config: {},
|
config: new WikiConfig({}),
|
||||||
repoId: '',
|
repoId: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,6 +80,13 @@ class Wiki extends Component {
|
|||||||
getWikiConfig = () => {
|
getWikiConfig = () => {
|
||||||
wikiAPI.getWiki2Config(wikiId).then(res => {
|
wikiAPI.getWiki2Config(wikiId).then(res => {
|
||||||
const { wiki_config, repo_id } = res.data.wiki;
|
const { wiki_config, repo_id } = res.data.wiki;
|
||||||
|
try {
|
||||||
|
JSON.parse(wiki_config);
|
||||||
|
} catch (error) {
|
||||||
|
toaster.danger(gettext('Wiki config error'));
|
||||||
|
this.setState({ isConfigLoading: false });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const config = new WikiConfig(JSON.parse(wiki_config) || {});
|
const config = new WikiConfig(JSON.parse(wiki_config) || {});
|
||||||
this.setState({
|
this.setState({
|
||||||
config,
|
config,
|
||||||
@@ -114,12 +121,16 @@ class Wiki extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getFirstPageId = (config) => {
|
getFirstPageId = (config) => {
|
||||||
const item = config.navigation[0] || {};
|
if (!config || !Array.isArray(config.navigation)) return '';
|
||||||
|
for (let i = 0; i < config.navigation.length; i++) {
|
||||||
|
const item = config.navigation[i] || {};
|
||||||
if (item.type === 'page') {
|
if (item.type === 'page') {
|
||||||
return item.id;
|
return item.id;
|
||||||
} else if (item.type === 'folder') {
|
}
|
||||||
|
if (item.type === 'folder' && item.children[0]) {
|
||||||
return item.children[0].id;
|
return item.children[0].id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
loadSidePanel = (initialPath) => {
|
loadSidePanel = (initialPath) => {
|
||||||
|
@@ -3,6 +3,6 @@ export default class Folder {
|
|||||||
this.type = 'folder';
|
this.type = 'folder';
|
||||||
this.id = object.id;
|
this.id = object.id;
|
||||||
this.name = object.name;
|
this.name = object.name;
|
||||||
this.children = object.children || [];
|
this.children = Array.isArray(object.children) ? object.children : [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,20 @@
|
|||||||
|
import Page from './page';
|
||||||
|
import Folder from './folder';
|
||||||
|
|
||||||
export default class WikiConfig {
|
export default class WikiConfig {
|
||||||
constructor(object) {
|
constructor(object) {
|
||||||
this.version = object.version || 1;
|
this.version = object.version || 1;
|
||||||
this.navigation = object.navigation || [];
|
this.navigation = (Array.isArray(object.navigation) ? object.navigation : []).map(item => {
|
||||||
this.pages = object.pages || [];
|
if (item.type === 'folder') {
|
||||||
|
return new Folder(item);
|
||||||
|
} else if (item.type === 'page') {
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
type: item.type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).filter(item => !!item);
|
||||||
|
this.pages = Array.isArray(object.pages) ? object.pages.map(page => new Page(page)) : [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ const generatorBase64Code = (keyLength = 4) => {
|
|||||||
return key;
|
return key;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateUniqueId = (navigation, length = 4) => {
|
const generateUniqueId = (navigation = [], length = 4) => {
|
||||||
let idMap = {};
|
let idMap = {};
|
||||||
function recurseItem(item) {
|
function recurseItem(item) {
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
@@ -29,6 +29,13 @@ class ViewEditPopover extends Component {
|
|||||||
this.props.toggleViewEditor();
|
this.props.toggleViewEditor();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleKeyDown = (e) => {
|
||||||
|
if (e.keyCode === 13) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.props.toggleViewEditor();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
renderViewName = () => {
|
renderViewName = () => {
|
||||||
const { viewName } = this.props;
|
const { viewName } = this.props;
|
||||||
return (
|
return (
|
||||||
@@ -40,6 +47,7 @@ class ViewEditPopover extends Component {
|
|||||||
onChange={this.onChangeName}
|
onChange={this.onChangeName}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
ref={this.viewInputRef}
|
ref={this.viewInputRef}
|
||||||
|
onKeyDown={this.handleKeyDown}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -55,6 +63,7 @@ class ViewEditPopover extends Component {
|
|||||||
onEnter={this.onEnter}
|
onEnter={this.onEnter}
|
||||||
hideArrow={true}
|
hideArrow={true}
|
||||||
popoverClassName="view-edit-popover"
|
popoverClassName="view-edit-popover"
|
||||||
|
boundariesElement={document.body}
|
||||||
>
|
>
|
||||||
<div className="view-edit-popover-header">
|
<div className="view-edit-popover-header">
|
||||||
<span className='header-text'>{gettext('Modify Name')}</span>
|
<span className='header-text'>{gettext('Modify Name')}</span>
|
||||||
|
Reference in New Issue
Block a user