diff --git a/src/common/helpers/bibframe.helper.ts b/src/common/helpers/bibframe.helper.ts index f97d2966..f22b5417 100644 --- a/src/common/helpers/bibframe.helper.ts +++ b/src/common/helpers/bibframe.helper.ts @@ -17,10 +17,10 @@ export const getMappedBFLiteUri = (uri: string | undefined, schema?: Schema, pat path?.forEach(elem => { const schemaElem = schema?.get(elem); - if (!schemaElem || !schemaElem.uri) return; + if (!schemaElem?.uri) return; const mappedUriTyped = mappedUri as BFMapEntry; - const schemaElemUri = schemaElem.uri as string; + const schemaElemUri = schemaElem.uri; const pathUri = mappedUriTyped?.[schemaElemUri]; if (pathUri) { @@ -50,7 +50,7 @@ export const getUris = ({ uri, dataTypeURI, schema, path }: GetUris) => { } const uriBFLite = getMappedBFLiteUri(uri, schema, path); - const uriWithSelector = uriBFLite || uri; + const uriWithSelector = uriBFLite ?? uri; return { uriBFLite, uriWithSelector }; }; diff --git a/src/common/helpers/profile.helper.ts b/src/common/helpers/profile.helper.ts index 5b0e288d..46e7b31d 100644 --- a/src/common/helpers/profile.helper.ts +++ b/src/common/helpers/profile.helper.ts @@ -89,7 +89,7 @@ export const getMappedLookupValue = ({ // Find lookup value in the map const selectedMappedUri = Object.entries(groupTypeMap.data)?.find(([_, value]) => value.uri === uri)?.[0]; - mappedUri = selectedMappedUri || uri; + mappedUri = selectedMappedUri ?? uri; } return mappedUri; @@ -152,7 +152,7 @@ const traverseSchema = ({ uriBFLite, label, basicLabel, - uri: uri || parentUri, + uri: uri ?? parentUri, type: type as AdvancedFieldType, nonBFMappedGroup: updatedNonBFMappedGroup, }); diff --git a/src/common/helpers/record.helper.ts b/src/common/helpers/record.helper.ts index 5480fd39..020ba6e0 100644 --- a/src/common/helpers/record.helper.ts +++ b/src/common/helpers/record.helper.ts @@ -21,7 +21,7 @@ type IGetAdjustedRecordContents = { }; export const getRecordId = (record: RecordEntry | null, selectedBlock?: string, previewBlock?: string) => { - const block = selectedBlock || TYPE_URIS.INSTANCE; + const block = selectedBlock ?? TYPE_URIS.INSTANCE; return previewBlock ? (record?.resource?.[block]?.[previewBlock] as any[])?.[0]?.id : record?.resource?.[block]?.id; }; @@ -159,7 +159,7 @@ export const getRecordTitle = (record: RecordEntry) => { TITLE_CONTAINER_URIS.every(uri => { const selectedTitleContainer = ( - recordContents[block!]?.['http://bibfra.me/vocab/marc/title'] as unknown as Record[] + recordContents[block!]?.['http://bibfra.me/vocab/marc/title'] as unknown as Record[] )?.find(obj => Object.hasOwn(obj, uri)); if (selectedTitleContainer) { diff --git a/src/common/helpers/schema.helper.ts b/src/common/helpers/schema.helper.ts index a7f49c5d..7f9667bf 100644 --- a/src/common/helpers/schema.helper.ts +++ b/src/common/helpers/schema.helper.ts @@ -198,7 +198,7 @@ export const getHtmlIdForEntry = ({ path = [] }: Partial, schema: S const uriSelector = uriBFLite ?? uri; const id = uriSelector ? uriSelector.split(BF_URI_DELIMITER).at(-1) : bfid?.split(BFID_DELIMITER).at(-1); - return [...acc, `${id}${ENTRY_COUNT_DELIMITER}${cloneIndex || 0}`]; + return [...acc, `${id}${ENTRY_COUNT_DELIMITER}${cloneIndex ?? 0}`]; }, [] as string[]) .join(ENTRY_DELIMITER); }; diff --git a/src/common/helpers/search.helper.ts b/src/common/helpers/search.helper.ts index b88e9f31..5f488680 100644 --- a/src/common/helpers/search.helper.ts +++ b/src/common/helpers/search.helper.ts @@ -19,10 +19,10 @@ export const getTitle = (titles: GenericStructDTO[] | undefined) => { export const formatItemSearchInstanceListData = (instanceList: InstanceAsSearchResultDTO[]): Row[] => { return instanceList.map(({ id, titles, identifiers, publications }) => { - // TODO: at the moment, picking the first match/first item in list for display + // at the moment, picking the first match/first item in list for display // this might change depending on requirements - const selectedPublisher = publications?.find(({ name, date }) => name || date); + const selectedPublisher = publications?.find(({ name, date }) => name ?? date); return { __meta: { diff --git a/src/common/helpers/validations.helper.ts b/src/common/helpers/validations.helper.ts index cd0ef73e..8626d71d 100644 --- a/src/common/helpers/validations.helper.ts +++ b/src/common/helpers/validations.helper.ts @@ -34,7 +34,7 @@ export const validateNonNormalizedLccn = (lccn: string) => { const preformatted = lccn.replaceAll(/\s+/g, '').split('/')[0]; - // TODO: try to have a single regexp rule? + // Refactor: try to have a single regexp rule? const passes = regexForNonNormalizedLccn.test(preformatted); // if passes, return string with only digits and letters in it diff --git a/src/common/hooks/useComplexLookup.ts b/src/common/hooks/useComplexLookup.ts index 264ba35a..225a7328 100644 --- a/src/common/hooks/useComplexLookup.ts +++ b/src/common/hooks/useComplexLookup.ts @@ -1,4 +1,4 @@ -import { ChangeEvent, useCallback, useContext, useState } from 'react'; +import { ChangeEvent, useCallback, useState } from 'react'; import { useRecoilState, useRecoilValue, useResetRecoilState } from 'recoil'; import { generateEmptyValueUuid, @@ -8,10 +8,10 @@ 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 { ServicesContext } from '@src/contexts'; import state from '@state'; import { useModalControls } from './useModalControls'; import { useMarcData } from './useMarcData'; +import { useServicesContext } from './useServicesContext'; export const useComplexLookup = ({ entry, @@ -24,7 +24,7 @@ export const useComplexLookup = ({ lookupConfig: ComplexLookupsConfigEntry; onChange: (uuid: string, contents: Array) => void; }) => { - const { selectedEntriesService } = useContext(ServicesContext) as Required; + const { selectedEntriesService } = useServicesContext() as Required; const [localValue, setLocalValue] = useState(value || []); const schema = useRecoilValue(state.config.schema); const marcPreviewMetadata = useRecoilValue(state.data.marcPreviewMetadata); diff --git a/src/common/hooks/useConfig.hook.ts b/src/common/hooks/useConfig.hook.ts index 710a2927..ac8505bf 100644 --- a/src/common/hooks/useConfig.hook.ts +++ b/src/common/hooks/useConfig.hook.ts @@ -1,12 +1,12 @@ -import { useContext, useRef } from 'react'; +import { useRef } from 'react'; import { useRecoilState, useSetRecoilState } from 'recoil'; import { v4 as uuidv4 } from 'uuid'; import state from '@state'; import { fetchProfiles } from '@common/api/profiles.api'; import { PROFILE_NAMES } from '@common/constants/bibframe.constants'; import { getPrimaryEntitiesFromRecord, getRecordTitle } from '@common/helpers/record.helper'; -import { ServicesContext } from '@src/contexts'; import { useProcessedRecordAndSchema } from './useProcessedRecordAndSchema.hook'; +import { useServicesContext } from './useServicesContext'; export type PreviewParams = { singular?: boolean; @@ -20,9 +20,8 @@ type GetProfiles = { }; export const useConfig = () => { - const { schemaCreatorService, userValuesService, selectedEntriesService } = useContext( - ServicesContext, - ) as Required; + const { schemaCreatorService, userValuesService, selectedEntriesService } = + useServicesContext() as Required; const [profiles, setProfiles] = useRecoilState(state.config.profiles); const setSelectedProfile = useSetRecoilState(state.config.selectedProfile); const setUserValues = useSetRecoilState(state.inputs.userValues); @@ -87,7 +86,7 @@ export const useConfig = () => { return { updatedSchema, initKey }; }; - const getProfiles = async ({ record, recordId, previewParams, asClone }: GetProfiles): Promise => { + const getProfiles = async ({ record, recordId, previewParams, asClone }: GetProfiles): Promise => { if (isProcessingProfiles.current && (record || recordId)) return; try { diff --git a/src/common/hooks/useProcessedRecordAndSchema.hook.ts b/src/common/hooks/useProcessedRecordAndSchema.hook.ts index 13cdc5dc..7eb5c183 100644 --- a/src/common/hooks/useProcessedRecordAndSchema.hook.ts +++ b/src/common/hooks/useProcessedRecordAndSchema.hook.ts @@ -1,4 +1,5 @@ -import { useCallback, useContext } from 'react'; +import { useCallback } from 'react'; +import { useSetRecoilState } from 'recoil'; import { useIntl } from 'react-intl'; import { DUPLICATE_RESOURCE_TEMPLATE } from '@common/constants/resourceTemplates.constants'; import { @@ -7,9 +8,10 @@ import { wrapRecordValuesWithCommonContainer, } from '@common/helpers/record.helper'; import { applyIntlToTemplates } from '@common/helpers/recordFormatting.helper'; -import { ServicesContext } from '@src/contexts'; +import { UserNotificationFactory } from '@common/services/userNotification'; +import { StatusType } from '@common/constants/status.constants'; import state from '@state'; -import { useSetRecoilState } from 'recoil'; +import { useServicesContext } from './useServicesContext'; type IGetProcessedRecordAndSchema = { baseSchema: Schema; @@ -20,9 +22,10 @@ type IGetProcessedRecordAndSchema = { export const useProcessedRecordAndSchema = () => { const setRecord = useSetRecoilState(state.inputs.record); + const setStatusMessages = useSetRecoilState(state.status.commonMessages); const { formatMessage } = useIntl(); const { userValuesService, schemaWithDuplicatesService, recordNormalizingService, recordToSchemaMappingService } = - useContext(ServicesContext) as Required; + useServicesContext() as Required; const getProcessedRecordAndSchema = useCallback( async ({ baseSchema, record, userValues, asClone = false }: IGetProcessedRecordAndSchema) => { @@ -67,8 +70,12 @@ export const useProcessedRecordAndSchema = () => { updatedUserValues = userValuesService.getAllValues(); } } catch (error) { - // TODO: display an user error console.error(error); + + setStatusMessages(currentStatus => [ + ...currentStatus, + UserNotificationFactory.createMessage(StatusType.error, 'ld.errorLoadingResource'), + ]); } return { @@ -83,6 +90,7 @@ export const useProcessedRecordAndSchema = () => { recordToSchemaMappingService, schemaWithDuplicatesService, setRecord, + setStatusMessages, userValuesService, ], ); diff --git a/src/common/hooks/useProfileSchema.ts b/src/common/hooks/useProfileSchema.ts index c1fd23ed..afc29d0e 100644 --- a/src/common/hooks/useProfileSchema.ts +++ b/src/common/hooks/useProfileSchema.ts @@ -1,12 +1,9 @@ -import { useContext } from 'react'; import { useRecoilState, useSetRecoilState } from 'recoil'; -import { ServicesContext } from '@src/contexts'; import state from '@state'; +import { useServicesContext } from './useServicesContext'; export const useProfileSchema = () => { - const { selectedEntriesService, schemaWithDuplicatesService } = useContext( - ServicesContext, - ) as Required; + const { selectedEntriesService, schemaWithDuplicatesService } = useServicesContext() as Required; const [schema, setSchema] = useRecoilState(state.config.schema); const setSelectedEntries = useSetRecoilState(state.config.selectedEntries); const setClonePrototypes = useSetRecoilState(state.config.clonePrototypes); diff --git a/src/common/hooks/useRecordControls.ts b/src/common/hooks/useRecordControls.ts index a75d16c9..66994971 100644 --- a/src/common/hooks/useRecordControls.ts +++ b/src/common/hooks/useRecordControls.ts @@ -18,10 +18,10 @@ import { getRecordId, getSelectedRecordBlocks, saveRecordLocally, + getSavedRecord, } from '@common/helpers/record.helper'; import { UserNotificationFactory } from '@common/services/userNotification'; import { PreviewParams, useConfig } from '@common/hooks/useConfig.hook'; -import { getSavedRecord } from '@common/helpers/record.helper'; import { formatRecord } from '@common/helpers/recordFormatting.helper'; import { QueryParams, ROUTES } from '@common/constants/routes.constants'; import { BLOCKS_BFLITE } from '@common/constants/bibframeMapping.constants'; @@ -120,7 +120,6 @@ export const useRecordControls = () => { selectedRecordBlocks: updatedSelectedRecordBlocks, }) as RecordEntry; - // TODO: define a type const recordId = getRecordId(record, selectedRecordBlocks?.block); const shouldPostRecord = !recordId || getRecordId(record) === DEFAULT_RECORD_ID || isClone; @@ -138,7 +137,7 @@ export const useRecordControls = () => { UserNotificationFactory.createMessage(StatusType.success, recordId ? 'ld.rdUpdateSuccess' : 'ld.rdSaveSuccess'), ]); - // TODO: isEdited state update is not immediately reflected in the + // isEdited state update is not immediately reflected in the // blocker component, forcing to block the navigation call below // right before isEdited is set to false, disabling // @@ -163,7 +162,7 @@ export const useRecordControls = () => { if (asRefToNewRecord) { const blocksBfliteKey = ( - searchParams.get(QueryParams.Type) || ResourceType.instance + searchParams.get(QueryParams.Type) ?? ResourceType.instance )?.toUpperCase() as BibframeEntities; const selectedBlock = BLOCKS_BFLITE[blocksBfliteKey]?.uri; diff --git a/src/common/hooks/useSearch.ts b/src/common/hooks/useSearch.ts index 857483b7..52fd01cb 100644 --- a/src/common/hooks/useSearch.ts +++ b/src/common/hooks/useSearch.ts @@ -6,9 +6,9 @@ import { DEFAULT_PAGES_METADATA } from '@common/constants/api.constants'; import { SearchIdentifiers, SearchSegment } from '@common/constants/search.constants'; import { generateSearchParamsState } from '@common/helpers/search.helper'; import { usePagination } from '@common/hooks/usePagination'; +import { useSearchContext } from '@common/hooks/useSearchContext'; +import { useFetchSearchData } from '@common/hooks/useFetchSearchData'; import state from '@state'; -import { useSearchContext } from './useSearchContext'; -import { useFetchSearchData } from './useFetchSearchData'; export const useSearch = () => { const { @@ -49,7 +49,7 @@ export const useSearch = () => { setFacetsBySegments(prevValue => ({ ...prevValue, - [selectedNavigationSegment as string]: { + [selectedNavigationSegment]: { query, searchBy, facets, @@ -139,7 +139,7 @@ export const useSearch = () => { pageMetadataSelectorType: 'prev' | 'next'; }) => { const isInitialPage = pageNumber === 0; - const selectedQuery = (isInitialPage ? query : pageMetadata?.[pageMetadataSelectorType]) || query; + const selectedQuery = (isInitialPage ? query : pageMetadata?.[pageMetadataSelectorType]) ?? query; const baseQuerySelector = isBrowseSearch && !isInitialPage ? baseQuerySelectorType : SearchableIndexQuerySelector.Query; diff --git a/src/common/hooks/useSearchFilterLookupOptions.ts b/src/common/hooks/useSearchFilterLookupOptions.ts index b181fba1..c042725f 100644 --- a/src/common/hooks/useSearchFilterLookupOptions.ts +++ b/src/common/hooks/useSearchFilterLookupOptions.ts @@ -21,9 +21,9 @@ export const useSearchFilterLookupOptions = ({ options = facetValues.reduce((accum, { id, totalRecords }) => { const sourceElem = sourceData?.find(({ id: sourceDataId }) => sourceDataId === id); const selectedLabel = hasMappedSourceData ? sourceElem?.name : id; - const label = selectedLabel?.trim() || formatMessage({ id: 'ld.notSpecified' }); + const label = selectedLabel?.trim() ?? formatMessage({ id: 'ld.notSpecified' }); - // TODO: uncomment when the way to filter the options list is approved + // Uncomment when the way to filter the options list is approved // if (excludedOptions?.includes(id)) return accum; accum.push({ diff --git a/src/common/hooks/useSearchFiltersData.ts b/src/common/hooks/useSearchFiltersData.ts index ab776ed6..aa62b756 100644 --- a/src/common/hooks/useSearchFiltersData.ts +++ b/src/common/hooks/useSearchFiltersData.ts @@ -1,5 +1,7 @@ import { useEffect } from 'react'; import { useRecoilState, useResetRecoilState, useSetRecoilState } from 'recoil'; +import { StatusType } from '@common/constants/status.constants'; +import { UserNotificationFactory } from '@common/services/userNotification'; import * as SearchApi from '@common/api/search.api'; import state from '@state'; @@ -11,6 +13,7 @@ export const useSearchFiltersData = () => { const resetSelectedFacetsGroups = useResetRecoilState(state.search.selectedFacetsGroups); const setFacetsData = useSetRecoilState(state.search.facetsData); const setSourceData = useSetRecoilState(state.search.sourceData); + const setCommonStatus = useSetRecoilState(state.status.commonMessages); useEffect(() => { return resetSelectedFacetsGroups(); @@ -35,8 +38,12 @@ export const useSearchFiltersData = () => { setSourceData(sourceData); } catch (error) { - // TODO: handle error and show notification console.error(error); + + setCommonStatus(currentStatus => [ + ...currentStatus, + UserNotificationFactory.createMessage(StatusType.error, 'ld.errorFetching'), + ]); } }; @@ -47,14 +54,18 @@ export const useSearchFiltersData = () => { try { const facetsQueryParam = updatedSelectedFacetsGroups.join(','); - // TODO: generate query by selected values + // Generate query by selected values const query = DEFAULT_SEARCH_FACETS_QUERY; const response = await SearchApi.getSearchData(url, { facet: facetsQueryParam, query }); setFacetsData(response.facets); } catch (error) { - // TODO: handle error and show notification console.error(error); + + setCommonStatus(currentStatus => [ + ...currentStatus, + UserNotificationFactory.createMessage(StatusType.error, 'ld.errorFetching'), + ]); } }; diff --git a/src/common/hooks/useServicesContext.ts b/src/common/hooks/useServicesContext.ts new file mode 100644 index 00000000..f0c80b3f --- /dev/null +++ b/src/common/hooks/useServicesContext.ts @@ -0,0 +1,6 @@ +import { useContext } from 'react'; +import { ServicesContext } from '@src/contexts'; + +export const useServicesContext = () => { + return useContext(ServicesContext); +}; diff --git a/src/common/hooks/useSimpleLookupData.ts b/src/common/hooks/useSimpleLookupData.ts index 055c2dc5..ee8067e0 100644 --- a/src/common/hooks/useSimpleLookupData.ts +++ b/src/common/hooks/useSimpleLookupData.ts @@ -1,11 +1,10 @@ -import { useContext } from 'react'; import { loadSimpleLookup } from '@common/helpers/api.helper'; import { alphabeticSortLabel } from '@common/helpers/common.helper'; import { filterLookupOptionsByMappedValue, formatLookupOptions } from '@common/helpers/lookupOptions.helper'; -import { ServicesContext } from '@src/contexts'; +import { useServicesContext } from './useServicesContext'; export const useSimpleLookupData = () => { - const { lookupCacheService } = useContext(ServicesContext) as Required; + const { lookupCacheService } = useServicesContext() as Required; const getLookupData = lookupCacheService.getAll; @@ -17,7 +16,7 @@ export const useSimpleLookupData = () => { const formattedLookupData = formatLookupOptions(response, uri); const filteredLookupData = filterLookupOptionsByMappedValue(formattedLookupData, propertyURI); - const sortedLookupData = filteredLookupData?.sort(alphabeticSortLabel); + const sortedLookupData = filteredLookupData?.toSorted(alphabeticSortLabel); lookupCacheService.save?.(uri, sortedLookupData); diff --git a/src/common/services/recordNormalizing/recordProcessingCases.ts b/src/common/services/recordNormalizing/recordProcessingCases.ts index 47a3783c..2057018b 100644 --- a/src/common/services/recordNormalizing/recordProcessingCases.ts +++ b/src/common/services/recordNormalizing/recordProcessingCases.ts @@ -7,7 +7,7 @@ import { export const getLabelUri = (blockKey: string, groupKey: string, fieldKey: string) => { const typedMap = NEW_BF2_TO_BFLITE_MAPPING as BF2BFLiteMap; - return typedMap?.[blockKey]?.[groupKey]?.fields?.[fieldKey]?.label || ''; + return typedMap?.[blockKey]?.[groupKey]?.fields?.[fieldKey]?.label ?? ''; }; export const wrapWithContainer = (record: RecordEntry, blockKey: string, key: string, container: string) => { diff --git a/src/common/services/recordToSchemaMapping/recordToSchemaMapping.service.ts b/src/common/services/recordToSchemaMapping/recordToSchemaMapping.service.ts index f8943cea..c98d150c 100644 --- a/src/common/services/recordToSchemaMapping/recordToSchemaMapping.service.ts +++ b/src/common/services/recordToSchemaMapping/recordToSchemaMapping.service.ts @@ -95,8 +95,8 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { private async processRecordGroup( recordGroupIndex: string, - recordEntry: any, - recordGroup: any, + recordEntry: unknown, + recordGroup: unknown, schemaEntries: SchemaEntry[], containerBf2Uri: string, containerDataTypeUri: string, @@ -186,8 +186,6 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { entry.path.forEach(parentElemKey => { const parentElem = this.updatedSchema?.get(parentElemKey) as SchemaEntry; - // TODO: select a correct block - // TODO: use the mapped values instead of 'uriBFLite' if (parentElem.uriBFLite === this.currentBlockUri) { hasProperBlock = true; } @@ -216,7 +214,6 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { if (entry?.type === AdvancedFieldTypeEnum.dropdownOption) { this.selectedEntriesService.remove(entry.uuid); - // TODO: use the mapped values instead of 'uriBFLite' if (entry.uriBFLite === recordKey) { selectedSchemaEntryUuid = entry.uuid; this.selectedEntriesService.addNew(undefined, entry.uuid); @@ -317,7 +314,7 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { }: { schemaEntry: SchemaEntry; recordKey: string; - recordEntryValue: string | string[] | RecordBasic[]; + recordEntryValue: RecordEntryValue; id?: string; }) { let schemaElemUuid = this.findSchemaUIControl({ @@ -377,12 +374,12 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { data, }: { schemaUiElem: SchemaEntry; - recordEntryValue: string | string[] | RecordBasic[]; + recordEntryValue: RecordEntryValue; id: string | undefined; recordKey: string; labelSelector: string; valueKey: string; - data: string | string[] | RecordBasic[]; + data: RecordEntryValue; }) { let newValueKey = valueKey; let updatedData = data; @@ -451,7 +448,7 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { labelSelector, }: { valueKey: string; - data: string | string[] | RecordBasic[]; + data: RecordEntryValue; fieldUri: string; schemaUiElem: SchemaEntry; id?: string; @@ -493,7 +490,7 @@ export class RecordToSchemaMappingService implements IRecordToSchemaMapping { }: { schemaEntry: SchemaEntry; templates: ResourceTemplateMetadata[]; - value: string | string[] | RecordBasic[]; + value: RecordEntryValue; }) { const isValueArray = Array.isArray(value); diff --git a/src/common/services/schema/schema.service.ts b/src/common/services/schema/schema.service.ts index 9f25aaa4..42348b5d 100644 --- a/src/common/services/schema/schema.service.ts +++ b/src/common/services/schema/schema.service.ts @@ -320,7 +320,6 @@ export class SchemaService implements ISchema { this.schema.set(newUuid, schemaEntry); - // TODO: how to avoid circular references when handling META | HIDE if (type === AdvancedFieldType.group) return; for (const [index, item] of valueTemplateRefs.entries()) { diff --git a/src/common/services/userNotification/userNotification.factory.ts b/src/common/services/userNotification/userNotification.factory.ts index 59550363..1f0cfc43 100644 --- a/src/common/services/userNotification/userNotification.factory.ts +++ b/src/common/services/userNotification/userNotification.factory.ts @@ -9,7 +9,6 @@ const notificationMap = { [Status.warning]: Warning, }; -// TODO: define the default message type const DefaultNotification = Info as unknown as BaseNotification; type notificationTypes = (typeof notificationMap)[StatusType]; diff --git a/src/common/services/userValues/userValueTypes/literal.ts b/src/common/services/userValues/userValueTypes/literal.ts index ad906499..f1ba08d1 100644 --- a/src/common/services/userValues/userValueTypes/literal.ts +++ b/src/common/services/userValues/userValueTypes/literal.ts @@ -6,7 +6,7 @@ export class LiteralUserValueService implements IUserValueType { const typedData = data as string | string[]; return { - uuid: uuid || '', + uuid: uuid ?? '', contents: [{ label: Array.isArray(typedData) ? typedData[0] : typedData }], }; } diff --git a/src/common/services/userValues/userValueTypes/simpleLookup.ts b/src/common/services/userValues/userValueTypes/simpleLookup.ts index 9c854ef8..a58ce28b 100644 --- a/src/common/services/userValues/userValueTypes/simpleLookup.ts +++ b/src/common/services/userValues/userValueTypes/simpleLookup.ts @@ -133,7 +133,7 @@ export class SimpleLookupUserValueService extends UserValueType implements IUser const formattedLookupData = formatLookupOptions(response, this.uri); const filteredLookupData = filterLookupOptionsByMappedValue(formattedLookupData, this.propertyUri); - this.loadedData = filteredLookupData?.sort(alphabeticSortLabel); + this.loadedData = filteredLookupData?.toSorted(alphabeticSortLabel); this.saveLoadedData(); } diff --git a/src/common/services/userValues/userValues.service.ts b/src/common/services/userValues/userValues.service.ts index 3e951094..fc809242 100644 --- a/src/common/services/userValues/userValues.service.ts +++ b/src/common/services/userValues/userValues.service.ts @@ -16,8 +16,8 @@ export class UserValuesService implements IUserValues { constructor( private userValues: UserValues, - private apiClient: IApiClient, - private cacheService: ILookupCacheService, + private readonly apiClient: IApiClient, + private readonly cacheService: ILookupCacheService, ) { this.set(userValues); this.initialize(); @@ -28,7 +28,7 @@ export class UserValuesService implements IUserValues { } async setValue({ type, key, value }: { type: AdvancedFieldType; key: string; value: UserValueDTO }) { - this.type = type as AdvancedFieldType; + this.type = type; this.key = key; this.value = value; diff --git a/src/components/Accordion/Accordion.tsx b/src/components/Accordion/Accordion.tsx index 79dbda4d..89174180 100644 --- a/src/components/Accordion/Accordion.tsx +++ b/src/components/Accordion/Accordion.tsx @@ -1,8 +1,8 @@ import { FC, ReactNode, useState } from 'react'; -import './Accordion.scss'; -import CaretDown from '@src/assets/caret-down.svg?react'; import classNames from 'classnames'; +import CaretDown from '@src/assets/caret-down.svg?react'; import { Button, ButtonType } from '@components/Button'; +import './Accordion.scss'; type Accordion = { id?: string; @@ -15,7 +15,9 @@ type Accordion = { export const Accordion: FC = ({ id, title, groupId, defaultState = false, onToggle, children }) => { const [isOpen, setIsOpen] = useState(defaultState); - const identifier = id || groupId; + const identifier = id ?? groupId; + const togglerTestId = identifier ? `accordion-toggle-${identifier}` : ''; + const contentsTestId = identifier ? `accordion-contents-${identifier}` : ''; const handleVisibilityToggle = () => { const updatedIsOpenState = !isOpen; @@ -26,10 +28,7 @@ export const Accordion: FC = ({ id, title, groupId, defaultState = fa return (
-
+
-
diff --git a/src/components/AdvancedSearchModal/AdvancedSearchModal.tsx b/src/components/AdvancedSearchModal/AdvancedSearchModal.tsx index 0451d94e..bce73fca 100644 --- a/src/components/AdvancedSearchModal/AdvancedSearchModal.tsx +++ b/src/components/AdvancedSearchModal/AdvancedSearchModal.tsx @@ -91,7 +91,7 @@ export const AdvancedSearchModal: FC = memo(({ clearValues }) => { onChangeInput(value, AdvancedSearchInputs.Query, rowIndex)} />