Skip to content

Commit

Permalink
Table block: Fix an issue when removing all columns does not prompt t…
Browse files Browse the repository at this point in the history
…able creation
  • Loading branch information
gziolo committed Aug 23, 2018
1 parent 19b7cb3 commit b9c92ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/block-library/src/table/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ export function deleteColumn( state, {
return {
[ section ]: state[ section ].map( ( row ) => ( {
cells: row.cells.filter( ( cell, index ) => index !== columnIndex ),
} ) ),
} ) ).filter( ( row ) => row.cells.length ),

This comment has been minimized.

Copy link
@ellatrix

ellatrix Aug 23, 2018

Member

Nice! Thanks!

};
}
33 changes: 33 additions & 0 deletions packages/block-library/src/table/test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,37 @@ describe( 'deleteColumn', () => {

expect( state ).toEqual( expected );
} );

it( 'should delete all rows when only one column present', () => {
const tableWithOneColumn = {
body: [
{
cells: [
{
content: [],
tag: 'td',
},
],
},
{
cells: [
{
content: [ 'test' ],
tag: 'td',
},
],
},
],
};
const state = deleteColumn( tableWithOneColumn, {
section: 'body',
columnIndex: 0,
} );

const expected = {
body: [],
};

expect( state ).toEqual( expected );
} );
} );

0 comments on commit b9c92ed

Please sign in to comment.