Skip to content

Commit

Permalink
fix(composables): showing whole filters collection on SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus committed Oct 29, 2020
1 parent 7d52cba commit 7b2a43e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe("Composables - createListingComposable", () => {
});
await setInitialListing({
currentFilters: {
manufacturer: {},
manufacturer: ["1234567"],
},
} as any);
expect(searchMethodMock).toBeCalledWith({});
Expand All @@ -205,7 +205,7 @@ describe("Composables - createListingComposable", () => {
initialListing: {
aggregations: undefined,
currentFilters: {
manufacturer: {},
manufacturer: ["1234567"],
},
},
});
Expand Down
24 changes: 15 additions & 9 deletions packages/composables/src/factories/createListingComposable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ export function createListingComposable<ELEMENTS_TYPE>({
() => vuexStore.getters.getInitialListings[listingKey] || {}
);
const setInitialListing = async (initialListing: ProductListingResult) => {
// TODO: remove before v0.6.0 release (SW v6.4.x).
// note: only v6.3.x compatible
/* istanbul ignore next */
if (
initialListing.currentFilters?.manufacturer ||
initialListing.currentFilters?.properties
initialListing?.currentFilters?.manufacturer?.length ||
initialListing?.currentFilters?.properties?.length
) {
loading.value = true;
const allFiltersResult = await searchMethod({});
const allFiltersResult = await searchMethod({
query: initialListing.currentFilters.search || undefined,
});
initialListing = Object.assign({}, initialListing, {
aggregations: allFiltersResult?.aggregations,
});
Expand All @@ -102,10 +105,8 @@ export function createListingComposable<ELEMENTS_TYPE>({
loading.value = true;
try {
const searchCriteria = merge({}, searchDefaults, criteria);

const result = await searchMethod(searchCriteria);

setInitialListing(result);
await setInitialListing(result);
} catch (e) {
throw e;
} finally {
Expand Down Expand Up @@ -137,8 +138,13 @@ export function createListingComposable<ELEMENTS_TYPE>({
const result = await searchMethod(searchCriteria);

// TODO: remove before v0.6.0 release (SW v6.4.x).
if (searchCriteria.manufacturer || searchCriteria.properties) {
const allFiltersResult = await searchMethod({});
if (
searchCriteria.manufacturer?.length ||
searchCriteria.properties?.length
) {
const allFiltersResult = await searchMethod({
query: searchCriteria.query,
});
appliedListing.value = Object.assign({}, result, {
aggregations: allFiltersResult?.aggregations,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default {
async clearAllFilters() {
this.closeFiltersSidebar()
this.search({
search: this.getCurrentFilters && this.getCurrentFilters.search,
query: this.getCurrentFilters && this.getCurrentFilters.search,
})
},
openFiltersSidebar() {
Expand Down

0 comments on commit 7b2a43e

Please sign in to comment.