1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-10 03:11:07 +00:00

change publish wiki custom URL (#6817)

This commit is contained in:
Michael An
2024-09-21 17:18:04 +08:00
committed by GitHub
parent adf6591e59
commit ae4115ff15
3 changed files with 66 additions and 23 deletions

View File

@@ -2,26 +2,39 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import copy from 'copy-to-clipboard'; import copy from 'copy-to-clipboard';
import { gettext, serviceURL } from '../../utils/constants'; import { gettext, serviceURL } from '../../utils/constants';
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Alert, InputGroup, InputGroupAddon } from 'reactstrap'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Alert, InputGroup, InputGroupText } from 'reactstrap';
import toaster from '../toast'; import toaster from '../toast';
import wikiAPI from '../../utils/wiki-api'; import wikiAPI from '../../utils/wiki-api';
import '../../css/publish-wiki-dialog.css';
const propTypes = { const propTypes = {
wiki: PropTypes.object, wiki: PropTypes.object,
onPublish: PropTypes.func.isRequired, onPublish: PropTypes.func.isRequired,
toggleCancel: PropTypes.func.isRequired, toggleCancel: PropTypes.func.isRequired,
}; };
const DEFAULT_URL = serviceURL + '/wiki/publish/';
class PublishWikiDialog extends React.Component { class PublishWikiDialog extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
url: serviceURL + '/wiki/publish/' + this.props.customUrl, url: this.props.customUrl,
errMessage: '', errMessage: '',
isSubmitBtnActive: false, isSubmitBtnActive: false,
}; };
this.newInput = React.createRef(); this.newInput = React.createRef();
this.preTextRef = React.createRef();
}
componentDidMount() {
setTimeout(() => {
const preTextWidth = this.preTextRef.current.offsetWidth;
this.newInput.current.style.paddingLeft = (preTextWidth + 12) + 'px';
this.newInput.current.focus();
}, 1);
} }
handleChange = (e) => { handleChange = (e) => {
@@ -36,18 +49,19 @@ class PublishWikiDialog extends React.Component {
if (!isValid) { if (!isValid) {
this.setState({ this.setState({
errMessage: errMessage, errMessage: errMessage,
url: serviceURL + '/wiki/publish/', url: '',
}); });
} else { } else {
this.props.onPublish(this.state.url.trim()); this.props.onPublish(DEFAULT_URL + this.state.url.trim());
this.toggle();
} }
}; };
deleteCustomUrl = () => { deleteCustomUrl = () => {
let wiki_id = this.props.wiki.id; let wiki_id = this.props.wiki.id;
wikiAPI.deletePublishWikiLink(wiki_id).then((res) => { wikiAPI.deletePublishWikiLink(wiki_id).then((res) => {
this.setState({ url: serviceURL + '/wiki/publish/' }); this.setState({ url: '' });
toaster.success(gettext('Successfully.')); toaster.success(gettext('Successfully'));
}).catch((error) => { }).catch((error) => {
if (error.response) { if (error.response) {
let errorMsg = error.response.data.error_msg; let errorMsg = error.response.data.error_msg;
@@ -56,7 +70,6 @@ class PublishWikiDialog extends React.Component {
}); });
}; };
handleKeyDown = (e) => { handleKeyDown = (e) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
this.handleSubmit(); this.handleSubmit();
@@ -73,43 +86,44 @@ class PublishWikiDialog extends React.Component {
let errMessage = ''; let errMessage = '';
if (!url) { if (!url) {
isValid = false; isValid = false;
errMessage = gettext('url is required.'); errMessage = gettext('URL is required');
return { isValid, errMessage };
}
if (!(url.includes(serviceURL + '/wiki/publish/'))) {
isValid = false;
errMessage = gettext('url need include specific prefix.');
return { isValid, errMessage }; return { isValid, errMessage };
} }
return { isValid, errMessage }; return { isValid, errMessage };
}; };
copyLink = () => { copyLink = () => {
copy(this.state.url); copy(DEFAULT_URL + this.state.url.trim());
toaster.success(gettext('URL is copied to the clipboard')); toaster.success(gettext('URL is copied to the clipboard'));
}; };
onClickPreText = () => {
this.newInput.current.focus();
};
render() { render() {
return ( return (
<Modal isOpen={true} toggle={this.toggle}> <Modal isOpen={true} toggle={this.toggle}>
<ModalHeader toggle={this.toggle}>{gettext('Publish Wiki')}</ModalHeader> <ModalHeader toggle={this.toggle}>{gettext('Publish Wiki')}</ModalHeader>
<ModalBody> <ModalBody>
<p>{gettext('Customize URL')}</p> <p>{gettext('Customize URL')}</p>
<InputGroup> <InputGroup className="publish-wiki-custom-url-inputs">
<Input <span className="input-pretext" ref={this.preTextRef} onClick={this.onClickPreText}>{DEFAULT_URL}</span>
onKeyDown={this.handleKeyDown} <input
innerRef={this.newInput} className="publish-wiki-custom-url-input form-control"
placeholder="customize url" type="text"
value={this.state.url} value={this.state.url}
onChange={this.handleChange} onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
ref={this.newInput}
/> />
<InputGroupAddon addonType="append"> <InputGroupText>
<Button color="primary" onClick={this.copyLink} className="border-0">{gettext('Copy')}</Button> <Button color="primary" onClick={this.copyLink} className="border-0">{gettext('Copy')}</Button>
</InputGroupAddon> </InputGroupText>
</InputGroup> </InputGroup>
<span className='tip mb-1' style={{ fontSize: '14px' }}> <p className='sf-tip-default mt-2'>
{gettext('The custom part of the URL must be between 5 and 30 characters long and may only contain letters (a-z), numbers, and hyphens.')} {gettext('The custom part of the URL must be between 5 and 30 characters long and may only contain letters (a-z), numbers, and hyphens.')}
</span> </p>
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>} {this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>

View File

@@ -346,3 +346,8 @@ img[src=""],img:not([src]) { /* for first loading img*/
align-items: center; align-items: center;
text-align: center; text-align: center;
} }
.sf-tip-default {
font-size: 13px;
color: #666;
}

View File

@@ -0,0 +1,24 @@
.publish-wiki-custom-url-inputs .input-pretext {
position: absolute;
left: 12px;
top: 0;
height: 38px;
line-height: 38px;
z-index: 1;
color: #666;
}
.publish-wiki-custom-url-inputs .publish-wiki-custom-url-input {
background-color: transparent;
border-radius: 4px 0 0 4px !important;
border-right: none;
}
.publish-wiki-custom-url-inputs .input-group-text {
padding: 0;
border: none;
}
.publish-wiki-custom-url-inputs .input-group-text .btn {
border-radius: 0 4px 4px 0;
}