Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWA-970 Added new category selectors. Converted list component to be … #258

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions libraries/commerce/category/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ export const getCurrentCategoryChildCount = createSelector(
category => (category ? category.childrenCount : null)
);

/**
* Returns true when the given category id contains children.
* @param {Object} state The application state.
* @param {Object} props The component props.
* @returns {boolean}
*/
export const hasChildren = createSelector(
getCurrentCategoryChildCount,
count => count > 0
);

/**
* Retrieves the current categories collection from the state.
* @param {Object} state The application state.
Expand Down Expand Up @@ -137,6 +148,17 @@ export const getCategoryProductCount = createSelector(
}
);

/**
* Returns true when the given category id contains products.
* @param {Object} state The application state.
* @param {Object} props The component props.
* @returns {boolean}
*/
export const hasProducts = createSelector(
getCategoryProductCount,
count => count > 0
);

export const getChildCategoriesById = createSelector(
getCategoriesState,
getChildCategoriesState,
Expand Down
4 changes: 2 additions & 2 deletions libraries/common/components/List/__snapshots__/spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`<List /> renders with children 1`] = `
<ul
className="css-gkw1j5 "
className=""
>
<ListItem
className={null}
Expand All @@ -24,6 +24,6 @@ exports[`<List /> renders with children 1`] = `

exports[`<List /> renders without children 1`] = `
<ul
className="css-gkw1j5 "
className=""
/>
`;
47 changes: 15 additions & 32 deletions libraries/common/components/List/index.jsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import React, { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import ListItem from './components/Item';
import styles from './style';

/**
* The list component.
* @param {Object} props - The component props.
* @param {React.Children} props.children - Some content to display inside.
* The List component.
* @param {Object} props The component props.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No @returns in the JSDoc

* @returns {JSX}
*/
class List extends Component {
static Item = ListItem;
const List = ({ children, className }) => (
<ul className={className}>{children}</ul>
);

static propTypes = {
className: PropTypes.string,
};
List.Item = ListItem;

static defaultProps = {
className: '',
};
List.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.shape()]),
};

/**
* Composes the props.
* @returns {Object} The composed props.
*/
getProps() {
return {
...this.props,
className: `${styles} ${this.props.className}`,
};
}

/**
* Renders the component.
* @returns {JSX}
*/
render() {
return React.createElement('ul', this.getProps());
}
}
List.defaultProps = {
className: '',
};

export default List;
7 changes: 0 additions & 7 deletions libraries/common/components/List/style.js

This file was deleted.