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

[BUGFIX] Show a message when a category has no products assigned #1496

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3018588
[BUGFIX] Show a message when a category has no products assigned - re…
Jul 31, 2019
989cff0
[REFACTOR][#1496] Change if statement to be more clear and simple
Aug 7, 2019
912bf1c
[REFACTOR] Resolved merge conflict
Aug 7, 2019
ae6be6c
Merge branch 'develop' into bugfix/empty-category
Aug 7, 2019
4b43f41
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 8, 2019
c20c1b8
Merge branch 'develop' into bugfix/empty-category
Aug 15, 2019
c4b26d1
[FEATURE][1496] Add categories to the no products found message
Aug 15, 2019
5e73908
Merge branch 'bugfix/empty-category' of github.com:Jordaneisenburger/…
Aug 15, 2019
e82a243
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 15, 2019
825ce07
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 16, 2019
d925133
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 19, 2019
5dce267
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 20, 2019
06cb6dd
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 21, 2019
bccc13e
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 22, 2019
b2addf8
Merge branch 'develop' into bugfix/empty-category
supernova-at Aug 29, 2019
94f664b
Merge branch 'develop' into bugfix/empty-category
supernova-at Sep 5, 2019
b07ceda
Merge branch 'develop' into bugfix/empty-category
supernova-at Sep 6, 2019
0844342
Merge branch 'develop' into bugfix/empty-category
supernova-at Sep 9, 2019
1b154c5
Merge branch 'develop' into bugfix/empty-category
supernova-at Sep 10, 2019
a12f1b6
Merge branch 'develop' of https://github.com/magento/pwa-studio into …
Sep 11, 2019
2b338c8
[FEATURE] Add the actual image, make sure webpack can process png files
Sep 11, 2019
1f381b2
Merge branch 'bugfix/empty-category' of github.com:Jordaneisenburger/…
Sep 11, 2019
4f765aa
[PRETTIER] Just ran prettier
Sep 11, 2019
021ea77
Merge branch 'develop' into bugfix/empty-category
supernova-at Sep 18, 2019
9171171
Merge remote-tracking branch 'origin/develop' into bugfix/empty-category
supernova-at Sep 30, 2019
eb44b1f
Randomizes category recommendations
supernova-at Sep 30, 2019
670041c
Removes blank line
supernova-at Sep 30, 2019
7ad6717
Merge branch 'develop' into bugfix/empty-category
supernova-at Sep 30, 2019
88d3227
Merge branch 'develop' into bugfix/empty-category
sirugh Oct 1, 2019
71f2b0f
Addresses feedback
supernova-at Oct 1, 2019
9ee21f3
Merge branch 'develop' into bugfix/empty-category
dpatil-magento Oct 2, 2019
08b16d5
Merge branch 'develop' into bugfix/empty-category
dpatil-magento Oct 2, 2019
0fde73c
Merge branch 'develop' into bugfix/empty-category
dpatil-magento Oct 2, 2019
f6fce9c
Adds return statement to useMemo function
supernova-at Oct 2, 2019
f0d6f9e
Merge branch 'bugfix/empty-category' of github.com:Jordaneisenburger/…
supernova-at Oct 2, 2019
481b28e
Merge branch 'develop' into bugfix/empty-category
dpatil-magento Oct 2, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './noProductsFound';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.root {
align-items: center;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
}

.title {
font-size: 1rem;
font-weight: 600;
text-align: center;
}

.categories {
margin-top: 2rem;
}

.list {
margin-top: 1rem;
}

.listItem {
text-align: center;
text-decoration: underline;
}

.listItem:not(:last-child) {
margin-bottom: 0.5rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import { string, shape, objectOf, number } from 'prop-types';
import { mergeClasses } from '../../../classify';
import { Link, resourceUrl } from '@magento/venia-drivers';
import defaultClasses from './noProductsFound.css';

const NoProductsFound = props => {
const classes = mergeClasses(defaultClasses, props.classes);
const categories = props.categories;

// TODO: get categoryUrlSuffix from graphql storeOptions when it is ready
const categoryUrlSuffix = '.html';
revanth0212 marked this conversation as resolved.
Show resolved Hide resolved

const categoryList = (
<ul className={classes.list}>
{Object.values(categories)
.filter(category => category.isActive)
supernova-at marked this conversation as resolved.
Show resolved Hide resolved
.map(category => {
const uri = resourceUrl(
`/${category.urlKey}${categoryUrlSuffix}`
);

return (
<li key={category.id} className={classes.listItem}>
<Link to={uri}>{category.name}</Link>
</li>
);
})}
</ul>
);

return (
<div className={classes.root}>
<img src={''} alt="Sorry! There are no products in this category" />
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like an app-accessibility trick but since there is no Image src, can we achieve this using a div or p? Or find a good background for the Sorry! There are no products in this category. string.

Copy link
Member Author

Choose a reason for hiding this comment

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

@revanth0212 When i made this commit there was no image available, it is now (see comments above). I will make a new commit with a working image soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

I unresolved the conversation just to keep easy track of the work left to do on this PR:

I will make a new commit with a working image soon.

<h2 className={classes.title}>
Sorry! There are no products in this category
supernova-at marked this conversation as resolved.
Show resolved Hide resolved
</h2>
<div className={classes.categories}>
<p>Try one of these categories</p>
{categoryList}
</div>
</div>
);
};

export default NoProductsFound;

NoProductsFound.propTypes = {
classes: shape({
root: string,
title: string,
list: string,
categories: string,
listItem: string
}),
categories: objectOf(
shape({
name: string.isRequired,
id: number.isRequired
})
).isRequired
};
19 changes: 15 additions & 4 deletions packages/venia-ui/lib/RootComponents/Category/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import isObjectEmpty from '../../util/isObjectEmpty';
import { getFilterParams } from '../../util/getFilterParamsFromUrl';
import CategoryContent from './categoryContent';
import defaultClasses from './category.css';
import NoProductsFound from './NoProductsFound';

const Category = props => {
const { filterClear, id, openDrawer, pageSize } = props;
const { filterClear, id, openDrawer, pageSize, categories } = props;
const classes = mergeClasses(defaultClasses, props.classes);

const [paginationValues, paginationApi] = usePagination({
Expand Down Expand Up @@ -91,11 +92,13 @@ const Category = props => {
}

// Show the loading indicator until data has been fetched.
if (!totalPagesFromData) {
if (totalPagesFromData === null) {
return fullPageLoadingIndicator;
}

return (
return totalPagesFromData === 0 ? (
<NoProductsFound categories={categories} />
) : (
<CategoryContent
classes={classes}
data={loading ? null : data}
Expand Down Expand Up @@ -123,6 +126,14 @@ Category.defaultProps = {
pageSize: 6
};

const mapStateToProps = ({ catalog }) => {
const categories = catalog.categories;
revanth0212 marked this conversation as resolved.
Show resolved Hide resolved

return {
categories
};
};

const mapDispatchToProps = dispatch => ({
filterClear: () => dispatch(catalogActions.filterOption.clear()),
openDrawer: () => dispatch(toggleDrawer('filter'))
Expand All @@ -131,7 +142,7 @@ const mapDispatchToProps = dispatch => ({
export default compose(
withRouter,
connect(
null,
mapStateToProps,
mapDispatchToProps
)
)(Category);