From 1b17951789cb330848c6cb827701b3c122f75ec5 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 9 Aug 2019 15:55:09 +0800 Subject: [PATCH] Remove superflouous update of selectedCell already handled by RichText unstableOnFocus prop --- packages/block-library/src/table/edit.js | 7 +++---- packages/block-library/src/table/navigable-table.js | 3 +-- packages/block-library/src/table/state.js | 2 +- packages/block-library/src/table/test/state.js | 12 ++++++------ 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/table/edit.js b/packages/block-library/src/table/edit.js index d84f1ca2832ff..5580e753600f0 100644 --- a/packages/block-library/src/table/edit.js +++ b/packages/block-library/src/table/edit.js @@ -32,7 +32,7 @@ import { */ import { createTable, - updateSelectedCell, + updateSelectedCellAttributes, getCellAttribute, insertRow, deleteRow, @@ -182,7 +182,7 @@ export class TableEdit extends Component { const { attributes, setAttributes } = this.props; - setAttributes( updateSelectedCell( + setAttributes( updateSelectedCellAttributes( attributes, selectedCell, ( cellAttributes ) => ( { ...cellAttributes, content } ), @@ -209,7 +209,7 @@ export class TableEdit extends Component { }; const { attributes, setAttributes } = this.props; - const newAttributes = updateSelectedCell( + const newAttributes = updateSelectedCellAttributes( attributes, columnSelection, ( cellAttributes ) => ( { ...cellAttributes, align } ), @@ -599,7 +599,6 @@ export class TableEdit extends Component { className={ tableClasses } tableState={ attributes } selectedCell={ selectedCell } - onNavigation={ ( cellLocation ) => this.updateSelectedCell( cellLocation ) } >
diff --git a/packages/block-library/src/table/navigable-table.js b/packages/block-library/src/table/navigable-table.js index ed323cc11988a..62bd966eef058 100644 --- a/packages/block-library/src/table/navigable-table.js +++ b/packages/block-library/src/table/navigable-table.js @@ -82,7 +82,7 @@ function getCellContentEditableElement( tableElement, { sectionName, rowIndex, c return rowElement.querySelectorAll( '*[contenteditable="true"]' )[ columnIndex ]; } -export default function NavigableTable( { children, className, tableState, selectedCell, onNavigation } ) { +export default function NavigableTable( { children, className, tableState, selectedCell } ) { const tableRef = useRef(); const handleKeyDown = ( event ) => { @@ -143,7 +143,6 @@ export default function NavigableTable( { children, className, tableState, selec } placeCaretAtHorizontalEdge( contentEditableElement, isReverse ); - onNavigation( nextCellLocation ); }; // Disable reason: Wrapper itself is non-interactive, but must capture diff --git a/packages/block-library/src/table/state.js b/packages/block-library/src/table/state.js index 3f3772e7140f6..ebfd2fd4fbedc 100644 --- a/packages/block-library/src/table/state.js +++ b/packages/block-library/src/table/state.js @@ -111,7 +111,7 @@ export function getCellAttribute( state, cellLocation, attributeName ) { * * @return {Object} New table state including the updated cells. */ -export function updateSelectedCell( state, selection, updateCell ) { +export function updateSelectedCellAttributes( state, selection, updateCell ) { if ( ! selection ) { return state; } diff --git a/packages/block-library/src/table/test/state.js b/packages/block-library/src/table/test/state.js index a5fd9e30b0def..c0a233aa45884 100644 --- a/packages/block-library/src/table/test/state.js +++ b/packages/block-library/src/table/test/state.js @@ -18,7 +18,7 @@ import { isEmptyTableSection, isEmptyRow, isCellSelected, - updateSelectedCell, + updateSelectedCellAttributes, getCellAbove, getCellBelow, getCellToLeft, @@ -1213,21 +1213,21 @@ describe( 'isCellSelected', () => { } ); } ); -describe( 'updateSelectedCell', () => { +describe( 'updateSelectedCellAttributes', () => { it( 'returns an unchanged table state if there is no selection', () => { - const updated = updateSelectedCell( table, undefined, ( cell ) => ( { ...cell, content: 'test' } ) ); + const updated = updateSelectedCellAttributes( table, undefined, ( cell ) => ( { ...cell, content: 'test' } ) ); expect( table ).toEqual( updated ); } ); it( 'returns an unchanged table state if the selection is outside the bounds of the table', () => { const cellSelection = { type: 'cell', sectionName: 'body', rowIndex: 100, columnIndex: 100 }; - const updated = updateSelectedCell( table, cellSelection, ( cell ) => ( { ...cell, content: 'test' } ) ); + const updated = updateSelectedCellAttributes( table, cellSelection, ( cell ) => ( { ...cell, content: 'test' } ) ); expect( table ).toEqual( updated ); } ); it( 'updates only the individual cell when the selection type is `cell`', () => { const cellSelection = { type: 'cell', sectionName: 'body', rowIndex: 0, columnIndex: 0 }; - const updated = updateSelectedCell( table, cellSelection, ( cell ) => ( { ...cell, content: 'test' } ) ); + const updated = updateSelectedCellAttributes( table, cellSelection, ( cell ) => ( { ...cell, content: 'test' } ) ); expect( updated ).toEqual( { body: [ @@ -1247,7 +1247,7 @@ describe( 'updateSelectedCell', () => { it( 'updates every cell in the column when the selection type is `column`', () => { const cellSelection = { type: 'column', columnIndex: 1 }; - const updated = updateSelectedCell( table, cellSelection, ( cell ) => ( { ...cell, content: 'test' } ) ); + const updated = updateSelectedCellAttributes( table, cellSelection, ( cell ) => ( { ...cell, content: 'test' } ) ); expect( updated ).toEqual( { body: [