Skip to content

Commit

Permalink
Merge pull request #131 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
tiberiuichim committed Apr 17, 2024
2 parents b6af714 + 02471a8 commit 91a6da3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [0.9.3](https://github.com/eea/volto-searchlib/compare/0.9.2...0.9.3) - 17 April 2024

#### :rocket: New Features

- feat: when facet isMulti=false use clearFilters() to clear the filters [laszlocseh - [`b3a797a`](https://github.com/eea/volto-searchlib/commit/b3a797a2790c0e496e1e560bb1ed41dce23af1aa)]

### [0.9.2](https://github.com/eea/volto-searchlib/compare/0.9.1...0.9.2) - 25 March 2024

#### :bug: Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-searchlib",
"version": "0.9.2",
"version": "0.9.3",
"description": "@eeacms/volto-searchlib: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
27 changes: 22 additions & 5 deletions searchlib/components/Facets/ActiveFilters.jsx
Expand Up @@ -3,11 +3,16 @@
import React from 'react';
import { Button, Card } from 'semantic-ui-react';
import { Icon, Term } from '@eeacms/search/components';
import { useSearchContext } from '@eeacms/search/lib/hocs';
import { useAppConfig, useSearchContext } from '@eeacms/search/lib/hocs';

const ActiveFilters = (props) => {
const { onRemove, field } = props;
const { appConfig } = useAppConfig();
const { clearFilters } = useSearchContext();

const filterConfig = appConfig.facets.find(
(f) => (f.id || f.field) === field,
);
const searchContext = useSearchContext();
const { filters = [] } = searchContext;

Expand Down Expand Up @@ -36,11 +41,19 @@ const ActiveFilters = (props) => {
// (v) => v !== option,
// );
// // setActiveFilter(filteredValues);
onRemove(option);
if (!filterConfig.isMulti) {
clearFilters();
} else {
onRemove(option);
}
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
onRemove(option);
if (!filterConfig.isMulti) {
clearFilters();
} else {
onRemove(option);
}
}
}}
>
Expand All @@ -60,7 +73,9 @@ const ActiveFilters = (props) => {
className="clear-btn"
content="Clear all"
onClick={() => {
if (Array.isArray(activeFilter)) {
if (!filterConfig.isMulti) {
clearFilters();
} else if (Array.isArray(activeFilter)) {
(activeFilter || []).forEach((v) => {
onRemove(v);
});
Expand All @@ -70,7 +85,9 @@ const ActiveFilters = (props) => {
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
if (Array.isArray(activeFilter)) {
if (!filterConfig.isMulti) {
clearFilters();
} else if (Array.isArray(activeFilter)) {
(activeFilter || []).forEach((v) => {
onRemove(v);
});
Expand Down
17 changes: 15 additions & 2 deletions searchlib/components/Facets/Unconnected/SingleTermFacet.jsx
Expand Up @@ -3,7 +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 { useAppConfig, useSearchContext } from '@eeacms/search/lib/hocs';

function getFilterValueDisplay(filterValue) {
if (filterValue === undefined || filterValue === null) return '';
Expand Down Expand Up @@ -68,6 +68,11 @@ const SingleTermFacetViewComponent = (props) => {
onSearch,
field,
} = props;
const searchContext = useSearchContext();
const { filters = [] } = searchContext;

const initialValue =
(filters.find((f) => f.field === field) || {})?.values || [];

const { appConfig } = useAppConfig();
const facetConfig = appConfig.facets.find((f) => f.field === field);
Expand All @@ -91,6 +96,13 @@ const SingleTermFacetViewComponent = (props) => {
field,
);

const sortedOptionsAdjusted = sortedOptions.map((item) => {
if (initialValue.includes(item.value)) {
item.selected = true;
}
return item;
});

return (
<fieldset className={cx('sui-facet searchlib-multiterm-facet', className)}>
{/*<legend className="sui-facet__title">{label}</legend>*/}
Expand Down Expand Up @@ -145,7 +157,8 @@ const SingleTermFacetViewComponent = (props) => {
</div>
<Resizable>
<FacetOptions
sortedOptions={sortedOptions}
// sortedOptions={sortedOptions}
sortedOptions={sortedOptionsAdjusted}
label={label}
onSelect={onSelect}
onRemove={onRemove}
Expand Down
7 changes: 5 additions & 2 deletions searchlib/components/FilterList/ActiveFilterValue.jsx
@@ -1,11 +1,12 @@
import React from 'react';
import { useAppConfig } from '@eeacms/search/lib/hocs';
import { useAppConfig, useSearchContext } from '@eeacms/search/lib/hocs';
import { Term } from '@eeacms/search/components';
import { Label, Icon } from 'semantic-ui-react';

const ActiveFilterValue = (props) => {
const { field, values, type, removeFilter } = props;
const { appConfig } = useAppConfig();
const { clearFilters } = useSearchContext();

const filterConfig = appConfig.facets.find(
(f) => (f.id || f.field) === field,
Expand Down Expand Up @@ -37,7 +38,9 @@ const ActiveFilterValue = (props) => {
name="close"
tabIndex={0}
onClick={() => {
if (values.length === 1) {
if (!filterConfig.isMulti) {
clearFilters();
} else if (values.length === 1) {
removeFilter(field, null, type || filterConfig.filterType);
} else {
removeFilter(field, value, type || filterConfig.filterType);
Expand Down
9 changes: 6 additions & 3 deletions searchlib/lib/utils.js
Expand Up @@ -59,7 +59,10 @@ export function applyConfigurationSchema(config) {
config.disjunctiveFacets = [...(config.disjunctiveFacets || [])];
const { facets = [] } = config;
facets.forEach((facet) => {
if (facet.isMulti && !config.disjunctiveFacets.includes(facet.field)) {
if (
facet.factory === 'SingleTermFacet' ||
(facet.isMulti && !config.disjunctiveFacets.includes(facet.field))
) {
config.disjunctiveFacets.push(facet.field);
}
});
Expand Down Expand Up @@ -291,8 +294,8 @@ export function getBuckets({

let filtered_data = blacklist.length
? unfiltered_data.filter(
(bucket) => blacklist.indexOf(bucket.value) === -1,
)
(bucket) => blacklist.indexOf(bucket.value) === -1,
)
: unfiltered_data;

filtered_data = whitelist.length
Expand Down

0 comments on commit 91a6da3

Please sign in to comment.