From a059998b0eb2d98374837960e6e7966dd6394963 Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Wed, 13 Mar 2024 12:50:08 +0100 Subject: [PATCH] Prepare for Block Model v3, backwards compatible --- src/components/Data.jsx | 7 +++++-- src/components/Edit.jsx | 1 + src/components/View.jsx | 20 +++++++++++++------- src/index.js | 1 + 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/Data.jsx b/src/components/Data.jsx index 510aa10..7174857 100644 --- a/src/components/Data.jsx +++ b/src/components/Data.jsx @@ -11,7 +11,8 @@ const messages = defineMessages({ }); const ButtonData = (props) => { - const { data, block, onChangeBlock, schemaEnhancer } = props; + const { data, block, onChangeBlock, schemaEnhancer, navRoot, contentType } = + props; const intl = useIntl(); const schema = schemaEnhancer ? schemaEnhancer(ButtonSchema({ ...props, intl }), props) @@ -27,9 +28,11 @@ const ButtonData = (props) => { [id]: value, }); }} + onChangeBlock={onChangeBlock} formData={data} - fieldIndex={data.index} block={block} + navRoot={navRoot} + contentType={contentType} /> ); }; diff --git a/src/components/Edit.jsx b/src/components/Edit.jsx index f33f2a1..f08b620 100644 --- a/src/components/Edit.jsx +++ b/src/components/Edit.jsx @@ -5,6 +5,7 @@ import View from './View'; const Edit = (props) => { const { data, block, onChangeBlock, selected } = props; + return ( <> diff --git a/src/components/View.jsx b/src/components/View.jsx index 821e863..62a6ba4 100644 --- a/src/components/View.jsx +++ b/src/components/View.jsx @@ -1,8 +1,9 @@ import React from 'react'; import { Button } from 'semantic-ui-react'; import cx from 'classnames'; -import { ConditionalLink } from '@plone/volto/components'; +import { ConditionalLink, MaybeWrap } from '@plone/volto/components'; import { defineMessages, useIntl } from 'react-intl'; +import config from '@plone/volto/registry'; const messages = defineMessages({ ButtonText: { @@ -11,9 +12,16 @@ const messages = defineMessages({ }, }); -const View = ({ data, isEditMode, className }) => { +const LegacyWrapper = (props) => ( +
+
{props.children}
+
+); + +const View = ({ data, isEditMode, className, blocksConfig }) => { const [hasLink, setHasLink] = React.useState(false); const intl = useIntl(); + const isBlockModelv3 = blocksConfig?.__button?.v3; React.useEffect(() => { if (data.href) { @@ -47,11 +55,9 @@ const View = ({ data, isEditMode, className }) => { ); return ( -
-
-
{link}
-
-
+ +
{link}
+
); }; diff --git a/src/index.js b/src/index.js index e65bde2..6dffb80 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ const applyConfig = (config) => { restricted: false, mostUsed: true, sidebarTab: 1, + category: 'action', }; return config; };