@abcagency/hc-ui-components 1.3.52 → 1.3.54

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.
@@ -1,280 +1,310 @@
1
- /* eslint-disable no-undef */
2
- import { getDistinctItemsByProximity } from '~/util/mapUtil';
3
-
4
- import Fuse from 'fuse.js';
5
-
6
- export const getFilterOptions = (listings, filteredListings, field, excludeZeroCount = null) => {
7
- const options = new Set();
8
- listings.forEach(listing => {
9
- if (listing.fields[field]) {
10
- options.add(listing.fields[field]);
11
- }
12
- });
13
-
14
- const optionCounts = {};
15
- options.forEach(option => {
16
- optionCounts[option] = 0;
17
- });
18
-
19
- filteredListings.forEach(listing => {
20
- const value = listing.fields[field];
21
- if (value && optionCounts.hasOwnProperty(value)) {
22
- optionCounts[value] += 1;
23
- }
24
- });
25
-
26
- return Array.from(options)
27
- .sort()
28
- .map(option => ({
29
- name: option,
30
- count: optionCounts[option] || 0
31
- }))
32
- .filter(option => !(excludeZeroCount === true && option.count === 0));
33
- };
34
-
35
- export const getSpecialFeatureOptions = (listings, filteredListings, siteConfig, favorites) => {
36
- const specialFeatures = siteConfig.specialFeatures;
37
- const featureCounts = Object.keys(specialFeatures).sort().reduce((acc, key) => {
38
- acc[specialFeatures[key]] = 0;
39
- return acc;
40
- }, {});
41
-
42
- filteredListings.forEach(listing => {
43
- Object.entries(specialFeatures).forEach(([featureKey, featureName]) => {
44
- if (listing.fields[featureKey] == 1) {
45
- featureCounts[featureName] += 1;
46
- }
47
- });
48
- });
49
-
50
- const specialFeatureOptions = Object.entries(featureCounts).map(([name, count]) => ({
51
- name,
52
- count
53
- }));
54
-
55
- for (let option of specialFeatureOptions) {
56
- if (option.name === 'Favorite') {
57
- option.count = filteredListings.filter(x => favorites.includes(x.id)).length;
58
- }
59
- }
60
-
61
- return specialFeatureOptions;
62
- };
63
-
64
- const getPointsOfInterestOptions = pointsOfInterestNames => {
65
- return Object.entries(pointsOfInterestNames).sort().map(([key, name]) => ({
66
- key,
67
- name
68
- }));
69
- };
70
-
71
- export const generateFilterOptions = (
72
- filteredListings,
73
- allListings,
74
- siteConfig,
75
- filterOptions,
76
- parentField,
77
- favorites,
78
- selectedFilters
79
- ) => {
80
- if (allListings.length > 0) {
81
- const dynamicFilters = siteConfig.fieldFiltersShown.map(fieldName => {
82
- if (fieldName === parentField && filterOptions?.filters) {
83
- return filterOptions.filters.find(filter => filter.id === fieldName);
84
- }
85
- if (fieldName == "specialFeatures") {
86
- return {
87
- id: fieldName,
88
- title: siteConfig.fieldNames[fieldName],
89
- items: getSpecialFeatureOptions(allListings, filteredListings, siteConfig, favorites).sort()
90
- };
91
- }
92
- return {
93
- id: fieldName,
94
- title: siteConfig.fieldNames[fieldName],
95
- items: getFilterOptions(allListings, filteredListings, fieldName)
96
- };
97
- });
98
-
99
- const locations =
100
- siteConfig.locationFiltersShown.map((fieldName, index) => {
101
- if (index === 0 && filterOptions?.locations) {
102
- return filterOptions.locations.find(filter => filter.id === fieldName);
103
- }
104
- if (fieldName === 'entityName' && filterOptions?.locations) {
105
- const cityIncluded = siteConfig.locationFiltersShown.includes('city');
106
- const stateIncluded = siteConfig.locationFiltersShown.includes('state');
107
- const cityStateIncluded = siteConfig.locationFiltersShown.includes('cityState');
108
- const uniqueCities = cityIncluded ? [...new Set(filteredListings.map(listing => listing.fields.city))] : [];
109
- const uniqueStates = stateIncluded ? [...new Set(filteredListings.map(listing => listing.fields.state))] : [];
110
- const uniqueCityStates = cityStateIncluded ? [...new Set(filteredListings.map(listing => listing.fields.cityState))] : [];
111
- const filteredByLocation = allListings.filter(listing => {
112
- const cityMatches = cityIncluded ? uniqueCities.includes(listing.fields.city) : true;
113
- const stateMatches = stateIncluded ? uniqueStates.includes(listing.fields.state) : true;
114
- const cityStateMatches = cityStateIncluded ? uniqueCityStates.includes(listing.fields.cityState) : true;
115
- return cityMatches && stateMatches && cityStateMatches;
116
- });
117
- return {
118
- id: fieldName,
119
- title: siteConfig.fieldNames[fieldName],
120
- items: getFilterOptions(allListings, filteredByLocation, fieldName, true)
121
- };
122
- }
123
- if(fieldName == 'city'){
124
- console.log(selectedFilters.state);
125
- console.log(selectedFilters);
126
- if(siteConfig.locationFiltersShown.includes('state') && selectedFilters.state){
127
- const stateMatches = [...new Set(filteredListings.map(listing => listing.fields.state))];
128
- const filteredByLocation = allListings.filter(listing => stateMatches.includes(listing.fields.state));
129
- return {
130
- id: fieldName,
131
- title: siteConfig.fieldNames[fieldName],
132
- items: getFilterOptions(allListings, filteredByLocation, fieldName, true)
133
- };
134
- }else{
135
- return {
136
- id: fieldName,
137
- title: siteConfig.fieldNames[fieldName],
138
- items: getFilterOptions(allListings, allListings, fieldName, true)
139
- };
140
- }
141
- }
142
-
143
- return {
144
- id: fieldName,
145
- title: siteConfig.fieldNames[fieldName],
146
- items: getFilterOptions(allListings, filteredListings, fieldName, true)
147
- };
148
- });
149
-
150
- const pointsOfInterest = {
151
- id: "pointsOfInterest",
152
- title: siteConfig.pointsOfInterestConfig.title,
153
- items: getPointsOfInterestOptions(
154
- siteConfig.pointsOfInterestConfig.pointsOfInterestNames
155
- )
156
- };
157
-
158
- return {
159
- filters: dynamicFilters,
160
- locations: locations,
161
- pointsOfInterest: pointsOfInterest
162
- };
163
- }
164
-
165
- return null;
166
- };
167
-
168
- export const applyFilters = (
169
- allListings,
170
- selectedFilters,
171
- query,
172
- listingEntities,
173
- favorites,
174
- siteConfig
175
- ) => {
176
- let results = allListings;
177
- let invertedSpecialFeaturesMap;
178
- if (siteConfig.specialFeatures) {
179
- invertedSpecialFeaturesMap = Object.entries(siteConfig.specialFeatures).reduce((acc, [key, value]) => {
180
- acc[value] = key;
181
- return acc;
182
- }, {});
183
-
184
- }
185
- const hasFavorite = !!selectedFilters.specialFeatures && !!selectedFilters.specialFeatures.Favorite;
186
-
187
- if (hasFavorite && selectedFilters.specialFeatures.Favorite == true) {
188
- results = results.filter(x => favorites.includes(x.id));
189
- }
190
- var favorite;
191
- if (hasFavorite) {
192
- favorite = selectedFilters.specialFeatures.Favorite;
193
- delete selectedFilters.specialFeatures.Favorite;
194
- }
195
- for (const [field, filterItems] of Object.entries(selectedFilters)) {
196
- const formattedField = field;
197
- if (field === "pointsOfInterest") continue;
198
- if (field === "specialFeatures" && invertedSpecialFeaturesMap && Object.keys(filterItems).length > 0) {
199
- results = results.filter(listing => {
200
- return Object.entries(filterItems).some(([filterName, filterValue]) => {
201
- const listingFieldName = invertedSpecialFeaturesMap[filterName];
202
- return filterValue && listing.fields[listingFieldName] == 1;
203
- });
204
- });
205
- } else if (Object.keys(filterItems).length > 0) {
206
- results = results.filter(listing =>
207
- filterItems.hasOwnProperty(listing.fields[formattedField])
208
- );
209
- }
210
- }
211
- if (query) {
212
- results = searchResults(results, query);
213
- }
214
- const distinctItems = getDistinctItemsByProximity(results, listingEntities);
215
- if (hasFavorite) {
216
- selectedFilters.specialFeatures.Favorite = favorite;
217
- }
218
- return { filteredListings: results, mapItems: distinctItems };
219
- };
220
-
221
- function searchResults(results, query) {
222
- const fields = [
223
- 'id',
224
- 'fields.posted',
225
- 'fields.subtitle',
226
- 'fields.education',
227
- 'fields.position',
228
- 'fields.category',
229
- 'fields.categoryclass',
230
- 'fields.shift',
231
- 'fields.citystate',
232
- 'fields.city',
233
- 'fields.state',
234
- 'fields.schedule',
235
- 'fields.customflag1',
236
- 'fields.bonus',
237
- 'fields.remote',
238
- 'fields.useclientjoburl',
239
- 'fields.datecreated',
240
- 'fields.datelastedited'
241
- ];
242
-
243
- const options = {
244
- includeScore: true,
245
- threshold: 0.3,
246
- keys: fields
247
- };
248
-
249
- const fuse = new Fuse(results, options);
250
- const lowerCaseQuery = query.toLowerCase();
251
- const queryTerms = lowerCaseQuery.split(' ');
252
-
253
- const exactIdMatch = results.find(result => result.id.toString() === query);
254
- if (exactIdMatch) {
255
- return [exactIdMatch];
256
- }
257
-
258
- const fuseQuery = queryTerms.map(term => ({
259
- $or: fields.map(field => ({ [field]: term }))
260
- }));
261
-
262
- const fuseResults = fuse.search({ $and: fuseQuery });
263
-
264
- return fuseResults.map(result => result.item);
265
- }
266
-
267
- export const filterListingsByLocation = (
268
- allListings,
269
- selectedLocation,
270
- listingEntities
271
- ) => {
272
- let results = allListings;
273
- if (selectedLocation !== null) {
274
- results = results.filter(item =>
275
- selectedLocation.items.hasOwnProperty(item.id)
276
- );
277
- }
278
- const mapItems = getDistinctItemsByProximity(results, listingEntities);
279
- return { filteredListings: results, mapItems: mapItems };
280
- };
1
+ /* eslint-disable no-undef */
2
+ import { getDistinctItemsByProximity } from '~/util/mapUtil';
3
+
4
+ import Fuse from 'fuse.js';
5
+
6
+ export const getFilterOptions = (listings, filteredListings, field, excludeZeroCount = null) => {
7
+ const options = new Set();
8
+ listings.forEach(listing => {
9
+ if (listing.fields[field]) {
10
+ options.add(listing.fields[field]);
11
+ }
12
+ });
13
+
14
+ const optionCounts = {};
15
+ options.forEach(option => {
16
+ optionCounts[option] = 0;
17
+ });
18
+
19
+ filteredListings.forEach(listing => {
20
+ const value = listing.fields[field];
21
+ if (value && optionCounts.hasOwnProperty(value)) {
22
+ optionCounts[value] += 1;
23
+ }
24
+ });
25
+
26
+ return Array.from(options)
27
+ .sort()
28
+ .map(option => ({
29
+ name: option,
30
+ count: optionCounts[option] || 0
31
+ }))
32
+ .filter(option => !(excludeZeroCount === true && option.count === 0));
33
+ };
34
+
35
+ export const getSpecialFeatureOptions = (listings, filteredListings, siteConfig, favorites) => {
36
+ const specialFeatures = siteConfig.specialFeatures;
37
+ const featureCounts = Object.keys(specialFeatures).sort().reduce((acc, key) => {
38
+ acc[specialFeatures[key]] = 0;
39
+ return acc;
40
+ }, {});
41
+
42
+ filteredListings.forEach(listing => {
43
+ Object.entries(specialFeatures).forEach(([featureKey, featureName]) => {
44
+ if (listing.fields[featureKey] == 1) {
45
+ featureCounts[featureName] += 1;
46
+ }
47
+ });
48
+ });
49
+
50
+ const specialFeatureOptions = Object.entries(featureCounts).map(([name, count]) => ({
51
+ name,
52
+ count
53
+ }));
54
+
55
+ for (let option of specialFeatureOptions) {
56
+ if (option.name === 'Favorite') {
57
+ option.count = filteredListings.filter(x => favorites.includes(x.id)).length;
58
+ }
59
+ }
60
+
61
+ return specialFeatureOptions;
62
+ };
63
+
64
+ const getPointsOfInterestOptions = pointsOfInterestNames => {
65
+ return Object.entries(pointsOfInterestNames).sort().map(([key, name]) => ({
66
+ key,
67
+ name
68
+ }));
69
+ };
70
+
71
+ export const generateFilterOptions = (
72
+ filteredListings,
73
+ allListings,
74
+ siteConfig,
75
+ filterOptions,
76
+ parentField,
77
+ favorites,
78
+ selectedFilters
79
+ ) => {
80
+ if (allListings.length > 0) {
81
+ const dynamicFilters = siteConfig.fieldFiltersShown.map(fieldName => {
82
+ if (fieldName === parentField && filterOptions?.filters) {
83
+ return filterOptions.filters.find(filter => filter.id === fieldName);
84
+ }
85
+ if(fieldName == 'categoryClass'){
86
+ return {
87
+ id: fieldName,
88
+ title: siteConfig.fieldNames[fieldName],
89
+ items: getFilterOptions(allListings, allListings, fieldName)
90
+ };
91
+ }
92
+ if(fieldName == 'category' && selectedFilters.categoryClass){
93
+ const categoryClassKeys = Object.keys(selectedFilters.categoryClass);
94
+ const filteredListings = allListings.filter(
95
+ x => categoryClassKeys.includes(x.fields?.categoryClass)
96
+ );
97
+ return {
98
+ id: fieldName,
99
+ title: siteConfig.fieldNames[fieldName],
100
+ items: getFilterOptions(allListings, filteredListings, fieldName, false)
101
+ };
102
+ }
103
+ if (fieldName == "specialFeatures") {
104
+ return {
105
+ id: fieldName,
106
+ title: siteConfig.fieldNames[fieldName],
107
+ items: getSpecialFeatureOptions(allListings, filteredListings, siteConfig, favorites).sort()
108
+ };
109
+ }
110
+ return {
111
+ id: fieldName,
112
+ title: siteConfig.fieldNames[fieldName],
113
+ items: getFilterOptions(allListings, filteredListings, fieldName)
114
+ };
115
+ });
116
+
117
+ const locations =
118
+ siteConfig.locationFiltersShown.map((fieldName, index) => {
119
+ let locationFilteredListings = allListings;
120
+ locationFilteredListings = allListings.filter(listing => {
121
+ return Object.entries(selectedFilters).every(([key, value]) => {
122
+ if (siteConfig.locationFiltersShown.includes(key)) return true;
123
+ if (value && typeof value === 'object' && value[listing.fields[key]] === true) {
124
+ return true;
125
+ }
126
+ return false;
127
+ });
128
+ });
129
+ if (index === 0) {
130
+ return {
131
+ id: fieldName,
132
+ title: siteConfig.fieldNames[fieldName],
133
+ items: getFilterOptions(allListings, locationFilteredListings, fieldName, true)
134
+ };
135
+ }
136
+ if (fieldName === 'entityName' && filterOptions?.locations) {
137
+ const cityIncluded = siteConfig.locationFiltersShown.includes('city');
138
+ const stateIncluded = siteConfig.locationFiltersShown.includes('state');
139
+ const cityStateIncluded = siteConfig.locationFiltersShown.includes('cityState');
140
+ const uniqueCities = cityIncluded ? [...new Set(filteredListings.map(listing => listing.fields.city))] : [];
141
+ const uniqueStates = stateIncluded ? [...new Set(filteredListings.map(listing => listing.fields.state))] : [];
142
+ const uniqueCityStates = cityStateIncluded ? [...new Set(filteredListings.map(listing => listing.fields.cityState))] : [];
143
+ const filteredByLocation = locationFilteredListings.filter(listing => {
144
+ const cityMatches = cityIncluded ? uniqueCities.includes(listing.fields.city) : true;
145
+ const stateMatches = stateIncluded ? uniqueStates.includes(listing.fields.state) : true;
146
+ const cityStateMatches = cityStateIncluded ? uniqueCityStates.includes(listing.fields.cityState) : true;
147
+ return cityMatches && stateMatches && cityStateMatches;
148
+ });
149
+ return {
150
+ id: fieldName,
151
+ title: siteConfig.fieldNames[fieldName],
152
+ items: getFilterOptions(allListings, filteredByLocation, fieldName, true)
153
+ };
154
+ }
155
+ if (fieldName === 'city') {
156
+ if (siteConfig.locationFiltersShown.includes('state') && selectedFilters.state) {
157
+ const selectedStates = Object.keys(selectedFilters.state).filter(
158
+ state => selectedFilters.state[state] === true
159
+ );
160
+
161
+ const filteredByLocation = locationFilteredListings.filter(listing =>
162
+ selectedStates.includes(listing.fields.state)
163
+ );
164
+
165
+ return {
166
+ id: fieldName,
167
+ title: siteConfig.fieldNames[fieldName],
168
+ items: getFilterOptions(allListings, filteredByLocation, fieldName, true)
169
+ };
170
+ }
171
+ }
172
+
173
+ return {
174
+ id: fieldName,
175
+ title: siteConfig.fieldNames[fieldName],
176
+ items: getFilterOptions(allListings, filteredListings, fieldName, true)
177
+ };
178
+ });
179
+
180
+ const pointsOfInterest = {
181
+ id: "pointsOfInterest",
182
+ title: siteConfig.pointsOfInterestConfig.title,
183
+ items: getPointsOfInterestOptions(
184
+ siteConfig.pointsOfInterestConfig.pointsOfInterestNames
185
+ )
186
+ };
187
+
188
+ return {
189
+ filters: dynamicFilters,
190
+ locations: locations,
191
+ pointsOfInterest: pointsOfInterest
192
+ };
193
+ }
194
+
195
+ return null;
196
+ };
197
+
198
+ export const applyFilters = (
199
+ allListings,
200
+ selectedFilters,
201
+ query,
202
+ listingEntities,
203
+ favorites,
204
+ siteConfig
205
+ ) => {
206
+ let results = allListings;
207
+ let invertedSpecialFeaturesMap;
208
+ if (siteConfig.specialFeatures) {
209
+ invertedSpecialFeaturesMap = Object.entries(siteConfig.specialFeatures).reduce((acc, [key, value]) => {
210
+ acc[value] = key;
211
+ return acc;
212
+ }, {});
213
+
214
+ }
215
+ const hasFavorite = !!selectedFilters.specialFeatures && !!selectedFilters.specialFeatures.Favorite;
216
+
217
+ if (hasFavorite && selectedFilters.specialFeatures.Favorite == true) {
218
+ results = results.filter(x => favorites.includes(x.id));
219
+ }
220
+ var favorite;
221
+ if (hasFavorite) {
222
+ favorite = selectedFilters.specialFeatures.Favorite;
223
+ delete selectedFilters.specialFeatures.Favorite;
224
+ }
225
+ for (const [field, filterItems] of Object.entries(selectedFilters)) {
226
+ const formattedField = field;
227
+ if (field === "pointsOfInterest") continue;
228
+ if (field === "specialFeatures" && invertedSpecialFeaturesMap && Object.keys(filterItems).length > 0) {
229
+ results = results.filter(listing => {
230
+ return Object.entries(filterItems).some(([filterName, filterValue]) => {
231
+ const listingFieldName = invertedSpecialFeaturesMap[filterName];
232
+ return filterValue && listing.fields[listingFieldName] == 1;
233
+ });
234
+ });
235
+ } else if (Object.keys(filterItems).length > 0) {
236
+ results = results.filter(listing =>
237
+ filterItems.hasOwnProperty(listing.fields[formattedField])
238
+ );
239
+ }
240
+ }
241
+ if (query) {
242
+ results = searchResults(results, query);
243
+ }
244
+ const distinctItems = getDistinctItemsByProximity(results, listingEntities);
245
+ if (hasFavorite) {
246
+ selectedFilters.specialFeatures.Favorite = favorite;
247
+ }
248
+ return { filteredListings: results, mapItems: distinctItems };
249
+ };
250
+
251
+ function searchResults(results, query) {
252
+ const fields = [
253
+ 'id',
254
+ 'fields.posted',
255
+ 'fields.subtitle',
256
+ 'fields.education',
257
+ 'fields.position',
258
+ 'fields.category',
259
+ 'fields.categoryclass',
260
+ 'fields.shift',
261
+ 'fields.citystate',
262
+ 'fields.city',
263
+ 'fields.state',
264
+ 'fields.schedule',
265
+ 'fields.customflag1',
266
+ 'fields.bonus',
267
+ 'fields.remote',
268
+ 'fields.useclientjoburl',
269
+ 'fields.datecreated',
270
+ 'fields.datelastedited'
271
+ ];
272
+
273
+ const options = {
274
+ includeScore: true,
275
+ threshold: 0.3,
276
+ keys: fields
277
+ };
278
+
279
+ const fuse = new Fuse(results, options);
280
+ const lowerCaseQuery = query.toLowerCase();
281
+ const queryTerms = lowerCaseQuery.split(' ');
282
+
283
+ const exactIdMatch = results.find(result => result.id.toString() === query);
284
+ if (exactIdMatch) {
285
+ return [exactIdMatch];
286
+ }
287
+
288
+ const fuseQuery = queryTerms.map(term => ({
289
+ $or: fields.map(field => ({ [field]: term }))
290
+ }));
291
+
292
+ const fuseResults = fuse.search({ $and: fuseQuery });
293
+
294
+ return fuseResults.map(result => result.item);
295
+ }
296
+
297
+ export const filterListingsByLocation = (
298
+ allListings,
299
+ selectedLocation,
300
+ listingEntities
301
+ ) => {
302
+ let results = allListings;
303
+ if (selectedLocation !== null) {
304
+ results = results.filter(item =>
305
+ selectedLocation.items.hasOwnProperty(item.id)
306
+ );
307
+ }
308
+ const mapItems = getDistinctItemsByProximity(results, listingEntities);
309
+ return { filteredListings: results, mapItems: mapItems };
310
+ };