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 <js029@gmail.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -61,7 +61,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with
|
|||||||
className="DataGrid_rows"
|
className="DataGrid_rows"
|
||||||
style={Object {}}
|
style={Object {}}
|
||||||
>
|
>
|
||||||
<DataGridRow
|
<Memo(DataGridRow)
|
||||||
columns={
|
columns={
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -87,7 +87,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<DataGridRow
|
<Memo(DataGridRow)
|
||||||
columns={
|
columns={
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -113,7 +113,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<DataGridRow
|
<Memo(DataGridRow)
|
||||||
columns={
|
columns={
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -170,7 +170,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with
|
|||||||
className="DataGrid_rows"
|
className="DataGrid_rows"
|
||||||
style={Object {}}
|
style={Object {}}
|
||||||
>
|
>
|
||||||
<DataGridRow
|
<Memo(DataGridRow)
|
||||||
columns={
|
columns={
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -193,7 +193,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<DataGridRow
|
<Memo(DataGridRow)
|
||||||
columns={
|
columns={
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -216,7 +216,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot with
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<DataGridRow
|
<Memo(DataGridRow)
|
||||||
columns={
|
columns={
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
|
|||||||
@@ -9,48 +9,57 @@ import type {Row, Column} from './data_grid';
|
|||||||
|
|
||||||
import './data_grid.scss';
|
import './data_grid.scss';
|
||||||
|
|
||||||
type Props = {
|
type DataGridRowProps = {
|
||||||
columns: Column[];
|
columns: Column[];
|
||||||
row: Row;
|
row: Row;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataGridRow extends React.Component<Props> {
|
type DataGridCellProps = {
|
||||||
renderCell(row: Row, column: Column) {
|
column: Column;
|
||||||
const style: CSSProperties = {};
|
row: Row;
|
||||||
if (column.width) {
|
|
||||||
style.flexGrow = column.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column.textAlign) {
|
|
||||||
style.textAlign = column.textAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column.overflow) {
|
|
||||||
style.overflow = column.overflow;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={column.field}
|
|
||||||
className={classNames('DataGrid_cell', column.className)}
|
|
||||||
style={style}
|
|
||||||
>
|
|
||||||
{row.cells[column.field]}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const cells = this.props.columns.map((col) => this.renderCell(this.props.row, col));
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className='DataGrid_row'
|
|
||||||
onClick={this.props.row.onClick}
|
|
||||||
>
|
|
||||||
{cells}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
||||||
|
<div
|
||||||
|
key={column.field}
|
||||||
|
className={classNames('DataGrid_cell', column.className)}
|
||||||
|
style={style}
|
||||||
|
>
|
||||||
|
{row.cells[column.field]}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const DataGridRow = ({row, columns}: DataGridRowProps) => {
|
||||||
|
const cells = columns.map((column, index) => (
|
||||||
|
<DataGridCell
|
||||||
|
key={index}
|
||||||
|
row={row}
|
||||||
|
column={column}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className='DataGrid_row'
|
||||||
|
onClick={row.onClick}
|
||||||
|
>
|
||||||
|
{cells}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(DataGridRow);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user