mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 00:00:00 +00:00
support rename Wiki (#6142)
* 01 UI support rename Wiki * rename wiki * old wiki support rename * fix wiki-v1 and wiki-v2 have same id * fix format --------- Co-authored-by: ‘JoinTyang’ <yangtong1009@163.com>
This commit is contained in:
93
frontend/src/components/dialog/rename-wiki-dialog.js
Normal file
93
frontend/src/components/dialog/rename-wiki-dialog.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Alert } from 'reactstrap';
|
||||
|
||||
const propTypes = {
|
||||
wiki: PropTypes.object,
|
||||
onRename: PropTypes.func.isRequired,
|
||||
toggleCancel: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class RenameWikiDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
newName: props.wiki.name,
|
||||
errMessage: '',
|
||||
isSubmitBtnActive: false,
|
||||
};
|
||||
this.newInput = React.createRef();
|
||||
}
|
||||
|
||||
handleChange = (e) => {
|
||||
this.setState({
|
||||
isSubmitBtnActive: !!e.target.value.trim(),
|
||||
newName: e.target.value
|
||||
});
|
||||
};
|
||||
|
||||
handleSubmit = () => {
|
||||
let { isValid, errMessage } = this.validateInput();
|
||||
if (!isValid) {
|
||||
this.setState({ errMessage : errMessage });
|
||||
} else {
|
||||
this.props.onRename(this.state.newName.trim());
|
||||
}
|
||||
};
|
||||
|
||||
handleKeyDown = (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
this.handleSubmit();
|
||||
}
|
||||
};
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggleCancel();
|
||||
};
|
||||
|
||||
validateInput = () => {
|
||||
let newName = this.state.newName.trim();
|
||||
let isValid = true;
|
||||
let errMessage = '';
|
||||
if (!newName) {
|
||||
isValid = false;
|
||||
errMessage = gettext('Name is required.');
|
||||
return { isValid, errMessage };
|
||||
}
|
||||
if (newName.indexOf('/') > -1) {
|
||||
isValid = false;
|
||||
errMessage = gettext('Name should not include ' + '\'/\'' + '.');
|
||||
return { isValid, errMessage };
|
||||
}
|
||||
return { isValid, errMessage };
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} toggle={this.toggle}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Rename Wiki')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>{gettext('New Wiki name')}</p>
|
||||
<Input
|
||||
onKeyDown={this.handleKeyDown}
|
||||
innerRef={this.newInput}
|
||||
placeholder="newName"
|
||||
value={this.state.newName}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
RenameWikiDialog.propTypes = propTypes;
|
||||
|
||||
export default RenameWikiDialog;
|
Reference in New Issue
Block a user