@@ -123,13 +123,16 @@ export function GenericResultView({
123
123
const getField = useCallback (
124
124
( field : string ) => {
125
125
try {
126
- return autoUnwrap (
126
+ const value = autoUnwrap (
127
127
z
128
128
. string ( )
129
- . or ( z . object ( { raw : z . string ( ) } ) )
129
+ . or ( z . number ( ) )
130
+ . or ( z . object ( { raw : z . string ( ) . or ( z . number ( ) ) } ) )
130
131
. optional ( )
131
132
. parse ( result [ field ] )
132
133
)
134
+
135
+ return value ? value + "" : undefined
133
136
} catch ( e ) {
134
137
console . warn ( `Parsing field ${ field } failed` , e )
135
138
return undefined
@@ -141,14 +144,17 @@ export function GenericResultView({
141
144
const getArrayField = useCallback (
142
145
( field : string ) => {
143
146
try {
144
- return autoUnwrapArray (
147
+ const value = autoUnwrapArray < string | number > (
145
148
z
146
149
. string ( )
147
150
. array ( )
151
+ . or ( z . number ( ) . array ( ) )
148
152
. or ( z . object ( { raw : z . string ( ) . array ( ) } ) )
153
+ . or ( z . object ( { raw : z . number ( ) . array ( ) } ) )
149
154
. optional ( )
150
155
. parse ( result [ field ] )
151
156
)
157
+ return value ? value . map ( ( v ) => v + "" ) : [ ]
152
158
} catch ( e ) {
153
159
console . warn ( `Parsing array field ${ field } failed` , e )
154
160
return [ ]
@@ -179,12 +185,14 @@ export function GenericResultView({
179
185
} , [ getField , pidField ] )
180
186
181
187
const title = useMemo ( ( ) => {
182
- return getField ( titleField ?? "name" )
183
- } , [ getField , titleField ] )
188
+ const maybeArray = getArrayOrSingleField ( titleField ?? "name" )
189
+ return Array . isArray ( maybeArray ) ? maybeArray . join ( ", " ) : maybeArray
190
+ } , [ getArrayOrSingleField , titleField ] )
184
191
185
192
const description = useMemo ( ( ) => {
186
- return getField ( descriptionField ?? "description" )
187
- } , [ descriptionField , getField ] )
193
+ const maybeArray = getArrayOrSingleField ( descriptionField ?? "description" )
194
+ return Array . isArray ( maybeArray ) ? maybeArray . join ( "\n\r" ) : maybeArray
195
+ } , [ descriptionField , getArrayOrSingleField ] )
188
196
189
197
const doLocation = useMemo ( ( ) => {
190
198
const value = getField ( digitalObjectLocationField ?? "digitalObjectLocation" )
@@ -203,8 +211,9 @@ export function GenericResultView({
203
211
} , [ getArrayOrSingleField , imageField ] )
204
212
205
213
const identifier = useMemo ( ( ) => {
206
- return getField ( additionalIdentifierField ?? "identifier" )
207
- } , [ getField , additionalIdentifierField ] )
214
+ const maybeArray = getArrayOrSingleField ( additionalIdentifierField ?? "identifier" )
215
+ return Array . isArray ( maybeArray ) ? maybeArray . join ( " - " ) : maybeArray
216
+ } , [ getArrayOrSingleField , additionalIdentifierField ] )
208
217
209
218
const isMetadataFor = useMemo ( ( ) => {
210
219
const val = getArrayOrSingleField ( relatedItemPidsField ?? "isMetadataFor" )
0 commit comments