Skip to content

Commit

Permalink
Fixed facet values default sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
zotya committed Dec 18, 2023
1 parent 8867b80 commit 2b8b17c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions searchlib/components/Facets/Unconnected/MultiTermFacet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Icon } from 'semantic-ui-react';
import cx from 'classnames';
import { Resizable, ToggleSort, Term } from '@eeacms/search/components';
import { useSort } from '@eeacms/search/lib/hocs';
import { useAppConfig } from '@eeacms/search/lib/hocs';
// import MultiTypeFacetWrapper from './MultiTypeFacetWrapper';

function getFilterValueDisplay(filterValue) {
Expand Down Expand Up @@ -97,14 +98,27 @@ const MultiTermFacetViewComponent = (props) => {
];

// const sortedOptions = sorted(options, sortOn, sortOrder);
const { appConfig } = useAppConfig();
const facetConfig = appConfig.facets.find((f) => f.field === field);
const configSortOn = facetConfig.sortOn || 'count';
const configSortOrder = facetConfig.sortOrder || 'descending';
debugger;
let defaultSortOrder = {
// each criteria has its own default sort order
count: 'descending',
value: 'ascending',
custom: 'ascending',
};

defaultSortOrder[configSortOn] = configSortOrder;
const { sortedValues: sortedOptions, toggleSort, sorting } = useSort(
options,
['value', 'count'],
{
defaultSortOn: 'count',
defaultSortOrder: 'descending',
defaultSortOn: configSortOn,
defaultSortOrder: defaultSortOrder,
},
field,
);

return (
Expand Down

0 comments on commit 2b8b17c

Please sign in to comment.