From c6a868988145525a97234a0cb77bf0d7dc53d0b8 Mon Sep 17 00:00:00 2001 From: Siarhei Karol Date: Tue, 17 Dec 2024 12:36:41 +0300 Subject: [PATCH] authorities lookup config extended --- src/common/hooks/useApi.ts | 1 + src/common/hooks/useComplexLookup.ts | 24 +++++++++---------- .../ComplexLookupField/ComplexLookupField.tsx | 1 + .../configs/Authorities.tsx | 6 ++--- .../complexLookup/complexLookup.config.ts | 5 ++++ src/types/complexLookup.d.ts | 2 ++ 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/common/hooks/useApi.ts b/src/common/hooks/useApi.ts index 50838a17..960bada9 100644 --- a/src/common/hooks/useApi.ts +++ b/src/common/hooks/useApi.ts @@ -37,6 +37,7 @@ export function useApi() { urlParams, requestParams: { method, + headers: { 'content-type': 'application/json' }, ...requestParams, ...(typeof body === 'object' && body !== null ? { body: JSON.stringify(body, null, 2) } : {}), }, diff --git a/src/common/hooks/useComplexLookup.ts b/src/common/hooks/useComplexLookup.ts index d39f0e3e..0877fe8a 100644 --- a/src/common/hooks/useComplexLookup.ts +++ b/src/common/hooks/useComplexLookup.ts @@ -8,23 +8,26 @@ import { } from '@common/helpers/complexLookup.helper'; import { __MOCK_URI_CHANGE_WHEN_IMPLEMENTING } from '@common/constants/complexLookup.constants'; import { AdvancedFieldType } from '@common/constants/uiControls.constants'; +import { useInputsState, useMarcPreviewState, useProfileState, useStatusState, useUIState } from '@src/store'; +import { UserNotificationFactory } from '@common/services/userNotification'; +import { StatusType } from '@common/constants/status.constants'; +import { AUTHORITY_ASSIGNMENT_CHECK_API_ENDPOINT } from '@common/constants/api.constants'; import { useModalControls } from './useModalControls'; import { useMarcData } from './useMarcData'; import { useServicesContext } from './useServicesContext'; -import { useInputsState, useMarcPreviewState, useProfileState, useStatusState, useUIState } from '@src/store'; import { useApi } from './useApi'; -import { UserNotificationFactory } from '@common/services/userNotification'; -import { StatusType } from '@common/constants/status.constants'; export const useComplexLookup = ({ entry, value, lookupConfig, + baseLabelType = 'creator', onChange, }: { entry: SchemaEntry; value?: UserValueContents[]; lookupConfig: ComplexLookupsConfigEntry; + baseLabelType?: string; onChange: (uuid: string, contents: Array) => void; }) => { const { selectedEntriesService } = useServicesContext() as Required; @@ -72,16 +75,13 @@ export const useComplexLookup = ({ resetIsMarcPreviewOpen(); }; - const validateMarcRecord = async (marcData: MarcDTO | null) => { - return await makeRequest({ - url: '/linked-data/authority-assignment-check', + const validateMarcRecord = (marcData: MarcDTO | null) => { + const { endpoints, validationTarget } = lookupConfig.api; + + return makeRequest({ + url: endpoints.validation ?? AUTHORITY_ASSIGNMENT_CHECK_API_ENDPOINT, method: 'POST', - body: generateValidationRequestBody(marcData), - requestParams: { - headers: { - 'content-type': 'application/json', - }, - }, + body: generateValidationRequestBody(marcData, validationTarget?.[baseLabelType]), }); }; diff --git a/src/components/ComplexLookupField/ComplexLookupField.tsx b/src/components/ComplexLookupField/ComplexLookupField.tsx index d1897d13..7c792720 100644 --- a/src/components/ComplexLookupField/ComplexLookupField.tsx +++ b/src/components/ComplexLookupField/ComplexLookupField.tsx @@ -30,6 +30,7 @@ export const ComplexLookupField: FC = ({ value = undefined, id, entry, on entry, value, lookupConfig, + baseLabelType: layout?.baseLabelType, onChange, }); diff --git a/src/components/ComplexLookupField/configs/Authorities.tsx b/src/components/ComplexLookupField/configs/Authorities.tsx index 3a2c416d..f4b80271 100644 --- a/src/components/ComplexLookupField/configs/Authorities.tsx +++ b/src/components/ComplexLookupField/configs/Authorities.tsx @@ -16,18 +16,18 @@ export const authoritiesTableConfig: SearchResultsTableConfig = { }, title: { label: 'ld.headingReference', - position: 1, + position: 2, className: 'cell-fixed cell-fixed-370', formatter: TitleFormatter, }, subclass: { label: 'ld.typeOfHeading', - position: 2, + position: 3, className: 'cell-fixed cell-fixed-140', }, authoritySource: { label: 'ld.authoritySource', - position: 3, + position: 4, className: 'cell-fixed cell-fixed-250', }, }, diff --git a/src/configs/complexLookup/complexLookup.config.ts b/src/configs/complexLookup/complexLookup.config.ts index 310ac4b9..d985e627 100644 --- a/src/configs/complexLookup/complexLookup.config.ts +++ b/src/configs/complexLookup/complexLookup.config.ts @@ -1,5 +1,6 @@ import { SearchSegment } from '@common/constants/search.constants'; import { ComplexLookupType, SearchableIndex } from '@common/constants/complexLookup.constants'; +import { AUTHORITY_ASSIGNMENT_CHECK_API_ENDPOINT } from '@common/constants/api.constants'; import { COMPLEX_LOOKUP_FILTERS_CONFIG } from './complexLookupFilters.config'; import { COMPLEX_LOOKUP_SEARCH_BY_CONFIG } from './complexLookupSearchBy.config'; import { COMPLEX_LOOKUP_SEARCHABLE_INDICES_MAP } from './complexLookupSeachableIndicesMap'; @@ -16,6 +17,10 @@ export const COMPLEX_LOOKUPS_CONFIG: ComplexLookupsConfig = { [SearchSegment.Browse]: '/browse/authorities', }, marcPreview: '/source-storage/records/:recordId/formatted?idType=AUTHORITY', + validation: AUTHORITY_ASSIGNMENT_CHECK_API_ENDPOINT, + }, + validationTarget: { + creator: 'CREATOR_OF_WORK', }, sourceKey: 'authoritySourceFiles', searchQuery: { diff --git a/src/types/complexLookup.d.ts b/src/types/complexLookup.d.ts index 3265ff28..3c53718d 100644 --- a/src/types/complexLookup.d.ts +++ b/src/types/complexLookup.d.ts @@ -40,7 +40,9 @@ type ComplexLookupApiEntryConfig = { [key in SearchSegment]: string; }; marcPreview?: string; + validation?: string; }; + validationTarget?: Record; sourceKey?: string; searchQuery: { filter?: string;