File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
packages/discovery-react-components/src
components/SearchResults/components/Result Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -129,10 +129,6 @@ export const Result: React.FunctionComponent<ResultProps> = ({
129129
130130 let title = getDocumentTitle ( result , resultTitleField ) ;
131131
132- if ( Array . isArray ( title ) ) {
133- title = title [ 0 ] ; // only first element will be shown if title is array
134- }
135-
136132 const searchResultClasses = [ searchResultClass ] ;
137133 if ( isEqual ( result , selectedResult . document ) ) {
138134 searchResultClasses . push ( searchResultSelectedClass ) ;
Original file line number Diff line number Diff line change @@ -6,12 +6,23 @@ export const getDocumentTitle = (
66 titleField : string
77) : string => {
88 if ( document ) {
9- return (
9+ let title =
1010 get ( document , titleField ) ||
1111 get ( document , 'extracted_metadata.title' ) ||
1212 get ( document , 'extracted_metadata.filename' ) ||
13- document . document_id
14- ) ;
13+ document . document_id ;
14+ if ( Array . isArray ( title ) ) {
15+ title = title [ 0 ] ; // only first element will be shown if title is array
16+ } else if ( typeof title === 'object' ) {
17+ if ( title . hasOwnProperty ( 'text' ) && typeof get ( title , 'text' ) === 'string' ) {
18+ // if title is an object return 'text' field if it exists
19+ title = get ( title , 'text' ) ;
20+ } else {
21+ // else return toString to prevent the component from crashing
22+ title = title . toString ( ) ;
23+ }
24+ }
25+ return title ;
1526 }
1627 return '' ;
1728} ;
You can’t perform that action at this time.
0 commit comments