Skip to content

Commit

Permalink
Show a console logging when there's facets defined with custom sort b…
Browse files Browse the repository at this point in the history
…ut no custom facet values
  • Loading branch information
tiberiuichim committed Jan 24, 2024
1 parent 3780596 commit fa3988a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions searchlib/lib/hocs/useSort.js
Expand Up @@ -4,7 +4,7 @@ import { useAppConfig } from '@eeacms/search/lib/hocs';

const useSort = (
values,
criterias,
// criterias,
{ defaultSortOn, defaultSortOrder },
field = null, // in case of custom order, we get the facetValues order from field's configuration
) => {
Expand All @@ -27,6 +27,13 @@ const useSort = (
if (sortOn === 'custom') {
const fConfig = appConfig.facets.filter((f) => f.field === field);
const facetValues = fConfig[0].facetValues;
if (!facetValues || facetValues.length === 0) {
// eslint-disable-next-line no-console
console.warn(
'You need to configure the custom facet values for',
field,
);
}

return sortOrder === 'ascending'
? customOrder(options, facetValues, 'ascending')
Expand All @@ -40,10 +47,10 @@ const useSort = (
: 0
: -1
: b[sortOn] > a[sortOn]
? b[sortOn] !== a[sortOn]
? 1
: 0
: -1;
? b[sortOn] !== a[sortOn]
? 1
: 0
: -1;
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion searchlib/lib/utils.js
Expand Up @@ -262,7 +262,7 @@ export const customOrder = (values, facetValues, sortOrder = 'ascending') => {
// facetValues: ['sq', 'bg', ...]
// Return values ordered as in facetValues
let result = [];
for (let value of facetValues) {
for (let value of facetValues || []) {
let item = values.filter((c) => c.value === value)[0];
if (item !== undefined) {
result.push(item);
Expand Down

0 comments on commit fa3988a

Please sign in to comment.