2016-08-24 15:09:42 +02:00
|
|
|
/**
|
2017-03-18 17:34:00 +01:00
|
|
|
*
|
|
|
|
* LeftMenuLink
|
|
|
|
*
|
|
|
|
*/
|
2016-08-24 15:09:42 +02:00
|
|
|
|
2017-09-26 16:36:28 +02:00
|
|
|
import React from 'react';
|
2018-01-04 11:24:27 +01:00
|
|
|
import { startsWith, upperFirst } from 'lodash';
|
2017-09-20 11:12:04 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2017-08-17 15:39:09 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-08-21 15:12:53 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
2017-08-17 15:39:09 +02:00
|
|
|
|
2018-03-01 13:12:22 +01:00
|
|
|
import en from 'translations/en.json';
|
|
|
|
|
2017-08-17 15:39:09 +02:00
|
|
|
import styles from './styles.scss';
|
2016-08-24 15:09:42 +02:00
|
|
|
|
2018-05-02 11:01:27 +02:00
|
|
|
class LeftMenuLink extends React.Component {
|
|
|
|
// eslint-disable-line react/prefer-stateless-function
|
2016-08-24 15:09:42 +02:00
|
|
|
render() {
|
2017-07-21 18:15:43 +02:00
|
|
|
// We need to create our own active url checker,
|
|
|
|
// because of the two levels router.
|
2018-05-02 11:01:27 +02:00
|
|
|
const isLinkActive = startsWith(
|
|
|
|
window.location.pathname.replace('/admin', ''),
|
|
|
|
this.props.destination,
|
|
|
|
);
|
|
|
|
const plugin =
|
|
|
|
this.props.source !== 'content-manager' && this.props.source !== '' ? (
|
|
|
|
<div className={styles.plugin}>
|
|
|
|
<span>{upperFirst(this.props.source.split('-').join(' '))}</span>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
''
|
|
|
|
);
|
2017-07-21 18:15:43 +02:00
|
|
|
|
2018-03-01 13:12:22 +01:00
|
|
|
// Check if messageId exists in en locale to prevent warning messages
|
|
|
|
const content = en[this.props.label] ? (
|
|
|
|
<FormattedMessage
|
|
|
|
id={this.props.label}
|
2018-05-02 11:01:27 +02:00
|
|
|
defaultMessage="{label}"
|
2018-03-01 13:12:22 +01:00
|
|
|
values={{
|
|
|
|
label: `${this.props.label}`,
|
|
|
|
}}
|
|
|
|
className={styles.linkLabel}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<span className={styles.linkLabel}>{this.props.label}</span>
|
|
|
|
);
|
|
|
|
|
2016-08-24 15:09:42 +02:00
|
|
|
return (
|
2017-08-17 15:03:03 +02:00
|
|
|
<li className={styles.item}>
|
2017-11-27 17:27:16 +01:00
|
|
|
<Link
|
|
|
|
className={`${styles.link} ${isLinkActive ? styles.linkActive : ''}`}
|
|
|
|
to={{
|
|
|
|
pathname: this.props.destination,
|
2017-12-05 15:28:31 +01:00
|
|
|
search: this.props.source ? `?source=${this.props.source}` : '',
|
2017-11-27 17:27:16 +01:00
|
|
|
}}
|
|
|
|
>
|
2018-05-02 11:01:27 +02:00
|
|
|
<i className={`${styles.linkIcon} fa-${this.props.icon} fa`} />
|
2018-03-01 13:12:22 +01:00
|
|
|
{content}
|
2016-08-25 10:47:15 +02:00
|
|
|
</Link>
|
2018-01-04 11:24:27 +01:00
|
|
|
{plugin}
|
2016-08-24 15:09:42 +02:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeftMenuLink.propTypes = {
|
2017-09-20 11:12:04 +02:00
|
|
|
destination: PropTypes.string.isRequired,
|
|
|
|
icon: PropTypes.string.isRequired,
|
|
|
|
label: PropTypes.string.isRequired,
|
2017-11-27 17:27:16 +01:00
|
|
|
source: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
LeftMenuLink.defaultProps = {
|
|
|
|
source: '',
|
2016-08-24 15:09:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default LeftMenuLink;
|