mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 09:35:10 +01:00
b45c68b2dc
Conflicts: ownership/serializers.py
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
import React from 'react';
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
let AclProxy = React.createClass({
|
|
propTypes: {
|
|
children: React.PropTypes.oneOfType([
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
React.PropTypes.element
|
|
]).isRequired,
|
|
aclObject: React.PropTypes.object,
|
|
aclName: React.PropTypes.string,
|
|
show: React.PropTypes.bool
|
|
},
|
|
|
|
getChildren() {
|
|
if (this.props.children.length && this.props.children.length > 1){
|
|
/*
|
|
This might ruin styles for header items in the navbar etc
|
|
*/
|
|
return (
|
|
<span>
|
|
{this.props.children}
|
|
</span>
|
|
);
|
|
}
|
|
/* can only do this when there is only 1 child, but will preserve styles */
|
|
return this.props.children;
|
|
},
|
|
|
|
render() {
|
|
if(this.props.show) {
|
|
return this.getChildren();
|
|
} else {
|
|
if(this.props.aclObject) {
|
|
if(this.props.aclObject[this.props.aclName]) {
|
|
return this.getChildren();
|
|
} else {
|
|
/* if(typeof this.props.aclObject[this.props.aclName] === 'undefined') {
|
|
console.warn('The aclName you\'re filtering for was not present (or undefined) in the aclObject.');
|
|
} */
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
});
|
|
|
|
export default AclProxy;
|