From b02a79fdbce5040b5b0bd6c3f9251a785c314151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katja=20Su=CC=88ss?= Date: Wed, 4 Jan 2023 13:42:35 +0100 Subject: [PATCH] Catch error on non existing subjects field name. Array.isArray(result[subjectsFieldname]) --- src/components/Views/FacetedSearch.jsx | 194 ++++++++++++------------- 1 file changed, 95 insertions(+), 99 deletions(-) diff --git a/src/components/Views/FacetedSearch.jsx b/src/components/Views/FacetedSearch.jsx index f067eca4..bc2b8176 100644 --- a/src/components/Views/FacetedSearch.jsx +++ b/src/components/Views/FacetedSearch.jsx @@ -45,13 +45,16 @@ import { CustomESRequestSerializer } from '../Searchkit/CustomESRequestSerialize import { CustomESResponseSerializer } from '../Searchkit/CustomESResponseSerializer'; import { Results } from '../Searchkit/Results'; -import { flattenESUrlToPath, getObjectFromObjectList, scrollToTarget } from '../helpers'; +import { + flattenESUrlToPath, + getObjectFromObjectList, + scrollToTarget, +} from '../helpers'; import { ElasticSearchHighlights } from './ElasticSearchHighlights'; import StateLogger from '../StateLogger'; import './less/springisnow-volto-searchkit-block.less'; - // TODO Make reviewstatemapping configurable export const ploneSearchApi = (data) => { return new PloneSearchApi({ @@ -89,25 +92,30 @@ const MyResults = (props) => { const OnResults = withState(MyResults); - class _ExtraInfo extends React.Component { render() { - const {result} = this.props; - const extrainfo_fields = getObjectFromObjectList(this.props.currentQueryState.data.extrainfo_fields); - const facet_fields = getObjectFromObjectList(this.props.currentQueryState.data.facet_fields); - let subjectsFieldname = this.props.currentQueryState.data.subjectsFieldname; // "subjects"; + const { result } = this.props; + const extrainfo_fields = getObjectFromObjectList( + this.props.currentQueryState.data.extrainfo_fields, + ); + const facet_fields = getObjectFromObjectList( + this.props.currentQueryState.data.facet_fields, + ); + let subjectsFieldname = this.props.currentQueryState.data?.subjectsFieldname; // "subjects"; return ( {Object.keys(extrainfo_fields).map((extrainfo_key, idx) => { - if (! result[extrainfo_key]) { - console.debug("not indexed:", extrainfo_key) - return + if (!result[extrainfo_key]) { + console.debug('not indexed:', extrainfo_key); + return; } - const extrainfo_value = Array.isArray(result[extrainfo_key]) ? result[extrainfo_key] : [result[extrainfo_key]]; + const extrainfo_value = Array.isArray(result[extrainfo_key]) + ? result[extrainfo_key] + : [result[extrainfo_key]]; return Object.keys(facet_fields).includes(extrainfo_key) ? ( - {extrainfo_fields[extrainfo_key]}: + {extrainfo_fields[extrainfo_key]}: {extrainfo_value?.map((item, index) => { let tito = item.title || item.token; let payloadOfFilter = { @@ -117,7 +125,12 @@ class _ExtraInfo extends React.Component { layout: 'list', page: 1, size: 10, - filters: [[`${extrainfo_key}_agg.inner.${extrainfo_key}_token`, item.token]], + filters: [ + [ + `${extrainfo_key}_agg.inner.${extrainfo_key}_token`, + item.token, + ], + ], }, }; return ( @@ -137,9 +150,8 @@ class _ExtraInfo extends React.Component { )} ) : ( - - {extrainfo_fields[extrainfo_key]}: + {extrainfo_fields[extrainfo_key]}: {extrainfo_value?.map((item, index) => { let tito = item.title || item.token || item; return ( @@ -156,13 +168,11 @@ class _ExtraInfo extends React.Component { ); })} - {result[subjectsFieldname]?.length > 0 ? ( + {Array.isArray(result[subjectsFieldname]) && + result[subjectsFieldname]?.length > 0 ? (
- - : + + : {result[subjectsFieldname]?.map((item, index) => { let tito = item; @@ -195,7 +205,7 @@ class _ExtraInfo extends React.Component {
) : null}
- ) + ); } } @@ -256,9 +266,7 @@ const CustomResultsListItem = (props) => { {truncate(result.description, { length: 200 })} - + { }; const customBucketAggregationValuesElement = (props) => { - const { - bucket, - isSelected, - onFilterClicked, - keyField, - } = props; + const { bucket, keyField, isSelected, onFilterClicked, childAggCmps } = props; const label = bucket.label ? `${bucket.label} (${bucket.doc_count})` : `${keyField} (${bucket.doc_count})`; @@ -386,7 +389,7 @@ const customBucketAggregationValuesElement = (props) => { > {label} - + {childAggCmps} ); }; @@ -396,12 +399,9 @@ const customEmpytResultsElement = (props) => { return (
- +
-