diff --git a/src/common/helpers/search/formatters/authorities.ts b/src/common/helpers/search/formatters/authorities.ts index 6b1dbb0..4fac6d0 100644 --- a/src/common/helpers/search/formatters/authorities.ts +++ b/src/common/helpers/search/formatters/authorities.ts @@ -1,34 +1,41 @@ import { v4 as uuidv4 } from 'uuid'; export const formatAuthorityItem = ( - authoritiesList: AuthorityAsSearchResultDTO[], + authoritiesList: AuthorityAsSearchResultDTO[] | AuthorityAsBrowseResultDTO[], sourceData?: SourceDataDTO, ): SearchResultsTableRow[] => - authoritiesList?.map( - ({ id = '', authRefType = '', headingRef = '', headingType = '', sourceFileId = '', isAnchor = false }) => { - const sourceLabel = sourceData?.find(({ id: sourceId }) => sourceId === sourceFileId)?.name ?? sourceFileId; + authoritiesList?.map(authorityEntry => { + const selectedEntry = (authorityEntry.authority ?? authorityEntry) as AuthorityAsSearchResultDTO; + const { + id = '', + authRefType = '', + headingRef = '', + headingType = '', + sourceFileId = '', + isAnchor = false, + } = selectedEntry; + const sourceLabel = sourceData?.find(({ id: sourceId }) => sourceId === sourceFileId)?.name ?? sourceFileId; - return { - __meta: { - id, - key: uuidv4(), - isAnchor, - }, - authorized: { - label: authRefType, - }, - title: { - label: headingRef, - className: 'title', - }, - subclass: { - label: headingType, - className: 'heading-type', - }, - authoritySource: { - label: sourceLabel, - className: 'authority-source', - }, - }; - }, - ); + return { + __meta: { + id, + key: uuidv4(), + isAnchor, + }, + authorized: { + label: authRefType, + }, + title: { + label: headingRef, + className: 'title', + }, + subclass: { + label: headingType, + className: 'heading-type', + }, + authoritySource: { + label: sourceLabel, + className: 'authority-source', + }, + }; + }); diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 448495a..ca20eb5 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -59,6 +59,11 @@ type AuthorityAsSearchResultDTO = { [key: string]: string | string[]; }; +type AuthorityAsBrowseResultDTO = { + headingRef?: string; + authority?: AuthorityAsSearchResultDTO[]; +}; + interface IApiClient { loadSimpleLookupData: (uris: string | string[]) => Promise; }