Skip to content

Commit

Permalink
fix: fix slate block
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Oct 10, 2023
1 parent 5a7f8ee commit d2637e3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const Block = ({
data,
inEditMode,
selected,
focusOn,
block,
onChange,
intl,
Expand Down Expand Up @@ -61,7 +60,7 @@ const Block = ({
onChange({ ...data, title: _data.value });
}}
setSelected={() => {
focusOn('title');
otherProps.onSubblockChangeFocus(index);
}}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Body extends SubblockEdit {
inEditMode={this.props.inEditMode}
selected={this.props.selected || this.state.focusOn === 'title'}
block={this.props.block}
focusOn={this.props.focusOn}
focusOn={this.state.focusOn}
intl={this.props.intl}
onChange={this.onChange}
/>
Expand Down
11 changes: 9 additions & 2 deletions src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const Block = ({ data, block, inEditMode, selected, ...otherProps }) => {
}
}, [selected]);

useEffect(() => {
if (!selected && selectedField) {
otherProps.onSelectBlock(block);
}
}, [selectedField]);

return (
<div
className={cx('cta-block-wrapper', {
Expand Down Expand Up @@ -87,16 +93,17 @@ const Block = ({ data, block, inEditMode, selected, ...otherProps }) => {
title
)}
</h2>

{inEditMode ? (
<TextEditorWidget
{...otherProps}
showToolbar={true}
data={data}
fieldName="cta_content"
selected={selectedField === 'content'}
setSelected={() => setSelectedField('content')}
block={block}
selected={selectedField === 'content'}
placeholder={intl.formatMessage(messages.cta_content)}
setSelected={() => setSelectedField('content')}
focusPrevField={() => {
setSelectedField('title');
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class EditBlock extends SubblockEdit {
}
});
}

UNSAFE_componentWillReceiveProps(nextProps) {
if (!this.props.selected && nextProps.focusOn) {
this.props.onSelectBlock(this.props.block);
}

if (nextProps.selected && !this.state.focusOn) {
this.setState({ focusOn: 'title' });
} else if (!nextProps.selected) {
this.setState({ focusOn: null });
}
}
/**
* Render method.
* @method render
Expand All @@ -81,7 +93,6 @@ class EditBlock extends SubblockEdit {
<CardBody tag="div">
<div className="contact-title">
{/* eslint-disable */}

<TextEditorWidget
{...this.props}
key="title"
Expand Down
18 changes: 10 additions & 8 deletions src/components/ItaliaTheme/Blocks/ContactsBlock/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Edit extends SubblocksEdit {
super(props);
this.state.selectedField = 'title';
}

/**
* Render method.
* @method render
Expand All @@ -67,12 +68,11 @@ class Edit extends SubblocksEdit {
<div className="title">
<TextEditorWidget
{...this.props}
key="title"
showToolbar={false}
data={this.props.data}
onSelectBlock={null}
fieldName="title"
selected={this.state.selectedField === 'title'}
onChangeBlock={this.props.onChangeBlock}
placeholder={this.props.intl.formatMessage(messages.title)}
setSelected={() => {
this.setState({ selectedField: 'title' });
Expand All @@ -86,18 +86,17 @@ class Edit extends SubblocksEdit {
<div className="description">
<TextEditorWidget
{...this.props}
showToolbar={true}
key="description"
data={this.props.data}
fieldName="description"
selected={this.state.selectedField === 'description'}
onSelectBlock={null}
onChangeBlock={this.props.onChangeBlock}
placeholder={this.props.intl.formatMessage(
messages.description,
)}
setSelected={() =>
this.setState({ selectedField: 'description' })
}
onSelectBlock={null}
setSelected={() => {
this.setState({ selectedField: 'description' });
}}
focusPrevField={() => {
this.setState({ selectedField: 'title' });
}}
Expand Down Expand Up @@ -129,6 +128,9 @@ class Edit extends SubblocksEdit {
onSubblockChangeFocus={this.onSubblockChangeFocus}
isLast={this.state.subblocks.length - 1 === subindex}
isFirst={subindex === 0}
onFocusPreviousBlock={() => {
this.setState({ selectedField: 'description' });
}}
/>
</Col>
))}
Expand Down
20 changes: 7 additions & 13 deletions src/components/ItaliaTheme/Blocks/CountDown/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ const messages = defineMessages({
});

const Edit = (props) => {
const {
data,
block,
onChangeBlock,
selected,
onSelectBlock,
onAddBlock,
index,
...otherProps
} = props;
const { data, block, selected, ...otherProps } = props;
const intl = useIntl();
const [selectedField, setSelectedField] = useState('text');
useEffect(() => {
Expand All @@ -37,6 +28,12 @@ const Edit = (props) => {
}
}, [selected]);

useEffect(() => {
if (!selected && selectedField) {
props.onSelectBlock(block);
}
}, [selectedField]);

return (
<>
<div className="public-ui">
Expand Down Expand Up @@ -74,12 +71,10 @@ const Edit = (props) => {
>
<TextEditorWidget
{...otherProps}
showToolbar={true}
data={data}
fieldName="text"
selected={selectedField === 'text'}
block={block}
onChangeBlock={onChangeBlock}
placeholder={intl.formatMessage(messages.text)}
setSelected={() => {
setSelectedField('text');
Expand Down Expand Up @@ -113,7 +108,6 @@ const Edit = (props) => {
block={block}
fieldName="countdown_text"
selected={selectedField === 'countdown_text'}
onChangeBlock={onChangeBlock}
placeholder={intl.formatMessage(messages.text)}
setSelected={() => {
setSelectedField('countdown_text');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const TextEditorWidget = (props) => {
const _value = value ?? data[fieldName];

const selectThis = () => {
if (onSelectBlock) {
onSelectBlock(block);
} else {
if (setSelected) {
setSelected();
} else if (onSelectBlock) {
onSelectBlock(block);
}
};
return (
Expand Down Expand Up @@ -131,7 +131,6 @@ const TextEditorWidget = (props) => {
TextEditorWidget.propTypes = {
data: PropTypes.objectOf(PropTypes.any).isRequired,
setSelected: PropTypes.func.isRequired,
onSelectBlock: PropTypes.func.isRequired,
onChangeBlock: PropTypes.func.isRequired,
block: PropTypes.string.isRequired,
selected: PropTypes.bool.isRequired,
Expand All @@ -143,6 +142,7 @@ TextEditorWidget.propTypes = {
properties: PropTypes.objectOf(PropTypes.any).isRequired,
onFocusPreviousBlock: PropTypes.objectOf(PropTypes.any).isRequired,
onFocusNextBlock: PropTypes.objectOf(PropTypes.any).isRequired,
onSelectBlock: PropTypes.func.isRequired,
};

export default connect(
Expand Down
2 changes: 2 additions & 0 deletions src/config/Blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ const italiaBlocks = {
view: [],
},
sidebarTab: 1,
blockHasOwnFocusManagement: true,
},

video_gallery: {
Expand Down Expand Up @@ -362,6 +363,7 @@ const italiaBlocks = {
view: [],
},
sidebarTab: 1,
blockHasOwnFocusManagement: true,
},
callout_block: {
id: 'callout_block',
Expand Down

0 comments on commit d2637e3

Please sign in to comment.