Skip to content

Commit

Permalink
fixed rendering of 0 instead of error message
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-o committed Sep 21, 2024
1 parent d4bfeba commit 8dc3f1f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions assets/editor/blocks/main/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function BlockEdit(props) {
// as this indicates we've just inserted the block and don't want
// to alarm the user with error messages.
const [allowErrorNotice, setAllowErrorNotice] = useState(!isSelected);
const [isBlockInvalid, setIsBlockInvalid] = useState(0);
const [invalidControlsCount, setInvalidControlsCount] = useState(0);

const { innerBlockSelected, postType } = useSelect(
(select) => {
Expand Down Expand Up @@ -90,11 +90,11 @@ export default function BlockEdit(props) {
if (errorsCount) {
blocksWithErrors[clientId] = errorsCount;

setIsBlockInvalid(errorsCount);
setInvalidControlsCount(errorsCount);
} else if (typeof blocksWithErrors[clientId] !== 'undefined') {
delete blocksWithErrors[clientId];

setIsBlockInvalid(0);
setInvalidControlsCount(0);
}

if (Object.keys(blocksWithErrors).length) {
Expand Down Expand Up @@ -232,7 +232,7 @@ export default function BlockEdit(props) {

const className = classnames(
'lazyblock',
isBlockInvalid && !isSelected && 'lzb-invalid',
invalidControlsCount > 0 && !isSelected && 'lzb-invalid',
blockUniqueClass
);

Expand Down Expand Up @@ -300,17 +300,17 @@ export default function BlockEdit(props) {
className="lzb-inspector-controls"
data-lazyblocks-block-name={props.name}
>
{allowErrorNotice && isBlockInvalid && (
{allowErrorNotice && invalidControlsCount > 0 && (
<div className="lzb-invalid-notice">
{sprintf(
// translators: %d: number of child controls.
_n(
'Validation failed. %d control require attention.',
'Validation failed. %d controls require attention.',
isBlockInvalid,
invalidControlsCount,
'lazy-blocks'
),
isBlockInvalid
invalidControlsCount
)}
</div>
)}
Expand Down

0 comments on commit 8dc3f1f

Please sign in to comment.