sr-npm 1.7.705 → 1.7.707

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.
@@ -18,6 +18,11 @@ const CAREERS_MULTI_BOXES_PAGE_CONSTS={
18
18
  paginationTotalCountText: '#paginationTotalCount',
19
19
  }
20
20
 
21
+ const fieldTitlesInCMS={
22
+ "brand": "Brands",
23
+ category: "Category",
24
+ }
25
+
21
26
  const FiltersIds={
22
27
  Category: 'Category',
23
28
  "Company Segment": 'CompanySegment',
@@ -32,4 +37,5 @@ const FiltersIds={
32
37
  module.exports = {
33
38
  CAREERS_MULTI_BOXES_PAGE_CONSTS,
34
39
  FiltersIds,
40
+ fieldTitlesInCMS
35
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.705",
3
+ "version": "1.7.707",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
2
- const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds} = require('../backend/careersMultiBoxesPageIds');
2
+ const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS} = require('../backend/careersMultiBoxesPageIds');
3
3
  const { query,queryParams,onChange} = require("wix-location-frontend");
4
- const { groupValuesByField, debounce, getAllRecords } = require('./pagesUtils');
4
+ const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle } = require('./pagesUtils');
5
5
 
6
6
  let dontUpdateThisCheckBox;
7
7
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
@@ -37,8 +37,25 @@ async function handleUrlParams(_$w,urlParams) {
37
37
  console.log("brandValue: ", brandValue);
38
38
  console.log("selectedByField: ", selectedByField);
39
39
  console.log("optionsByFieldId: ", optionsByFieldId);
40
- //await updateJobsAndNumbersAndFilters(_$w);
40
+ console.log("allfields: ", allfields);
41
+ const field=getFieldByTitle(fieldTitlesInCMS.brand,allfields);
42
+ console.log("field: ", field);
43
+ const options=optionsByFieldId.get(field._id);
44
+ console.log("all the options: are ", options);
45
+ const option=options.find(option=>option.label===brandValue);
46
+ console.log("the correctoption: ", option);
47
+ if(option) {
48
+ console.log("setting the value of the checkbox to: ", option.value);
49
+
50
+ _$w(`#${FiltersIds[field.title]}CheckBox`).value = [option.value];
51
+ selectedByField.set(field._id, [option.value]);
52
+ await updateJobsAndNumbersAndFilters(_$w);
53
+ }
54
+ else {
55
+ console.warn("brand value not found in dropdown options");
56
+ }
41
57
 
58
+
42
59
  }
43
60
  }
44
61
 
@@ -80,13 +97,14 @@ async function loadSelectedValuesRepeater(_$w) {
80
97
  selectedByField.delete(fieldId);
81
98
  }
82
99
 
83
- for(const field of allfields) {
84
- if(field._id===fieldId) {
85
- const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
86
- const nextVals = currentVals.filter(v => v !== valueId);
87
- _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
88
- }
89
- }
100
+ const field=getFieldById(fieldId,allfields);
101
+
102
+
103
+ const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
104
+ const nextVals = currentVals.filter(v => v !== valueId);
105
+ _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
106
+
107
+
90
108
  await updateJobsAndNumbersAndFilters(_$w);
91
109
  });
92
110
  });
@@ -146,47 +164,46 @@ async function loadJobsRepeater(_$w) {
146
164
  counter[city.city]=city.count
147
165
  }
148
166
  for(const [key, value] of valuesByFieldId) {
149
- for(const field of allfields) {
150
- if(field._id===key) {
151
- let originalOptions=[];
152
- if(key==="Location") {
153
- originalOptions=value.map(city=>({
154
- label: city.city,
155
- value: city._id
156
- }));
157
- }
158
- else{
159
- originalOptions=value
160
- }
167
+ const field=getFieldById(key,allfields);
168
+ let originalOptions=[];
169
+ if(key==="Location") {
170
+ originalOptions=value.map(city=>({
171
+ label: city.city,
172
+ value: city._id
173
+ }));
174
+ }
175
+ else{
176
+ originalOptions=value
177
+ }
161
178
 
162
- optionsByFieldId.set(key, originalOptions);
163
- for (const val of allvaluesobjects) {
164
- counter[val.title]=val.totalJobs
165
- }
179
+ optionsByFieldId.set(key, originalOptions);
180
+ for (const val of allvaluesobjects) {
181
+ counter[val.title]=val.totalJobs
182
+ }
166
183
 
167
- countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
168
- updateOptionsUI(_$w,field.title, field._id, ''); // no search query
169
- _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
170
- _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
171
- dontUpdateThisCheckBox=field._id;
172
- const selected = ev.target.value; // array of selected value IDs
173
- if (selected && selected.length) {
174
- selectedByField.set(field._id, selected);
175
- } else {
176
- selectedByField.delete(field._id);
177
- }
178
- await updateJobsAndNumbersAndFilters(_$w);
179
-
180
- });
184
+ countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
185
+ updateOptionsUI(_$w,field.title, field._id, ''); // no search query
186
+ _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
187
+ _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
188
+ dontUpdateThisCheckBox=field._id;
189
+ const selected = ev.target.value; // array of selected value IDs
190
+ if (selected && selected.length) {
191
+ selectedByField.set(field._id, selected);
192
+ } else {
193
+ selectedByField.delete(field._id);
194
+ }
195
+ await updateJobsAndNumbersAndFilters(_$w);
196
+
197
+ });
181
198
 
182
- const runFilter = debounce(() => {
183
- const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
184
- updateOptionsUI(_$w, field.title, field._id, query);
185
- }, 150);
199
+ const runFilter = debounce(() => {
200
+ const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
201
+ updateOptionsUI(_$w, field.title, field._id, query);
202
+ }, 150);
186
203
 
187
- _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
188
- }
189
- }
204
+ _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
205
+
206
+
190
207
  }
191
208
  await refreshFacetCounts(_$w);
192
209
 
@@ -195,6 +212,8 @@ async function loadJobsRepeater(_$w) {
195
212
  }
196
213
  }
197
214
 
215
+
216
+
198
217
  async function updateJobsAndNumbersAndFilters(_$w) {
199
218
  await applyJobFilters(_$w); // re-query jobs
200
219
  await refreshFacetCounts(_$w); // recompute and update counts in all lists
@@ -37,8 +37,18 @@ function groupValuesByField(values, refKey) {
37
37
  return items;
38
38
  }
39
39
 
40
+ function getFieldById(fieldId,allFields) {
41
+ return allFields.find(field=>field._id===fieldId);
42
+ }
43
+
44
+ function getFieldByTitle(title,allFields) {
45
+ return allFields.find(field=>field.title===title);
46
+ }
47
+
40
48
  module.exports = {
41
49
  groupValuesByField,
42
50
  debounce,
43
51
  getAllRecords,
52
+ getFieldById,
53
+ getFieldByTitle,
44
54
  }