From 9956479587d5cdb7f8ed080fa3359e43d83e07b8 Mon Sep 17 00:00:00 2001 From: Rob Gietema Date: Thu, 22 Feb 2024 11:26:24 +0100 Subject: [PATCH] Fix sidebar form update. (#5779) --- packages/volto-slate/news/5779.bugfix | 1 + .../src/blocks/Table/TableBlockEdit.jsx | 16 +++++----------- packages/volto/news/5779.bugfix | 1 + src/components/manage/Form/Form.jsx | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 packages/volto-slate/news/5779.bugfix create mode 100644 packages/volto/news/5779.bugfix diff --git a/packages/volto-slate/news/5779.bugfix b/packages/volto-slate/news/5779.bugfix new file mode 100644 index 0000000000..5c1f633b25 --- /dev/null +++ b/packages/volto-slate/news/5779.bugfix @@ -0,0 +1 @@ +Fix sidebar form update. @robgietema \ No newline at end of file diff --git a/packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx b/packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx index 478ba15be9..397bff13fd 100644 --- a/packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx +++ b/packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx @@ -5,7 +5,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { map, remove } from 'lodash'; +import { isEmpty, map, remove } from 'lodash'; import { Button, Table } from 'semantic-ui-react'; import cx from 'classnames'; import { defineMessages, injectIntl } from 'react-intl'; @@ -227,7 +227,7 @@ class Edit extends Component { * @returns {undefined} */ componentDidMount() { - if (!this.props.data.table) { + if (!this.props.data.table || isEmpty(this.props.data.table)) { this.props.onChangeBlock(this.props.block, { ...this.props.data, table: initialTable, @@ -243,7 +243,7 @@ class Edit extends Component { * @returns {undefined} */ UNSAFE_componentWillReceiveProps(nextProps) { - if (!nextProps.data.table) { + if (!nextProps.data.table || isEmpty(nextProps.data.table)) { this.props.onChangeBlock(nextProps.block, { ...nextProps.data, table: initialTable, @@ -528,10 +528,7 @@ class Edit extends Component { icon basic onClick={this.onDeleteRow} - disabled={ - this.props.data.table && - this.props.data.table.rows.length === 1 - } + disabled={this.props.data.table?.rows?.length === 1} title={this.props.intl.formatMessage(messages.deleteRow)} aria-label={this.props.intl.formatMessage(messages.deleteRow)} > @@ -569,10 +566,7 @@ class Edit extends Component { icon basic onClick={this.onDeleteCol} - disabled={ - this.props.data.table && - this.props.data.table.rows[0].cells.length === 1 - } + disabled={this.props.data.table?.rows?.[0].cells.length === 1} title={this.props.intl.formatMessage(messages.deleteCol)} aria-label={this.props.intl.formatMessage(messages.deleteCol)} > diff --git a/packages/volto/news/5779.bugfix b/packages/volto/news/5779.bugfix new file mode 100644 index 0000000000..5c1f633b25 --- /dev/null +++ b/packages/volto/news/5779.bugfix @@ -0,0 +1 @@ +Fix sidebar form update. @robgietema \ No newline at end of file diff --git a/src/components/manage/Form/Form.jsx b/src/components/manage/Form/Form.jsx index 7b635139ef..af6d1ceaca 100644 --- a/src/components/manage/Form/Form.jsx +++ b/src/components/manage/Form/Form.jsx @@ -260,7 +260,7 @@ class Form extends Component { } if ( this.props.global && - !isEqual(this.props.globalData, this.state.formData) + !isEqual(this.props.globalData, prevProps.globalData) ) { this.setState({ formData: this.props.globalData,