Skip to content

Commit

Permalink
Add story about blocksState
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Sep 22, 2020
1 parent 5d3726b commit c4fde42
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/ColumnsBlock/ColumnsBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isEmpty } from 'lodash';
import { BlocksForm, SidebarPortal, InlineForm } from '@plone/volto/components'; // BlocksForm
import { emptyBlocksForm } from '@plone/volto/helpers';

// import from BlocksForm '../futurevolto/BlocksForm';
import { ColumnsBlockSchema } from './schema';
import { getColumns, empty } from './utils';

Expand All @@ -16,6 +15,24 @@ class ColumnsBlockEdit extends React.Component {
this.state = {
colSelections: {},
};

// This special variable is needed because of the onChangeField(block...) is
// immediately followed by onChangeField(blocks_layout...), we want to save
// this incoming information as data for the block, but because it is only
// partial, we'll overwrite it in the second request. So we take advantage
// of what happens between batched updates, we know that there will be two
// calls, so even if we overwrite the state improperly on the first pass,
// it will be fixed on the second pass if we have access to the proper
// value from the first pass.
//
// We have volto-slate that does:
// ReactDOM.unstable_batchedUpdates(() => {
// this.onChangeField(blocks, {})
// this.onChangeField(blocks_layout, {})
// }
// volto-slate needs to be neutral, to work in the main Volto form, but
// also these types of subforms, so it should continue to use batched
// onChangeField, as that works fine.
this.blocksState = {};
}

Expand All @@ -29,13 +46,6 @@ class ColumnsBlockEdit extends React.Component {
selected,
} = this.props;

// React.useEffect(() => {
// if (!data.coldata) {
// // TODO: this is a hack that causes volto-slate to lose focus
// onChangeBlock(block, { ...data, coldata: empty() });
// }
// });

const { coldata = empty() } = data;
const columnList = getColumns(coldata);

Expand Down

0 comments on commit c4fde42

Please sign in to comment.