Skip to content

Commit

Permalink
chore: add internal mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs committed Aug 18, 2024
1 parent d9303c8 commit b3fa12e
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
2 changes: 1 addition & 1 deletion _layouts/egazette-search-landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 class="h2 pb-3"><b>{{- page.title -}}</b></h2>
<div>
<div class="algolia-search-category-item">
<input id="category-legislative" type="checkbox" data-category="category" value="Legislative Supplements">
<label for="category-legislative"><b>Legislative Supplements</b></label>
<label for="category-legislative"><b>Legislation Supplements</b></label>
</div>
<div id="legislative-supplements" class="pl-7"></div>
</div>
Expand Down
31 changes: 31 additions & 0 deletions assets/js/algolia-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const CATEGORY_INTERNAL_MAPPING = {
"Government Gazette": "Government Gazette",
"Legislative Supplements": "Legislation Supplements",
"Other Supplements": "Other Supplements",
"Advertisements": "Advertisements",
"Appointments": "Appointments",
"Audited Reports": "Audited Reports",
"Cessation of Service": "Cessation of Service",
"Corrigendum": "Corrigendum",
"Death": "Death",
"Dismissals": "Dismissals",
"Leave": "Leave",
"Bankruptcy Act Notice": "Notices (Bankruptcy Act)",
"Companies Act Notice": "Notices (Companies Act)",
"Notices under the Constitution": "Notices (Constitution)",
"Notices under other Acts": "Notices (other Acts)",
"Revocation": "Revocation",
"Tenders": "Tenders",
"Termination of Service": "Termination of Service",
"Vacation of Service": "Vacation of Service",
"Others": "Others",
"Bills Supplement": "Bills Supplement",
"Acts Supplement": "Acts Supplement",
"Subsidiary Legislation Supplement": "Subsidiary Legislation Supplement",
"Revised Acts": "Revised Acts",
"Revised Subsidiary Legislation": "Revised Subsidiary Legislation",
"Government Gazette Supplement": "Government Gazette Supplement",
"Industrial Relations Supplement": "Industrial Relations Supplement",
"Trade Marks Supplement": "Trade Marks Supplement",
"Treaties Supplement": "Treaties Supplement"
}
34 changes: 33 additions & 1 deletion assets/js/algolia-search-landing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
const CATEGORY_INTERNAL_MAPPING = {
"Government Gazette": "Government Gazette",
"Legislative Supplements": "Legislation Supplements",
"Other Supplements": "Other Supplements",
"Advertisements": "Advertisements",
"Appointments": "Appointments",
"Audited Reports": "Audited Reports",
"Cessation of Service": "Cessation of Service",
"Corrigendum": "Corrigendum",
"Death": "Death",
"Dismissals": "Dismissals",
"Leave": "Leave",
"Bankruptcy Act Notice": "Notices (Bankruptcy Act)",
"Companies Act Notice": "Notices (Companies Act)",
"Notices under the Constitution": "Notices (Constitution)",
"Notices under other Acts": "Notices (other Acts)",
"Revocation": "Revocation",
"Tenders": "Tenders",
"Termination of Service": "Termination of Service",
"Vacation of Service": "Vacation of Service",
"Others": "Others",
"Bills Supplement": "Bills Supplement",
"Acts Supplement": "Acts Supplement",
"Subsidiary Legislation Supplement": "Subsidiary Legislation Supplement",
"Revised Acts": "Revised Acts",
"Revised Subsidiary Legislation": "Revised Subsidiary Legislation",
"Government Gazette Supplement": "Government Gazette Supplement",
"Industrial Relations Supplement": "Industrial Relations Supplement",
"Trade Marks Supplement": "Trade Marks Supplement",
"Treaties Supplement": "Treaties Supplement"
}

const searchClient = algoliasearch(
"1V7DZGZJKK",
"0ba2c5f100ff5fd004415e4abbcf9b9c"
Expand Down Expand Up @@ -44,7 +76,7 @@ function createCheckboxes(container, categories, searchCategoryName) {
checkbox.dataset.category = searchCategoryName
const label = document.createElement('label');
label.htmlFor = checkbox.id;
label.textContent = categoryItem;
label.textContent = CATEGORY_INTERNAL_MAPPING[categoryItem];
container.appendChild(itemWrapper)
itemWrapper.appendChild(checkbox);
itemWrapper.appendChild(label);
Expand Down
50 changes: 46 additions & 4 deletions assets/js/algolia-search.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
const CATEGORY_INTERNAL_MAPPING = {
"Government Gazette": "Government Gazette",
"Legislative Supplements": "Legislation Supplements",
"Other Supplements": "Other Supplements",
"Advertisements": "Advertisements",
"Appointments": "Appointments",
"Audited Reports": "Audited Reports",
"Cessation of Service": "Cessation of Service",
"Corrigendum": "Corrigendum",
"Death": "Death",
"Dismissals": "Dismissals",
"Leave": "Leave",
"Bankruptcy Act Notice": "Notices (Bankruptcy Act)",
"Companies Act Notice": "Notices (Companies Act)",
"Notices under the Constitution": "Notices (Constitution)",
"Notices under other Acts": "Notices (other Acts)",
"Revocation": "Revocation",
"Tenders": "Tenders",
"Termination of Service": "Termination of Service",
"Vacation of Service": "Vacation of Service",
"Others": "Others",
"Bills Supplement": "Bills Supplement",
"Acts Supplement": "Acts Supplement",
"Subsidiary Legislation Supplement": "Subsidiary Legislation Supplement",
"Revised Acts": "Revised Acts",
"Revised Subsidiary Legislation": "Revised Subsidiary Legislation",
"Government Gazette Supplement": "Government Gazette Supplement",
"Industrial Relations Supplement": "Industrial Relations Supplement",
"Trade Marks Supplement": "Trade Marks Supplement",
"Treaties Supplement": "Treaties Supplement"
}

const searchClient = algoliasearch(
"1V7DZGZJKK",
"0ba2c5f100ff5fd004415e4abbcf9b9c"
Expand Down Expand Up @@ -131,7 +163,8 @@ search.addWidgets([
// Map all possible values to their corresponding item or a default item with count 0
const orderedItems = categories.map(value => {
if (currentItemsMap.has(value)) {
return currentItemsMap.get(value)
const adjustedMapping = { ...currentItemsMap.get(value), highlighted: CATEGORY_INTERNAL_MAPPING[value] }
return adjustedMapping
} else if (selectedCategories.includes(value)) {
return { highlighted:value, value, label: value, count: 0, isRefined: true }
}
Expand All @@ -158,11 +191,11 @@ search.addWidgets([
const orderedItems = availableSubcategories.map(value => {
const res = currentItemsMap.get(value)
if (currentItemsMap.has(value)) {
return { ...res, highlighted: `${res.count === 0 ? `${value} (No results)` : value}`}
return { ...res, highlighted: `${res.count === 0 ? `${CATEGORY_INTERNAL_MAPPING[value]} (No results)` : CATEGORY_INTERNAL_MAPPING[value]}`}
} else if (selectedSubcategories.includes(value)) {
return { highlighted: `${value} (No results)`, value, label: value, count: 0, isRefined: true }
return { highlighted: `${CATEGORY_INTERNAL_MAPPING[value]} (No results)`, value, label: value, count: 0, isRefined: true }
}
return { highlighted: `${value} (No results)`, value, label: value, count: 0, isRefined: false }
return { highlighted: `${CATEGORY_INTERNAL_MAPPING[value]} (No results)`, value, label: value, count: 0, isRefined: false }
});
return orderedItems;
}
Expand All @@ -177,6 +210,15 @@ search.addWidgets([
cssClasses: {
delete: "currentRefinementsIsomer",
},
transformItems(items) {
return items.map(item => ({
...item,
refinements: item.refinements.map(refinement => ({
...refinement,
label: CATEGORY_INTERNAL_MAPPING[refinement.label] || refinement.label, // Map the label using internalMapping
}))
}));
}
}),
instantsearch.widgets.clearRefinements({
container: "#clear-refinements",
Expand Down

0 comments on commit b3fa12e

Please sign in to comment.