Skip to content

Commit

Permalink
fix: transform empty blocks to slate - refs #273976
Browse files Browse the repository at this point in the history
  • Loading branch information
dobri1408 authored Aug 28, 2024
1 parent cb2a3c6 commit 0925e79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/customizations/volto/components/manage/Blocks/Grid/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RenderBlocks } from '@plone/volto/components';
import { withBlockExtensions } from '@plone/volto/helpers';
import config from '@plone/volto/registry';

const convertTeaserToGridIfNecessary = (data) => {
const convertTeaserToGridIfNecessaryAndTransformEmptyBlocksToSlate = (data) => {
if (data?.['@type'] === 'teaserGrid')
return {
...data,
Expand All @@ -13,11 +13,24 @@ const convertTeaserToGridIfNecessary = (data) => {
blocks: data?.columns?.reduce((acc, current) => {
return {
...acc,
[current?.id]: current,
[current?.id]: { current, '@type': current['@type'] || 'slate' },
};
}, {}),
};
return data;
if (data.blocks)
return {
...data,
blocks: Object.keys(data.blocks).reduce((acc, current) => {
return {
...acc,
[current]: {
...data.blocks[current],
'@type': data.blocks[current]?.['@type'] || 'slate',
},
};
}, {}),
};
else return data;
};

const GridBlockView = (props) => {
Expand Down Expand Up @@ -48,7 +61,9 @@ const GridBlockView = (props) => {
{...props}
blockWrapperTag={Grid.Column}
metadata={metadata}
content={convertTeaserToGridIfNecessary(data)}
content={convertTeaserToGridIfNecessaryAndTransformEmptyBlocksToSlate(
data,
)}
location={location}
blocksConfig={blocksConfig}
isContainer
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
These two customizations ensure backward compatibility with the legacy @kitconcept/volto-blocks-grid. For more details, refer to the ticket here: https://taskman.eionet.europa.eu/issues/265726.
Also, if there is an empty block, it will convert to slate, so the "Unkown block" message will not appear

0 comments on commit 0925e79

Please sign in to comment.