Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Improved: code to display the filter count on initial load (#554) #560

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 3 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
19 changes: 6 additions & 13 deletions pages/Category.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ export default {
currentPage: 1,
getMoreCategoryProducts: [],
browserWidth: 0,
isFilterSidebarOpen: false,
unsubscribeFromStoreAction: null,
aggregations: null
isFilterSidebarOpen: false
};
},
computed: {
Expand All @@ -296,6 +294,7 @@ export default {
getAvailableFilters: 'category-next/getAvailableFilters',
getCurrentFilters: 'category-next/getCurrentFilters',
getSystemFilterNames: 'category-next/getSystemFilterNames',
getAggregations: 'category-next/getAggregations',
getCategories: 'category/getCategories',
getBreadcrumbsRoutes: 'breadcrumbs/getBreadcrumbsRoutes',
getBreadcrumbsCurrent: 'breadcrumbs/getBreadcrumbsCurrent'
Expand Down Expand Up @@ -389,7 +388,7 @@ export default {
.reduce((result, [filterType, filters]) => {
result[`${filterType}_filter`] = filters.map(filter => ({
...filter,
count: this.getFilterCount(filter) || '',
count: this.getFilterCount(filter) || '0',
color:
filterType === 'color'
? (config.products.colorMappings &&
Expand Down Expand Up @@ -455,17 +454,11 @@ export default {
}
},
mounted () {
this.unsubscribeFromStoreAction = this.$store.subscribeAction(action => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure about this part? Have you test it manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have tested it. Actually, on the initial load of the category page, only two specific actions are getting subscribed so, I think this part is of no use.

if (action.type === 'category-next/loadAvailableFiltersFrom') {
this.aggregations = action.payload.aggregations;
}
});
this.$bus.$on('product-after-list', this.initPagination);
window.addEventListener('resize', this.getBrowserWidth);
this.getBrowserWidth();
},
beforeDestroy () {
this.unsubscribeFromStoreAction();
this.$bus.$off('product-after-list', this.initPagination);
window.removeEventListener('resize', this.getBrowserWidth);
},
Expand Down Expand Up @@ -545,9 +538,9 @@ export default {
return aggregations
.reduce((result, aggregation) => {
const bucket =
this.aggregations &&
this.aggregations[aggregation] &&
this.aggregations[aggregation].buckets.find(
this.getAggregations &&
this.getAggregations[aggregation] &&
this.getAggregations[aggregation].buckets.find(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add Array.isArray(this.getAggregations[aggregation].buckets) check too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the check for the aggregations array

bucket => String(bucket.key) === String(filter.id)
);

Expand Down