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:
parent
cb6c4aaf0e
commit
f850176b7c
@ -17,29 +17,47 @@ let NavRoutesLinks = React.createClass({
|
|||||||
userAcl: React.PropTypes.object
|
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) {
|
extractLinksFromRoutes(node, userAcl, i) {
|
||||||
if(!node) {
|
if(!node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let links = node.props.children.map((child, j) => {
|
let links = node.props.children.map((child, j) => {
|
||||||
|
|
||||||
let childrenFn = null;
|
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) {
|
if(child.props.children && child.props.children.length > 0) {
|
||||||
childrenFn = this.extractLinksFromRoutes(child, userAcl, i++);
|
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(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') {
|
if(aclName && typeof aclName !== 'undefined') {
|
||||||
return (
|
return (
|
||||||
<AclProxy
|
<AclProxy
|
||||||
|
key={j}
|
||||||
aclName={aclName}
|
aclName={aclName}
|
||||||
aclObject={this.props.userAcl}>
|
aclObject={this.props.userAcl}>
|
||||||
<NavRoutesLinksLink
|
<NavRoutesLinksLink
|
||||||
key={j}
|
|
||||||
headerTitle={headerTitle}
|
headerTitle={headerTitle}
|
||||||
routeName={name}
|
routeName={name}
|
||||||
depth={i}
|
depth={i}
|
||||||
|
@ -22,6 +22,8 @@ let NavRoutesLinksLink = React.createClass({
|
|||||||
render() {
|
render() {
|
||||||
let { children, headerTitle, depth, routeName } = this.props;
|
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) {
|
if(children) {
|
||||||
return (
|
return (
|
||||||
<DropdownButton title={headerTitle}>
|
<DropdownButton title={headerTitle}>
|
||||||
|
Loading…
Reference in New Issue
Block a user