-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add new features to the table component #488
Conversation
Pull Request Test Coverage Report for Build 1020
💛 - Coveralls |
src/components/Column/index.js
Outdated
}; | ||
|
||
Column.defaultProps = { | ||
header: undefined, | ||
component: undefined, | ||
sortable: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
column shouldn't be sortable by default
src/components/Table/body/cell.js
Outdated
return ( | ||
<td className="rainbow-table_cell"> | ||
<td className="rainbow-table_cell" style={{ width }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use a style object directly, instead create a const:
const cellStyle = { width };
}; | ||
|
||
ArrowDown.defaultProps = { | ||
direction: 'desc', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default is asc
@@ -0,0 +1,122 @@ | |||
/* eslint-disable no-param-reassign,class-methods-use-this */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add tests for this file
src/components/Table/head/header.js
Outdated
{ | ||
'rainbow-table_header--sortable': sortable, | ||
'rainbow-table_header--selected': selected, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is right but if we always put this inside the class why here it is outside?
src/components/Table/head/header.js
Outdated
<ArrowDown direction={sortDirection} /> | ||
</RenderIf> | ||
</div> | ||
<div |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we need to use a input type="range" to make this accessible
src/components/Table/index.js
Outdated
onColumnSelect(e, columnIndex) { | ||
const { onSort } = this.props; | ||
onSort(e, this.state.columns[columnIndex].field); | ||
this.setState({ selectedColumn: columnIndex }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this make that the table rerender completely and this is not needed, you can select the cell making it focusable
src/components/Table/index.js
Outdated
const { columns } = this.state; | ||
const resizedColumn = Object.assign({}, columns[columnIndex]); | ||
resizedColumn.width = width; | ||
columns[columnIndex] = resizedColumn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you are mutating the state directly, this is prohibitive.
src/components/Table/index.js
Outdated
const resizedColumn = Object.assign({}, columns[columnIndex]); | ||
resizedColumn.width = width; | ||
columns[columnIndex] = resizedColumn; | ||
this.setState({ columns }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here when you resize the table is completely rerendered, we need to find a way to optimize this. I think you can change only the width of the header column without recreate the table.
# Conflicts: # src/components/Table/head/header.js # src/components/Table/head/index.js
src/components/Column/index.js
Outdated
@@ -31,9 +31,14 @@ Column.propTypes = { | |||
* for a column that want to represent names on a collection of people. | |||
*/ | |||
field: PropTypes.string.isRequired, | |||
/** Sets whether the column should control the sorting order of the data */ | |||
sortable: PropTypes.bool, | |||
width: PropTypes.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add description:
Specifies the width of a column in pixels and makes the column non-resizable.
and change prop type to number.
src/components/Table/body/cell.js
Outdated
@@ -18,9 +18,11 @@ CellValue.defaultProps = { | |||
value: undefined, | |||
}; | |||
|
|||
export default function Cell({ component, value }) { | |||
export default function Cell({ component, value, width }) { | |||
const cellStyle = { width }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discard all this changes since width is not longer needed here
src/components/Table/body/row.js
Outdated
const cells = columns.map(({ component, field }) => ( | ||
<Cell key={uniqueId('cell')} component={component} value={data[field]} /> | ||
const cells = columns.map(({ component, field, width }) => ( | ||
<Cell key={uniqueId('cell')} component={component} value={data[field]} width={width} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ^^. Discard changes.
src/components/Table/head/index.js
Outdated
constructor(props) { | ||
super(props); | ||
this.state = { | ||
columnWidths: props.columns.map(column => column.width), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the point of this?
it is only for change the column width?
if it is, then is better to not send a resize event to Head and instead change the width directly in the Header component with a width state.
src/components/Table/index.js
Outdated
<thead className="rainbow-table_head"> | ||
<div className={this.getContainerClassNames()} style={style}> | ||
<table className="rainbow-table"> | ||
<thead className="rainbow-table_head"> | ||
<tr className="rainbow-table_header-row"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
@import "../../styles/colors"; | ||
@import "../../styles/font-sizes"; | ||
@import "../../styles/paddings"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this css file will become too huge, so we need to put the head specific styles in another css file inside the head folder, and the same for body.
you forgot to add the input type range
By default, columns are resizable. Users can click and drag the width to a minimum of 50px and a maximum of 1000px, unless the default values are changed. To change the minimum and maximum width column, use the minColumnWidth and maxColumnWidth props. |
src/components/Table/head/header.js
Outdated
@@ -13,6 +13,21 @@ export default class Header extends Component { | |||
this.handleMouseUp = this.handleMouseUp.bind(this); | |||
this.headerContainer = React.createRef(); | |||
this.resizeBar = React.createRef(); | |||
this.state = { | |||
width: this.props.width, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can use:
props.width
src/components/Table/head/header.js
Outdated
document.addEventListener('mousemove', this.handleMouseMove); | ||
document.addEventListener('mouseup', this.handleMouseUp); | ||
const { resizeColumnDisabled } = this.props; | ||
const isResizable = !resizeColumnDisabled || this.state.width === undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&&
const { resizeColumnDisabled } = this.props; | ||
const isResizable = !resizeColumnDisabled || this.state.width === undefined; | ||
if (isResizable) { | ||
this.startXPosition = dragEvent.clientX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to declare:
this.newXPosition = 0;
because if I click de resize bar without move it this variable is never declared and then in handleMouseUp when:
const width = headerContainerWidth + this.newXPosition;
we got NaN since this.newXPosition is undefined
Also we need to declare it here because whenever we click the resize bar we need to reset this value to 0 since if we move the resize bar 30px to right then this.newXPosition get 30 and when we press the resize bar again without move, it will resize the column with 30 and we don't want this.
src/components/Table/head/header.js
Outdated
minColumnWidth, | ||
maxColumnWidth, | ||
} = this.props; | ||
const headerStyles = { width: `${width}px` }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use width directly:
const headerStyles = { width };
fixes: #453