Skip to content

Commit

Permalink
Merge pull request #64 from uptick/enhance/onclick-handlers
Browse files Browse the repository at this point in the history
Add onclick functionality for items in a dataset
  • Loading branch information
tabby-or-not committed Aug 3, 2018
2 parents 96d250e + 3a230e6 commit f034d30
Show file tree
Hide file tree
Showing 17 changed files with 731 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/ObjectList.demo.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import { withInfo } from '@storybook/addon-info'
import {TextContainsFilter, SearchFilter} from './filters'

Expand Down Expand Up @@ -154,6 +155,7 @@ class InteractiveObjectList extends React.Component {
removeFilter={this.removeFilter}
updateFilter={this.updateFilter}
searchKey="first_name"
itemOnClick={action('clicked on')}
/>
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/ObjectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class ObjectList extends Component {
...FILTER_BASE_TYPE,
active: PropTypes.bool,
})),
/** function called when a datapoint's representation is clicked on **/
itemOnClick: PropTypes.func,
/** the column renderer to use, if 2d array they are grouped together */
columns: PropTypes.arrayOf(PropTypes.oneOfType([COLUMN_TYPE, PropTypes.arrayOf(COLUMN_TYPE)])),
/** callback function when toggling an extra column on or off */
Expand Down Expand Up @@ -118,7 +120,7 @@ class ObjectList extends Component {
const {
DataRenderer, Pagination, ErrorMessage,
filters, addFilter, updateFilter, meta, status, searchKey,
data, columns, updateColumns,
data, columns, updateColumns, itemOnClick,
favourites, handleDeleteFavourite, handleAddFavourite, favouritesEnabled,
selectedFavouriteName, loadFavourite, maxPages, removeFilter,
updatePage, updateSorting, selection, selectItems, customActions, error,
Expand Down Expand Up @@ -166,6 +168,7 @@ class ObjectList extends Component {
select={selectItems}
status={status}
numSelected={numSelected}
itemOnClick={itemOnClick}
/>
{ (totalCount / perPage) > 0 &&
<Pagination
Expand Down
42 changes: 28 additions & 14 deletions src/__snapshots__/ObjectList.demo.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
className="objectlist-list__list"
>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -167,7 +168,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
</div>
</li>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -216,7 +218,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
</div>
</li>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -265,7 +268,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
</div>
</li>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -314,7 +318,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
</div>
</li>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -363,7 +368,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
</div>
</li>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -412,7 +418,8 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
</div>
</li>
<li
className="objectlist-list__item"
className="objectlist-list__item objectlist-list__item--clickable"
onClick={[Function]}
>
<div
className="objectlist-list__content"
Expand Down Expand Up @@ -780,7 +787,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</thead>
<tbody>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand All @@ -800,7 +808,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</td>
</tr>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand All @@ -820,7 +829,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</td>
</tr>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand All @@ -840,7 +850,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</td>
</tr>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand All @@ -860,7 +871,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</td>
</tr>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand All @@ -880,7 +892,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</td>
</tr>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand All @@ -900,7 +913,8 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
</td>
</tr>
<tr
className="objectlist-table__row"
className="objectlist-table__row objectlist-table__row--clickable"
onClick={[Function]}
>
<td
className="objectlist-table__td"
Expand Down
Loading

0 comments on commit f034d30

Please sign in to comment.