From a1e493d48179e7749d61f52504fdeb3c11dfa53e Mon Sep 17 00:00:00 2001 From: henrikmv <110386561+henrikmv@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:51:16 +0100 Subject: [PATCH] fix: [DHIS2-18569] Relationship widget limited to 50 entries (#3927) * fix: set paging to false * fix: paging parameter based on version --- .../featuresSupport/support.js | 2 ++ .../useRelationships/useRelationships.js | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/core_modules/capture-core-utils/featuresSupport/support.js b/src/core_modules/capture-core-utils/featuresSupport/support.js index ff5fb4f11a..6c721144d9 100644 --- a/src/core_modules/capture-core-utils/featuresSupport/support.js +++ b/src/core_modules/capture-core-utils/featuresSupport/support.js @@ -11,6 +11,7 @@ export const FEATURES = Object.freeze({ trackedEntitiesCSV: 'trackedEntitiesCSV', newAocApiSeparator: 'newAocApiSeparator', newEntityFilterQueryParam: 'newEntityFilterQueryParam', + newRelationshipQueryParam: 'newRelationshipQueryParam', }); // The first minor version that supports the feature @@ -26,6 +27,7 @@ const MINOR_VERSION_SUPPORT = Object.freeze({ [FEATURES.trackedEntitiesCSV]: 40, [FEATURES.newAocApiSeparator]: 41, [FEATURES.newEntityFilterQueryParam]: 41, + [FEATURES.newRelationshipQueryParam]: 41, }); export const hasAPISupportForFeature = (minorVersion: string | number, featureName: 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 84f3db620e..489d83a8fd 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 @@ -1,6 +1,7 @@ // @flow import { useMemo } from 'react'; import { handleAPIResponse, REQUESTED_ENTITIES } from 'capture-core/utils/api'; +import { featureAvailable, FEATURES } from 'capture-core-utils'; import { useApiDataQuery } from '../../../../utils/reactQueryHelpers'; import type { InputRelationshipData, RelationshipTypes } from '../Types'; import { determineLinkedEntity } from '../RelationshipsWidget/useGroupedLinkedEntities'; @@ -20,14 +21,21 @@ type Props = {| type ReturnData = Array; export const useRelationships = ({ entityId, searchMode, relationshipTypes }: Props) => { - const query = useMemo(() => ({ - resource: 'tracker/relationships', - params: { - // $FlowFixMe - searchMode should be a valid key of RelationshipSearchEntities - [searchMode]: entityId, - fields: 'relationship,relationshipType,createdAt,from[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]],to[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]]', - }, - }), [entityId, searchMode]); + const query = useMemo(() => { + const supportForFeature = featureAvailable(FEATURES.newRelationshipQueryParam); + + return { + resource: 'tracker/relationships', + params: { + // $FlowFixMe - searchMode should be a valid key of RelationshipSearchEntities + [searchMode]: entityId, + fields: 'relationship,relationshipType,createdAt,from[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]],to[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]]', + ...(supportForFeature + ? { paging: false } + : { skipPaging: true }), + }, + }; + }, [entityId, searchMode]); return useApiDataQuery( ['relationships', entityId],