Skip to content

Commit

Permalink
React components: First working step with language
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed Apr 10, 2024
1 parent 7181cca commit a60c62c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/components/Searchkit/CustomESRequestSerializer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class CustomESRequestSerializer {
this.allowed_content_types = config.allowed_content_types;
this.allowed_review_states = config.allowed_review_states;
this.search_sections = config.search_sections;
this.language = config.language;
}
/**
* Convert Array of filters to Object of filters
Expand Down Expand Up @@ -258,6 +259,11 @@ export class CustomESRequestSerializer {

// Generate terms of global filters
let terms = [];
terms.push({
terms: {
language: [this.language], // TODO language
},
});
this.allowed_content_types?.length > 0 &&
terms.push({
terms: {
Expand Down
1 change: 1 addition & 0 deletions src/components/Searchkit/ESSearchApi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class PloneSearchApi {
allowed_content_types: config.allowed_content_types,
allowed_review_states: config.allowed_review_states,
search_sections: config.search_sections,
language: config.language,
});
this.responseSerializer = new responseSerializerCls({
backend_url: config.backend_url,
Expand Down
6 changes: 4 additions & 2 deletions src/components/Views/FacetedSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import './less/springisnow-volto-searchkit-block.less';
import config from '@plone/volto/registry';

// TODO Make reviewstatemapping configurable
export const ploneSearchApi = (data) => {
export const ploneSearchApi = (data, language='en') => {
const cookies = new Cookies();
const authToken = cookies.get('auth_token');
return new PloneSearchApi({
Expand All @@ -78,6 +78,7 @@ export const ploneSearchApi = (data) => {
allowed_content_types: data.allowed_content_types,
allowed_review_states: data.allowed_review_states,
search_sections: data.search_sections,
language: language,
backend_url: data.backend_url,
frontend_url: data.frontend_url,
// elastic_search_api_url: data.elastic_search_api_url,
Expand Down Expand Up @@ -708,6 +709,7 @@ const FacetedSearch = ({ data, overriddenComponents }) => {
};

// TODO Check if check on client could be made simpler
const language = useSelector((state) => state.intl.locale);
const [isClient, setIsClient] = React.useState(null);
React.useEffect(() => setIsClient(true), []);

Expand All @@ -716,7 +718,7 @@ const FacetedSearch = ({ data, overriddenComponents }) => {
{isClient && (
<OverridableContext.Provider value={overriddenComponents}>
<ReactSearchKit
searchApi={ploneSearchApi(data)}
searchApi={ploneSearchApi(data, language)}
eventListenerEnabled={true}
initialQueryState={{
...initialState,
Expand Down

0 comments on commit a60c62c

Please sign in to comment.