Skip to content
Snippets Groups Projects
Commit 9d6cce54 authored by Tomasz Knapik's avatar Tomasz Knapik Committed by Todd Dembrey
Browse files

Update grouped listing to use new listing

parent 180344fc
No related branches found
No related tags found
No related merge requests found
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Listing from '@components/Listing';
import ListingGroup from '@components/ListingGroup'; import ListingGroup from '@components/ListingGroup';
import ListingItem from '@components/ListingItem'; import ListingItem from '@components/ListingItem';
import LoadingPanel from '@components/LoadingPanel';
import '@components/Listing/style.scss'; import '@components/Listing/style.scss';
...@@ -45,49 +45,6 @@ export default class GroupedListing extends React.Component { ...@@ -45,49 +45,6 @@ export default class GroupedListing extends React.Component {
} }
} }
renderListItems() {
const { isLoading, error, items, onItemSelection, activeItem } = this.props;
if (isLoading) {
return (
<div className="listing__list is-loading">
<LoadingPanel />
</div>
)
} else if (error) {
return (
<div className="listing__list is-loading">
<p>Something went wrong. Please try again later.</p>
<p>{ error }</p>
</div>
)
} else if (items.length === 0) {
return (
<div className="listing__list is-loading">
<p>No results found.</p>
</div>
)
}
return (
<ul className="listing__list">
{this.state.orderedItems.map(group => {
return (
<ListingGroup key={`listing-group-${group.name}`} item={group}>
{group.items.map(item => {
return <ListingItem
selected={!!activeItem && activeItem===item.id}
onClick={() => onItemSelection(item.id)}
key={`listing-item-${item.id}`}
item={item}/>;
})}
</ListingGroup>
);
})}
</ul>
);
}
getGroupedItems() { getGroupedItems() {
const { groupBy, items } = this.props; const { groupBy, items } = this.props;
...@@ -113,12 +70,26 @@ export default class GroupedListing extends React.Component { ...@@ -113,12 +70,26 @@ export default class GroupedListing extends React.Component {
}); });
} }
render() { renderItem = group => {
const { activeItem, onItemSelection } = this.props;
return ( return (
<div className="listing"> <ListingGroup key={`listing-group-${group.name}`} item={group}>
<div className="listing__header"></div> {group.items.map(item => {
{this.renderListItems()} return <ListingItem
</div> selected={!!activeItem && activeItem===item.id}
onClick={() => onItemSelection(item.id)}
key={`listing-item-${item.id}`}
item={item}/>;
})}
</ListingGroup>
); );
} }
render() {
const passProps = {
items: this.state.orderedItems,
renderItem: this.renderItem,
};
return <Listing {...passProps} />;
}
} }
...@@ -7,8 +7,7 @@ import './style.scss'; ...@@ -7,8 +7,7 @@ import './style.scss';
export default class Listing extends React.Component { export default class Listing extends React.Component {
static propTypes = { static propTypes = {
items: PropTypes.array, items: PropTypes.array.isRequired,
activeItem: PropTypes.number,
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
isError: PropTypes.bool, isError: PropTypes.bool,
error: PropTypes.string, error: PropTypes.string,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment