* Fixed #237

* Solved lint errors

* Removed test cases for display: none checks
- added test cases for hidden columns check
This commit is contained in:
Parth Prajapati
2018-03-18 13:12:21 +05:30
committed by Allen
parent c11539b9fb
commit 6bc81dddd0
8 changed files with 99 additions and 104 deletions

View File

@@ -39,7 +39,6 @@ class Cell extends Component {
} = this.props;
const {
dataField,
hidden,
formatter,
formatExtraData,
style,
@@ -80,10 +79,6 @@ class Cell extends Component {
_.isFunction(align) ? align(content, row, rowIndex, columnIndex) : align;
}
if (hidden) {
cellStyle.display = 'none';
}
if (cellClasses) cellAttrs.className = cellClasses;
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;

View File

@@ -24,7 +24,6 @@ const HeaderCell = (props) => {
text,
sort,
filter,
hidden,
headerTitle,
headerAlign,
headerFormatter,
@@ -58,10 +57,6 @@ const HeaderCell = (props) => {
cellStyle.textAlign = _.isFunction(headerAlign) ? headerAlign(column, index) : headerAlign;
}
if (hidden) {
cellStyle.display = 'none';
}
if (sort) {
const customClick = cellAttrs.onClick;
cellAttrs.onClick = (e) => {

View File

@@ -27,20 +27,23 @@ const Header = (props) => {
}
{
columns.map((column, i) => {
const currSort = column.dataField === sortField;
const isLastSorting = column.dataField === sortField;
if (!column.hidden) {
const currSort = column.dataField === sortField;
const isLastSorting = column.dataField === sortField;
return (
<HeaderCell
index={ i }
key={ column.dataField }
column={ column }
onSort={ onSort }
sorting={ currSort }
onFilter={ onFilter }
sortOrder={ sortOrder }
isLastSorting={ isLastSorting }
/>);
return (
<HeaderCell
index={ i }
key={ column.dataField }
column={ column }
onSort={ onSort }
sorting={ currSort }
onFilter={ onFilter }
sortOrder={ sortOrder }
isLastSorting={ isLastSorting }
/>);
}
return false;
})
}
</tr>

View File

@@ -58,46 +58,49 @@ class Row extends eventDelegater(Component) {
}
{
columns.map((column, index) => {
const { dataField } = column;
const content = _.get(row, dataField);
let editable = _.isDefined(column.editable) ? column.editable : true;
if (dataField === keyField || !editableRow) editable = false;
if (_.isFunction(column.editable)) {
editable = column.editable(content, row, rowIndex, index);
}
if (rowIndex === editingRowIdx && index === editingColIdx) {
let editCellstyle = column.editCellStyle || {};
let editCellclasses = column.editCellClasses;
if (_.isFunction(column.editCellStyle)) {
editCellstyle = column.editCellStyle(content, row, rowIndex, index);
if (!column.hidden) {
const { dataField } = column;
const content = _.get(row, dataField);
let editable = _.isDefined(column.editable) ? column.editable : true;
if (dataField === keyField || !editableRow) editable = false;
if (_.isFunction(column.editable)) {
editable = column.editable(content, row, rowIndex, index);
}
if (_.isFunction(column.editCellClasses)) {
editCellclasses = column.editCellClasses(content, row, rowIndex, index);
if (rowIndex === editingRowIdx && index === editingColIdx) {
let editCellstyle = column.editCellStyle || {};
let editCellclasses = column.editCellClasses;
if (_.isFunction(column.editCellStyle)) {
editCellstyle = column.editCellStyle(content, row, rowIndex, index);
}
if (_.isFunction(column.editCellClasses)) {
editCellclasses = column.editCellClasses(content, row, rowIndex, index);
}
return (
<EditingCell
key={ `${content}-${index}` }
row={ row }
column={ column }
className={ editCellclasses }
style={ editCellstyle }
{ ...rest }
/>
);
}
return (
<EditingCell
<Cell
key={ `${content}-${index}` }
row={ row }
rowIndex={ rowIndex }
columnIndex={ index }
column={ column }
className={ editCellclasses }
style={ editCellstyle }
{ ...rest }
onStart={ onStart }
editable={ editable }
clickToEdit={ mode === CLICK_TO_CELL_EDIT }
dbclickToEdit={ mode === DBCLICK_TO_CELL_EDIT }
/>
);
}
return (
<Cell
key={ `${content}-${index}` }
row={ row }
rowIndex={ rowIndex }
columnIndex={ index }
column={ column }
onStart={ onStart }
editable={ editable }
clickToEdit={ mode === CLICK_TO_CELL_EDIT }
dbclickToEdit={ mode === DBCLICK_TO_CELL_EDIT }
/>
);
return false;
})
}
</tr>

View File

@@ -27,24 +27,6 @@ describe('Cell', () => {
});
});
describe('when column.hidden prop is true', () => {
const column = {
dataField: 'id',
text: 'ID',
hidden: true
};
beforeEach(() => {
wrapper = shallow(<Cell row={ row } columnIndex={ 1 } rowIndex={ 1 } column={ column } />);
});
it('should have \'none\' value for style.display', () => {
const style = wrapper.find('td').prop('style');
expect(style).toBeDefined();
expect(style.display).toEqual('none');
});
});
describe('when column.formatter prop is defined', () => {
const rowIndex = 1;
const column = {
@@ -390,20 +372,6 @@ describe('Cell', () => {
});
});
describe('when column.hidden prop is defined', () => {
it('attrs.style.hidden should be overwrited', () => {
column.hidden = true;
column.attrs = { style: { hidden: true } };
wrapper = shallow(
<Cell row={ row } columnIndex={ columnIndex } rowIndex={ 1 } column={ column } />);
const style = wrapper.find('td').prop('style');
expect(style).toBeDefined();
expect(style.display).toEqual('none');
});
});
describe('when column.align prop is defined', () => {
it('attrs.style.textAlign should be overwrited', () => {
column.align = 'center';

View File

@@ -33,24 +33,6 @@ describe('HeaderCell', () => {
});
});
describe('when column.hidden props is true', () => {
const column = {
dataField: 'id',
text: 'ID',
hidden: true
};
beforeEach(() => {
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
});
it('should have \'none\' value for style.display', () => {
const style = wrapper.find('th').prop('style');
expect(style).toBeDefined();
expect(style.display).toEqual('none');
});
});
describe('when column.headerTitle prop is defined', () => {
let column;
beforeEach(() => {

View File

@@ -101,6 +101,29 @@ describe('Header', () => {
});
});
describe('when column.hidden is true', () => {
beforeEach(() => {
const newColumns = [{
dataField: 'id',
text: 'ID',
hidden: true
}, {
dataField: 'name',
text: 'Name'
}];
wrapper = shallow(
<Header
{ ...mockHeaderResolvedProps }
columns={ newColumns }
/>
);
});
it('should not render column with hidden value true', () => {
expect(wrapper.find(HeaderCell).length).toBe(1);
});
});
describe('when selectRow.mode is checkbox (multiple selection)', () => {
beforeEach(() => {
const selectRow = { mode: 'checkbox' };

View File

@@ -502,6 +502,32 @@ describe('Row', () => {
});
});
describe('when cloumn.hidden is true', () => {
beforeEach(() => {
const newColumns = [{
dataField: 'id',
text: 'ID',
hidden: true
}, {
dataField: 'name',
text: 'Name'
}, {
dataField: 'price',
text: 'Price'
}];
wrapper = shallow(
<Row
{ ...mockBodyResolvedProps }
rowIndex={ rowIndex }
columns={ newColumns }
row={ row }
/>);
});
it('should not render column with hidden value true', () => {
expect(wrapper.find(Cell).length).toBe(2);
});
});
describe('selectRow', () => {
let selectRow;