This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from plone/introducesupportviews
Support views - RenderBlocks
- Loading branch information
Showing
15 changed files
with
2,034 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
news | ||
lib | ||
towncrier.toml | ||
.towncrier | ||
.storybook | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"plone": { | ||
"packages": { | ||
"@plone/types/*": "/packages/types/*" | ||
}, | ||
"url": "git@github.com:plone/volto.git", | ||
"https": "https://github.com/plone/volto.git", | ||
"branch": "plone/types" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Introduce support views - Add `RenderBlocks` view @sneridagh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const DefaultBlockView = () => { | ||
return <>This block has no view assigned</>; | ||
}; | ||
|
||
export default DefaultBlockView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Fragment } from 'react'; | ||
// import { defineMessages, useIntl } from 'react-intl'; | ||
|
||
import { map } from 'lodash'; | ||
import { hasBlocksData } from '../../helpers/blocks'; | ||
import DefaultBlockView from './DefaultBlockView'; | ||
import type { GetContentResponse } from '@plone/types/content/get'; | ||
import type { BlocksConfig } from '@plone/types/config/Blocks'; | ||
import type { Location } from 'history'; | ||
|
||
type RenderBlocksProps = { | ||
/** | ||
* Plone content object | ||
*/ | ||
content: GetContentResponse; | ||
/** | ||
* Current blocks configuration object | ||
* From the registry or local to this instance (eg. in a blocks in block container) | ||
*/ | ||
blocksConfig: BlocksConfig; | ||
/** | ||
* Wrap the blocks in an enclosing tag | ||
* From the registry or local to this instance (eg. in a blocks in block container) | ||
*/ | ||
as: React.ElementType; | ||
/** | ||
* Router location object | ||
*/ | ||
location: Location; | ||
/** | ||
* Metadata object | ||
* In case of the blocks in block container use case, it's the metadata (content data) | ||
* from the parent container, passed down to the contained blocks | ||
*/ | ||
metadata?: GetContentResponse; | ||
}; | ||
|
||
const RenderBlocks = (props: RenderBlocksProps) => { | ||
const { blocksConfig, content, location, metadata } = props; | ||
const CustomTag = props.as || Fragment; | ||
|
||
return hasBlocksData(content) ? ( | ||
<CustomTag> | ||
{map(content.blocks_layout.items, (block) => { | ||
const blockData = content.blocks?.[block]; | ||
const blockType = blockData?.['@type']; | ||
const Block = blocksConfig[blockType]?.view || DefaultBlockView; | ||
|
||
return Block ? ( | ||
<Block | ||
id={block} | ||
metadata={metadata} | ||
properties={content} | ||
data={blockData} | ||
path={location?.pathname || ''} | ||
blocksConfig={blocksConfig} | ||
/> | ||
) : blockData ? ( | ||
<div key={block}>Unknown block found: {blockType}</div> | ||
) : ( | ||
<div key={block}>Invalid Block</div> | ||
); | ||
})} | ||
</CustomTag> | ||
) : ( | ||
'' | ||
); | ||
}; | ||
|
||
export default RenderBlocks; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { GetContentResponse } from '@plone/types/content/get'; | ||
import { find, keys, endsWith } from 'lodash'; | ||
|
||
export function hasBlocksData(content: GetContentResponse) { | ||
return ( | ||
find( | ||
keys(content), | ||
(key) => key !== 'volto.blocks' && endsWith(key, 'blocks'), | ||
) !== undefined | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.