2015-07-14 11:11:28 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2015-07-14 11:14:15 +02:00
|
|
|
/**
|
|
|
|
* This component can easily be used to present another component conditionally
|
|
|
|
* - dependent on their acl.
|
|
|
|
*
|
|
|
|
* In order to do that, just wrap AclProxy around the component, add aclObject and
|
|
|
|
* the acl name you're looking for.
|
|
|
|
*/
|
2015-07-14 11:11:28 +02:00
|
|
|
let AclProxy = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
children: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element
|
|
|
|
]).isRequired,
|
2015-07-14 22:34:34 +02:00
|
|
|
aclObject: React.PropTypes.object,
|
|
|
|
aclName: React.PropTypes.string,
|
|
|
|
show: React.PropTypes.bool
|
2015-07-14 11:11:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2015-07-14 22:34:34 +02:00
|
|
|
if(this.props.show) {
|
2015-07-14 11:11:28 +02:00
|
|
|
return (
|
2015-07-14 17:49:31 +02:00
|
|
|
<span>
|
2015-07-14 11:11:28 +02:00
|
|
|
{this.props.children}
|
2015-07-14 17:49:31 +02:00
|
|
|
</span>
|
2015-07-14 11:11:28 +02:00
|
|
|
);
|
|
|
|
} else {
|
2015-07-14 22:50:48 +02:00
|
|
|
if(this.props.aclObject) {
|
|
|
|
if(this.props.aclObject[this.props.aclName]) {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{this.props.children}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
2015-08-07 13:05:50 +02:00
|
|
|
/* if(typeof this.props.aclObject[this.props.aclName] === 'undefined') {
|
2015-07-15 01:40:48 +02:00
|
|
|
console.warn('The aclName you\'re filtering for was not present (or undefined) in the aclObject.');
|
2015-08-07 13:05:50 +02:00
|
|
|
} */
|
2015-07-14 22:50:48 +02:00
|
|
|
return null;
|
2015-07-14 22:34:34 +02:00
|
|
|
}
|
2015-07-14 11:11:28 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-14 22:50:48 +02:00
|
|
|
return null;
|
2015-07-14 11:11:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-14 22:50:48 +02:00
|
|
|
export default AclProxy;
|