@abcagency/hc-ui-components 1.3.21 → 1.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{bundle.js → bundleDist/bundle.js} +30 -19
- package/bundleDist/bundle.js.map +1 -0
- package/bundleDist/dist/styles/index.css +3 -0
- package/bundleDist/dist/types/apis/hcApi.d.ts +5 -0
- package/bundleDist/dist/types/clientToken.d.ts +2 -0
- package/bundleDist/dist/types/components/containers/accordions/map-accordion-item-container.d.ts +12 -0
- package/bundleDist/dist/types/components/containers/jobListing/listing-details-container.d.ts +6 -0
- package/bundleDist/dist/types/components/containers/list/item-list-container.d.ts +9 -0
- package/bundleDist/dist/types/components/containers/list/list-item/list-item-container.d.ts +14 -0
- package/bundleDist/dist/types/components/modules/accordions/MapAccordionItem.d.ts +10 -0
- package/bundleDist/dist/types/components/modules/accordions/default.d.ts +19 -0
- package/bundleDist/dist/types/components/modules/buttons/button-group-apply.d.ts +24 -0
- package/bundleDist/dist/types/components/modules/buttons/commute-pill.d.ts +5 -0
- package/bundleDist/dist/types/components/modules/buttons/default.d.ts +48 -0
- package/bundleDist/dist/types/components/modules/buttons/pill-wrapper.d.ts +3 -0
- package/bundleDist/dist/types/components/modules/dialogs/apply-dialog.d.ts +8 -0
- package/bundleDist/dist/types/components/modules/filter/sort.d.ts +8 -0
- package/bundleDist/dist/types/components/modules/grid.d.ts +8 -0
- package/bundleDist/dist/types/components/modules/icon.d.ts +10 -0
- package/bundleDist/dist/types/components/modules/jobListing/listing-details.d.ts +18 -0
- package/bundleDist/dist/types/components/modules/list/field-mapper.d.ts +10 -0
- package/bundleDist/dist/types/components/modules/list/header-item.d.ts +11 -0
- package/bundleDist/dist/types/components/modules/list/header.d.ts +11 -0
- package/bundleDist/dist/types/components/modules/list/item-expand-card/index.d.ts +7 -0
- package/bundleDist/dist/types/components/modules/list/item-expand-card/recruiter-contact-nav.d.ts +17 -0
- package/bundleDist/dist/types/components/modules/list/item-expand-card/recruiter-details.d.ts +21 -0
- package/bundleDist/dist/types/components/modules/list/item-expand-card/recruiter-headshot.d.ts +8 -0
- package/bundleDist/dist/types/components/modules/list/item-list.d.ts +20 -0
- package/bundleDist/dist/types/components/modules/list/list-item/list-item.d.ts +3 -0
- package/bundleDist/dist/types/constants/eventTypes.d.ts +13 -0
- package/bundleDist/dist/types/contexts/mapContext.d.ts +29 -0
- package/bundleDist/dist/types/contexts/mapListContext.d.ts +59 -0
- package/bundleDist/dist/types/contexts/trackEventContext.d.ts +6 -0
- package/bundleDist/dist/types/enums/SectionType.d.ts +9 -0
- package/bundleDist/dist/types/hooks/useList.d.ts +13 -0
- package/bundleDist/dist/types/services/configService.d.ts +6 -0
- package/bundleDist/dist/types/services/googlePlacesNearbyService.d.ts +5 -0
- package/bundleDist/dist/types/services/listingAggregatorService.d.ts +12 -0
- package/bundleDist/dist/types/services/listingEntityService.d.ts +6 -0
- package/bundleDist/dist/types/services/listingService.d.ts +9 -0
- package/bundleDist/dist/types/services/recruiterService.d.ts +6 -0
- package/bundleDist/dist/types/types/Address.d.ts +7 -0
- package/bundleDist/dist/types/types/ContentSection.d.ts +8 -0
- package/bundleDist/dist/types/types/GetListingParams.d.ts +8 -0
- package/bundleDist/dist/types/types/LatLng.d.ts +4 -0
- package/bundleDist/dist/types/types/ListingEntity.d.ts +10 -0
- package/bundleDist/dist/types/types/ListingFields.d.ts +25 -0
- package/bundleDist/dist/types/types/Listings.d.ts +31 -0
- package/bundleDist/dist/types/types/Recruiter.d.ts +9 -0
- package/bundleDist/dist/types/types/SimilarListing.d.ts +24 -0
- package/bundleDist/dist/types/types/config/Colors.d.ts +8 -0
- package/bundleDist/dist/types/types/config/MapConfig.d.ts +30 -0
- package/bundleDist/dist/types/types/config/PointsOfInterestConfig.d.ts +13 -0
- package/bundleDist/dist/types/types/config/SearchConfig.d.ts +4 -0
- package/bundleDist/dist/types/util/filterUtil.d.ts +28 -0
- package/bundleDist/dist/types/util/loading.d.ts +3 -0
- package/bundleDist/dist/types/util/localStorageUtil.d.ts +3 -0
- package/bundleDist/dist/types/util/mapUtil.d.ts +15 -0
- package/bundleDist/dist/types/util/sortUtil.d.ts +1 -0
- package/bundleDist/dist/types/util/stringUtils.d.ts +1 -0
- package/bundleDist/dist/types/util/urlFilterUtil.d.ts +8 -0
- package/bundleDist/styles/index.css +3 -0
- package/dist/components/containers/accordions/filter-container.js +4 -2
- package/dist/components/containers/accordions/filter-container.js.map +1 -1
- package/dist/components/containers/accordions/filter-item-container.js +6 -1
- package/dist/components/containers/accordions/filter-item-container.js.map +1 -1
- package/dist/components/containers/accordions/map-accordion-item-container.js +4 -2
- package/dist/components/containers/accordions/map-accordion-item-container.js.map +1 -1
- package/dist/components/containers/jobListing/listing-details-container.js +2 -2
- package/dist/components/containers/jobListing/listing-details-container.js.map +1 -1
- package/dist/components/containers/list/item-list-container.js +2 -2
- package/dist/components/containers/list/item-list-container.js.map +1 -1
- package/dist/components/modules/accordions/MapAccordionItem.js +2 -1
- package/dist/components/modules/accordions/MapAccordionItem.js.map +1 -1
- package/dist/components/modules/dialogs/apply-dialog.js +1 -1
- package/dist/components/modules/dialogs/apply-dialog.js.map +1 -1
- package/dist/components/modules/filter/search.js +1 -1
- package/dist/components/modules/filter/search.js.map +1 -1
- package/dist/components/modules/jobListing/listing-details.js +5 -4
- package/dist/components/modules/jobListing/listing-details.js.map +1 -1
- package/dist/components/modules/list/field-mapper.js +1 -1
- package/dist/components/modules/list/field-mapper.js.map +1 -1
- package/dist/components/modules/list/item-list.js.map +1 -1
- package/dist/contexts/mapListContext.js.map +1 -1
- package/dist/services/listingAggregatorService.js.map +1 -1
- package/dist/styles/index.css +3 -1
- package/dist/types/components/containers/jobListing/listing-details-container.d.ts +2 -2
- package/dist/types/components/modules/accordions/MapAccordionItem.d.ts +2 -1
- package/dist/types/components/modules/jobListing/listing-details.d.ts +2 -2
- package/dist/types/components/modules/list/item-list.d.ts +0 -1
- package/dist/types/types/ListingFields.d.ts +5 -0
- package/dist/types/types/config/MapConfig.d.ts +1 -0
- package/dist/util/filterUtil.js +2 -2
- package/dist/util/filterUtil.js.map +1 -1
- package/package.json +1 -1
- package/postcss.config.js +5 -4
- package/rollup.config.mjs +1 -1
- package/src/components/containers/accordions/filter-container.js +2 -1
- package/src/components/containers/accordions/filter-item-container.js +66 -62
- package/src/components/containers/accordions/map-accordion-item-container.js +70 -70
- package/src/components/containers/jobListing/listing-details-container.js +2 -2
- package/src/components/containers/list/item-list-container.tsx +2 -3
- package/src/components/modules/accordions/MapAccordionItem.js +30 -29
- package/src/components/modules/dialogs/apply-dialog.js +48 -48
- package/src/components/modules/filter/search.js +1 -1
- package/src/components/modules/jobListing/listing-details.js +5 -5
- package/src/components/modules/list/field-mapper.js +1 -1
- package/src/components/modules/list/item-list.tsx +0 -1
- package/src/contexts/mapListContext.tsx +311 -311
- package/src/services/listingAggregatorService.ts +76 -76
- package/src/styles/index.css +14 -115
- package/src/types/ListingFields.ts +5 -0
- package/src/types/config/MapConfig.ts +1 -0
- package/src/util/filterUtil.js +239 -239
- package/stats.html +1 -1
- package/tailwind.config.js +4 -4
- package/bundle.js.map +0 -1
- package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +0 -12
- package/dist/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/styles/index.css +0 -1
package/src/util/filterUtil.js
CHANGED
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
import { getDistinctItemsByProximity } from '~/util/mapUtil';
|
|
2
|
-
|
|
3
|
-
import Fuse from 'fuse.js';
|
|
4
|
-
|
|
5
|
-
export const getFilterOptions = (listings, filteredListings, field, excludeZeroCount = null) => {
|
|
6
|
-
const options = new Set();
|
|
7
|
-
listings.forEach(listing => {
|
|
8
|
-
if (listing.fields[field]) {
|
|
9
|
-
options.add(listing.fields[field]);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const optionCounts = {};
|
|
14
|
-
options.forEach(option => {
|
|
15
|
-
optionCounts[option] = 0;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
filteredListings.forEach(listing => {
|
|
19
|
-
const value = listing.fields[field];
|
|
20
|
-
if (value && optionCounts.hasOwnProperty(value)) {
|
|
21
|
-
optionCounts[value] += 1;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return Array.from(options)
|
|
26
|
-
.sort()
|
|
27
|
-
.map(option => ({
|
|
28
|
-
name: option,
|
|
29
|
-
count: optionCounts[option] || 0
|
|
30
|
-
}))
|
|
31
|
-
.filter(option => !(excludeZeroCount === true && option.count === 0));
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const getSpecialFeatureOptions = (listings, filteredListings, siteConfig, favorites) => {
|
|
35
|
-
const specialFeatures = siteConfig.specialFeatures;
|
|
36
|
-
const featureCounts = Object.keys(specialFeatures).sort().reduce((acc, key) => {
|
|
37
|
-
acc[specialFeatures[key]] = 0;
|
|
38
|
-
return acc;
|
|
39
|
-
}, {});
|
|
40
|
-
|
|
41
|
-
filteredListings.forEach(listing => {
|
|
42
|
-
Object.entries(specialFeatures).forEach(([featureKey, featureName]) => {
|
|
43
|
-
if (listing.fields[featureKey]
|
|
44
|
-
featureCounts[featureName] += 1;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const specialFeatureOptions = Object.entries(featureCounts).map(([name, count]) => ({
|
|
50
|
-
name,
|
|
51
|
-
count
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
for (let option of specialFeatureOptions) {
|
|
55
|
-
if (option.name === 'Favorite') {
|
|
56
|
-
option.count = filteredListings.filter(x => favorites.includes(x.id)).length;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return specialFeatureOptions;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const getPointsOfInterestOptions = pointsOfInterestNames => {
|
|
64
|
-
return Object.entries(pointsOfInterestNames).sort().map(([key, name]) => ({
|
|
65
|
-
key,
|
|
66
|
-
name
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const generateFilterOptions = (
|
|
71
|
-
filteredListings,
|
|
72
|
-
allListings,
|
|
73
|
-
siteConfig,
|
|
74
|
-
filterOptions,
|
|
75
|
-
parentField,
|
|
76
|
-
favorites
|
|
77
|
-
) => {
|
|
78
|
-
if (allListings.length > 0) {
|
|
79
|
-
const dynamicFilters = siteConfig.fieldFiltersShown.map(fieldName => {
|
|
80
|
-
if (fieldName === parentField && filterOptions?.filters) {
|
|
81
|
-
return filterOptions.filters.find(filter => filter.id === fieldName);
|
|
82
|
-
}
|
|
83
|
-
if (fieldName == "specialFeatures") {
|
|
84
|
-
return {
|
|
85
|
-
id: fieldName,
|
|
86
|
-
title: siteConfig.fieldNames[fieldName],
|
|
87
|
-
items: getSpecialFeatureOptions(allListings, filteredListings, siteConfig, favorites).sort()
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
id: fieldName,
|
|
92
|
-
title: siteConfig.fieldNames[fieldName],
|
|
93
|
-
items: getFilterOptions(allListings, filteredListings, fieldName)
|
|
94
|
-
};
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const locations =
|
|
98
|
-
siteConfig.locationFiltersShown.map((fieldName, index) => {
|
|
99
|
-
if (index === 0 && filterOptions?.locations) {
|
|
100
|
-
return filterOptions.locations.find(filter => filter.id === fieldName);
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
id: fieldName,
|
|
104
|
-
title: siteConfig.fieldNames[fieldName],
|
|
105
|
-
items: getFilterOptions(allListings, filteredListings, fieldName, true)
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const pointsOfInterest = {
|
|
110
|
-
id: "pointsOfInterest",
|
|
111
|
-
title: siteConfig.pointsOfInterestConfig.title,
|
|
112
|
-
items: getPointsOfInterestOptions(
|
|
113
|
-
siteConfig.pointsOfInterestConfig.pointsOfInterestNames
|
|
114
|
-
)
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
filters: dynamicFilters,
|
|
119
|
-
locations: locations,
|
|
120
|
-
pointsOfInterest: pointsOfInterest
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return null;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const applyFilters = (
|
|
128
|
-
allListings,
|
|
129
|
-
selectedFilters,
|
|
130
|
-
query,
|
|
131
|
-
listingEntities,
|
|
132
|
-
favorites,
|
|
133
|
-
siteConfig
|
|
134
|
-
) => {
|
|
135
|
-
let results = allListings;
|
|
136
|
-
let invertedSpecialFeaturesMap;
|
|
137
|
-
if (siteConfig.specialFeatures) {
|
|
138
|
-
invertedSpecialFeaturesMap = Object.entries(siteConfig.specialFeatures).reduce((acc, [key, value]) => {
|
|
139
|
-
acc[value] = key;
|
|
140
|
-
return acc;
|
|
141
|
-
}, {});
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
const hasFavorite = !!selectedFilters.specialFeatures && !!selectedFilters.specialFeatures.Favorite;
|
|
145
|
-
|
|
146
|
-
if (hasFavorite && selectedFilters.specialFeatures.Favorite == true) {
|
|
147
|
-
results = results.filter(x => favorites.includes(x.id));
|
|
148
|
-
}
|
|
149
|
-
var favorite;
|
|
150
|
-
if (hasFavorite) {
|
|
151
|
-
favorite = selectedFilters.specialFeatures.Favorite;
|
|
152
|
-
delete selectedFilters.specialFeatures.Favorite;
|
|
153
|
-
}
|
|
154
|
-
for (const [field, filterItems] of Object.entries(selectedFilters)) {
|
|
155
|
-
const formattedField = field;
|
|
156
|
-
if (field === "pointsOfInterest") continue;
|
|
157
|
-
if (field === "specialFeatures" && invertedSpecialFeaturesMap && Object.keys(filterItems).length > 0) {
|
|
158
|
-
results = results.filter(listing => {
|
|
159
|
-
return Object.entries(filterItems).some(([filterName, filterValue]) => {
|
|
160
|
-
const listingFieldName = invertedSpecialFeaturesMap[filterName];
|
|
161
|
-
return filterValue && listing.fields[listingFieldName]
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
} else if (Object.keys(filterItems).length > 0) {
|
|
165
|
-
results = results.filter(listing =>
|
|
166
|
-
filterItems.hasOwnProperty(listing.fields[formattedField])
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (query) {
|
|
171
|
-
results = searchResults(results, query);
|
|
172
|
-
}
|
|
173
|
-
const distinctItems = getDistinctItemsByProximity(results, listingEntities);
|
|
174
|
-
if (hasFavorite) {
|
|
175
|
-
selectedFilters.specialFeatures.Favorite = favorite;
|
|
176
|
-
}
|
|
177
|
-
return { filteredListings: results, mapItems: distinctItems };
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
function searchResults(results, query) {
|
|
181
|
-
const fields = [
|
|
182
|
-
'id',
|
|
183
|
-
'fields.posted',
|
|
184
|
-
'fields.subtitle',
|
|
185
|
-
'fields.education',
|
|
186
|
-
'fields.position',
|
|
187
|
-
'fields.category',
|
|
188
|
-
'fields.categoryclass',
|
|
189
|
-
'fields.shift',
|
|
190
|
-
'fields.citystate',
|
|
191
|
-
'fields.city',
|
|
192
|
-
'fields.state',
|
|
193
|
-
'fields.schedule',
|
|
194
|
-
'fields.customflag1',
|
|
195
|
-
'fields.bonus',
|
|
196
|
-
'fields.remote',
|
|
197
|
-
'fields.useclientjoburl',
|
|
198
|
-
'fields.datecreated',
|
|
199
|
-
'fields.datelastedited'
|
|
200
|
-
];
|
|
201
|
-
|
|
202
|
-
const options = {
|
|
203
|
-
includeScore: true,
|
|
204
|
-
threshold: 0.3,
|
|
205
|
-
keys: fields
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const fuse = new Fuse(results, options);
|
|
209
|
-
const lowerCaseQuery = query.toLowerCase();
|
|
210
|
-
const queryTerms = lowerCaseQuery.split(' ');
|
|
211
|
-
|
|
212
|
-
const exactIdMatch = results.find(result => result.id.toString() === query);
|
|
213
|
-
if (exactIdMatch) {
|
|
214
|
-
return [exactIdMatch];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const fuseQuery = queryTerms.map(term => ({
|
|
218
|
-
$or: fields.map(field => ({ [field]: term }))
|
|
219
|
-
}));
|
|
220
|
-
|
|
221
|
-
const fuseResults = fuse.search({ $and: fuseQuery });
|
|
222
|
-
|
|
223
|
-
return fuseResults.map(result => result.item);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export const filterListingsByLocation = (
|
|
227
|
-
allListings,
|
|
228
|
-
selectedLocation,
|
|
229
|
-
listingEntities
|
|
230
|
-
) => {
|
|
231
|
-
let results = allListings;
|
|
232
|
-
if (selectedLocation !== null) {
|
|
233
|
-
results = results.filter(item =>
|
|
234
|
-
selectedLocation.items.hasOwnProperty(item.id)
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
const mapItems = getDistinctItemsByProximity(results, listingEntities);
|
|
238
|
-
return { filteredListings: results, mapItems: mapItems };
|
|
239
|
-
};
|
|
1
|
+
import { getDistinctItemsByProximity } from '~/util/mapUtil';
|
|
2
|
+
|
|
3
|
+
import Fuse from 'fuse.js';
|
|
4
|
+
|
|
5
|
+
export const getFilterOptions = (listings, filteredListings, field, excludeZeroCount = null) => {
|
|
6
|
+
const options = new Set();
|
|
7
|
+
listings.forEach(listing => {
|
|
8
|
+
if (listing.fields[field]) {
|
|
9
|
+
options.add(listing.fields[field]);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const optionCounts = {};
|
|
14
|
+
options.forEach(option => {
|
|
15
|
+
optionCounts[option] = 0;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
filteredListings.forEach(listing => {
|
|
19
|
+
const value = listing.fields[field];
|
|
20
|
+
if (value && optionCounts.hasOwnProperty(value)) {
|
|
21
|
+
optionCounts[value] += 1;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return Array.from(options)
|
|
26
|
+
.sort()
|
|
27
|
+
.map(option => ({
|
|
28
|
+
name: option,
|
|
29
|
+
count: optionCounts[option] || 0
|
|
30
|
+
}))
|
|
31
|
+
.filter(option => !(excludeZeroCount === true && option.count === 0));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const getSpecialFeatureOptions = (listings, filteredListings, siteConfig, favorites) => {
|
|
35
|
+
const specialFeatures = siteConfig.specialFeatures;
|
|
36
|
+
const featureCounts = Object.keys(specialFeatures).sort().reduce((acc, key) => {
|
|
37
|
+
acc[specialFeatures[key]] = 0;
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
|
|
41
|
+
filteredListings.forEach(listing => {
|
|
42
|
+
Object.entries(specialFeatures).forEach(([featureKey, featureName]) => {
|
|
43
|
+
if (listing.fields[featureKey] == 1) {
|
|
44
|
+
featureCounts[featureName] += 1;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const specialFeatureOptions = Object.entries(featureCounts).map(([name, count]) => ({
|
|
50
|
+
name,
|
|
51
|
+
count
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
for (let option of specialFeatureOptions) {
|
|
55
|
+
if (option.name === 'Favorite') {
|
|
56
|
+
option.count = filteredListings.filter(x => favorites.includes(x.id)).length;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return specialFeatureOptions;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getPointsOfInterestOptions = pointsOfInterestNames => {
|
|
64
|
+
return Object.entries(pointsOfInterestNames).sort().map(([key, name]) => ({
|
|
65
|
+
key,
|
|
66
|
+
name
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const generateFilterOptions = (
|
|
71
|
+
filteredListings,
|
|
72
|
+
allListings,
|
|
73
|
+
siteConfig,
|
|
74
|
+
filterOptions,
|
|
75
|
+
parentField,
|
|
76
|
+
favorites
|
|
77
|
+
) => {
|
|
78
|
+
if (allListings.length > 0) {
|
|
79
|
+
const dynamicFilters = siteConfig.fieldFiltersShown.map(fieldName => {
|
|
80
|
+
if (fieldName === parentField && filterOptions?.filters) {
|
|
81
|
+
return filterOptions.filters.find(filter => filter.id === fieldName);
|
|
82
|
+
}
|
|
83
|
+
if (fieldName == "specialFeatures") {
|
|
84
|
+
return {
|
|
85
|
+
id: fieldName,
|
|
86
|
+
title: siteConfig.fieldNames[fieldName],
|
|
87
|
+
items: getSpecialFeatureOptions(allListings, filteredListings, siteConfig, favorites).sort()
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
id: fieldName,
|
|
92
|
+
title: siteConfig.fieldNames[fieldName],
|
|
93
|
+
items: getFilterOptions(allListings, filteredListings, fieldName)
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const locations =
|
|
98
|
+
siteConfig.locationFiltersShown.map((fieldName, index) => {
|
|
99
|
+
if (index === 0 && filterOptions?.locations) {
|
|
100
|
+
return filterOptions.locations.find(filter => filter.id === fieldName);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
id: fieldName,
|
|
104
|
+
title: siteConfig.fieldNames[fieldName],
|
|
105
|
+
items: getFilterOptions(allListings, filteredListings, fieldName, true)
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const pointsOfInterest = {
|
|
110
|
+
id: "pointsOfInterest",
|
|
111
|
+
title: siteConfig.pointsOfInterestConfig.title,
|
|
112
|
+
items: getPointsOfInterestOptions(
|
|
113
|
+
siteConfig.pointsOfInterestConfig.pointsOfInterestNames
|
|
114
|
+
)
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
filters: dynamicFilters,
|
|
119
|
+
locations: locations,
|
|
120
|
+
pointsOfInterest: pointsOfInterest
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const applyFilters = (
|
|
128
|
+
allListings,
|
|
129
|
+
selectedFilters,
|
|
130
|
+
query,
|
|
131
|
+
listingEntities,
|
|
132
|
+
favorites,
|
|
133
|
+
siteConfig
|
|
134
|
+
) => {
|
|
135
|
+
let results = allListings;
|
|
136
|
+
let invertedSpecialFeaturesMap;
|
|
137
|
+
if (siteConfig.specialFeatures) {
|
|
138
|
+
invertedSpecialFeaturesMap = Object.entries(siteConfig.specialFeatures).reduce((acc, [key, value]) => {
|
|
139
|
+
acc[value] = key;
|
|
140
|
+
return acc;
|
|
141
|
+
}, {});
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
const hasFavorite = !!selectedFilters.specialFeatures && !!selectedFilters.specialFeatures.Favorite;
|
|
145
|
+
|
|
146
|
+
if (hasFavorite && selectedFilters.specialFeatures.Favorite == true) {
|
|
147
|
+
results = results.filter(x => favorites.includes(x.id));
|
|
148
|
+
}
|
|
149
|
+
var favorite;
|
|
150
|
+
if (hasFavorite) {
|
|
151
|
+
favorite = selectedFilters.specialFeatures.Favorite;
|
|
152
|
+
delete selectedFilters.specialFeatures.Favorite;
|
|
153
|
+
}
|
|
154
|
+
for (const [field, filterItems] of Object.entries(selectedFilters)) {
|
|
155
|
+
const formattedField = field;
|
|
156
|
+
if (field === "pointsOfInterest") continue;
|
|
157
|
+
if (field === "specialFeatures" && invertedSpecialFeaturesMap && Object.keys(filterItems).length > 0) {
|
|
158
|
+
results = results.filter(listing => {
|
|
159
|
+
return Object.entries(filterItems).some(([filterName, filterValue]) => {
|
|
160
|
+
const listingFieldName = invertedSpecialFeaturesMap[filterName];
|
|
161
|
+
return filterValue && listing.fields[listingFieldName] == 1;
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
} else if (Object.keys(filterItems).length > 0) {
|
|
165
|
+
results = results.filter(listing =>
|
|
166
|
+
filterItems.hasOwnProperty(listing.fields[formattedField])
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (query) {
|
|
171
|
+
results = searchResults(results, query);
|
|
172
|
+
}
|
|
173
|
+
const distinctItems = getDistinctItemsByProximity(results, listingEntities);
|
|
174
|
+
if (hasFavorite) {
|
|
175
|
+
selectedFilters.specialFeatures.Favorite = favorite;
|
|
176
|
+
}
|
|
177
|
+
return { filteredListings: results, mapItems: distinctItems };
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
function searchResults(results, query) {
|
|
181
|
+
const fields = [
|
|
182
|
+
'id',
|
|
183
|
+
'fields.posted',
|
|
184
|
+
'fields.subtitle',
|
|
185
|
+
'fields.education',
|
|
186
|
+
'fields.position',
|
|
187
|
+
'fields.category',
|
|
188
|
+
'fields.categoryclass',
|
|
189
|
+
'fields.shift',
|
|
190
|
+
'fields.citystate',
|
|
191
|
+
'fields.city',
|
|
192
|
+
'fields.state',
|
|
193
|
+
'fields.schedule',
|
|
194
|
+
'fields.customflag1',
|
|
195
|
+
'fields.bonus',
|
|
196
|
+
'fields.remote',
|
|
197
|
+
'fields.useclientjoburl',
|
|
198
|
+
'fields.datecreated',
|
|
199
|
+
'fields.datelastedited'
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
const options = {
|
|
203
|
+
includeScore: true,
|
|
204
|
+
threshold: 0.3,
|
|
205
|
+
keys: fields
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const fuse = new Fuse(results, options);
|
|
209
|
+
const lowerCaseQuery = query.toLowerCase();
|
|
210
|
+
const queryTerms = lowerCaseQuery.split(' ');
|
|
211
|
+
|
|
212
|
+
const exactIdMatch = results.find(result => result.id.toString() === query);
|
|
213
|
+
if (exactIdMatch) {
|
|
214
|
+
return [exactIdMatch];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const fuseQuery = queryTerms.map(term => ({
|
|
218
|
+
$or: fields.map(field => ({ [field]: term }))
|
|
219
|
+
}));
|
|
220
|
+
|
|
221
|
+
const fuseResults = fuse.search({ $and: fuseQuery });
|
|
222
|
+
|
|
223
|
+
return fuseResults.map(result => result.item);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const filterListingsByLocation = (
|
|
227
|
+
allListings,
|
|
228
|
+
selectedLocation,
|
|
229
|
+
listingEntities
|
|
230
|
+
) => {
|
|
231
|
+
let results = allListings;
|
|
232
|
+
if (selectedLocation !== null) {
|
|
233
|
+
results = results.filter(item =>
|
|
234
|
+
selectedLocation.items.hasOwnProperty(item.id)
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
const mapItems = getDistinctItemsByProximity(results, listingEntities);
|
|
238
|
+
return { filteredListings: results, mapItems: mapItems };
|
|
239
|
+
};
|