-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6195 from haiwen/wiki-link-shortcut
feat: fix compatitablily to wiki shortcut
- Loading branch information
Showing
23 changed files
with
305 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Alert } from 'reactstrap'; | ||
import { gettext } from '../../utils/constants'; | ||
|
||
const propTypes = { | ||
wikiPageName: PropTypes.string, | ||
onAddPage: PropTypes.func, | ||
handleClose: PropTypes.func, | ||
}; | ||
|
||
class AddWikiPageDialog extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
const { wikiPageName = '' } = props; | ||
this.state = { | ||
wikiPageName, | ||
errMessage: '', | ||
isSubmitBtnActive: !!wikiPageName.length, | ||
}; | ||
this.inputRef = React.createRef(); | ||
} | ||
|
||
handleChange = (e) => { | ||
const isSubmitBtnActive = !!e.target.value.trim(); | ||
const wikiPageName = e.target.value; | ||
this.setState({ isSubmitBtnActive, wikiPageName }); | ||
}; | ||
|
||
handleSubmit = () => { | ||
if (!this.state.isSubmitBtnActive) return; | ||
// first param set false to prevent redirect to new page | ||
this.props.onAddPage(false, this.state.wikiPageName); | ||
this.props.handleClose(); | ||
}; | ||
|
||
handleKeyDown = (e) => { | ||
if (e.key === 'Enter') { | ||
e.preventDefault(); | ||
this.handleSubmit(); | ||
} | ||
}; | ||
|
||
onDialogLoad = () => { | ||
const input = this.inputRef.current; | ||
if (!input) return; | ||
|
||
input.focus(); | ||
const focusPosition = this.props.wikiPageName.length; | ||
input.setSelectionRange(focusPosition,focusPosition); | ||
}; | ||
|
||
render() { | ||
const { handleClose } = this.props; | ||
return ( | ||
<Modal isOpen={true} toggle={handleClose} onOpened={this.onDialogLoad}> | ||
<ModalHeader toggle={handleClose}>{gettext('New Wiki Page')}</ModalHeader> | ||
<ModalBody> | ||
<Form> | ||
<FormGroup> | ||
<Label for="pageName">{gettext('Name')}</Label> | ||
<Input | ||
id="pageName" | ||
onKeyDown={this.handleKeyDown} | ||
innerRef={this.inputRef} | ||
value={this.state.wikiPageName} | ||
onChange={this.handleChange} | ||
/> | ||
</FormGroup> | ||
</Form> | ||
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>} | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button color="secondary" onClick={handleClose}>{gettext('Cancel')}</Button> | ||
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button> | ||
</ModalFooter> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
AddWikiPageDialog.propTypes = propTypes; | ||
|
||
export default AddWikiPageDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { EventBus, EXTERNAL_EVENT } from '@seafile/sdoc-editor'; | ||
import AddWikiPageDialog from '../../components/dialog/add-wiki-page-dialog'; | ||
|
||
const propTypes = { | ||
onAddWikiPage: PropTypes.func.isRequired, | ||
}; | ||
|
||
class WikiExternalOperations extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isShowAddWikiPageDialog: false, | ||
wikiPageName: '', | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const eventBus = EventBus.getInstance(); | ||
this.unsubscribeCreateWikiPage = eventBus.subscribe(EXTERNAL_EVENT.CREATE_WIKI_PAGE, this.onAddWikiPageDialogDisplayed); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.unsubscribeCreateWikiPage(); | ||
} | ||
|
||
onAddWikiPageDialogDisplayed = ({ newFileName: wikiPageName = '' }) => { | ||
this.setState({ | ||
wikiPageName, | ||
isShowAddWikiPageDialog: true, | ||
}); | ||
}; | ||
|
||
changeAddWikiPageDialogDisplayed = () => { | ||
this.setState({ isShowAddWikiPageDialog: !this.state.isShowAddWikiPageDialog }); | ||
}; | ||
|
||
render() { | ||
const { onAddWikiPage } = this.props; | ||
const { isShowAddWikiPageDialog, wikiPageName } = this.state; | ||
|
||
return ( | ||
<> | ||
{isShowAddWikiPageDialog && ( | ||
<AddWikiPageDialog | ||
wikiPageName={wikiPageName} | ||
onAddPage={onAddWikiPage} | ||
handleClose={this.changeAddWikiPageDialogDisplayed} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
WikiExternalOperations.propTypes = propTypes; | ||
|
||
export default WikiExternalOperations; |
Oops, something went wrong.