Skip to content

Commit 68f7091

Browse files
devin-ai-integration[bot]henrik.vadet@dhis2.orghenrikmv
authored
refactor: convert reactQueryHelpers folder from Flow to TypeScript (#4357)
* refactor: convert reactQueryHelpers folder from Flow to TypeScript - Convert all 6 JavaScript files to TypeScript with minimal changes - Remove Flow type annotations and replace with TypeScript equivalents - Update imports to use TypeScript syntax (import type) - Maintain all existing function logic and structure - Update ResourceQuery type to support function-based id properties - Follow existing TypeScript patterns from the codebase Files converted: - reactQueryHelpers.const.js → .ts - query/useMetadataQuery.types.js → .ts - query/useMetadataQuery.js → .ts - query/useApiDataQuery.js → .ts - query/index.js → .ts - index.js → .ts Co-Authored-By: [email protected] <[email protected]> * fix: update ResourceQuery type to be compatible with existing codebase - Use 'any' type for id, data, and params properties to maintain compatibility - Resolves TypeScript compilation errors in converted reactQueryHelpers files - Maintains minimal changes approach as requested Co-Authored-By: [email protected] <[email protected]> * fix: allow optional ResourceQuery in useApiMetadataQuery to handle conditional queries - Update useApiMetadataQuery function signature to accept ResourceQuery | undefined - Add null check in queryFn implementation to return empty object when no query provided - This fixes TypeScript errors in files using conditional query patterns like useRelationshipTypes.ts Co-Authored-By: [email protected] <[email protected]> * fix: update useApiDataQuery to handle optional ResourceQuery parameters - Allow ResourceQuery | undefined parameter type - Add enabled: !!queryObject to prevent queries when queryObject is undefined - Use non-null assertion in queryFn since query is disabled when queryObject is undefined - This should resolve remaining 'Property X does not exist on type {}' errors Co-Authored-By: [email protected] <[email protected]> * fix: return undefined when queryObject is undefined to match React Query disabled query behavior Co-Authored-By: [email protected] <[email protected]> * fix: add enabled flag and remove select function for disabled queries Co-Authored-By: [email protected] <[email protected]> * fix: simplify query functions to return undefined when queryObject is undefined Co-Authored-By: [email protected] <[email protected]> * fix: use enabled flag to prevent query execution when queryObject is undefined Co-Authored-By: [email protected] <[email protected]> * fix: return undefined when queryObject is undefined to resolve TypeScript errors Co-Authored-By: [email protected] <[email protected]> * fix: update Result type to include undefined for disabled queries Co-Authored-By: [email protected] <[email protected]> * fix: ensure enabled flag takes precedence over queryOptions Co-Authored-By: [email protected] <[email protected]> * fix: ts errors --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: henrikmv <[email protected]>
1 parent b7fc969 commit 68f7091

File tree

24 files changed

+150
-129
lines changed

24 files changed

+150
-129
lines changed

src/core_modules/capture-core-utils/types/app-runtime.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ export type QueryParameters = {
99
page?: number
1010
fields?: string | string[]
1111
filter?: string | string[]
12+
[key: string]: any
1213
}
1314
export type QueryVariables = any;
1415

1516
export type ResourceQuery = {
16-
resource: string
17-
id?: string
18-
data?: any
19-
params?: any
17+
resource: string;
18+
id?: any;
19+
data?: any;
20+
params?: any;
2021
};
2122

src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { scopeTypes } from '../../../metaData';
88
import { DiscardDialog } from '../../Dialogs/DiscardDialog.component';
99
import { EnrollmentDataEntry } from '../Enrollment';
1010
import type { Props, PlainProps } from './EnrollmentRegistrationEntry.types';
11+
import type { Enrollment } from '../../../metaData';
1112
import { withSaveHandler } from '../../DataEntry';
1213
import { withLoadingIndicator } from '../../../HOC';
1314
import { InfoIconText } from '../../InfoIconText';
@@ -72,14 +73,14 @@ const EnrollmentRegistrationEntryPlain =
7273
return (
7374
<>
7475
{
75-
scopeType === scopeTypes.TRACKER_PROGRAM && formId && orgUnit &&
76+
scopeType === scopeTypes.TRACKER_PROGRAM && formId && orgUnit && enrollmentMetadata && 'enrollmentForm' in enrollmentMetadata && formFoundation &&
7677
<>
7778
<EnrollmentDataEntry
7879
teiId={teiId}
7980
orgUnit={orgUnit}
8081
programId={selectedScopeId}
8182
formFoundation={formFoundation}
82-
enrollmentMetadata={enrollmentMetadata}
83+
enrollmentMetadata={enrollmentMetadata as Enrollment}
8384
id={id}
8485
onPostProcessErrorMessage={onPostProcessErrorMessage}
8586
onGetUnsavedAttributeValues={() => console.log('onGetUnsavedAttributeValues will be here in the future')}

src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({
3737
dataEntryId: id,
3838
orgUnitId,
3939
teiId,
40-
trackedEntityTypeId: enrollmentMetadata?.trackedEntityType?.id,
40+
trackedEntityTypeId: enrollmentMetadata?.trackedEntityType?.id || undefined,
4141
});
4242

4343
const isUserInteractionInProgress: boolean = useSelector(

src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RenderCustomCardActions } from '../../CardList';
33
import type { SaveForDuplicateCheck } from '../common/TEIAndEnrollment/DuplicateCheckOnSave';
44
import type { ExistingUniqueValueDialogActionsComponent } from '../withErrorMessagePostProcessor';
55
import type { InputAttribute } from './hooks/useFormValues';
6-
import { RenderFoundation, ProgramStage, Enrollment } from '../../../metaData';
6+
import { RenderFoundation, ProgramStage, Enrollment, TeiRegistration } from '../../../metaData';
77
import type { RelatedStageRefPayload } from '../../WidgetRelatedStages';
88
import { relatedStageActions } from '../../WidgetRelatedStages';
99

@@ -14,7 +14,7 @@ type TrackedEntityAttributes = Array<{
1414

1515
export type EnrollmentPayload = {
1616
trackedEntity: string;
17-
trackedEntityType: string;
17+
trackedEntityType?: string;
1818
orgUnit: string;
1919
geometry: any;
2020
attributes: TrackedEntityAttributes;
@@ -82,8 +82,8 @@ type ContainerProps = {
8282
onCancel: () => void;
8383
isUserInteractionInProgress: boolean;
8484
isSavingInProgress: boolean;
85-
enrollmentMetadata: Enrollment;
86-
formFoundation: RenderFoundation;
85+
enrollmentMetadata: Enrollment | TeiRegistration | null;
86+
formFoundation: RenderFoundation | null;
8787
formId: string | null;
8888
saveButtonText: string;
8989
};

src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/hooks/useBuildEnrollmentPayload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type DataEntryReduxConverterProps = {
3535
itemId?: string;
3636
orgUnitId: string;
3737
teiId?: string;
38-
trackedEntityTypeId: string;
38+
trackedEntityTypeId?: string;
3939
};
4040

4141
function getClientValuesForFormData(formValues: Record<string, unknown>, formFoundation: RenderFoundation) {
@@ -181,7 +181,7 @@ export const useBuildEnrollmentPayload = ({
181181
teiWithEnrollment: {
182182
trackedEntity: teiId || generateUID(),
183183
orgUnit: orgUnitId,
184-
trackedEntityType: trackedEntityTypeId,
184+
trackedEntityType: trackedEntityTypeId || undefined,
185185
attributes,
186186
geometry: tetGeometry,
187187
enrollments: [enrollment],

src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/hooks/useLifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const useLifecycle = (
8888
skipDuplicateCheck: !!teiId,
8989
firstStageMetaData,
9090
formId,
91-
enrollmentMetadata,
91+
enrollmentMetadata: scopeType === scopeTypes.TRACKER_PROGRAM ? enrollmentMetadata : null,
9292
formFoundation,
9393
};
9494
};

src/core_modules/capture-core/components/DataEntries/common/ProgramStage/useMetadataForProgramStage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export const useMetadataForProgramStage = ({
7171
);
7272

7373
return {
74-
formFoundation: programStageMetadata?.stageForm,
75-
stage: programStageMetadata,
74+
formFoundation: programStageMetadata?.stageForm ?? null,
75+
stage: programStageMetadata ?? null,
7676
isLoading: isLoading || isIdle,
7777
isError,
7878
};

src/core_modules/capture-core/components/DataEntries/common/TEIAndEnrollment/useMetadataForRegistrationForm/hooks/useDataEntryFormConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const useDataEntryFormConfig = ({ selectedScopeId }: Props) => {
1414
configQuery,
1515
{
1616
enabled: !!selectedScopeId,
17-
select: dataEntryFormConfigQuery => dataEntryFormConfigQuery[selectedScopeId],
17+
select: (dataEntryFormConfigQuery: any) => dataEntryFormConfigQuery[selectedScopeId],
1818
},
1919
);
2020

src/core_modules/capture-core/components/DataEntries/common/TEIAndEnrollment/useMetadataForRegistrationForm/hooks/useTrackedEntityTypeCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ export const useTrackedEntityTypeCollection = ({
6666
);
6767

6868
return {
69-
trackedEntityTypeCollection,
69+
trackedEntityTypeCollection: trackedEntityTypeCollection || null,
7070
};
7171
};

src/core_modules/capture-core/components/MetadataAutoSelectInitializer/hooks/useMetadataAutoSelect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const useMetadataAutoSelect = () => {
4040
if (programs && programs.length === 1) {
4141
paramsToAdd.programId = programs[0].id;
4242
}
43-
if (searchOrgUnits && searchOrgUnits.length === 1) {
43+
if (searchOrgUnits && (searchOrgUnits as any).length === 1) {
4444
paramsToAdd.orgUnitId = searchOrgUnits[0].id;
4545
}
4646

0 commit comments

Comments
 (0)