diff --git a/frontend/src/components/cur-dir-path/dir-path.js b/frontend/src/components/cur-dir-path/dir-path.js index 7150af4a1a..b8b9abdd55 100644 --- a/frontend/src/components/cur-dir-path/dir-path.js +++ b/frontend/src/components/cur-dir-path/dir-path.js @@ -3,8 +3,8 @@ import PropTypes from 'prop-types'; import { Link } from '@gatsbyjs/reach-router'; import { UncontrolledTooltip } from 'reactstrap'; import { siteRoot, gettext } from '../../utils/constants'; -import InternalLinkDialog from '../dialog/internal-link-dialog'; import { Utils } from '../../utils/utils'; +import { InternalLinkOperation } from '../operations'; const propTypes = { repoName: PropTypes.string.isRequired, @@ -103,12 +103,9 @@ class DirPath extends React.Component { {repoName} } {pathElem} - {this.props.isViewFile && - - } + {this.props.isViewFile && ( + + )} {(this.props.isViewFile && fileTags.length !== 0) && {fileTags.map((fileTag, index) => { diff --git a/frontend/src/components/dialog/internal-link-dialog.js b/frontend/src/components/dialog/internal-link-dialog.js index a40bafeb4c..aa5b3b966f 100644 --- a/frontend/src/components/dialog/internal-link-dialog.js +++ b/frontend/src/components/dialog/internal-link-dialog.js @@ -7,69 +7,63 @@ import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; -import '../../css/internal-link.css'; - const propTypes = { path: PropTypes.string.isRequired, repoID: PropTypes.string.isRequired, + onInternalLinkDialogToggle: PropTypes.func.isRequired, }; class InternalLinkDialog extends React.Component { + constructor(props) { super(props); this.state = { - isOpen: false, smartLink: '', + isLoading: true, }; - - this.toggle = this.toggle.bind(this); - this.getInternalLink = this.getInternalLink.bind(this); - this.copyToClipBoard = this.copyToClipBoard.bind(this); } - toggle() { - this.setState({ - isOpen: !this.state.isOpen, - }); + componentDidMount() { + this.getInternalLink(); } - getInternalLink() { + getInternalLink = () => { let repoID = this.props.repoID; let path = this.props.path; seafileAPI.getInternalLink(repoID, path).then(res => { + const { smart_link } = res.data; this.setState({ - isOpen: true, - smartLink: res.data.smart_link + isLoading: false, + smartLink: smart_link, }); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); + this.setState({isLoading: false}); }); } - copyToClipBoard() { + copyToClipBoard = () => { copy(this.state.smartLink); - this.setState({ - isOpen: false - }); - let message = gettext('Internal link has been copied to clipboard'); - toaster.success(message), { - duration: 2 - }; + const message = gettext('Internal link has been copied to clipboard'); + toaster.success(message, {duration: 2}); + this.toggle(); + } + + toggle = () => { + this.props.onInternalLinkDialogToggle(); } render() { + const tipMessage = gettext('An internal link is a link to a file or folder that can be accessed by users with read permission to the file or folder.'); return ( - - + {gettext('Internal Link')} - - {gettext('An internal link is a link to a file or folder that can be accessed by users with read permission to the file or folder.')} - + {tipMessage} - {this.state.smartLink} + {this.state.smartLink} diff --git a/frontend/src/components/file-view/file-info.js b/frontend/src/components/file-view/file-info.js index cfa6d98386..ef68195d5c 100644 --- a/frontend/src/components/file-view/file-info.js +++ b/frontend/src/components/file-view/file-info.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import { isPro, gettext, mediaUrl, siteRoot } from '../../utils/constants'; -import InternalLinkDialog from '../dialog/internal-link-dialog'; +import { InternalLinkOperation } from '../operations'; const propTypes = { toggleStar: PropTypes.func.isRequired, @@ -40,7 +40,7 @@ class FileInfo extends React.PureComponent { aria-label={isStarred ? gettext('Unstar') : gettext('Star')} onClick={this.toggleStar}> - + {(isPro && isLocked) && { + this.setState({isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog}); + } + + render() { + const { repoID, path } = this.props; + const { isShowInternalLinkDialog } = this.state; + const title = gettext('Internal Link'); + return ( + + + + + {isShowInternalLinkDialog && ( + + )} + + ); + } + +} + +InternalLinkOperation.propTypes = propTypes; + +export default InternalLinkOperation; diff --git a/frontend/src/components/operations/style.css b/frontend/src/components/operations/style.css new file mode 100644 index 0000000000..b819cfad66 --- /dev/null +++ b/frontend/src/components/operations/style.css @@ -0,0 +1,17 @@ +.dialog-operation { + display: flex; + align-items: center; +} + +.dialog-operation .file-internal-link { + font-size: 12px; + font-weight: 700; + cursor: pointer; + margin-left: 0.5rem; + color: #999; + margin-top: 2px; +} + +.dialog-operation .file-internal-link:hover { + color: #333; +} diff --git a/frontend/src/css/file-view.css b/frontend/src/css/file-view.css index c2674fe941..ee7e97c000 100644 --- a/frontend/src/css/file-view.css +++ b/frontend/src/css/file-view.css @@ -15,8 +15,7 @@ body { line-height: 1.5; margin-bottom: 0; } -.file-star, -.file-internal-link { +.file-star { font-size: .875rem; color: #999; margin-left: .5rem; diff --git a/frontend/src/css/internal-link.css b/frontend/src/css/internal-link.css deleted file mode 100644 index ff6803ab2e..0000000000 --- a/frontend/src/css/internal-link.css +++ /dev/null @@ -1,10 +0,0 @@ -.file-internal-link { - font-size: .8em; - color: #808080; - cursor: pointer; - margin-left: .5rem; - vertical-align: text-bottom; -} -.file-internal-link:hover { - color: #333; -} diff --git a/frontend/src/css/markdown-viewer/markdown-editor.css b/frontend/src/css/markdown-viewer/markdown-editor.css index d6e4d845e6..c42ed55a54 100644 --- a/frontend/src/css/markdown-viewer/markdown-editor.css +++ b/frontend/src/css/markdown-viewer/markdown-editor.css @@ -200,8 +200,7 @@ font-size: 0.875rem; } -.topbar-file-info .file-title .file-star, -.topbar-file-info .file-title .file-internal-link { +.topbar-file-info .file-title .file-star { font-size: 0.875rem; cursor: pointer; margin-left: 0.5rem; @@ -209,15 +208,6 @@ color: #999; } -.topbar-file-info .file-title .file-internal-link { - font-size: 12px; - font-weight: 700; -} - -.topbar-file-info .file-title .file-internal-link:hover { - color: #333; -} - .topbar-file-info .file-title .file-star .star { color: #999; } diff --git a/frontend/src/pages/markdown-editor/header-toolbar/file-info.js b/frontend/src/pages/markdown-editor/header-toolbar/file-info.js index 1ef9e37719..8b52557628 100644 --- a/frontend/src/pages/markdown-editor/header-toolbar/file-info.js +++ b/frontend/src/pages/markdown-editor/header-toolbar/file-info.js @@ -1,7 +1,7 @@ import React from 'react'; import moment from 'moment'; import { gettext } from '../../../utils/constants'; -import InternalLinkDialog from '../../../components/dialog/internal-link-dialog'; +import { InternalLinkOperation } from '../../../components/operations'; const { repoID, filePath } = window.app.pageOptions; @@ -22,7 +22,7 @@ class FileInfo extends React.PureComponent { - + {(isPro && isLocked) && ( }; ReactDom.render(
- {gettext('An internal link is a link to a file or folder that can be accessed by users with read permission to the file or folder.')} -
{tipMessage}
- {this.state.smartLink} + {this.state.smartLink}