Overwrite changes when using sidebar
This commit is contained in:
parent
0d3bce262f
commit
bff9b8bf00
|
@ -63,15 +63,13 @@ class ProductByCategoryBlock extends Component {
|
||||||
stopEditing() {
|
stopEditing() {
|
||||||
this.setState( {
|
this.setState( {
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
changedAttributes: null,
|
changedAttributes: {},
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
setChangedAttributes( attributes ) {
|
setChangedAttributes( attributes ) {
|
||||||
this.setState( ( prevState ) => {
|
this.setState( ( prevState ) => {
|
||||||
if ( prevState.changedAttributes !== null ) {
|
return { changedAttributes: { ...prevState.changedAttributes, ...attributes } };
|
||||||
return { changedAttributes: { ...prevState.changedAttributes, ...attributes } };
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,12 +131,18 @@ class ProductByCategoryBlock extends Component {
|
||||||
selected={ attributes.categories }
|
selected={ attributes.categories }
|
||||||
onChange={ ( value = [] ) => {
|
onChange={ ( value = [] ) => {
|
||||||
const ids = value.map( ( { id } ) => id );
|
const ids = value.map( ( { id } ) => id );
|
||||||
setAttributes( { categories: ids } );
|
const changes = { categories: ids };
|
||||||
|
|
||||||
|
// Changes in the sidebar save instantly and overwrite any unsaved changes.
|
||||||
|
setAttributes( changes );
|
||||||
|
this.setChangedAttributes( changes );
|
||||||
} }
|
} }
|
||||||
operator={ catOperator }
|
operator={ catOperator }
|
||||||
onOperatorChange={ ( value = 'any' ) =>
|
onOperatorChange={ ( value = 'any' ) => {
|
||||||
setAttributes( { catOperator: value } )
|
const changes = { catOperator: value };
|
||||||
}
|
setAttributes( changes );
|
||||||
|
this.setChangedAttributes( changes );
|
||||||
|
} }
|
||||||
/>
|
/>
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
<PanelBody
|
<PanelBody
|
||||||
|
|
Loading…
Reference in New Issue