Skip to content

Commit

Permalink
fix: [DHIS2-18569] Relationship widget limited to 50 entries (#3927)
Browse files Browse the repository at this point in the history
* fix: set paging to false

* fix: paging parameter based on version
  • Loading branch information
henrikmv authored Jan 9, 2025
1 parent 5da6126 commit a1e493d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,14 +21,21 @@ type Props = {|
type ReturnData = Array<InputRelationshipData>;

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<ReturnData>(
['relationships', entityId],
Expand Down

0 comments on commit a1e493d

Please sign in to comment.