From c97731e4a669da2f7b84880ab6701319985156a1 Mon Sep 17 00:00:00 2001 From: js029 <75493971+js029@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:11:53 +0200 Subject: [PATCH] MM-24743 Migrate DataRowGrid to functional component (#24795) * Migrate DataRowGrid to functional component * Change renderCell to a functional component dataGridCell and memoize DataGridRow * Adjust test snapshot to include memoised DataGridRow * use component notation when using DataGridCell --------- Co-authored-by: js029 Co-authored-by: Mattermost Build --- .../__snapshots__/data_grid.test.tsx.snap | 12 +-- .../admin_console/data_grid/data_grid_row.tsx | 87 ++++++++++--------- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap b/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap index ee6cc8a43f..9ce41e5db3 100644 --- a/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap +++ b/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap @@ -61,7 +61,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with className="DataGrid_rows" style={Object {}} > - - - - - - { - renderCell(row: Row, column: Column) { - const style: CSSProperties = {}; - if (column.width) { - style.flexGrow = column.width; - } - - if (column.textAlign) { - style.textAlign = column.textAlign; - } - - if (column.overflow) { - style.overflow = column.overflow; - } - - return ( -
- {row.cells[column.field]} -
- ); - } - - render() { - const cells = this.props.columns.map((col) => this.renderCell(this.props.row, col)); - return ( -
- {cells} -
- ); - } +type DataGridCellProps = { + column: Column; + row: Row; } -export default DataGridRow; +const DataGridCell = ({row, column}: DataGridCellProps) => { + const style: CSSProperties = {}; + if (column.width) { + style.flexGrow = column.width; + } + + if (column.textAlign) { + style.textAlign = column.textAlign; + } + + if (column.overflow) { + style.overflow = column.overflow; + } + + return ( +
+ {row.cells[column.field]} +
+ ); +}; + +const DataGridRow = ({row, columns}: DataGridRowProps) => { + const cells = columns.map((column, index) => ( + + )); + return ( +
+ {cells} +
+ ); +}; + +export default React.memo(DataGridRow);