Skip to content

Commit

Permalink
Fix saving values
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Dec 25, 2022
1 parent 26a38ce commit 2b2c7d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions searchlib/components/SearchApp/FacetApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,37 @@ function BoostrapFacetView(props) {
}, [value, filters, field, setFilter, driver]); // searchContext

React.useEffect(() => {
if (!driver.events.plugins.find((plug) => plug.id === 'trackFilters')) {
const { plugins } = driver.events;
const plugId = `trackFilters-${field}`;

if (!plugins.find((plug) => plug.id === plugId)) {
function subscribe(payload) {
const { filters } = driver.state;
const activeValue = filters.find((f) => f.field === field);
if (!activeValue) {
onChange(null);
}
if (!isEqual(activeValue, value)) {
// console.log('onChange', {
// activeValue,
// value,
// filters: driver.state.filters,
// });
onChange(activeValue);
}
}
driver.events.plugins.push({
id: 'trackFilters',
plugins.push({
id: plugId,
subscribe,
});
}

return () => {
driver.events.plugins = driver.events.plugins.filter(
(plug) => plug.id !== 'trackFilters',
);

// handle deleting the facet
// handles deleting the facet
driver._setState({
filters: [
...driver.state.filters.filter((f) => f.field !== field),
Expand Down
1 change: 1 addition & 0 deletions src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function SearchBlockView(props) {
return (
<div>
{mode !== 'view' && 'EEA Semantic Search block'}
{JSON.stringify(data.defaultFilters)}
<Variation
registry={registry}
appName={appName}
Expand Down

0 comments on commit 2b2c7d7

Please sign in to comment.