Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Cleanup RenderBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Sep 22, 2020
1 parent 5408c94 commit 15919b4
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions src/components/theme/View/RenderBlocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,51 @@ import { getBaseUrl } from '@plone/volto/helpers';
import { defineMessages } from 'react-intl';
import { map } from 'lodash';
import {
getBlocksFieldname,
getBlocksLayoutFieldname,
hasBlocksData,
getBlocksFieldname,
getBlocksLayoutFieldname,
hasBlocksData,
} from '@plone/volto/helpers';
import { blocks } from '~/config';

const messages = defineMessages({
unknownBlock: {
id: 'Unknown Block',
defaultMessage: 'Unknown Block {block}',
},
unknownBlock: {
id: 'Unknown Block',
defaultMessage: 'Unknown Block {block}',
},
});

const RenderBlocks = (props) => {
const { location, intl, content } = props;
const blocksFieldname = getBlocksFieldname(content);
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);
const { location, intl, content } = props;
const blocksFieldname = getBlocksFieldname(content);
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);

return hasBlocksData(content) ? (
<div>
{map(content[blocksLayoutFieldname].items, (block) => {
const Block =
blocks.blocksConfig[content[blocksFieldname]?.[block]?.['@type']]?.[
'view'
] || null;
return Block !== null ? (
<Block
key={block}
id={block}
properties={content}
data={content[blocksFieldname][block]}
path={getBaseUrl(location?.pathname || '')}
/>
) : (
<div key={block}>
{intl.formatMessage(messages.unknownBlock, {
block: content[blocksFieldname]?.[block]?.['@type'],
})}
</div>
);
})}
</div>
) : (
''
);
return hasBlocksData(content) ? (
<div>
{map(content[blocksLayoutFieldname].items, (block) => {
const Block =
blocks.blocksConfig[content[blocksFieldname]?.[block]?.['@type']]?.[
'view'
] || null;
return Block !== null ? (
<Block
key={block}
id={block}
properties={content}
data={content[blocksFieldname][block]}
path={getBaseUrl(location?.pathname || '')}
/>
) : (
<div key={block}>
{intl.formatMessage(messages.unknownBlock, {
block: content[blocksFieldname]?.[block]?.['@type'],
})}
</div>
);
})}
</div>
) : (
''
);
};

export default RenderBlocks;

0 comments on commit 15919b4

Please sign in to comment.