Skip to content

Commit

Permalink
Added global form state (#5721) (#5788)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Gietema <rob.gietema@gmail.com>
  • Loading branch information
sneridagh and robgietema authored Feb 26, 2024
1 parent c3f3214 commit 790af07
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 63 deletions.
1 change: 1 addition & 0 deletions news/5721.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add global form state. @robgietema
1 change: 1 addition & 0 deletions packages/volto-slate/news/5779.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sidebar form update. @robgietema
16 changes: 5 additions & 11 deletions packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)}
>
Expand Down Expand Up @@ -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)}
>
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/5779.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sidebar form update. @robgietema
19 changes: 19 additions & 0 deletions src/actions/form/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Form actions.
* @module actions/form/form
*/

import { SET_FORM_DATA } from '@plone/volto/constants/ActionTypes';

/**
* Set form data function.
* @function setFormData
* @param {Object} data New form data.
* @returns {Object} Set sidebar action.
*/
export function setFormData(data) {
return {
type: SET_FORM_DATA,
data,
};
}
14 changes: 14 additions & 0 deletions src/actions/form/form.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { setFormData } from './form';
import { SET_FORM_DATA } from '@plone/volto/constants/ActionTypes';

describe('Form action', () => {
describe('setFormData', () => {
it('should create an action to set the form data', () => {
const data = { foo: 'bar' };
const action = setFormData(data);

expect(action.type).toEqual(SET_FORM_DATA);
expect(action.data).toEqual(data);
});
});
});
1 change: 1 addition & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export {
export { getQuerystring } from '@plone/volto/actions/querystring/querystring';
export { getQueryStringResults } from '@plone/volto/actions/querystringsearch/querystringsearch';
export { setSidebarTab } from '@plone/volto/actions/sidebar/sidebar';
export { setFormData } from '@plone/volto/actions/form/form';
export {
deleteLinkTranslation,
getTranslationLocator,
Expand Down
1 change: 1 addition & 0 deletions src/components/manage/Add/Add.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class Add extends Component {
onSelectForm={() => {
this.setState({ formSelected: 'addForm' });
}}
global
/>
{this.state.isClient && (
<Portal node={document.getElementById('toolbar')}>
Expand Down
1 change: 1 addition & 0 deletions src/components/manage/Edit/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class Edit extends Component {
onSelectForm={() => {
this.setState({ formSelected: 'editForm' });
}}
global
/>
);

Expand Down
Loading

0 comments on commit 790af07

Please sign in to comment.