Skip to content

Commit 84cf9ca

Browse files
authored
Merge pull request #388 from puppetlabs/DATA-GRID-COMPLIY-CHANGES
(MAINT) Data-grid onRowClick handler
2 parents 3b3b9b3 + 5b96b23 commit 84cf9ca

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

packages/data-grid/src/__test__/Table.test.jsx

+16
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@ describe('Custom classes', () => {
272272

273273
describe('Selection Props', () => {
274274
const rowCheckMockfunc = jest.fn();
275+
const rowClickMockfunc = jest.fn();
275276
const wrapper9 = mount(
276277
<Table
277278
columns={columns}
278279
data={data}
279280
selectable
280281
onRowChecked={rowCheckMockfunc}
282+
onRowClick={rowClickMockfunc}
281283
/>,
282284
);
283285

@@ -332,4 +334,18 @@ describe('Selection Props', () => {
332334
.prop('checked'),
333335
).toEqual(true);
334336
});
337+
338+
test('When row is clicked fire onRowClick', () => {
339+
wrapper9
340+
.find('.dg-table-row')
341+
.first()
342+
.simulate('click');
343+
344+
expect(rowClickMockfunc).toHaveBeenCalledWith(undefined, 0, {
345+
affectedDevices: 20,
346+
detections: 634,
347+
eventType: 'Virus/Malware',
348+
id: 0,
349+
});
350+
});
335351
});

packages/data-grid/src/__test__/__snapshots__/Table.test.jsx.snap

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
8484
loadingMessage="Loading"
8585
onHeaderChecked={[Function]}
8686
onRowChecked={[Function]}
87+
onRowClick={[Function]}
8788
onSort={[Function]}
8889
rowClassName={[Function]}
8990
selectable={false}
@@ -210,6 +211,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
210211
<tr
211212
className="dg-table-row"
212213
key="0"
214+
onClick={[Function]}
213215
>
214216
<td
215217
className="rc-table-cell testColumnClassName"
@@ -237,6 +239,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
237239
<tr
238240
className="dg-table-row"
239241
key="1"
242+
onClick={[Function]}
240243
>
241244
<td
242245
className="rc-table-cell testColumnClassName"
@@ -264,6 +267,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
264267
<tr
265268
className="dg-table-row"
266269
key="2"
270+
onClick={[Function]}
267271
>
268272
<td
269273
className="rc-table-cell testColumnClassName"
@@ -291,6 +295,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
291295
<tr
292296
className="dg-table-row"
293297
key="3"
298+
onClick={[Function]}
294299
>
295300
<td
296301
className="rc-table-cell testColumnClassName"
@@ -318,6 +323,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
318323
<tr
319324
className="dg-table-row"
320325
key="4"
326+
onClick={[Function]}
321327
>
322328
<td
323329
className="rc-table-cell testColumnClassName"
@@ -345,6 +351,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
345351
<tr
346352
className="dg-table-row"
347353
key="5"
354+
onClick={[Function]}
348355
>
349356
<td
350357
className="rc-table-cell testColumnClassName"
@@ -372,6 +379,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 1`] = `
372379
<tr
373380
className="dg-table-row"
374381
key="6"
382+
onClick={[Function]}
375383
>
376384
<td
377385
className="rc-table-cell testColumnClassName"
@@ -441,6 +449,7 @@ exports[`Snapshot test Check component matches previous HTML snapshot 2`] = `
441449
loadingMessage="Loading"
442450
onHeaderChecked={[Function]}
443451
onRowChecked={[Function]}
452+
onRowClick={[Function]}
444453
onSort={[Function]}
445454
rowClassName={[Function]}
446455
selectable={false}

packages/data-grid/src/table/Table.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const propTypes = {
4848
rowKey: oneOfType([func, string]),
4949
/** Optional function which can be used to render styling on specific rows */
5050
rowClassName: oneOfType([func, string]),
51+
/** Optional function which can be used to execute a function on row click, will return rowKey, rowIndex, rowData */
52+
onRowClick: func,
5153
/** Render table in fixed-layout mode */
5254
fixed: bool,
5355
/** Optional additional table className */
@@ -102,6 +104,7 @@ const defaultProps = {
102104
selectable: false,
103105
onRowChecked: () => {},
104106
onHeaderChecked: () => {},
107+
onRowClick: () => {},
105108
headerCheckState: false,
106109
headerIndeterminateState: true,
107110
};
@@ -156,6 +159,7 @@ class Table extends Component {
156159
onRowChecked,
157160
onSort,
158161
headerIndeterminateState,
162+
onRowClick,
159163
...rest
160164
} = this.props;
161165

@@ -223,6 +227,7 @@ class Table extends Component {
223227
},
224228
)}
225229
key={this.uniqueIDCheck(rowKey, rowData, rowIndex)}
230+
onClick={() => onRowClick(rowKey, rowIndex, rowData)}
226231
>
227232
{selectable ? (
228233
<td

0 commit comments

Comments
 (0)