Skip to content
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

Merged
merged 19 commits into from
Jan 5, 2019
Merged

Conversation

AlejandroYanes
Copy link
Collaborator

fixes: #453

@coveralls
Copy link

coveralls commented Dec 27, 2018

Pull Request Test Coverage Report for Build 1020

  • 42 of 72 (58.33%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-1.08%) to 76.857%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Table/head/arrowDown.js 2 4 50.0%
src/components/Table/head/header.js 21 49 42.86%
Files with Coverage Reduction New Missed Lines %
src/components/Table/head/index.js 1 81.82%
Totals Coverage Status
Change from base Build 942: -1.08%
Covered Lines: 1333
Relevant Lines: 1661

💛 - Coveralls

};

Column.defaultProps = {
header: undefined,
component: undefined,
sortable: true,
Copy link
Collaborator

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

return (
<td className="rainbow-table_cell">
<td className="rainbow-table_cell" style={{ width }}>

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',

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 */

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

{
'rainbow-table_header--sortable': sortable,
'rainbow-table_header--selected': selected,
},

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?

<ArrowDown direction={sortDirection} />
</RenderIf>
</div>
<div

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

onColumnSelect(e, columnIndex) {
const { onSort } = this.props;
onSort(e, this.state.columns[columnIndex].field);
this.setState({ selectedColumn: columnIndex });

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

const { columns } = this.state;
const resizedColumn = Object.assign({}, columns[columnIndex]);
resizedColumn.width = width;
columns[columnIndex] = resizedColumn;

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.

const resizedColumn = Object.assign({}, columns[columnIndex]);
resizedColumn.width = width;
columns[columnIndex] = resizedColumn;
this.setState({ columns });

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.

@@ -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,

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.

@@ -18,9 +18,11 @@ CellValue.defaultProps = {
value: undefined,
};

export default function Cell({ component, value }) {
export default function Cell({ component, value, width }) {
const cellStyle = { width };

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

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} />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same ^^. Discard changes.

constructor(props) {
super(props);
this.state = {
columnWidths: props.columns.map(column => column.width),

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.

<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">

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";

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.

@LeandroTorresSicilia
Copy link
Member

you forgot to add the input type range
also add the following props to Table:

  • resizeColumnDisabled
  • minColumnWidth (default to 50)
  • maxColumnWidth(default to 1000)

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.
You can disable column resizing for all columns by setting the datatable's resizeColumnDisabled prop to true. You can disable column resizing for a specific column by setting the width column prop.

@@ -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,

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

document.addEventListener('mousemove', this.handleMouseMove);
document.addEventListener('mouseup', this.handleMouseUp);
const { resizeColumnDisabled } = this.props;
const isResizable = !resizeColumnDisabled || this.state.width === undefined;

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;

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.

minColumnWidth,
maxColumnWidth,
} = this.props;
const headerStyles = { width: `${width}px` };

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 };

@LeandroTorresSicilia LeandroTorresSicilia merged commit 0acfc73 into master Jan 5, 2019
@TahimiLeonBravo TahimiLeonBravo deleted the improve-table branch September 23, 2019 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add new feature to the table component
4 participants