From 3ad94479c70264011c1bb7f94e53e30cb26a7f23 Mon Sep 17 00:00:00 2001 From: eirikhaugstulen Date: Thu, 7 Dec 2023 21:00:20 +0100 Subject: [PATCH] fix: pr-reviews --- .../useGroupedLinkedEntities.js | 21 ++++++++++--------- .../useRelationships/useRelationships.js | 4 ++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetsRelationship/common/RelationshipsWidget/useGroupedLinkedEntities.js b/src/core_modules/capture-core/components/WidgetsRelationship/common/RelationshipsWidget/useGroupedLinkedEntities.js index 0042150918..095f8e5c8a 100644 --- a/src/core_modules/capture-core/components/WidgetsRelationship/common/RelationshipsWidget/useGroupedLinkedEntities.js +++ b/src/core_modules/capture-core/components/WidgetsRelationship/common/RelationshipsWidget/useGroupedLinkedEntities.js @@ -137,18 +137,19 @@ const getLinkedEntityData = (apiLinkedEntity, relationshipCreatedAt, pendingApiR return null; }; -export const determineLinkedEntity = (fromEntity: ApiLinkedEntity, toEntity: ApiLinkedEntity, sourceId: string) => { - if (fromEntity.trackedEntity?.trackedEntity === sourceId || fromEntity.event?.event === sourceId) { - return toEntity; - } +export const determineLinkedEntity = + (fromEntity: ApiLinkedEntity, toEntity: ApiLinkedEntity, sourceId: string): ApiLinkedEntity | null => { + if (fromEntity.trackedEntity?.trackedEntity === sourceId || fromEntity.event?.event === sourceId) { + return toEntity; + } - if (toEntity.trackedEntity?.trackedEntity === sourceId || toEntity.event?.event === sourceId) { - return fromEntity; - } + if (toEntity.trackedEntity?.trackedEntity === sourceId || toEntity.event?.event === sourceId) { + return fromEntity; + } - log.error(errorCreator('Could not determine linked entity')({ fromEntity, toEntity, sourceId })); - return null; -}; + log.error(errorCreator('Could not determine linked entity')({ fromEntity, toEntity, sourceId })); + return null; + }; export const useGroupedLinkedEntities = ( sourceId: string, diff --git a/src/core_modules/capture-core/components/WidgetsRelationship/common/useRelationships/useRelationships.js b/src/core_modules/capture-core/components/WidgetsRelationship/common/useRelationships/useRelationships.js index 968606fac2..7f626a84c1 100644 --- a/src/core_modules/capture-core/components/WidgetsRelationship/common/useRelationships/useRelationships.js +++ b/src/core_modules/capture-core/components/WidgetsRelationship/common/useRelationships/useRelationships.js @@ -47,6 +47,10 @@ export const useRelationships = ({ entityId, searchMode, relationshipTypes }: Pr const { from, to } = relationship; const apiLinkedEntity = determineLinkedEntity(from, to, entityId); + if (!apiLinkedEntity) { + return acc; + } + if (!relationshipType.bidirectional && apiLinkedEntity === from) { return acc; }