sr-npm 1.2.75 → 1.2.76

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.
@@ -31,6 +31,7 @@ const CAREERS_MULTI_BOXES_PAGE_CONSTS={
31
31
  PRIMARY_SEARCH_CATEGORY_BUTTON: '#primarySearchCategoryButton',
32
32
  RESULTS_CONTAINER: '#resultsContainer',
33
33
  PRIMARY_SEARCH_BUTTON: '#primarySearchButton',
34
+ RESULTS_MULTI_STATE_BOX: '#multiStateBox1',
34
35
  }
35
36
 
36
37
  const TWG_JOBS_COLLECTION_FIELDS={
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.2.75",
3
+ "version": "1.2.76",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -47,7 +47,6 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
47
47
  onChange(async ()=>{
48
48
  await handleBackAndForth(_$w);
49
49
  });
50
-
51
50
  await loadData(_$w);
52
51
  await loadJobsRepeater(_$w); // if we remove the await here the job list will be flaky , it doesn't fill it properly
53
52
  handlePrimarySearch(_$w, allvaluesobjects);
@@ -55,16 +54,14 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
55
54
  loadSelectedValuesRepeater(_$w);
56
55
  bindSearchInput(_$w);
57
56
  loadPaginationButtons(_$w);
58
-
59
57
  if (await window.formFactor() === "Mobile") {
60
58
  handleFilterInMobile(_$w);
61
59
  }
62
-
63
60
  await handleUrlParams(_$w, urlParams);
64
61
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CLEAR_ALL_BUTTON_ID).onClick(async () => {
65
62
  await clearAll(_$w);
66
63
  });
67
-
64
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_MULTI_STATE_BOX).changeState("results");
68
65
  }
69
66
 
70
67
  async function handleBackAndForth(_$w){
@@ -439,16 +436,20 @@ function getValueFromValueId(valueIds, value) {
439
436
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
440
437
  let base = optionsByFieldId.get(fieldId) || [];
441
438
  const countsMap = countsByFieldId.get(fieldId) || new Map();
442
- if(dontUpdateThisCheckBox===fieldId && !clearAll)
439
+ if(dontUpdateThisCheckBox===fieldId && !clearAll && selectedByField.has(fieldId) )
443
440
  {
444
- dontUpdateThisCheckBox=null;
445
- return;
441
+ dontUpdateThisCheckBox=null;
442
+ return;
446
443
  }
447
444
  let filteredbase=[]
448
445
  for (const element of base)
449
446
  {
450
447
  if(countsMap.get(element.value))
451
448
  {
449
+ if(countsMap.get(element.value)==-1)
450
+ {
451
+ countsMap.set(element.value,0);
452
+ }
452
453
  filteredbase.push(element)
453
454
  }
454
455
  }
@@ -466,19 +467,31 @@ function getValueFromValueId(valueIds, value) {
466
467
  : withCounts;
467
468
 
468
469
  // Preserve currently selected values that are still visible
469
- let prevSelected=[]
470
- clearAll? prevSelected=[]:prevSelected= _$w(`#${FiltersIds[fieldTitle]}CheckBox`).value;
470
+ // let prevSelected=[]
471
+ // clearAll? prevSelected=[]:prevSelected= _$w(`#${FiltersIds[fieldTitle]}CheckBox`).value;
471
472
  const visibleSet = new Set(filtered.map(o => o.value));
472
- const preserved = prevSelected.filter(v => visibleSet.has(v));
473
+ //const preserved = prevSelected.filter(v => visibleSet.has(v));
473
474
  if(filtered.length===0) {
474
475
  _$w(`#${FiltersIds[fieldTitle]}MultiBox`).changeState(`${FiltersIds[fieldTitle]}NoResults`);
475
476
  }
476
477
  else{
477
478
  _$w(`#${FiltersIds[fieldTitle]}MultiBox`).changeState(`${FiltersIds[fieldTitle]}Results`);
478
479
  _$w(`#${FiltersIds[fieldTitle]}CheckBox`).options = filtered;
479
- _$w(`#${FiltersIds[fieldTitle]}CheckBox`).value = preserved;
480
+ clearAll?_$w(`#${FiltersIds[fieldTitle]}CheckBox`).value=[]:_$w(`#${FiltersIds[fieldTitle]}CheckBox`).value = visibleSet
481
+ if(visibleSet.size>0 && selectedByField.has(fieldId)) {
482
+ let selectedindices=[];
483
+ for(const value of selectedByField.get(fieldId)) {
484
+ const options = optionsByFieldId.get(fieldId) || [];
485
+ const option = getCorrectOption(value,options,fieldTitle);
486
+ if(option) {
487
+ const optionIndex = getOptionIndexFromCheckBox(_$w(`#${FiltersIds[fieldTitle]}CheckBox`).options,option.value);
488
+ selectedindices.push(optionIndex);
489
+ }
490
+ }
491
+ _$w(`#${FiltersIds[fieldTitle]}CheckBox`).selectedIndices = selectedindices;
480
492
  }
481
493
  }
494
+ }
482
495
 
483
496
  async function applyJobFilters(_$w) {
484
497
  let tempFilteredJobs=[];
@@ -591,7 +604,18 @@ async function refreshFacetCounts(_$w,clearAll=false) {
591
604
  counter.set(option.value, (counter.get(option.value) || 0) + 1);
592
605
  }
593
606
  }
607
+
594
608
  }
609
+ if(selectedByField.has(fieldId)) {
610
+ for (const value of selectedByField.get(fieldId)) {
611
+ console.log("value: ",value)
612
+ if(counter.get(value)===undefined)
613
+ {
614
+ //it is -1 as a flag, so in case it was selected and after selecting more filters from different field and suddenly no more jobs have it, we will show 0
615
+ counter.set(value, -1);
616
+ }
617
+ }
618
+ }
595
619
  countsByFieldId.set(fieldId, counter);
596
620
  }
597
621
  }
@@ -78,10 +78,12 @@ function getFieldByTitle(title,allFields) {
78
78
 
79
79
  function getCorrectOption(value,options,param) {
80
80
  const standardizedValue = normalizeString(value.toLowerCase())
81
- if(param==="employmenttype") //employmenttype have a problematic value
81
+ if(param==="employmenttype" || param==="Employment Type" || param==="Store Name") //employmenttype have a problematic value, added Employment Type for updateOptionsUI fuinction, added Store Name because Store name and location have for example Blenheim
82
82
  {
83
+ //option.value is the id,
83
84
  return options.find(option=>normalizeString(option.value.toLowerCase())===standardizedValue);
84
85
  }
86
+ //option.label is what we see live in the UI
85
87
  return options.find(option=>normalizeString(option.label.toLowerCase())===standardizedValue);
86
88
  }
87
89
 
@@ -6,26 +6,55 @@ const { debounce } = require('../pages/pagesUtils');
6
6
 
7
7
  async function handlePrimarySearch(_$w, allvaluesobjects) {
8
8
  // load the categories list before clicking on the primary search input
9
+ loadCategoryRepeaterData(_$w, allvaluesobjects);
10
+
11
+ // wait for the jobs dataset to be ready
12
+ await _$w("#jobsDataset").onReadyAsync();
13
+
14
+ await bindPrimarySearch(_$w);
15
+ }
16
+
17
+ function loadCategoryRepeaterData(_$w, allvaluesobjects) {
9
18
  let categoryValues=[]
10
19
  for(const value of allvaluesobjects) {
11
20
  if(value.customField === CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
12
21
  categoryValues.push({title: value.title+` (${value.count})` , _id: value.valueId});
13
22
  }
14
23
  }
15
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
24
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
25
+ }
16
26
 
17
- // wait for the jobs dataset to be ready
18
- await _$w("#jobsDataset").onReadyAsync();
27
+ async function bindPrimarySearch(_$w) {
28
+ handleCategoryEvents(_$w);
19
29
 
20
- await bindPrimarySearch(_$w, allvaluesobjects);
30
+ await handleSearchInput(_$w);
31
+
32
+ // on mouse out collapse the results container
33
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
34
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
35
+ });
36
+
37
+ // handle the click on the search button
38
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
39
+ if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
40
+ const baseUrl = await location.baseUrl();
41
+ location.to(`${baseUrl}/search`);
42
+ }
43
+ else {
44
+ let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
45
+ const baseUrl = await location.baseUrl();
46
+ location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
47
+ }
48
+ });
21
49
  }
22
50
 
23
- function loadPrimarySearchRepeater(_$w) {
24
- // handle category state
25
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
51
+ function handleCategoryEvents(_$w) {
52
+ // set the label of the category repeater item
53
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
26
54
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_CATEGORY_BUTTON).label = itemData.title || '';
27
55
  });
28
56
 
57
+ // handle the category repeater item on click
29
58
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER_ITEM).onClick(async (event) => {
30
59
  const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data;
31
60
  const clickedItemData = data.find(
@@ -42,9 +71,10 @@ function getSearchQuery(_$w) {
42
71
  return _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value?.toLowerCase().trim() || '';
43
72
  }
44
73
 
45
- async function handleSearchInput(_$w, allvaluesobjects) {
74
+ async function handleSearchInput(_$w) {
46
75
  _$w('#primarySearchInput').enable();
47
76
 
77
+ // on Input call the queryPrimarySearchResults function
48
78
  const callQueryPrimarySearchResults = async () => {
49
79
  await queryPrimarySearchResults(_$w, getSearchQuery(_$w));
50
80
  }
@@ -52,7 +82,7 @@ async function handleSearchInput(_$w, allvaluesobjects) {
52
82
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
53
83
  await debounce(() => callQueryPrimarySearchResults(), 300)();
54
84
  });
55
-
85
+
56
86
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onClick(async () => {
57
87
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
58
88
 
@@ -61,62 +91,26 @@ async function handleSearchInput(_$w, allvaluesobjects) {
61
91
  await queryPrimarySearchResults(_$w, searchQuery);
62
92
  }
63
93
  else {
64
- await loadCategoriesListPrimarySearch(_$w, allvaluesobjects);
94
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
65
95
  }
66
96
  });
67
97
 
68
98
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onKeyPress(async (event) => {
69
- if( event.key === 'Enter') {
70
- if(getSearchQuery(_$w) === '') {
71
- // _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
72
- const baseUrl = await location.baseUrl();
73
- location.to(`${baseUrl}/search`);
74
-
75
- }
76
- else {
77
- let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
78
- const baseUrl = await location.baseUrl();
79
- location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
99
+ if( event.key === 'Enter') {
100
+ if(getSearchQuery(_$w) === '') {
101
+ // _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
102
+ const baseUrl = await location.baseUrl();
103
+ location.to(`${baseUrl}/search`);
104
+
105
+ }
106
+ else {
107
+ let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
108
+ const baseUrl = await location.baseUrl();
109
+ location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
110
+ }
80
111
  }
81
- }
82
- });
83
- }
84
-
85
- async function bindPrimarySearch(_$w, allvaluesobjects) {
86
- loadPrimarySearchRepeater(_$w);
87
-
88
- await handleSearchInput(_$w, allvaluesobjects);
89
-
90
- // on mouse out collapse the results container
91
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
92
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
93
- });
94
-
95
- // handle the click on the search button
96
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
97
- if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
98
- const baseUrl = await location.baseUrl();
99
- location.to(`${baseUrl}/search`);
100
- }
101
- else {
102
- let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
103
- const baseUrl = await location.baseUrl();
104
- location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
105
- }
106
112
  });
107
113
  }
108
-
109
- async function loadCategoriesListPrimarySearch(_$w, allvaluesobjects) {
110
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
111
-
112
- let categoryValues=[]
113
- for(const value of allvaluesobjects) {
114
- if(value.customField === CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
115
- categoryValues.push({title: value.title+` (${value.count})` , _id: value.valueId});
116
- }
117
- }
118
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
119
- }
120
114
 
121
115
  async function queryPrimarySearchResults(_$w, query) {
122
116
  if(query === undefined || query === '') {
@@ -157,8 +151,5 @@ return count > 0;
157
151
  }
158
152
 
159
153
  module.exports = {
160
- loadPrimarySearchRepeater,
161
- bindPrimarySearch,
162
- queryPrimarySearchResults,
163
154
  handlePrimarySearch,
164
155
  }