-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-grid): add tableRowTemplate to the TableView plugin (#317)
- Loading branch information
1 parent
a93a030
commit 24d9446
Showing
17 changed files
with
307 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/dx-react-grid-bootstrap3/src/templates/table-row.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const TableRow = ({ children, tableRow, ...restProps }) => ( | ||
<tr | ||
className={tableRow.selected ? 'active' : ''} | ||
{...restProps} | ||
> | ||
{children} | ||
</tr> | ||
); | ||
|
||
TableRow.propTypes = { | ||
tableRow: PropTypes.object.isRequired, | ||
children: PropTypes.node, | ||
}; | ||
|
||
TableRow.defaultProps = { | ||
children: null, | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/dx-react-grid-bootstrap3/src/templates/table-row.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { setupConsole } from '@devexpress/dx-testing'; | ||
import { TableRow } from './table-row'; | ||
|
||
describe('TableRow', () => { | ||
const mountTableRow = ({ tableRow }) => ( | ||
mount( | ||
<TableRow | ||
tableRow={tableRow} | ||
/>, | ||
) | ||
); | ||
|
||
let resetConsole; | ||
beforeAll(() => { | ||
resetConsole = setupConsole({ ignore: ['validateDOMNesting'] }); | ||
}); | ||
|
||
afterAll(() => { | ||
resetConsole(); | ||
}); | ||
|
||
it('should have correct className', () => { | ||
let tree = mountTableRow({ tableRow: {} }); | ||
expect(tree.find('tr').hasClass('active')).toBeFalsy(); | ||
|
||
tree = mountTableRow({ tableRow: { selected: true } }); | ||
expect(tree.find('tr').hasClass('active')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/dx-react-grid-bootstrap3/src/templates/table.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { setupConsole } from '@devexpress/dx-testing'; | ||
import { TableLayout } from '@devexpress/dx-react-grid'; | ||
import { Table } from './table'; | ||
|
||
jest.mock('@devexpress/dx-react-grid', () => ({ | ||
TableLayout: jest.fn(), | ||
})); | ||
|
||
describe('Table', () => { | ||
let resetConsole; | ||
beforeAll(() => { | ||
resetConsole = setupConsole({ ignore: ['validateDOMNesting'] }); | ||
}); | ||
afterAll(() => { | ||
resetConsole(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should pass rowTemplate to TableLayout', () => { | ||
const rowTemplateMock = jest.fn(); | ||
const rowTemplateArgs = { | ||
row: 'row', | ||
children: null, | ||
}; | ||
TableLayout.mockImplementation(({ rowTemplate }) => ( | ||
<table> | ||
{rowTemplate(rowTemplateArgs)} | ||
</table> | ||
)); | ||
|
||
mount( | ||
<Table | ||
rowTemplate={rowTemplateMock} | ||
headerRows={[]} | ||
bodyRows={[]} | ||
columns={[]} | ||
cellTemplate={() => {}} | ||
getRowId={() => {}} | ||
allowColumnReordering={false} | ||
setColumnOrder={() => {}} | ||
/>, | ||
); | ||
|
||
expect(rowTemplateMock).toBeCalledWith(rowTemplateArgs); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/dx-react-grid-material-ui/src/templates/table-row.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
TableRow as TableRowMUI, | ||
} from 'material-ui'; | ||
import { withStyles } from 'material-ui/styles'; | ||
|
||
const TableRowBase = ({ children, tableRow, ...restProps }) => ( | ||
<TableRowMUI | ||
selected={tableRow.selected} | ||
{...restProps} | ||
> | ||
{children} | ||
</TableRowMUI> | ||
); | ||
|
||
TableRowBase.propTypes = { | ||
tableRow: PropTypes.object.isRequired, | ||
children: PropTypes.node, | ||
}; | ||
|
||
TableRowBase.defaultProps = { | ||
children: null, | ||
}; | ||
|
||
export const TableRow = withStyles({}, { name: 'TableRow' })(TableRowBase); |
34 changes: 34 additions & 0 deletions
34
packages/dx-react-grid-material-ui/src/templates/table-row.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { TableRow as TableRowMUI } from 'material-ui'; | ||
import { createMount } from 'material-ui/test-utils'; | ||
import { setupConsole } from '@devexpress/dx-testing'; | ||
import { TableRow } from './table-row'; | ||
|
||
describe('TableRow', () => { | ||
let resetConsole; | ||
let mount; | ||
|
||
const mountTableCell = ({ tableRow }) => ( | ||
mount( | ||
<TableRow | ||
tableRow={tableRow} | ||
/>, | ||
) | ||
); | ||
beforeAll(() => { | ||
resetConsole = setupConsole({ ignore: ['validateDOMNesting'] }); | ||
mount = createMount(); | ||
}); | ||
afterAll(() => { | ||
resetConsole(); | ||
mount.cleanUp(); | ||
}); | ||
|
||
it('should have correct selected prop', () => { | ||
let tree = mountTableCell({ tableRow: { } }); | ||
expect(tree.find(TableRowMUI).prop('selected')).toBeFalsy(); | ||
|
||
tree = mountTableCell({ tableRow: { selected: true } }); | ||
expect(tree.find(TableRowMUI).prop('selected')).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.