Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Feat wiki editor title seperation" #6188

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@gatsbyjs/reach-router": "1.3.9",
"@seafile/react-image-lightbox": "2.0.2",
"@seafile/resumablejs": "1.1.16",
"@seafile/sdoc-editor": "0.5.70",
"@seafile/sdoc-editor": "0.5.69",
"@seafile/seafile-calendar": "0.0.12",
"@seafile/seafile-editor": "1.0.99",
"@uiw/codemirror-extensions-langs": "^4.19.4",
Expand Down
23 changes: 2 additions & 21 deletions frontend/src/pages/wiki2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Modal } from 'reactstrap';
import { Utils } from '../../utils/utils';
import wikiAPI from '../../utils/wiki-api';
import SDocServerApi from '../../utils/sdoc-server-api';
import { wikiId, siteRoot, lang, isWiki2, seadocServerUrl, gettext } from '../../utils/constants';
import { wikiId, siteRoot, lang, isWiki2, seadocServerUrl } from '../../utils/constants';
import WikiConfig from './models/wiki-config';
import toaster from '../../components/toast';
import SidePanel from './side-panel';
Expand Down Expand Up @@ -171,25 +171,8 @@ class Wiki extends Component {
callback && callback();
});
};

onUpdatePage = (pageId, newPage) => {
if (newPage.name === '') {
toaster.danger(gettext('Page name cannot be empty'));
return;
}
const { config } = this.state
let pages = config.pages;
let newPages = pages.map(page => {
if (page.id === pageId) {
return { ...page, ...newPage };
}
return page;
});
const newConfig = { ...config, pages: newPages };
this.saveWikiConfig(newConfig);
};
render() {

render() {
return (
<div id="main" className="wiki-main">
<SidePanel
Expand All @@ -200,7 +183,6 @@ class Wiki extends Component {
saveWikiConfig={this.saveWikiConfig}
setCurrentPage={this.setCurrentPage}
currentPageId={this.state.currentPageId}
onUpdatePage={this.onUpdatePage}
/>
<MainPanel
path={this.state.path}
Expand All @@ -213,7 +195,6 @@ class Wiki extends Component {
permission={this.state.permission}
seadoc_access_token={this.state.seadoc_access_token}
assets_url={this.state.assets_url}
onUpdatePage={this.onUpdatePage}
/>
<MediaQuery query="(max-width: 767.8px)">
<Modal isOpen={!this.state.closeSideBar} toggle={this.onCloseSide} contentClassName="d-none"></Modal>
Expand Down
49 changes: 15 additions & 34 deletions frontend/src/pages/wiki2/main-panel.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { SdocWikiViewer } from '@seafile/sdoc-editor';
import { Input } from 'reactstrap';
import { gettext, username } from '../../utils/constants';
import Loading from '../../components/loading';
import { Utils } from '../../utils/utils';
import Account from '../../components/common/account';
import WikiTopNav from './top-nav';
import { getCurrentPageConfig } from './utils';

const propTypes = {
path: PropTypes.string.isRequired,
Expand All @@ -20,7 +18,6 @@ const propTypes = {
assets_url: PropTypes.string,
config: PropTypes.object,
currentPageId: PropTypes.string,
onUpdatePage: PropTypes.func,
};

class MainPanel extends Component {
Expand All @@ -29,51 +26,36 @@ class MainPanel extends Component {
super(props);
this.state = {
docUuid: '',
currentPageConfig: {},
};
}

static getDerivedStateFromProps(props, state) {
const { seadoc_access_token, currentPageId, config } = props;
const appConfig = window.app.config;
const { seadoc_access_token } = props;
const config = window.app.config;
const pageOptions = window.app.pageOptions;
const { assetsUrl, seadocServerUrl: sdocServer, } = window.wiki.config;
window.seafile = {
...window.seafile, // need docUuid
...appConfig,
...config,
...pageOptions,
sdocServer,
assetsUrl: assetsUrl || props.assets_url,
accessToken: seadoc_access_token,
serviceUrl: appConfig.serviceURL,
assets_url: appConfig.assetsUrl,
serviceUrl: config.serviceURL,
assets_url: config.assetsUrl,
};
const currentPageConfig = getCurrentPageConfig(config.pages, currentPageId)
return { ...props, docUuid: window.seafile.docUuid, currentPageConfig };
}

handleRenameDocument = (e) => {
const newName = e.target.value.trim()
const { currentPageConfig } = this.state
const { id, name, icon } = currentPageConfig
if (newName === name) return;
const pageConfig = { name: newName, icon }
this.props.onUpdatePage(id, pageConfig)
// Reset title if name is empty
if (!newName) e.target.value = name;
return { ...props, docUuid: window.seafile.docUuid };
}

render() {
const { permission, pathExist, isDataLoading, isViewFile, config } = this.props;
const { currentPageConfig } = this.state
const { permission, pathExist, isDataLoading, isViewFile } = this.props;
const isViewingFile = pathExist && !isDataLoading && isViewFile;
const isReadOnly = !(permission === 'rw');

return (
<div className="wiki2-main-panel">
<div className='wiki2-main-panel-north'>
<WikiTopNav
config={config}
config={this.props.config}
currentPageId={this.props.currentPageId}
/>
{username &&
Expand All @@ -87,14 +69,13 @@ class MainPanel extends Component {
}
{this.props.pathExist && this.props.isDataLoading && <Loading />}
{isViewingFile && Utils.isSdocFile(this.props.path) && (
<div>
<SdocWikiViewer
document={this.props.editorContent}
docUuid={this.state.docUuid}
isWikiReadOnly={isReadOnly}
topSlot={<Input className='sf-wiki-title' bsSize="lg" onChange={this.handleRenameDocument} defaultValue={currentPageConfig.name} />}
/>
</div>
<SdocWikiViewer
document={this.props.editorContent}
showOutline={false}
showToolbar={false}
docUuid={this.state.docUuid}
isWikiReadOnly={isReadOnly}
/>
)}
</div>
</div>
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/pages/wiki2/side-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const propTypes = {
saveWikiConfig: PropTypes.func.isRequired,
setCurrentPage: PropTypes.func.isRequired,
currentPageId: PropTypes.string,
onUpdatePage: PropTypes.func.isRequired,
};

class SidePanel extends Component {
Expand Down Expand Up @@ -102,6 +101,19 @@ class SidePanel extends Component {
this.props.saveWikiConfig(config, onSuccess, errorCallback);
};

onUpdatePage = (pageId, newPage) => {
if (newPage.name === '') {
toaster.danger(gettext('Page name cannot be empty'));
return;
}
const { config } = this.props;
let pages = config.pages;
let currentPage = pages.find(page => page.id === pageId);
Object.assign(currentPage, newPage);
config.pages = pages;
this.props.saveWikiConfig(config);
};

movePage = ({ moved_view_id, target_view_id, source_view_folder_id, target_view_folder_id, move_position }) => {
let config = deepCopy(this.props.config);
let { navigation } = config;
Expand Down Expand Up @@ -274,7 +286,7 @@ class SidePanel extends Component {
};

renderFolderView = () => {
const { config, onUpdatePage } = this.props;
const { config } = this.props;
const { pages, navigation } = config;
return (
<div className="wiki2-pages-container">
Expand All @@ -284,7 +296,7 @@ class SidePanel extends Component {
views={pages}
onToggleAddView={this.openAddPageDialog}
onDeleteView={this.confirmDeletePage}
onUpdatePage={onUpdatePage}
onUpdatePage={this.onUpdatePage}
onSelectView={this.props.setCurrentPage}
onMoveView={this.movePage}
movePageOut={this.movePageOut}
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/pages/wiki2/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ const getIconURL = (repoId, fileName) => {
return serviceURL + '/lib/' + repoId + '/file/_Internal/Wiki/Icon/' + fileName + '?raw=1';
};

const getCurrentPageConfig = (pages,pageId) => {
return pages.filter(page => page.id === pageId)[0]
}

export { generatorBase64Code, generateUniqueId, isObjectNotEmpty, getIconURL, getCurrentPageConfig };
export { generatorBase64Code, generateUniqueId, isObjectNotEmpty, getIconURL };
13 changes: 1 addition & 12 deletions frontend/src/pages/wiki2/wiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ img[src=""] {
}
}

.main-panel-center .cur-view-content .sf-wiki-title {
border: none;
padding: 0 50px;
padding-left: 142px;
font-weight: bold;
font-size: 26pt;
}

/* reset article h1 */
.wiki2-main-panel .article h1 {
Expand Down Expand Up @@ -226,15 +219,11 @@ img[src=""] {
width: 100%;
}

.sdoc-editor-container .sdoc-editor-content {
flex-direction: column;
}

.sdoc-editor-container .sdoc-editor-content .article {
padding: 15px 142px 0px 142px;
width: 100%;
box-shadow: none;
border: none;
padding: 52px 142px 0;
}

.sdoc-editor-container .sdoc-editor-content .sdoc-side-toolbar-container {
Expand Down
2 changes: 1 addition & 1 deletion seahub/api2/endpoints/wiki2.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def post(self, request, wiki_id):
folder_id = request.data.get('folder_id', None)
wiki_config = get_wiki_config(repo_id, request.user.username)

navigation = wiki_config.get('navigation', [])
navigation = wiki_config.get('navigation')
if not folder_id:
page_ids = {element.get('id') for element in navigation if element.get('type') != 'folder'}
else:
Expand Down
Loading