diff --git a/frontend/src/components/dialog/publish-wiki-dialog.js b/frontend/src/components/dialog/publish-wiki-dialog.js index 08fb8d3c99..7b2d884195 100644 --- a/frontend/src/components/dialog/publish-wiki-dialog.js +++ b/frontend/src/components/dialog/publish-wiki-dialog.js @@ -2,26 +2,39 @@ import React from 'react'; import PropTypes from 'prop-types'; import copy from 'copy-to-clipboard'; 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 wikiAPI from '../../utils/wiki-api'; +import '../../css/publish-wiki-dialog.css'; + const propTypes = { wiki: PropTypes.object, onPublish: PropTypes.func.isRequired, toggleCancel: PropTypes.func.isRequired, }; +const DEFAULT_URL = serviceURL + '/wiki/publish/'; + class PublishWikiDialog extends React.Component { constructor(props) { super(props); this.state = { - url: serviceURL + '/wiki/publish/' + this.props.customUrl, + url: this.props.customUrl, errMessage: '', isSubmitBtnActive: false, }; 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) => { @@ -36,18 +49,19 @@ class PublishWikiDialog extends React.Component { if (!isValid) { this.setState({ errMessage: errMessage, - url: serviceURL + '/wiki/publish/', + url: '', }); } else { - this.props.onPublish(this.state.url.trim()); + this.props.onPublish(DEFAULT_URL + this.state.url.trim()); + this.toggle(); } }; deleteCustomUrl = () => { let wiki_id = this.props.wiki.id; wikiAPI.deletePublishWikiLink(wiki_id).then((res) => { - this.setState({ url: serviceURL + '/wiki/publish/' }); - toaster.success(gettext('Successfully.')); + this.setState({ url: '' }); + toaster.success(gettext('Successfully')); }).catch((error) => { if (error.response) { let errorMsg = error.response.data.error_msg; @@ -56,7 +70,6 @@ class PublishWikiDialog extends React.Component { }); }; - handleKeyDown = (e) => { if (e.key === 'Enter') { this.handleSubmit(); @@ -73,43 +86,44 @@ class PublishWikiDialog extends React.Component { let errMessage = ''; if (!url) { isValid = false; - errMessage = gettext('url is required.'); - return { isValid, errMessage }; - } - if (!(url.includes(serviceURL + '/wiki/publish/'))) { - isValid = false; - errMessage = gettext('url need include specific prefix.'); + errMessage = gettext('URL is required'); return { isValid, errMessage }; } return { isValid, errMessage }; }; copyLink = () => { - copy(this.state.url); + copy(DEFAULT_URL + this.state.url.trim()); toaster.success(gettext('URL is copied to the clipboard')); }; + onClickPreText = () => { + this.newInput.current.focus(); + }; + render() { return ( {gettext('Publish Wiki')}

{gettext('Customize URL')}

- - + {DEFAULT_URL} + - + - + - +

{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.')} - +

{this.state.errMessage && {this.state.errMessage}}
diff --git a/frontend/src/css/layout.css b/frontend/src/css/layout.css index b6ad2c241f..e0f734967c 100644 --- a/frontend/src/css/layout.css +++ b/frontend/src/css/layout.css @@ -346,3 +346,8 @@ img[src=""],img:not([src]) { /* for first loading img*/ align-items: center; text-align: center; } + +.sf-tip-default { + font-size: 13px; + color: #666; +} diff --git a/frontend/src/css/publish-wiki-dialog.css b/frontend/src/css/publish-wiki-dialog.css new file mode 100644 index 0000000000..5d95111d9c --- /dev/null +++ b/frontend/src/css/publish-wiki-dialog.css @@ -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; +}