1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-21 00:15:26 +00:00

add link choice (#3450)

This commit is contained in:
Michael An 2019-05-13 17:54:48 +08:00 committed by Daniel Pan
parent a9453d64dd
commit 31d39b6fa4
2 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,47 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import toaster from '../toast';
import copy from '@seafile/seafile-editor/dist/utils/copy-to-clipboard';
import { gettext } from '../../utils/constants';
const propTypes = {
currentLinkHref: PropTypes.string.isRequired,
toggle: PropTypes.func.isRequired,
};
class ViewLinkDialog extends React.Component {
constructor(props) {
super(props);
}
copyToClipBoard = () => {
copy(this.props.currentLinkHref);
let message = gettext('Link has been copied to clipboard');
toaster.success(message), {
duration: 2
};
this.props.toggle();
}
render() {
const href = this.props.currentLinkHref;
return (
<Modal isOpen={true} toggle={this.props.toggle}>
<ModalHeader toggle={this.props.toggle}>{gettext('Link')}</ModalHeader>
<ModalBody>
<p><a target="_blank" href={href}>{href}</a></p>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>{' '}
<Button color="primary" onClick={this.copyToClipBoard}>{gettext('Copy')}</Button>
</ModalFooter>
</Modal>
);
}
}
ViewLinkDialog.propTypes = propTypes;
export default ViewLinkDialog;

View File

@ -2,9 +2,10 @@ import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { seafileAPI } from '../../utils/seafile-api';
import { siteRoot, gettext } from '../../utils/constants';
import { siteRoot, gettext, serviceURL } from '../../utils/constants';
import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
import MainPanelTopbar from './main-panel-topbar';
import ViewLinkDialog from '../../components/dialog/view-link-dialog';
class OrgLinks extends React.Component {
@ -15,6 +16,8 @@ class OrgLinks extends React.Component {
page: 1,
pageNext: false,
isItemFreezed: false,
isShowLinkDialog: false,
currentLinkHref: '',
};
}
@ -56,6 +59,21 @@ class OrgLinks extends React.Component {
});
}
openLinkDialog = (link) => {
let href;
if (link.name.indexOf('/') > -1) {
href = serviceURL + '/d/' + link.token + '/';
} else {
href = serviceURL + '/f/' + link.token + '/';
}
this.setState({ currentLinkHref: href });
this.toggleLinkDialog();
}
toggleLinkDialog = () => {
this.setState({isShowLinkDialog: !this.state.isShowLinkDialog});
}
componentDidMount() {
this.listOrgLinks(this.state.page);
}
@ -91,6 +109,7 @@ class OrgLinks extends React.Component {
onFreezedItem={this.onFreezedItem}
onUnfreezedItem={this.onUnfreezedItem}
deleteOrgLink={this.deleteOrgLink}
openLinkDialog={this.openLinkDialog}
/>
</React.Fragment>
);
@ -105,6 +124,9 @@ class OrgLinks extends React.Component {
</div>
</div>
</div>
{this.state.isShowLinkDialog &&
<ViewLinkDialog currentLinkHref={this.state.currentLinkHref} toggle={this.toggleLinkDialog}/>
}
</Fragment>
);
}
@ -185,6 +207,7 @@ class RepoItem extends React.Component {
/>
<DropdownMenu>
<DropdownItem onClick={deleteOrgLink.bind(this, link.token)}>{gettext('Delete')}</DropdownItem>
<DropdownItem onClick={this.props.openLinkDialog.bind(this, link)}>{gettext('View Link')}</DropdownItem>
</DropdownMenu>
</Dropdown>
}