Skip to content

Commit

Permalink
Solve issue: Layout field is not automatically filled
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed Oct 12, 2020
1 parent 96f6b00 commit 20603e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ColumnsBlock/ColumnsBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class ColumnsBlockEdit extends React.Component {
const prevCols = prevProps.data.data?.blocks_layout?.items || [];

const colNumChanged = cols.length !== prevCols.length;
const notInitialLayoutSelection = prevCols.length !== 0;
const shouldUpdateLayout = colNumChanged && notInitialLayoutSelection;
const initialLayoutSelection = Object.keys(prevProps.data).length === 1;
const shouldUpdateLayout = colNumChanged && !initialLayoutSelection;

if (shouldUpdateLayout) {
const available_variants = variants.filter(
Expand Down
12 changes: 8 additions & 4 deletions src/Widgets/LayoutSelectWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,21 @@ export class LayoutSelectWidget extends Component {
this.setState({
selectedOption: {
value: this.props.value,
label: this.props.choices.find((x) => x[0] === this.props.value)?.[1],
label: this.props.choices.find((x) =>
isEqual(x[0], this.props.value),
)?.[1],
},
});
}

componentDidUpdate(prevProps) {
if (prevProps.value !== this.props.value) {
if (!isEqual(prevProps.value, this.props.value)) {
this.setState({
selectedOption: {
value: this.props.value,
label: this.props.choices.find((x) => x[0] === this.props.value)?.[1],
label: this.props.choices.find((x) =>
isEqual(x[0], this.props.value),
)?.[1],
},
});
}
Expand All @@ -114,7 +118,7 @@ export class LayoutSelectWidget extends Component {
* @returns {string} Markup for the component.
*/
render() {
const { id, choices, value, onChange } = this.props;
const { id, choices, onChange } = this.props;

return (
<FormFieldWrapper {...this.props}>
Expand Down

0 comments on commit 20603e3

Please sign in to comment.