2016-08-24 15:09:42 +02:00
|
|
|
/**
|
2017-03-15 11:48:56 +01:00
|
|
|
*
|
|
|
|
* LeftMenuLinkContainer
|
|
|
|
*
|
|
|
|
*/
|
2016-08-24 15:09:42 +02:00
|
|
|
|
2017-09-26 16:36:28 +02:00
|
|
|
import React from 'react';
|
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-11-27 12:22:20 +01:00
|
|
|
import { get, snakeCase, isEmpty, map, sortBy } from 'lodash';
|
2017-08-18 14:17:15 +02:00
|
|
|
|
2016-08-24 15:09:42 +02:00
|
|
|
import LeftMenuLink from 'components/LeftMenuLink';
|
2017-08-17 15:39:09 +02:00
|
|
|
|
2016-08-24 15:09:42 +02:00
|
|
|
import styles from './styles.scss';
|
2017-08-17 15:39:09 +02:00
|
|
|
import messages from './messages.json';
|
2016-08-24 15:09:42 +02:00
|
|
|
|
2017-10-11 16:54:58 +02:00
|
|
|
function LeftMenuLinkContainer({ plugins }) {
|
2017-11-27 12:22:20 +01:00
|
|
|
const pluginsObject = plugins.toJS();
|
|
|
|
|
2017-10-11 16:54:58 +02:00
|
|
|
// Generate the list of sections
|
2017-11-27 12:22:20 +01:00
|
|
|
const pluginsSections = Object.keys(pluginsObject).reduce((acc, current) => {
|
|
|
|
pluginsObject[current].leftMenuSections.forEach((section = {}) => {
|
|
|
|
acc[snakeCase(section.name)] = {
|
|
|
|
name: section.name,
|
|
|
|
links: (get(acc[snakeCase(section.name)], 'links') || []).concat(section.links.map(link => {
|
|
|
|
link.plugin = !isEmpty(pluginsObject[link.plugin] ? link.plugin : pluginsObject[current].id);
|
|
|
|
|
|
|
|
return link;
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const linkSections = Object.keys(pluginsSections).map((current, j) => (
|
|
|
|
<div key={j}>
|
|
|
|
<p className={styles.title}>{pluginsSections[current].name}</p>
|
|
|
|
<ul className={styles.list}>
|
|
|
|
{sortBy(pluginsSections[current].links, 'label').map(link =>
|
|
|
|
<LeftMenuLink key={link.label} icon={link.icon || 'link'} label={link.label} destination={`/plugins/${link.plugin}/${link.destination}`} />
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2017-10-11 16:54:58 +02:00
|
|
|
));
|
2016-08-24 15:09:42 +02:00
|
|
|
|
2017-10-26 17:21:53 +02:00
|
|
|
// Check if the plugins list is empty or not and display plugins by name
|
2017-11-27 12:22:20 +01:00
|
|
|
const pluginsLinks = !isEmpty(pluginsObject) ?
|
|
|
|
map(sortBy(pluginsObject, 'name'), plugin => (
|
2017-10-11 16:54:58 +02:00
|
|
|
<LeftMenuLink
|
2017-10-26 17:21:53 +02:00
|
|
|
key={get(plugin, 'id')}
|
|
|
|
icon={get(plugin, 'icon') || 'plug'}
|
|
|
|
label={get(plugin, 'name')}
|
|
|
|
destination={`/plugins/${get(plugin, 'id')}`}
|
2017-10-11 16:54:58 +02:00
|
|
|
/>
|
|
|
|
))
|
|
|
|
: (
|
|
|
|
<li className={styles.noPluginsInstalled}>
|
|
|
|
<FormattedMessage {...messages.noPluginsInstalled} />.
|
|
|
|
</li>
|
2016-08-24 15:09:42 +02:00
|
|
|
);
|
2017-10-11 16:54:58 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.leftMenuLinkContainer}>
|
|
|
|
{linkSections}
|
|
|
|
<div>
|
|
|
|
<p className={styles.title}><FormattedMessage {...messages.plugins} /></p>
|
|
|
|
<ul className={styles.list}>
|
|
|
|
{pluginsLinks}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<p className={styles.title}><FormattedMessage {...messages.general} /></p>
|
|
|
|
<ul className={styles.list}>
|
|
|
|
<LeftMenuLink
|
|
|
|
icon="cubes"
|
|
|
|
label={messages.listPlugins.id}
|
|
|
|
destination="/list-plugins"
|
|
|
|
/>
|
|
|
|
<LeftMenuLink
|
|
|
|
icon="download"
|
|
|
|
label={messages.installNewPlugin.id}
|
|
|
|
destination="/install-plugin"
|
|
|
|
/>
|
|
|
|
<LeftMenuLink
|
|
|
|
icon="gear"
|
|
|
|
label={messages.configuration.id}
|
|
|
|
destination="/configuration"
|
|
|
|
/>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-08-24 15:09:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LeftMenuLinkContainer.propTypes = {
|
2017-09-20 11:12:04 +02:00
|
|
|
plugins: PropTypes.object.isRequired,
|
2016-08-24 15:09:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default LeftMenuLinkContainer;
|