1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

add documentation for nav routes links

This commit is contained in:
Tim Daubenschütz 2015-09-08 14:26:56 +02:00
parent cb6c4aaf0e
commit f850176b7c
2 changed files with 23 additions and 3 deletions

View File

@ -17,29 +17,47 @@ let NavRoutesLinks = React.createClass({
userAcl: React.PropTypes.object
},
/**
* This method generales a bunch of react-bootstrap specific links
* from the routes we defined in one of the specific routes.js file
*
* We can define a headerTitle as well as a aclName and according to that the
* link will be created for a specific user
* @param {ReactElement} node Starts at the very top of a routes files root
* @param {object} userAcl ACL object we use throughout the whole app
* @param {number} i Depth of the route in comparison to the root
* @return {Array} Array of ReactElements that can be displayed to the user
*/
extractLinksFromRoutes(node, userAcl, i) {
if(!node) {
return;
}
let links = node.props.children.map((child, j) => {
let childrenFn = null;
let { aclName, headerTitle, name, children } = child.props;
// If the node has children that could be rendered, then we want
// to execute this function again with the child as the root
//
// Otherwise we'll just pass childrenFn as false
if(child.props.children && child.props.children.length > 0) {
childrenFn = this.extractLinksFromRoutes(child, userAcl, i++);
}
let { aclName, headerTitle, name, children } = child.props;
// We validate if the user has set the title correctly,
// otherwise we're not going to render his route
if(headerTitle && typeof headerTitle === 'string') {
// if there is an aclName present on the route definition,
// we evaluate it against the user's acl
if(aclName && typeof aclName !== 'undefined') {
return (
<AclProxy
key={j}
aclName={aclName}
aclObject={this.props.userAcl}>
<NavRoutesLinksLink
key={j}
headerTitle={headerTitle}
routeName={name}
depth={i}

View File

@ -22,6 +22,8 @@ let NavRoutesLinksLink = React.createClass({
render() {
let { children, headerTitle, depth, routeName } = this.props;
// if the route has children, we're returning a DropdownButton that will get filled
// with MenuItemLinks
if(children) {
return (
<DropdownButton title={headerTitle}>