61 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-11-30 18:07:30 +01:00
/**
2019-09-17 15:24:22 +02:00
*
* BoundRoute
*
*/
2017-11-30 18:07:30 +01:00
import React from 'react';
2017-12-07 16:53:30 +01:00
import { get, includes, map, tail, toLower } from 'lodash';
2017-11-30 18:07:30 +01:00
import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
2019-09-17 15:24:22 +02:00
import { Header, Path, Verb, Wrapper } from './Components';
2017-11-30 18:07:30 +01:00
function BoundRoute({ route }) {
const title = get(route, 'handler');
2019-09-17 15:24:22 +02:00
const formattedRoute = get(route, 'path')
? tail(get(route, 'path').split('/'))
: [];
const [controller = '', action = ''] = title ? title.split('.') : [];
2017-11-30 18:07:30 +01:00
return (
<div className="col-md-12">
2019-09-17 15:24:22 +02:00
<Header>
2017-11-30 18:07:30 +01:00
<FormattedMessage id="users-permissions.BoundRoute.title" />
&nbsp;
<span>{controller}</span>
<span>.{action} </span>
2019-09-17 15:24:22 +02:00
</Header>
<Wrapper>
<Verb className={toLower(get(route, 'method'))}>
2017-11-30 18:07:30 +01:00
{get(route, 'method')}
2019-09-17 15:24:22 +02:00
</Verb>
<Path>
2017-11-30 18:07:30 +01:00
{map(formattedRoute, value => (
<span
key={value}
style={includes(value, ':') ? { color: '#787E8F' } : {}}
>
/{value}
</span>
))}
2019-09-17 15:24:22 +02:00
</Path>
</Wrapper>
2017-11-30 18:07:30 +01:00
</div>
);
}
BoundRoute.defaultProps = {
route: {
handler: 'Nocontroller.error',
method: 'GET',
path: '/there-is-no-path',
},
};
BoundRoute.propTypes = {
route: PropTypes.object,
};
export default BoundRoute;