Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libs/blocks/caas-config/caas-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,10 @@ const FilterPanel = ({ tagsData }) => {
<${Select} label="Filter Location" prop="filterLocation" options=${defaultOptions.filterLocation} />
<${Select} label="Filter logic within each tag panel" prop="filterLogic" options=${defaultOptions.filterLogic} />
<${Select} label="Automatic or Custom Panel" prop="filterBuildPanel" options=${defaultOptions.filterBuildPanel} />
`;
<${Input} label="Categories mapping file (optional)" type="text"
prop="categoriesMappingFile"
value=${context.state.categoriesMappingFile}/>
`;

const FilterBuildPanel = html`
<${FilterOptions}>
Expand Down
20 changes: 20 additions & 0 deletions libs/blocks/caas/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,24 @@ const getFilterArray = async (state, country, lang, strs) => {
return filters;
};

const getCategoryMappings = async (state) => {
if (!state.categoriesMappingFile) return {};
const mappings = await fetch(state.categoriesMappingFile);
if (mappings.ok) {
const json = await mappings.json();
const data = json.data || [];
// Convert array to object keyed by id
return data.reduce((entries, entry) => {
entries[entry.id] = {
label: entry.label,
items: entry.items ? entry.items.split(',').map((item) => item.trim()) : [],
};
return entries;
}, {});
}
return {};
};

async function getLingoSiteLocale(origin, path) {
const host = origin.toLowerCase();
let lingoSiteMapping = {
Expand Down Expand Up @@ -941,6 +959,7 @@ export const getConfig = async (originalState, strs = {}) => {
filters: await getFilterArray(state, country, language, strs),
categories: await getCategoryArray(state, country, language),
filterLogic: state.filterLogic,
categoryMappings: await getCategoryMappings(state) || {},
i18n: {
leftPanel: {
header: strs.filterLeftPanel || 'Refine Your Results',
Expand Down Expand Up @@ -1106,6 +1125,7 @@ export const defaultState = {
filterBuildPanel: 'automatic',
filterLocation: 'left',
filterLogic: 'or',
categoriesMappingFile: '',
filters: [],
filtersCustom: [],
filtersShowEmpty: false,
Expand Down
1 change: 1 addition & 0 deletions test/blocks/caas-config/expectedConfigs/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const defaultConfig = {
showEmptyFilters: false,
filters: [],
filterLogic: 'or',
categoryMappings: {},
i18n: {
leftPanel: {
header: 'Refine Your Results',
Expand Down
3 changes: 3 additions & 0 deletions test/blocks/caas/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ describe('getConfig', () => {
eventFilter: [],
type: 'left',
showEmptyFilters: false,
categoryMappings: {},
categories: [
{
group: 'All Topics',
Expand Down Expand Up @@ -493,6 +494,7 @@ describe('getConfig', () => {
eventFilter: [],
type: 'left',
showEmptyFilters: false,
categoryMappings: {},
categories: [
{
group: 'All Topics',
Expand Down Expand Up @@ -931,6 +933,7 @@ describe('getFloodgateCaasConfig', () => {
eventFilter: [],
type: 'left',
showEmptyFilters: false,
categoryMappings: {},
categories: [
{
group: 'All Topics',
Expand Down
Loading