2019-07-22 10:29:59 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Button } from 'reactstrap';
|
|
|
|
import toaster from '../toast';
|
2020-02-03 08:43:49 +00:00
|
|
|
import copy from '../copy-to-clipboard';
|
2019-07-22 10:29:59 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
import { Utils } from '../../utils/utils';
|
2019-08-12 06:04:14 +00:00
|
|
|
import Loading from '../loading';
|
2019-07-22 10:29:59 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
2019-08-05 09:31:15 +00:00
|
|
|
direntType: PropTypes.string
|
2019-07-22 10:29:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class InternalLink extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
smartLink: '',
|
2019-08-12 06:04:14 +00:00
|
|
|
isInternalLoding: true,
|
2019-07-22 10:29:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-08-05 09:31:15 +00:00
|
|
|
let { repoID, path, direntType } = this.props;
|
|
|
|
seafileAPI.getInternalLink(repoID, path, direntType).then(res => {
|
2019-07-22 10:29:59 +00:00
|
|
|
this.setState({
|
2019-08-12 06:04:14 +00:00
|
|
|
smartLink: res.data.smart_link,
|
|
|
|
isInternalLoding: false
|
2019-07-22 10:29:59 +00:00
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
copyToClipBoard = () => {
|
|
|
|
copy(this.state.smartLink);
|
|
|
|
let message = gettext('Internal link has been copied to clipboard');
|
2023-09-13 00:40:50 +00:00
|
|
|
toaster.success(message, {
|
2019-07-22 10:29:59 +00:00
|
|
|
duration: 2
|
2023-09-13 00:40:50 +00:00
|
|
|
});
|
|
|
|
};
|
2019-07-22 10:29:59 +00:00
|
|
|
|
|
|
|
render() {
|
2019-08-12 06:04:14 +00:00
|
|
|
if (this.state.isInternalLoding) {
|
2024-07-18 03:58:42 +00:00
|
|
|
return (<Loading />);
|
2019-08-12 06:04:14 +00:00
|
|
|
}
|
2019-07-22 10:29:59 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p className="tip mb-1">
|
|
|
|
{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.')}
|
|
|
|
</p>
|
|
|
|
<p>
|
2023-09-13 00:40:50 +00:00
|
|
|
<a target="_blank" href={this.state.smartLink} rel="noreferrer">{this.state.smartLink}</a>
|
2019-07-22 10:29:59 +00:00
|
|
|
</p>
|
|
|
|
<Button onClick={this.copyToClipBoard} color="primary" className="mt-2">{gettext('Copy')}</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalLink.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default InternalLink;
|