Skip to content

Commit 2d19c8f

Browse files
authored
[1036] Improve case studies search filtering with dynamic facet counts and empty-state UX (#268)
## Summary - Update case studies filter counts to recalculate from the current result set (active search + active filters), instead of using static/global counts. - Keep existing result filtering behavior unchanged; only count calculation logic is synchronized with what the user currently sees.
1 parent 28713d9 commit 2d19c8f

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

website/modules/case-studies-page/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ const buildIndexQuery = function (self, req) {
6767
return query;
6868
};
6969

70+
const buildTagCountQuery = function (self, req) {
71+
const queryParams = { ...req.query };
72+
const searchTerm = SearchService.getSearchTerm(queryParams);
73+
delete queryParams.search;
74+
delete queryParams.page;
75+
76+
const query = self.pieces.find(req, {}).applyBuildersSafely(queryParams);
77+
self.filterByIndexPage(query, req.data.page);
78+
79+
const resolved = req.data.searchRelationships || {};
80+
const searchCondition = SearchService.buildSearchCondition(
81+
searchTerm,
82+
resolved,
83+
);
84+
if (searchCondition) {
85+
query.and(searchCondition);
86+
}
87+
return query;
88+
};
89+
7090
const runResolveSearchRelationships = async function (self, req) {
7191
req.data ||= {};
7292
const reqData = req.data;
@@ -125,10 +145,13 @@ const runApplyEnhancedSearchResults = async function (self, req) {
125145

126146
const runSetupIndexData = async function (self, req) {
127147
try {
148+
const countQuery = buildTagCountQuery(self, req);
149+
const caseStudiesForCounts = await countQuery.toArray();
128150
const tagCounts = await TagCountService.calculateTagCounts(
129151
req,
130152
self.apos.modules,
131153
self.options,
154+
caseStudiesForCounts,
132155
);
133156
UrlService.attachIndexData(req, tagCounts);
134157
} catch (error) {

website/modules/case-studies-page/services/TagCountService.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ class TagCountService {
4949
* @param {Object} options - Module options
5050
* @returns {Promise<Array>} Promise resolving to [caseStudies, casesTags, businessPartners] arrays
5151
*/
52-
static async fetchCaseStudiesAndTags(req, aposModules, options) {
53-
const [caseStudies, casesTags, businessPartners] = await Promise.all([
54-
aposModules[options.pieces].find(req).toArray(),
52+
static async fetchCaseStudiesAndTags(req, aposModules, options, caseStudies) {
53+
const [casesTags, businessPartners] = await Promise.all([
5554
aposModules['cases-tags'].find(req).toArray(),
5655
aposModules['business-partner'].find(req).toArray(),
5756
]);
58-
return [caseStudies, casesTags, businessPartners];
57+
let pieces = caseStudies;
58+
if (!pieces) {
59+
pieces = await aposModules[options.pieces].find(req).toArray();
60+
}
61+
return [pieces, casesTags, businessPartners];
5962
}
6063

6164
/**
@@ -96,7 +99,7 @@ class TagCountService {
9699
* @param {Object} options - Module options
97100
* @returns {Promise<Object>} Tag counts by type
98101
*/
99-
static async calculateTagCounts(req, aposModules, options) {
102+
static async calculateTagCounts(req, aposModules, options, caseStudiesInput) {
100103
const tagCounts = {
101104
industry: {},
102105
stack: {},
@@ -105,7 +108,12 @@ class TagCountService {
105108
};
106109

107110
const [caseStudies, casesTags, businessPartners] =
108-
await TagCountService.fetchCaseStudiesAndTags(req, aposModules, options);
111+
await TagCountService.fetchCaseStudiesAndTags(
112+
req,
113+
aposModules,
114+
options,
115+
caseStudiesInput,
116+
);
109117

110118
const tagMap = TagCountService.createIdToSlugMap(casesTags);
111119
const partnerMap = TagCountService.createIdToSlugMap(businessPartners);

0 commit comments

Comments
 (0)