Skip to content

Commit

Permalink
Fix strapi#7141 - Wrong conversion of to a boolean value (strapi#7161)
Browse files Browse the repository at this point in the history
Signed-off-by: agigleux <alexandre.gigleux@sonarsource.com>

Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
Signed-off-by: Gil Fernandes <gil.fernandes@onepointltd.com>
  • Loading branch information
2 people authored and onepointconsulting committed Aug 13, 2020
1 parent 57528d3 commit 5dd5682
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Inputs({
) : (
<Error inputError={inputError} name={name} type="text" validations={validations}>
{({ canCheck, error, dispatch }) => {
const hasError = error && error !== null;
const hasError = Boolean(error);

const handleChange = e => {
if (!canCheck) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,13 @@ class InputJSONWithErrors extends React.Component {
const handleBlur = isFunction(onBlur) ? onBlur : this.handleBlur;

return (
<Error
inputError={inputError}
name={name}
type="text"
validations={validations}
>
<Error inputError={inputError} name={name} type="text" validations={validations}>
{({ canCheck, onBlur, error, dispatch }) => {
const hasError = error && error !== null;
const hasError = Boolean(error);

return (
<Wrapper
className={`${cn(!isEmpty(className) && className)} ${
hasError ? 'bordered' : ''
}`}
className={`${cn(!isEmpty(className) && className)} ${hasError ? 'bordered' : ''}`}
>
<Label htmlFor={name}>{label}</Label>
<InputJSON
Expand Down Expand Up @@ -87,9 +80,7 @@ class InputJSONWithErrors extends React.Component {
tabIndex={tabIndex}
value={value}
/>
{!hasError && inputDescription && (
<Description>{inputDescription}</Description>
)}
{!hasError && inputDescription && <Description>{inputDescription}</Description>}
{hasError && <ErrorMessage>{error}</ErrorMessage>}
</Wrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const InputUID = ({
validations={{ ...validations, regex: UID_REGEX }}
>
{({ canCheck, onBlur, error, dispatch }) => {
const hasError = error && error !== null;
const hasError = Boolean(error);

return (
<Wrapper ref={wrapperRef}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,13 @@ class WysiwygWithErrors extends React.Component {
} = this.props;

return (
<Error
inputError={inputError}
name={name}
type="text"
validations={validations}
>
<Error inputError={inputError} name={name} type="text" validations={validations}>
{({ canCheck, onBlur, error, dispatch }) => {
const hasError = error && error !== null;
const hasError = Boolean(error);

return (
<Wrapper
className={`${cn(!isEmpty(className) && className)} ${
hasError ? 'bordered' : ''
}`}
className={`${cn(!isEmpty(className) && className)} ${hasError ? 'bordered' : ''}`}
style={style}
>
<Label htmlFor={name}>{label}</Label>
Expand Down Expand Up @@ -86,9 +79,7 @@ class WysiwygWithErrors extends React.Component {
tabIndex={tabIndex}
value={value}
/>
{!hasError && inputDescription && (
<Description>{inputDescription}</Description>
)}
{!hasError && inputDescription && <Description>{inputDescription}</Description>}
{hasError && <ErrorMessage>{error}</ErrorMessage>}
</Wrapper>
);
Expand Down

0 comments on commit 5dd5682

Please sign in to comment.