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

Conversation

ymaheshwari1
Copy link
Contributor

Related Issues

#554

Closes #554

Short Description and Why It's Useful

The changes will help in displaying the filter count on the initial load of category page.

Screenshots of Visual Changes before/after (If There Are Any)

IMPORTANT NOTICE - Remember to update CHANGELOG.md with description of your change

Contribution and Currently Important Rules Acceptance

@ymaheshwari1
Copy link
Contributor Author

ymaheshwari1 commented Dec 22, 2020

There are two solutions for the issue:

  1. call the composeInitialPageState in beforeRouteEnter hook. (57cb6cd)
  2. move the subscribeAction logic to asyncData and then using global variables to access the filter count. (b854467)

@@ -223,6 +223,8 @@ import {

const THEME_PAGE_SIZE = 12;
const LAZY_LOADING_ACTIVATION_BREAKPOINT = 1024;
var unsubscribeFromStoreAction = ''
var aggs = ''
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using global variables is not a good idea. It might cause race conditions in concurrent requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fifciu
The other solution can be to call the composeInitialPageState in the beforeRouteEnter hook. You can see the solution in this commit: 57cb6cd

Also, another thing that I can think of is to maintain a state for storing the aggregations and then using that state in our component, and thus we also not need to subscribe to the action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fifciu I have updated the solution to make use of state and getter to use the aggregations, please review.
vuestorefront/vue-storefront#5392

@CLAassistant
Copy link

CLAassistant commented Jan 11, 2021

CLA assistant check
All committers have signed the CLA.

@ymaheshwari1 ymaheshwari1 force-pushed the #554/filter-count-issue-on-initial-load branch from e93a4f6 to 95fc967 Compare January 11, 2021 13:01
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

@AishwaryShrivastav
Copy link
Contributor

@Fifciu can you look into this also, changes looks good to me

@@ -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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter count is not displayed on initial load
4 participants