Skip to content

Commit

Permalink
fix(DescriptionBlockEdit): set description block data if metadata exi…
Browse files Browse the repository at this point in the history
…sts, ref #265535
  • Loading branch information
razvanMiu committed Jul 2, 2024
1 parent 14497e6 commit 65464d2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/DescriptionBlock/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { isNil } from 'lodash';
import config from '@plone/volto/registry';
import { SidebarPortal, BlockDataForm } from '@plone/volto/components';
import { createParagraph } from '@plone/volto-slate/utils';
import { saveSlateBlockSelection } from '@plone/volto-slate/actions';
import { serializeNodesToText } from '@plone/volto-slate/editor/render';
import schema from './schema';
Expand All @@ -21,16 +23,21 @@ export const DescriptionBlockEdit = (props) => {
onChangeBlock,
data,
} = props;
const { slate } = config.settings;
const initialValue = data?.value || slate.defaultValue();
const text = metadata?.['description'] || properties?.['description'] || '';
const plainValue = data?.value ? serializeNodesToText(data.value) : null;

const plainValue = serializeNodesToText(initialValue);
useEffect(() => {
if (plainValue !== text) {
if (!isNil(plainValue) && plainValue !== text) {
onChangeField('description', plainValue);
}
}, [plainValue, text, onChangeField]);
if (isNil(plainValue) && !isNil(text)) {
onChangeBlock(block, {
...data,
value: [createParagraph(text)],
plaintext: text,
});
}
}, [plainValue, text, onChangeField, onChangeBlock, block]);

return (
<div className={config.blocks.blocksConfig.description.className}>
Expand Down

0 comments on commit 65464d2

Please sign in to comment.