sr-npm 1.2.17 → 1.2.19

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.
@@ -5,7 +5,7 @@ on:
5
5
  branches:
6
6
  - main
7
7
  workflow_dispatch:
8
-
8
+
9
9
  permissions:
10
10
  contents: write
11
11
  packages: write
@@ -39,6 +39,11 @@ const fieldTitlesInCMS={
39
39
  "brand": "Brands",
40
40
  category: "Category",
41
41
  visibility: "Visibility",
42
+ location: "Location",
43
+ employmenttype: "Employment Type",
44
+ contracttype: "Contract Type",
45
+ companysegment: "Company Segment",
46
+ storename: "Store Name",
42
47
  }
43
48
 
44
49
  const FiltersIds={
@@ -52,10 +57,21 @@ const FiltersIds={
52
57
  Visibility: 'Visibility',
53
58
  }
54
59
 
60
+ const possibleUrlParams=[
61
+ "brand",
62
+ "location",
63
+ "employmenttype",
64
+ "contracttype",
65
+ "visibility",
66
+ "category",
67
+ "companysegment",
68
+ "storename",
69
+ ]
55
70
 
56
71
  module.exports = {
57
72
  CAREERS_MULTI_BOXES_PAGE_CONSTS,
58
73
  FiltersIds,
59
74
  fieldTitlesInCMS,
60
75
  CATEGORY_CUSTOM_FIELD_ID_IN_CMS,
76
+ possibleUrlParams,
61
77
  }
@@ -31,6 +31,7 @@ const JOBS_COLLECTION_FIELDS = {
31
31
  MULTI_REF_JOBS_CUSTOM_VALUES: 'multiRefJobsCustomValues',
32
32
  EMPLOYMENT_TYPE: 'employmentType',
33
33
  RELEASED_DATE: 'releasedDate',
34
+ REF_ID: 'refId',
34
35
  }
35
36
  const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
36
37
  TITLE: 'title',
@@ -93,6 +94,7 @@ const COLLECTIONS_FIELDS = {
93
94
  {key: 'image', type: 'IMAGE' },
94
95
  {key:'employmentType', type: 'TEXT'},
95
96
  {key:'releasedDate', type: 'TEXT'},
97
+ {key:'refId', type: 'TEXT'},
96
98
  ],
97
99
  TEMPLATE_TYPE: [
98
100
  {key:'templateType', type: 'TEXT'},
package/backend/consts.js CHANGED
@@ -72,9 +72,6 @@ const TASKS = {
72
72
  }
73
73
  }
74
74
 
75
-
76
-
77
-
78
75
  const TASK_TYPE = {
79
76
  SCHEDULED: 'scheduled',
80
77
  EVENT: 'event',
@@ -92,10 +89,6 @@ const supportTeamsPageIds={
92
89
  VIDEO_TITLE: "#videoTitle",
93
90
  VIDEO_PLAYER: "#videoPlayer",
94
91
 
95
-
96
-
97
-
98
-
99
92
  RECENTLEY_ADDED_JOBS_ITEM: "#recentleyAddedJobsItem",
100
93
  JOB_LOCATION: "#jobLocation",
101
94
  JOB_TITLE: "#jobTitle",
@@ -137,12 +130,13 @@ const supportTeamsPageSections={
137
130
  VIDEO: "video",
138
131
  }
139
132
 
140
- module.exports = {
141
- TASKS_NAMES,
142
- TASK_TYPE,
143
- TASKS,
144
- QUERY_MAX_LIMIT,
145
- supportTeamsPageIds,
146
- LINKS,
147
- supportTeamsPageSections,
133
+
134
+ module.exports = {
135
+ TASKS_NAMES,
136
+ TASK_TYPE,
137
+ TASKS,
138
+ QUERY_MAX_LIMIT,
139
+ supportTeamsPageIds,
140
+ LINKS,
141
+ supportTeamsPageSections,
148
142
  };
package/backend/data.js CHANGED
@@ -6,8 +6,6 @@ const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocatio
6
6
  const { getAllPositions } = require('./queries');
7
7
  const { retrieveSecretVal, getTokenFromCMS ,getApiKeys} = require('./secretsData');
8
8
 
9
-
10
-
11
9
  let customValuesToJobs = {}
12
10
  let locationToJobs = {}
13
11
  let siteconfig;
@@ -21,6 +19,7 @@ async function getSiteConfig() {
21
19
  const queryresult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
22
20
  siteconfig = queryresult.items[0];
23
21
  }
22
+
24
23
  function validatePosition(position) {
25
24
  if (!position.id) {
26
25
  throw new Error('Position id is required');
@@ -40,22 +39,22 @@ function validatePosition(position) {
40
39
  async function filterBasedOnBrand(positions) {
41
40
  try{
42
41
 
43
- const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
44
- validateSingleDesiredBrand(desiredBrand);
45
- console.log("filtering positions based on brand: ", desiredBrand);
46
- return positions.content.filter(position => {
47
- const brand = getBrand(position.customField);
48
- if (!brand) return false;
49
- return brand === desiredBrand;
50
- });
51
- } catch (error) {
52
- if(error.message==="[getTokenFromCMS], No desiredBrand found")
53
- {
54
- console.log("no desiredBrand found, fetching all positions")
55
- return positions.content;
42
+ const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
43
+ validateSingleDesiredBrand(desiredBrand);
44
+ console.log("filtering positions based on brand: ", desiredBrand);\
45
+ return positions.content.filter(position => {
46
+ const brand = getBrand(position.customField);
47
+ if (!brand) return false;
48
+ return brand === desiredBrand;
49
+ });
50
+ } catch (error) {
51
+ if(error.message==="[getTokenFromCMS], No desiredBrand found")
52
+ {
53
+ console.log("no desiredBrand found, fetching all positions")
54
+ return positions.content;
55
+ }
56
+ throw error;
56
57
  }
57
- throw error;
58
- }
59
58
  }
60
59
 
61
60
  function validateSingleDesiredBrand(desiredBrand) {
@@ -63,11 +62,12 @@ function validateSingleDesiredBrand(desiredBrand) {
63
62
  throw new Error("Desired brand must be a single brand");
64
63
  }
65
64
  }
66
- function getLocation(position,basicJob) {
67
65
 
66
+ function getLocation(position,basicJob) {
68
67
  locationToJobs[basicJob.cityText] ? locationToJobs[basicJob.cityText].push(position.id) : locationToJobs[basicJob.cityText]=[position.id]
69
68
 
70
69
  }
70
+
71
71
  function getVisibility(position,customFieldsValues) {
72
72
  if (!customFieldsValues["Visibility"]) {
73
73
  customFieldsValues["Visibility"] = {};
@@ -99,8 +99,8 @@ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,custom
99
99
  if (!customFieldsValues[fieldId]) {
100
100
  customFieldsValues[fieldId] = {};
101
101
  }
102
+
102
103
  customFieldsValues[fieldId][valueId] = valueLabel;
103
-
104
104
  customValuesToJobs[valueId] ? customValuesToJobs[valueId].add(position.id) : customValuesToJobs[valueId]=new Set([position.id])
105
105
  }
106
106
  }
@@ -140,7 +140,8 @@ async function saveJobsDataToCMS() {
140
140
  brand: siteconfig.disableMultiBrand==="false" ? getBrand(position.customField) : '',
141
141
  jobDescription: null, // Will be filled later
142
142
  employmentType: position.typeOfEmployment.label,
143
- releasedDate: position.releasedDate
143
+ releasedDate: position.releasedDate,
144
+ refId: position.refNumber
144
145
  };
145
146
 
146
147
  getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
@@ -485,11 +486,14 @@ async function syncJobsFast() {
485
486
  await createCollections();
486
487
  await clearCollections();
487
488
  await fillSecretManagerMirror();
489
+
488
490
  console.log("saving jobs data to CMS");
489
491
  await saveJobsDataToCMS();
490
492
  console.log("saved jobs data to CMS successfully");
493
+
491
494
  console.log("saving jobs descriptions and location apply url to CMS");
492
495
  await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
496
+
493
497
  console.log("saved jobs descriptions and location apply url to CMS successfully");
494
498
  await aggregateJobs();
495
499
  await referenceJobs();
@@ -1,8 +1,9 @@
1
1
  const { fetch } = require('wix-fetch');
2
2
  const { TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
3
3
  const { getTokenFromCMS,getApiKeys } = require('./secretsData');
4
+
4
5
  async function makeSmartRecruitersRequest(path,templateType) {
5
- const baseUrl = 'https://api.smartrecruiters.com';
6
+ const baseUrl = 'https://api.smartrecruiters.com';
6
7
  const fullUrl = `${baseUrl}${path}`;
7
8
 
8
9
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,8 @@
1
1
  const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
2
- const { queryParams} = require('wix-location-frontend');
2
+
3
+ const { queryParams,onChange} = require('wix-location-frontend');
3
4
  const { location } = require("@wix/site-location");
4
- const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS} = require('../backend/careersMultiBoxesPageIds');
5
+ const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS,possibleUrlParams} = require('../backend/careersMultiBoxesPageIds');
5
6
  const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle,getCorrectOption,getOptionIndexFromCheckBox,loadPrimarySearchRepeater,bindPrimarySearch,primarySearch } = require('./pagesUtils');
6
7
 
7
8
  let dontUpdateThisCheckBox;
@@ -22,25 +23,39 @@ const pagination = {
22
23
  currentPage: 1,
23
24
  };
24
25
  async function careersMultiBoxesPageOnReady(_$w,urlParams) {
25
- bindSearchInput(_$w);
26
- // loadPrimarySearchRepeater(_$w);
26
+ //to handle back and forth , url changes
27
+ onChange(async ()=>{
28
+ await handleBackAndForth(_$w);
29
+ });
27
30
 
28
- // await loadData(_$w);
29
-
30
- // loadJobsRepeater(_$w);
31
+ bindSearchInput(_$w);
32
+ loadPaginationButtons(_$w);
33
+ await loadData(_$w);
34
+ loadJobsRepeater(_$w);
35
+ loadPrimarySearchRepeater(_$w);
36
+ await loadFilters(_$w);
37
+ loadSelectedValuesRepeater(_$w);
38
+
39
+ if (await window.formFactor() === "Mobile") {
40
+ handleFilterInMobile(_$w);
41
+ }
42
+
43
+ await handleUrlParams(_$w, urlParams);
44
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CLEAR_ALL_BUTTON_ID).onClick(async () => {
45
+ await clearAll(_$w);
46
+ });
31
47
 
32
- // await loadFilters(_$w);
33
- // loadSelectedValuesRepeater(_$w);
48
+ }
34
49
 
35
- // loadPaginationButtons(_$w);
36
-
37
- // await handleUrlParams(_$w, urlParams);
38
- // _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CLEAR_ALL_BUTTON_ID).onClick(async () => {
39
- // await clearAll(_$w);
40
- // });
50
+ async function handleBackAndForth(_$w){
51
+ const newQueryParams=await location.query();
52
+ console.log("newQueryParams: ", newQueryParams);
53
+ await clearAll(_$w,true);
54
+ await handleUrlParams(_$w,newQueryParams);
55
+
41
56
  }
42
57
 
43
- async function clearAll(_$w) {
58
+ async function clearAll(_$w,urlOnChange=false) {
44
59
  if(selectedByField.size>0 || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value) {
45
60
  for(const field of allfields) {
46
61
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [];
@@ -51,34 +66,76 @@ async function clearAll(_$w) {
51
66
  secondarySearchIsFilled=false;
52
67
  currentJobs=alljobs;
53
68
  keywordAllJobs=undefined;
69
+ if(!urlOnChange) {
70
+ queryParams.remove(possibleUrlParams.concat(["keyword", "page"]));
71
+ }
54
72
  await updateJobsAndNumbersAndFilters(_$w,true);
55
73
  }
56
74
  }
57
75
 
76
+ function handleFilterInMobile(_$w) {
77
+ const searchResultsSelectors = [
78
+ CAREERS_PAGE_SELECTORS.RESULT_BOX,
79
+ CAREERS_PAGE_SELECTORS.PAGINATION_BTN,
80
+ CAREERS_PAGE_SELECTORS.HEAD_BTNS,
81
+ CAREERS_PAGE_SELECTORS.SELECTED_VALUES_REPEATER,
82
+ CAREERS_PAGE_SELECTORS.BUTTOM_TXT,
83
+ CAREERS_PAGE_SELECTORS.SECTION_24,
84
+ CAREERS_PAGE_SELECTORS.SECTION_3,
85
+ CAREERS_PAGE_SELECTORS.LINE_3,
86
+ CAREERS_PAGE_SELECTORS.FILTER_ICON];
87
+
88
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_ICON).onClick(()=>{
89
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_BOX).expand();
90
+ searchResultsSelectors.forEach(selector => {
91
+ _$w(selector).collapse();
92
+ });
93
+ });
94
+
95
+ const exitFilterBox = () => {
96
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_BOX).collapse();
97
+ searchResultsSelectors.forEach(selector => {
98
+ _$w(selector).expand();
99
+ });
100
+ }
101
+
102
+ _$w(CAREERS_PAGE_SELECTORS.EXIT_BUTTON).onClick(()=>{
103
+ exitFilterBox();
104
+ });
105
+
106
+ _$w(CAREERS_PAGE_SELECTORS.REFINE_SEARCH_BUTTON).onClick(()=>{
107
+ exitFilterBox();
108
+ });
109
+ }
110
+
58
111
 
59
112
  async function handleUrlParams(_$w,urlParams) {
60
113
  try {
61
114
  let applyFiltering=false;
62
-
115
+ let currentApplyFilterFlag=false;
116
+ //apply this first to determine all jobs
63
117
  if(urlParams.keyword) {
64
118
  applyFiltering=await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
65
119
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value=decodeURIComponent(urlParams.keyword);
66
120
  currentJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
67
121
  keywordAllJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
68
122
  }
69
- if(urlParams.brand) {
70
- applyFiltering=await handleParams(_$w,"brand",urlParams.brand)
71
- }
72
- if(urlParams.visibility) {
73
- applyFiltering=await handleParams(_$w,"visibility",urlParams.visibility)
74
- }
75
- if(urlParams.category) {
76
- applyFiltering=await handleParams(_$w,"category",urlParams.category)
123
+
124
+ for (const url of possibleUrlParams)
125
+ {
126
+ if(urlParams[url])
127
+ {
128
+ currentApplyFilterFlag=await handleParams(_$w,url,urlParams[url])
129
+ if(currentApplyFilterFlag) {
130
+ applyFiltering=true;
131
+ }
77
132
  }
78
-
133
+ currentApplyFilterFlag=false;
134
+ }
79
135
  if(applyFiltering || keywordAllJobs) {
80
136
  await updateJobsAndNumbersAndFilters(_$w);
81
137
  }
138
+
82
139
  if(urlParams.page) {
83
140
  if(Number.isNaN(Number(urlParams.page)) || Number(urlParams.page)<=1 || Number(urlParams.page)>Math.ceil(currentJobs.length/pagination.pageSize)) {
84
141
  console.warn("page number is invalid, removing page from url");
@@ -86,14 +143,14 @@ async function handleUrlParams(_$w,urlParams) {
86
143
  return;
87
144
  }
88
145
  pagination.currentPage=Number(urlParams.page);
89
- let paginationCurrentText=Number(urlParams.page)*pagination.pageSize
146
+ //let paginationCurrentText=urlParams.page;
90
147
  let startSlicIndex=pagination.pageSize*(pagination.currentPage-1);
91
148
  let endSlicIndex=(pagination.pageSize)*(pagination.currentPage);
92
149
  if(Number(urlParams.page)==Math.ceil(currentJobs.length/pagination.pageSize)) {
93
- paginationCurrentText=paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize));
150
+ // paginationCurrentText=(paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize))).toString();
94
151
  endSlicIndex=currentJobs.length;
95
152
  }
96
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = paginationCurrentText.toString();
153
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = urlParams.page
97
154
  const jobsFirstPage=currentJobs.slice(startSlicIndex,endSlicIndex);
98
155
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
99
156
  handlePaginationButtons(_$w);
@@ -103,31 +160,49 @@ async function handleUrlParams(_$w,urlParams) {
103
160
  }
104
161
  }
105
162
 
106
- async function handleParams(_$w,param,value) {
163
+ async function handleParams(_$w,param,values) {
107
164
  let applyFiltering=false;
165
+ let valuesAsArray = values.split(',')
166
+ valuesAsArray=valuesAsArray.filter(value=>value.trim()!=='');
167
+
168
+ let selectedIndices=[];
169
+ const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
170
+
171
+ let existing = selectedByField.get(field._id) || [];
172
+ for(const value of valuesAsArray) {
173
+
108
174
  const decodedValue = decodeURIComponent(value);
109
- const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
175
+
110
176
  const options=optionsByFieldId.get(field._id);
111
- const option=getCorrectOption(decodedValue,options);
177
+
178
+ const option=getCorrectOption(decodedValue,options,param);
179
+
112
180
  if(option) {
113
181
  const optionIndex=getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
114
- _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [optionIndex];
115
- selectedByField.set(field._id, [option.value]);
182
+ selectedIndices.push(optionIndex);
183
+ existing.push(option.value);
116
184
  applyFiltering=true;
117
185
  dontUpdateThisCheckBox=field._id;
118
186
  }
119
187
  else {
120
188
  console.warn(`${param} value not found in dropdown options`);
121
189
  }
122
- return applyFiltering;
190
+ }
191
+
192
+ selectedByField.set(field._id, existing);
193
+ _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices=selectedIndices;
194
+
195
+ return applyFiltering;
196
+
123
197
  }
124
198
 
125
199
  function loadPaginationButtons(_$w) {
126
200
  try {
127
201
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).onClick(async () => {
128
202
  let nextPageJobs=currentJobs.slice(pagination.pageSize*pagination.currentPage,pagination.pageSize*(pagination.currentPage+1));
129
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (nextPageJobs.length+pagination.pageSize*pagination.currentPage).toString();
203
+
130
204
  pagination.currentPage++;
205
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
131
206
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = nextPageJobs;
132
207
  handlePaginationButtons(_$w);
133
208
  });
@@ -135,7 +210,7 @@ async function handleParams(_$w,param,value) {
135
210
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS).onClick(async () => {
136
211
  let previousPageJobs=currentJobs.slice(pagination.pageSize*(pagination.currentPage-2),pagination.pageSize*(pagination.currentPage-1));
137
212
  pagination.currentPage--;
138
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (pagination.pageSize*pagination.currentPage).toString();
213
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
139
214
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = previousPageJobs;
140
215
  handlePaginationButtons(_$w);
141
216
  });
@@ -150,21 +225,22 @@ async function handleParams(_$w,param,value) {
150
225
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER_ITEM_LABEL).text = itemData.label || '';
151
226
  // Deselect this value from both the selected map and the multibox
152
227
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.DESELECT_BUTTON_ID).onClick(async () => {
153
-
154
228
  const fieldId = itemData.fieldId;
155
229
  const valueId = itemData.valueId;
156
230
  dontUpdateThisCheckBox=fieldId;
157
231
  if (!fieldId || !valueId) return;
158
-
159
232
  const existing = selectedByField.get(fieldId) || [];
160
233
  const updated = existing.filter(v => v !== valueId);
234
+ const field=getFieldById(fieldId,allfields);
235
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
236
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
161
237
  if (updated.length) {
162
238
  selectedByField.set(fieldId, updated);
239
+ queryParams.add({ [fieldTitle] : updated.map(val=>encodeURIComponent(val)).join(',') });
163
240
  } else {
164
241
  selectedByField.delete(fieldId);
242
+ queryParams.remove([fieldTitle ]);
165
243
  }
166
-
167
- const field=getFieldById(fieldId,allfields);
168
244
  const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
169
245
  const nextVals = currentVals.filter(v => v !== valueId);
170
246
  _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
@@ -212,8 +288,8 @@ async function loadJobsRepeater(_$w) {
212
288
 
213
289
  const jobsFirstPage=alljobs.slice(0,pagination.pageSize);
214
290
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
215
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
216
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = currentJobs.length.toString();
291
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1"
292
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(currentJobs.length/pagination.pageSize).toString();
217
293
  updateTotalJobsCountText(_$w);
218
294
  handlePaginationButtons(_$w);
219
295
  } catch (error) {
@@ -254,32 +330,41 @@ async function loadJobsRepeater(_$w) {
254
330
  else{
255
331
  originalOptions=value
256
332
  }
257
-
258
333
  optionsByFieldId.set(key, originalOptions);
259
334
  for (const val of allvaluesobjects) {
260
335
  counter[val.title]=val.count
261
336
  }
262
-
263
337
  countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
264
338
  updateOptionsUI(_$w,field.title, field._id, ''); // no search query
265
339
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
266
340
  _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
267
- dontUpdateThisCheckBox=field._id;
268
- const selected = ev.target.value; // array of selected value IDs
269
- console.log("ev: ",ev)
270
- console.log("ev.target: ",ev.target)
271
- if (selected && selected.length) {
272
- selectedByField.set(field._id, selected);
273
- } else {
274
- selectedByField.delete(field._id);
275
- }
276
- await updateJobsAndNumbersAndFilters(_$w);
277
- });
278
-
279
- const runFilter = debounce(() => {
280
- const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
281
- updateOptionsUI(_$w, field.title, field._id, query);
341
+ dontUpdateThisCheckBox=field._id;
342
+ const selected = ev.target.value; // array of selected value IDs
343
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
344
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
345
+
346
+ if (selected && selected.length) {
347
+ selectedByField.set(field._id, selected);
348
+ if(fieldTitle==="brand" || fieldTitle==="storename") {
349
+ //in this case we need the label not valueid
350
+ const valueLabels=getValueFromValueId(selected,value);
351
+ queryParams.add({ [fieldTitle] : valueLabels.map(val=>encodeURIComponent(val)).join(',') });
352
+ }
353
+ else{
354
+ queryParams.add({ [fieldTitle] : selected.map(val=>encodeURIComponent(val)).join(',') });
355
+ }
356
+
357
+ } else {
358
+ selectedByField.delete(field._id);
359
+ queryParams.remove([fieldTitle ]);
360
+ }
282
361
 
362
+ await updateJobsAndNumbersAndFilters(_$w);
363
+
364
+ });
365
+ const runFilter = debounce(() => {
366
+ const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
367
+ updateOptionsUI(_$w, field.title, field._id, query);
283
368
  }, 150);
284
369
  _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
285
370
  }
@@ -290,8 +375,18 @@ async function loadJobsRepeater(_$w) {
290
375
  }
291
376
  }
292
377
 
378
+ function getValueFromValueId(valueIds,value) {
379
+ let valueLabels=[];
380
+ let currentVal
381
+ for(const valueId of valueIds) {
382
+ currentVal=value.find(val=>val.value===valueId);
383
+ if(currentVal) {
384
+ valueLabels.push(currentVal.label);
385
+ }
386
+ }
387
+ return valueLabels
388
+ }
293
389
 
294
-
295
390
  async function updateJobsAndNumbersAndFilters(_$w,clearAll=false) {
296
391
  await applyJobFilters(_$w); // re-query jobs
297
392
  await refreshFacetCounts(_$w,clearAll); // recompute and update counts in all lists
@@ -302,7 +397,6 @@ async function loadJobsRepeater(_$w) {
302
397
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
303
398
  let base = optionsByFieldId.get(fieldId) || [];
304
399
  const countsMap = countsByFieldId.get(fieldId) || new Map();
305
-
306
400
  if(dontUpdateThisCheckBox===fieldId && !clearAll)
307
401
  {
308
402
  dontUpdateThisCheckBox=null;
@@ -378,12 +472,15 @@ async function loadJobsRepeater(_$w) {
378
472
  finalFilteredJobs=tempFilteredJobs;
379
473
  tempFilteredJobs=[];
380
474
  }
475
+
381
476
  secondarySearchIsFilled? currentSecondarySearchJobs=finalFilteredJobs:currentJobs=finalFilteredJobs;
477
+
478
+
382
479
  let jobsFirstPage=[];
383
480
  secondarySearchIsFilled? jobsFirstPage=currentSecondarySearchJobs.slice(0,pagination.pageSize):jobsFirstPage=currentJobs.slice(0,pagination.pageSize);
384
481
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
385
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
386
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? currentSecondarySearchJobs.length.toString():currentJobs.length.toString();
482
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
483
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? Math.ceil(currentSecondarySearchJobs.length/pagination.pageSize).toString():Math.ceil(currentJobs.length/pagination.pageSize).toString();
387
484
  if(jobsFirstPage.length===0) {
388
485
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
389
486
  }
@@ -429,6 +526,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
429
526
 
430
527
  secondarySearchIsFilled? countJobsPerField(currentSecondarySearchJobs):countJobsPerField(currentJobs);
431
528
  for(const field of allfields) {
529
+
432
530
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
433
531
  clearAll? updateOptionsUI(_$w,field.title, field._id, '',true):updateOptionsUI(_$w,field.title, field._id, query);
434
532
  // no search query
@@ -481,9 +579,10 @@ async function secondarySearch(_$w,query) {
481
579
  currentSecondarySearchJobs=allsecondarySearchJobs;
482
580
  const jobsFirstPage=allsecondarySearchJobs.slice(0,pagination.pageSize);
483
581
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
484
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
485
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = allsecondarySearchJobs.length.toString();
582
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
583
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(allsecondarySearchJobs.length/pagination.pageSize).toString();
486
584
  pagination.currentPage=1;
585
+
487
586
  if(jobsFirstPage.length===0) {
488
587
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
489
588
  }
@@ -5,12 +5,10 @@ const { query,queryParams,onChange} = require("wix-location-frontend");
5
5
  const { location } = require("@wix/site-location");
6
6
  const { COLLECTIONS } = require('../backend/collectionConsts');
7
7
  const { careersMultiBoxesPageOnReady } = require('./careersMultiBoxesPage');
8
-
9
- const {
10
- debounce,
11
- getFilter,
12
- } = require('../public/filterUtils');
8
+ const { debounce, getFilter} = require('../public/filterUtils');
9
+ const { CAREERS_PAGE_SELECTORS, FILTER_FIELDS } = require('../public/selectors');
13
10
  const { filterBrokenMarkers } = require('../public/utils');
11
+
14
12
  let currentLoadedItems =100;
15
13
  const itemsPerPage = 100;
16
14
  let allJobs=[]
@@ -31,6 +29,10 @@ async function careersPageOnReady(_$w,thisObject=null,queryParams=null) {
31
29
  const queryResult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
32
30
  siteconfig = queryResult.items[0];
33
31
  }
32
+ if(siteconfig===undefined) {
33
+ const queryResult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
34
+ siteconfig = queryResult.items[0];
35
+ }
34
36
 
35
37
  if(siteconfig.customFields==="true") {
36
38
  await careersMultiBoxesPageOnReady(_$w,queryParams);
@@ -45,22 +47,25 @@ async function careersPageOnReady(_$w,thisObject=null,queryParams=null) {
45
47
  queryJobTypeVar=jobType;
46
48
  queryBrandVar=brand;
47
49
  thisObjectVar=thisObject;
48
- allJobs=await getAllPositions();
50
+ allJobs = await getAllPositions();
51
+
49
52
  activateAutoLoad(_$w);
50
53
  await bind(_$w);
51
54
  init(_$w);
52
55
  await handleBrandDropdown(_$w);
53
56
  await handleUrlParams(_$w);
57
+
54
58
  }
55
- }
56
59
 
60
+
61
+ }
57
62
 
58
63
  function activateAutoLoad(_$w)
59
64
  {
60
- _$w("#jobsDataset").onReady(() => {
65
+ _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).onReady(() => {
61
66
  updateCount(_$w);
62
- _$w("#section2").onViewportEnter(() => {
63
- if (currentLoadedItems<_$w("#jobsDataset").getTotalCount()) {
67
+ _$w(CAREERS_PAGE_SELECTORS.FOOTER).onViewportEnter(() => {
68
+ if (currentLoadedItems<_$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).getTotalCount()) {
64
69
  loadMoreJobs(_$w);
65
70
  }
66
71
  else {
@@ -80,10 +85,12 @@ async function loadMoreJobs(_$w) {
80
85
  pageParamSet = Number(pageParamSet) + 1;
81
86
  }
82
87
  if (shouldLoad) {
83
- _$w("#jobsDataset").loadMore();
88
+ _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).loadMore();
84
89
  console.log("loading more jobs");
90
+
85
91
  currentLoadedItems = currentLoadedItems + itemsPerPage;
86
- const data = _$w("#positionsRepeater").data;
92
+ const data = _$w(CAREERS_PAGE_SELECTORS.POSITIONS_REPEATER).data;
93
+
87
94
  console.log("data length is : ", data.length);
88
95
  setPageParamInUrl();
89
96
  }
@@ -106,26 +113,26 @@ async function handleUrlParams(_$w) {
106
113
  if (queryKeyWordVar) {
107
114
  await handleKeyWordParam(_$w,queryKeyWordVar);
108
115
  }
109
- if (queryBrandVar && _$w('#dropdownBrand').isVisible) { //if it is not visible, ignore it
116
+ if (queryBrandVar && _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).isVisible) { //if it is not visible, ignore it
110
117
  await handleBrandParam(_$w,queryBrandVar);
111
118
  }
112
- if (queryPageVar) {
113
- await handlePageParam(_$w);
114
- }
115
- if (queryDepartmentVar) {
116
- await handleDepartmentParam(_$w,queryDepartmentVar);
117
- }
118
- if (queryLocationVar) {
119
- await handleLocationParam(_$w,queryLocationVar);
120
- }
121
- if (queryJobTypeVar) {
122
- await handleJobTypeParam(_$w,queryJobTypeVar);
123
- }
119
+ if (queryPageVar) {
120
+ await handlePageParam(_$w);
121
+ }
122
+ if (queryDepartmentVar) {
123
+ await handleDepartmentParam(_$w,queryDepartmentVar);
124
+ }
125
+ if (queryLocationVar) {
126
+ await handleLocationParam(_$w,queryLocationVar);
127
+ }
128
+ if (queryJobTypeVar) {
129
+ await handleJobTypeParam(_$w,queryJobTypeVar);
130
+ }
124
131
  await applyFilters(_$w, true); // Skip URL update since we're handling initial URL params
125
132
  }
126
133
 
127
134
  async function handleKeyWordParam(_$w,keyWord) {
128
- _$w('#searchInput').value = keyWord;
135
+ _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).value = keyWord;
129
136
  // Use applyFilters to maintain consistency instead of directly setting filter
130
137
  }
131
138
 
@@ -145,18 +152,18 @@ async function handlePageParam(_$w) {
145
152
  //scrolls a bit to load the dataset data
146
153
  await window.scrollTo(0, 200,{scrollAnimation:false});
147
154
  for (let i = 2; i <= queryPageVar; i++) {
148
- await _$w("#jobsDataset").loadMore();
155
+ await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).loadMore();
149
156
  currentLoadedItems=currentLoadedItems+itemsPerPage
150
157
  }
151
158
  // the timeout is to wait for the repeater to render, then scroll to the last item.
152
159
  setTimeout(() => {
153
- const data = _$w("#positionsRepeater").data;
160
+ const data = _$w(CAREERS_PAGE_SELECTORS.POSITIONS_REPEATER).data;
154
161
  if (data && data.length > 0) {
155
162
  //the dataset each time it loads 100 items
156
163
  const lastIndex = data.length - itemsPerPage;
157
- _$w("#positionsRepeater").forEachItem(async ($item, itemData, index) => {
164
+ _$w(CAREERS_PAGE_SELECTORS.POSITIONS_REPEATER).forEachItem(async ($item, itemData, index) => {
158
165
  if (index === lastIndex) {
159
- await $item("#positionItem").scrollTo();
166
+ await $item(CAREERS_PAGE_SELECTORS.POSITION_ITEM).scrollTo();
160
167
  console.log("finishied scrolling inside handlePageParam")
161
168
  }
162
169
  });
@@ -167,40 +174,40 @@ async function handlePageParam(_$w) {
167
174
  }
168
175
 
169
176
  async function bind(_$w) {
170
- await _$w('#jobsDataset').onReady(async () => {
177
+ await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).onReady(async () => {
171
178
  await updateCount(_$w);
172
179
  await updateMapMarkers(_$w);
173
180
 
174
181
  });
175
182
 
176
183
  if (await window.formFactor() === "Mobile") {
177
- _$w('#dropdownsContainer').collapse();
184
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_CONTAINER).collapse();
178
185
  }
179
186
 
180
187
  }
181
188
 
182
189
  function init(_$w) {
183
190
  const debouncedSearch = debounce(()=>applyFilters(_$w), 400,thisObjectVar);
184
- _$w('#searchInput').onInput(debouncedSearch);
185
- _$w('#searchInput').onBlur(()=>{
186
- if(searchInputBlurredFirstTime && _$w('#searchInput').value.trim() !== '')
191
+ _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).onInput(debouncedSearch);
192
+ _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).onBlur(()=>{
193
+ if(searchInputBlurredFirstTime && _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).value.trim() !== '')
187
194
  {
188
- _$w('#searchInput').focus();
189
- searchInputBlurredFirstTime=false;
195
+ _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).focus();
196
+ searchInputBlurredFirstTime=false;
190
197
  }
191
198
  });
192
- _$w('#dropdownDepartment, #dropdownLocation, #dropdownJobType, #dropdownBrand').onChange(()=>{
199
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT, CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION, CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE, CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).onChange(()=>{
193
200
  console.log("dropdown onChange is triggered");
194
201
  applyFilters(_$w);
195
202
  });
196
- _$w('#resetFiltersButton, #clearSearch').onClick(()=>resetFilters(_$w));
203
+ _$w(CAREERS_PAGE_SELECTORS.RESET_FILTERS_BUTTON, CAREERS_PAGE_SELECTORS.CLEAR_SEARCH).onClick(()=>resetFilters(_$w));
197
204
 
198
- _$w('#openFiltersButton').onClick(()=>{
199
- _$w('#dropdownsContainer, #closeFiltersButton').expand();
205
+ _$w(CAREERS_PAGE_SELECTORS.OPEN_FILTERS_BUTTON).onClick(()=>{
206
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_CONTAINER, CAREERS_PAGE_SELECTORS.CLOSE_FILTERS_BUTTON).expand();
200
207
  });
201
208
 
202
- _$w('#closeFiltersButton').onClick(()=>{
203
- _$w('#dropdownsContainer, #closeFiltersButton').collapse();
209
+ _$w(CAREERS_PAGE_SELECTORS.CLOSE_FILTERS_BUTTON).onClick(()=>{
210
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_CONTAINER, CAREERS_PAGE_SELECTORS.CLOSE_FILTERS_BUTTON).collapse();
204
211
  });
205
212
 
206
213
  //URL onChange
@@ -219,7 +226,7 @@ async function handleBackAndForth(_$w){
219
226
  else{
220
227
  queryDepartmentVar=undefined;
221
228
  deletedParam=true;
222
- _$w('#dropdownDepartment').value = '';
229
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT).value = '';
223
230
  }
224
231
  if(newQueryParams.location){
225
232
  queryLocationVar=newQueryParams.location;
@@ -227,7 +234,7 @@ async function handleBackAndForth(_$w){
227
234
  else{
228
235
  queryLocationVar=undefined;
229
236
  deletedParam=true
230
- _$w('#dropdownLocation').value = '';
237
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION).value = '';
231
238
  }
232
239
  if(newQueryParams.keyWord){
233
240
  queryKeyWordVar=newQueryParams.keyWord;
@@ -235,7 +242,7 @@ async function handleBackAndForth(_$w){
235
242
  else{
236
243
  queryKeyWordVar=undefined;
237
244
  deletedParam=true;
238
- _$w('#searchInput').value = '';
245
+ _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).value = '';
239
246
  }
240
247
  if(newQueryParams.jobType){
241
248
  queryJobTypeVar=newQueryParams.jobType;
@@ -243,16 +250,16 @@ async function handleBackAndForth(_$w){
243
250
  else{
244
251
  queryJobTypeVar=undefined;
245
252
  deletedParam=true;
246
- _$w('#dropdownJobType').value = '';
253
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE).value = '';
247
254
  }
248
- if(_$w('#dropdownBrand').isVisible){
255
+ if(_$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).isVisible){
249
256
  if(newQueryParams.brand){
250
257
  queryBrandVar=newQueryParams.brand;
251
258
  }
252
259
  else{
253
260
  queryBrandVar=undefined;
254
261
  deletedParam=true;
255
- _$w('#dropdownBrand').value = '';
262
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).value = '';
256
263
  }
257
264
  }
258
265
  await handleUrlParams(_$w);
@@ -262,11 +269,11 @@ async function handleBackAndForth(_$w){
262
269
  async function applyFilters(_$w, skipUrlUpdate = false) {
263
270
  console.log("applying filters");
264
271
  const dropdownFiltersMapping = [
265
- { elementId: '#dropdownDepartment', field: 'department', value: _$w('#dropdownDepartment').value },
266
- { elementId: '#dropdownLocation', field: 'cityText', value: _$w('#dropdownLocation').value },
267
- { elementId: '#dropdownJobType', field: 'remote', value: _$w('#dropdownJobType').value},
268
- { elementId: '#dropdownBrand', field: 'brand', value: _$w('#dropdownBrand').value},
269
- { elementId: '#searchInput', field: 'title', value: _$w('#searchInput').value }
272
+ { elementId: CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT, field: 'department', value: _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT).value },
273
+ { elementId: CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION, field: 'cityText', value: _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION).value },
274
+ { elementId: CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE, field: 'remote', value: _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE).value},
275
+ { elementId: CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND, field: 'brand', value: _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).value},
276
+ { elementId: CAREERS_PAGE_SELECTORS.SEARCH_INPUT, field: 'title', value: _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT).value }
270
277
  ];
271
278
  console.log("dropdownFiltersMapping: ", dropdownFiltersMapping);
272
279
 
@@ -285,16 +292,16 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
285
292
  // build filters
286
293
  if (filter.value && filter.value.trim() !== '') {
287
294
  if (!skipUrlUpdate) {
288
- if(filter.field === 'title'){
295
+ if(filter.field === FILTER_FIELDS.SEARCH){
289
296
  queryParams.add({ keyWord: filter.value });
290
297
  }
291
- if(filter.field === 'department'){
298
+ if(filter.field === FILTER_FIELDS.DEPARTMENT){
292
299
  queryParams.add({ department: encodeURIComponent(filter.value) });
293
300
  }
294
- if(filter.field === 'cityText'){
301
+ if(filter.field === FILTER_FIELDS.LOCATION){
295
302
  queryParams.add({ location: encodeURIComponent(filter.value) });
296
303
  }
297
- if(filter.field === 'remote'){
304
+ if(filter.field === FILTER_FIELDS.JOB_TYPE){
298
305
  if(filter.value === 'true'){
299
306
  queryParams.add({ jobType: encodeURIComponent("remote") });
300
307
  }
@@ -302,11 +309,11 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
302
309
  queryParams.add({ jobType: encodeURIComponent("onsite") });
303
310
  }
304
311
  }
305
- if(filter.field === 'brand'){
312
+ if(filter.field === FILTER_FIELDS.BRAND){
306
313
  queryParams.add({ brand: encodeURIComponent(filter.value) });
307
314
  }
308
315
  }
309
- if(filter.field === 'remote') {
316
+ if(filter.field === FILTER_FIELDS.JOB_TYPE) {
310
317
  value = filter.value === 'true';
311
318
  } else {
312
319
  value = filter.value;
@@ -315,22 +322,22 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
315
322
  }
316
323
  else{
317
324
  if (!skipUrlUpdate) {
318
- if(filter.field === 'title'){
325
+ if(filter.field === FILTER_FIELDS.SEARCH){
319
326
  queryParams.remove(["keyWord" ]);
320
327
  }
321
- if(filter.field === 'department'){
328
+ if(filter.field === FILTER_FIELDS.DEPARTMENT){
322
329
  console.log("removing department from url")
323
330
  queryParams.remove(["department" ]);
324
331
  }
325
- if(filter.field === 'cityText'){
332
+ if(filter.field === FILTER_FIELDS.LOCATION){
326
333
  console.log("removing location from url")
327
334
  queryParams.remove(["location" ]);
328
335
  }
329
- if(filter.field === 'remote'){
336
+ if(filter.field === FILTER_FIELDS.JOB_TYPE){
330
337
  console.log("removing jobType from url")
331
338
  queryParams.remove(["jobType" ]);
332
339
  }
333
- if(filter.field === 'brand'){
340
+ if(filter.field === FILTER_FIELDS.BRAND){
334
341
  console.log("removing brand from url")
335
342
  queryParams.remove(["brand" ]);
336
343
  }
@@ -339,32 +346,32 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
339
346
  });
340
347
 
341
348
  const filter = await getFilter(filters, 'and');
342
- await _$w('#jobsDataset').setFilter(filter);
343
- await _$w('#jobsDataset').refresh();
349
+ await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).setFilter(filter);
350
+ await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).refresh();
344
351
 
345
352
  const count = await updateCount(_$w);
346
353
  console.log("updating map markers");
347
354
  await updateMapMarkers(_$w);
348
355
  console.log("updating map markers completed");
349
- count ? _$w('#resultsMultiState').changeState('results') : _$w('#resultsMultiState').changeState('noResults');
356
+ count ? _$w(CAREERS_PAGE_SELECTORS.RESULTS_MULTI_STATE).changeState('results') : _$w(CAREERS_PAGE_SELECTORS.RESULTS_MULTI_STATE).changeState('noResults');
350
357
 
351
358
 
352
359
  // Update reset button state
353
360
  const hasActiveFilters = filters.length > 0;
354
- hasActiveFilters? _$w('#resetFiltersButton').enable() : _$w('#resetFiltersButton').disable();
361
+ hasActiveFilters? _$w(CAREERS_PAGE_SELECTORS.RESET_FILTERS_BUTTON).enable() : _$w(CAREERS_PAGE_SELECTORS.RESET_FILTERS_BUTTON).disable();
355
362
 
356
363
 
357
364
  }
358
365
 
359
366
  async function resetFilters(_$w) {
360
- _$w('#searchInput, #dropdownDepartment, #dropdownLocation, #dropdownJobType, #dropdownBrand').value = '';
367
+ _$w(CAREERS_PAGE_SELECTORS.SEARCH_INPUT, CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT, CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION, CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE, CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).value = '';
361
368
 
362
- await _$w('#jobsDataset').setFilter(wixData.filter());
363
- await _$w('#jobsDataset').refresh();
369
+ await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).setFilter(wixData.filter());
370
+ await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).refresh();
364
371
 
365
- _$w('#resultsMultiState').changeState('results');
372
+ _$w(CAREERS_PAGE_SELECTORS.RESULTS_MULTI_STATE).changeState('results');
366
373
 
367
- _$w('#resetFiltersButton').disable();
374
+ _$w(CAREERS_PAGE_SELECTORS.RESET_FILTERS_BUTTON).disable();
368
375
 
369
376
  queryParams.remove(["keyWord", "department","page","location","jobType","brand"]);
370
377
 
@@ -376,7 +383,7 @@ async function resetFilters(_$w) {
376
383
  }
377
384
 
378
385
  async function updateCount(_$w) {
379
- const count = await _$w('#jobsDataset').getTotalCount();
386
+ const count = await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).getTotalCount();
380
387
  _$w('#numOfPositionText').text = `Showing ${count} Open Positions`;
381
388
 
382
389
  return count;
@@ -387,19 +394,19 @@ async function handleDepartmentParam(_$w,department) {
387
394
 
388
395
 
389
396
 
390
- let dropdownOptions = _$w('#dropdownDepartment').options;
397
+ let dropdownOptions = _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT).options;
391
398
  console.log("dropdown options:", dropdownOptions);
392
399
  const optionsFromCMS=await wixData.query("AmountOfJobsPerDepartment").find();
393
400
  //+1 because of the "All" option
394
401
 
395
402
  if(dropdownOptions.length!==optionsFromCMS.items.length+1){
396
- fixDropdownOptions('#dropdownDepartment',optionsFromCMS, _$w);
403
+ fixDropdownOptions(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT,optionsFromCMS, _$w);
397
404
  }
398
405
 
399
- if (_$w('#dropdownDepartment').options.find(option => option.value === departmentValue))
406
+ if (_$w(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT).options.find(option => option.value === departmentValue))
400
407
  {
401
408
  console.log("department value found in dropdown options ",departmentValue);
402
- _$w('#dropdownDepartment').value = departmentValue;
409
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_DEPARTMENT).value = departmentValue;
403
410
  }
404
411
  else{
405
412
  console.warn("department value not found in dropdown options");
@@ -428,18 +435,18 @@ function fixDropdownOptions(dropdown,optionsFromCMS, _$w){
428
435
 
429
436
  async function handleLocationParam(_$w,location) {
430
437
  const locationValue = decodeURIComponent(location);
431
- let dropdownOptions = _$w('#dropdownLocation').options;
438
+ let dropdownOptions = _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION).options;
432
439
  console.log("location dropdown options:", dropdownOptions);
433
440
  const optionsFromCMS=await wixData.query("cities").find();
434
441
  //+1 because of the "All" option
435
442
  if(dropdownOptions.length!==optionsFromCMS.items.length+1){
436
- fixDropdownOptions('#dropdownLocation',optionsFromCMS, _$w);
443
+ fixDropdownOptions(CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION,optionsFromCMS, _$w);
437
444
  }
438
445
 
439
- const option=_$w('#dropdownLocation').options.find(option => option.value.toLowerCase() === locationValue.toLowerCase())
446
+ const option=_$w(CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION).options.find(option => option.value.toLowerCase() === locationValue.toLowerCase())
440
447
 
441
448
  if(option){
442
- _$w('#dropdownLocation').value = option.value;
449
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_LOCATION).value = option.value;
443
450
  }
444
451
  else{
445
452
  console.warn("location value not found in dropdown options");
@@ -450,15 +457,15 @@ async function handleLocationParam(_$w,location) {
450
457
 
451
458
  async function handleBrandParam(_$w,brand){
452
459
  const brandValue = decodeURIComponent(brand);
453
- let dropdownOptions = _$w('#dropdownBrand').options;
460
+ let dropdownOptions = _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).options;
454
461
  console.log("brand dropdown options:", dropdownOptions);
455
462
  const optionsFromCMS=await wixData.query(COLLECTIONS.BRANDS).find();
456
463
  if(dropdownOptions.length!==optionsFromCMS.items.length+1){
457
- fixDropdownOptions('#dropdownBrand',optionsFromCMS, _$w);
464
+ fixDropdownOptions(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND,optionsFromCMS, _$w);
458
465
  }
459
- const option=_$w('#dropdownBrand').options.find(option => option.value.toLowerCase() === brandValue.toLowerCase())
466
+ const option=_$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).options.find(option => option.value.toLowerCase() === brandValue.toLowerCase())
460
467
  if(option){
461
- _$w('#dropdownBrand').value = option.value;
468
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).value = option.value;
462
469
  }
463
470
  else{
464
471
  console.warn("brand value not found in dropdown options");
@@ -468,7 +475,7 @@ async function handleBrandParam(_$w,brand){
468
475
 
469
476
  async function handleJobTypeParam(_$w,jobType) {
470
477
  const jobTypeValue = decodeURIComponent(jobType);
471
- let dropdownOptions = _$w('#dropdownJobType').options;
478
+ let dropdownOptions = _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE).options;
472
479
  console.log("jobType dropdown options:", dropdownOptions);
473
480
  let option;
474
481
  if(jobTypeValue.toLowerCase()==="remote"){
@@ -478,7 +485,7 @@ async function handleJobTypeParam(_$w,jobType) {
478
485
  option="false";
479
486
  }
480
487
  if(option){
481
- _$w('#dropdownJobType').value = option;
488
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_JOB_TYPE).value = option;
482
489
  }
483
490
  else{
484
491
  console.warn("jobType value not found in dropdown options");
@@ -487,8 +494,8 @@ async function handleJobTypeParam(_$w,jobType) {
487
494
  }
488
495
 
489
496
  async function updateMapMarkers(_$w){
490
- const numOfItems = await _$w('#jobsDataset').getTotalCount();
491
- const items = await _$w('#jobsDataset').getItems(0, numOfItems);
497
+ const numOfItems = await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).getTotalCount();
498
+ const items = await _$w(CAREERS_PAGE_SELECTORS.JOBS_DATASET).getItems(0, numOfItems);
492
499
  const markers = filterBrokenMarkers(items.items).map(item => {
493
500
  const location = item.locationAddress.location;
494
501
  return {
@@ -501,21 +508,21 @@ async function updateMapMarkers(_$w){
501
508
  };
502
509
  });
503
510
  //@ts-ignore
504
- _$w('#googleMaps').setMarkers(markers);
511
+ _$w(CAREERS_PAGE_SELECTORS.GOOGLE_MAPS).setMarkers(markers);
505
512
 
506
513
  }
507
514
 
508
515
  async function handleBrandDropdown(_$w){
509
516
  if(siteconfig.disableMultiBrand==="false"){
510
- const brands=await wixData.query(COLLECTIONS.BRANDS).find();
511
- if(brands.items.length>1){
512
- console.log("showing brand dropdown");
513
- _$w('#dropdownBrand').show();
517
+ const brands=await wixData.query(COLLECTIONS.BRANDS).find();
518
+ if(brands.items.length>1){
519
+ console.log("showing brand dropdown");
520
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).show();
521
+ }
522
+ }
523
+ else{
524
+ _$w(CAREERS_PAGE_SELECTORS.DROPDOWN_BRAND).hide();
514
525
  }
515
- }
516
- else{
517
- _$w('#dropdownBrand').hide();
518
- }
519
526
  }
520
527
  module.exports = {
521
528
  careersPageOnReady,
@@ -2,6 +2,7 @@ const { items: wixData } = require('@wix/data');
2
2
  const { JOBS_COLLECTION_FIELDS,COLLECTIONS } = require('../backend/collectionConsts');
3
3
  const { CAREERS_MULTI_BOXES_PAGE_CONSTS,CATEGORY_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
4
4
  const { location } = require("@wix/site-location");
5
+ const { normalizeString } = require('../backend/utils');
5
6
 
6
7
  function groupValuesByField(values, refKey) {
7
8
  const map = new Map();
@@ -62,14 +63,19 @@ function groupValuesByField(values, refKey) {
62
63
  return allFields.find(field=>field.title===title);
63
64
  }
64
65
 
65
- function getCorrectOption(value,options) {
66
- const standardizedValue = value.toLowerCase().trim().replace(/[^a-z0-9]/gi, '');
67
- return options.find(option=>option.label.toLowerCase().trim().replace(/[^a-z0-9]/gi, '')===standardizedValue);
66
+ function getCorrectOption(value,options,param) {
67
+ const standardizedValue = normalizeString(value.toLowerCase())
68
+ if(param==="employmenttype") //employmenttype have a problematic value
69
+ {
70
+ return options.find(option=>normalizeString(option.value.toLowerCase())===standardizedValue);
71
+ }
72
+ return options.find(option=>normalizeString(option.label.toLowerCase())===standardizedValue);
68
73
  }
69
74
 
70
75
  function getOptionIndexFromCheckBox(options,value) {
76
+ const normalizedValue=normalizeString(value.toLowerCase());
71
77
  for(let index=0;index<options.length;index++) {
72
- if(options[index].value===value) {
78
+ if(normalizeString(options[index].value.toLowerCase())===normalizedValue) {
73
79
  return index;
74
80
  }
75
81
  }
@@ -85,7 +91,10 @@ function loadPrimarySearchRepeater(_$w) {
85
91
  const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
86
92
  const clickedItemData = data.find(
87
93
  (item) => item._id === event.context.itemId,
94
+
88
95
  );
96
+ console.log("clickedItemData: ",clickedItemData);
97
+ console.log("clickedItemData['link-jobs-title']: ",clickedItemData["link-jobs-title"]);
89
98
  location.to(clickedItemData["link-jobs-title"]);
90
99
  });
91
100
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
@@ -109,7 +118,7 @@ function loadPrimarySearchRepeater(_$w) {
109
118
  const primarySearchDebounced = debounce(async () => {
110
119
  const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value || '').toLowerCase().trim();
111
120
  await primarySearch(_$w, query, alljobs);
112
- }, 150);
121
+ }, 300);
113
122
 
114
123
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
115
124
  await primarySearchDebounced();
@@ -0,0 +1,53 @@
1
+ const CAREERS_PAGE_SELECTORS = {
2
+ FILTER_ICON: '#filterIcon',
3
+ FILTER_BOX: '#filterBox',
4
+ RESULT_BOX: '#resultBox',
5
+ PAGINATION_BTN: '#paginationBtn',
6
+ HEAD_BTNS: '#headBtns',
7
+ SELECTED_VALUES_REPEATER: '#selectedValuesReapter',
8
+ BUTTOM_TXT: '#buttomTxt',
9
+ SECTION_24: '#section24',
10
+ SECTION_3: '#section3',
11
+ LINE_3: '#line3',
12
+ EXIT_BUTTON: '#exitBtn',
13
+ REFINE_SEARCH_BUTTON: '#refineSearchBtn',
14
+
15
+ POSITIONS_REPEATER: '#positionsRepeater',
16
+ POSITION_ITEM: '#positionItem',
17
+ SEARCH_INPUT: '#searchInput',
18
+ CLEAR_SEARCH: '#clearSearch',
19
+
20
+ DROPDOWN_BRAND: '#dropdownBrand',
21
+ DROPDOWN_CONTAINER: '#dropdownsContainer',
22
+ DROPDOWN_DEPARTMENT: '#dropdownDepartment',
23
+ DROPDOWN_LOCATION: '#dropdownLocation',
24
+ DROPDOWN_JOB_TYPE: '#dropdownJobType',
25
+
26
+ OPEN_FILTERS_BUTTON: '#openFiltersButton',
27
+ CLOSE_FILTERS_BUTTON: '#closeFiltersButton',
28
+ RESET_FILTERS_BUTTON: '#resetFiltersButton',
29
+ RESET_FILTERS_BUTTON: '#resetFiltersButton',
30
+
31
+ RESULTS_MULTI_STATE: '#resultsMultiState',
32
+ BRANDS_DATASET: '#brandsDataset',
33
+ DEPARTMENTS_DATASET: '#departmentsDataset',
34
+ LOCATIONS_DATASET: '#locationsDataset',
35
+ JOB_TYPES_DATASET: '#jobTypesDataset',
36
+ JOBS_DATASET: '#jobsDataset',
37
+
38
+ GOOGLE_MAPS: '#googleMaps',
39
+ FOOTER: '#footer',
40
+ }
41
+
42
+ const FILTER_FIELDS = {
43
+ DEPARTMENT: 'department',
44
+ LOCATION: 'cityText',
45
+ JOB_TYPE: 'remote',
46
+ BRAND: 'brand',
47
+ SEARCH: 'title',
48
+ }
49
+
50
+ module.exports = {
51
+ CAREERS_PAGE_SELECTORS,
52
+ FILTER_FIELDS,
53
+ }
@@ -1,3 +1,22 @@
1
+ jest.mock('wix-location-frontend');
2
+ jest.mock('@wix/site-location', () => ({
3
+ location: {
4
+ to: jest.fn()
5
+ }
6
+ }));
7
+ jest.mock('@wix/data', () => ({
8
+ items: {
9
+ query: jest.fn(() => ({
10
+ eq: jest.fn().mockReturnThis(),
11
+ find: jest.fn().mockResolvedValue({ items: [] }),
12
+ include: jest.fn().mockReturnThis(),
13
+ hasSome: jest.fn().mockReturnThis(),
14
+ ne: jest.fn().mockReturnThis(),
15
+ limit: jest.fn().mockReturnThis()
16
+ })),
17
+ queryReferenced: jest.fn()
18
+ }
19
+ }));
1
20
  const rewire = require('rewire');
2
21
  const MockJobBuilder = require('./mockJobBuilder');
3
22
  const { CAREERS_MULTI_BOXES_PAGE_CONSTS, CATEGORY_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
@@ -9,7 +28,13 @@ const pagesUtils = rewire('../pages/pagesUtils');
9
28
  const secondarySearch = careersMultiBoxesPage.__get__('secondarySearch');
10
29
  const primarySearch = pagesUtils.__get__('primarySearch');
11
30
  const loadCategoriesListPrimarySearch = pagesUtils.__get__('loadCategoriesListPrimarySearch');
12
-
31
+ const mockQueryParams = {
32
+ add: jest.fn(),
33
+ remove: jest.fn()
34
+ };
35
+ const mockOnChange = jest.fn();
36
+ careersMultiBoxesPage.__set__('queryParams', mockQueryParams);
37
+ careersMultiBoxesPage.__set__('onChange', mockOnChange);
13
38
 
14
39
  describe('secondarySearch function tests', () => {
15
40
  let mockW;
@@ -79,13 +104,11 @@ describe('secondarySearch function tests', () => {
79
104
  mockJobs.push(new MockJobBuilder().withTitle('Frontend Engineer').build());
80
105
 
81
106
  careersMultiBoxesPage.__set__('currentJobs', mockJobs);
82
-
83
107
  const result = await secondarySearch(mockW, 'product');
84
-
85
108
  expect(result.length).toBe(11);
86
109
  expect(mockTotalJobsCountText.text).toContain('11');
87
- expect(mockPaginationCurrentText.text).toBe('10');
88
- expect(mockPaginationTotalCountText.text).toBe('11');
110
+ expect(mockPaginationCurrentText.text).toBe('1');
111
+ expect(mockPaginationTotalCountText.text).toBe('2');
89
112
  expect(mockPageButtonNext.enable).toHaveBeenCalled();
90
113
  expect(mockPageButtonPrevious.disable).toHaveBeenCalled();
91
114
  });