Skip to content

Commit

Permalink
Browse result processing
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Oct 18, 2024
1 parent 8bc7806 commit 1cdb03a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
63 changes: 35 additions & 28 deletions src/common/helpers/search/formatters/authorities.ts
Original file line number Diff line number Diff line change
@@ -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',
},
};
});
5 changes: 5 additions & 0 deletions src/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type AuthorityAsSearchResultDTO = {
[key: string]: string | string[];
};

type AuthorityAsBrowseResultDTO = {
headingRef?: string;
authority?: AuthorityAsSearchResultDTO[];
};

interface IApiClient {
loadSimpleLookupData: (uris: string | string[]) => Promise<LoadSimpleLookupResponseItem[] | undefined>;
}
Expand Down

0 comments on commit 1cdb03a

Please sign in to comment.