From ec1e1933e8ec2b4c36307d7a21e5864939f5d8de Mon Sep 17 00:00:00 2001 From: Rodrigo Antinarelli Date: Tue, 24 Mar 2020 18:16:47 -0300 Subject: [PATCH] fix for TableBody --- .../ui/src/components/TableBody/TableBody.jsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/platform/ui/src/components/TableBody/TableBody.jsx b/platform/ui/src/components/TableBody/TableBody.jsx index d3e6d6357..d9f393dc0 100644 --- a/platform/ui/src/components/TableBody/TableBody.jsx +++ b/platform/ui/src/components/TableBody/TableBody.jsx @@ -11,9 +11,11 @@ const TableBody = ({ children, className, style }) => { )} style={style} > - {React.Children.map(children, child => - React.cloneElement(child, { isTableHead: false }) - )} + {React.isValidElement(children) + ? React.cloneElement(children, { + isTableHead: false, + }) + : children} ); }; @@ -24,7 +26,26 @@ TableBody.defaultProps = { }; TableBody.propTypes = { - children: PropTypes.node.isRequired, + children: function(props, propName, componentName) { + const elements = React.Children.toArray(props.children); + const isString = elements.some(child => typeof child === 'string'); + + if (isString) { + return new Error( + `Failed prop type: Invalid prop ${propName} supplied to ${componentName}, expected a valid element instead of a string.` + ); + } + + const isInvalidElement = elements.some( + child => !React.isValidElement(child) + ); + + if (isInvalidElement) { + return new Error( + `Failed prop type: Invalid prop ${propName} supplied to ${componentName}, expected a valid node element.` + ); + } + }, className: PropTypes.string, style: PropTypes.object, };