Skip to content

Commit

Permalink
authorities lookup config extended
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Dec 17, 2024
1 parent 90ee588 commit c6a8689
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/common/hooks/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function useApi<T>() {
urlParams,
requestParams: {
method,
headers: { 'content-type': 'application/json' },
...requestParams,
...(typeof body === 'object' && body !== null ? { body: JSON.stringify(body, null, 2) } : {}),
},
Expand Down
24 changes: 12 additions & 12 deletions src/common/hooks/useComplexLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserValueContents>) => void;
}) => {
const { selectedEntriesService } = useServicesContext() as Required<ServicesParams>;
Expand Down Expand Up @@ -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]),
});
};

Expand Down
1 change: 1 addition & 0 deletions src/components/ComplexLookupField/ComplexLookupField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const ComplexLookupField: FC<Props> = ({ value = undefined, id, entry, on
entry,
value,
lookupConfig,
baseLabelType: layout?.baseLabelType,
onChange,
});

Expand Down
6 changes: 3 additions & 3 deletions src/components/ComplexLookupField/configs/Authorities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand Down
5 changes: 5 additions & 0 deletions src/configs/complexLookup/complexLookup.config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions src/types/complexLookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ type ComplexLookupApiEntryConfig = {
[key in SearchSegment]: string;
};
marcPreview?: string;
validation?: string;
};
validationTarget?: Record<string, string>;
sourceKey?: string;
searchQuery: {
filter?: string;
Expand Down

0 comments on commit c6a8689

Please sign in to comment.