Skip to content

Commit 712d33d

Browse files
refactor: convert localeData and portal utils from Flow to TypeScript (#4328)
* refactor: convert localeData and portal utils from Flow to TypeScript - Convert useUserLocale.js to useUserLocale.ts with proper return type annotation - Convert CurrentLocaleData.js to CurrentLocaleData.ts with TypeScript type definitions - Convert usePlacementDomNode.js to usePlacementDomNode.ts with proper React hook types - Convert portal index.js to index.ts - Remove Flow directives and convert Flow types to TypeScript equivalents - Replace Flow Array<T> syntax with TypeScript T[] syntax - Replace Flow Object type with TypeScript any type - Ensure compatibility with existing consuming components All files pass TypeScript compilation (yarn tsc:check) and linting (yarn linter:check). Co-Authored-By: [email protected] <[email protected]> * fix: make CurrentLocaleData static property private to resolve SonarCloud issue - Change static currentData property from public to private - Resolves SonarCloud Code Analysis failure: 'Make this public static property readonly' - Property is accessed through existing getter/setter methods, so private access is appropriate - Maintains existing functionality while improving encapsulation Verified locally with yarn tsc:check and yarn linter:check Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
1 parent bd7e270 commit 712d33d

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/core_modules/capture-core/utils/localeData/CurrentLocaleData.js renamed to src/core_modules/capture-core/utils/localeData/CurrentLocaleData.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// @flow
21
export type LocaleDataType = {
3-
dateFnsLocale: Object,
4-
weekDaysShort: Array<string>,
5-
weekDays: Array<string>,
2+
dateFnsLocale: any,
3+
weekDaysShort: string[],
4+
weekDays: string[],
65
selectDatesText: string,
76
selectDateText: string,
87
calendarFormatHeaderLong: string,
@@ -13,8 +12,7 @@ export type LocaleDataType = {
1312
}
1413

1514
export class CurrentLocaleData {
16-
// $FlowFixMe[missing-annot] automated comment
17-
static currentData;
15+
private static currentData: LocaleDataType;
1816

1917
static set(data: LocaleDataType) {
2018
CurrentLocaleData.currentData = data;

src/core_modules/capture-core/utils/localeData/useUserLocale.js renamed to src/core_modules/capture-core/utils/localeData/useUserLocale.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { useDataEngine } from '@dhis2/app-runtime';
22
import { useQuery } from 'react-query';
33

4-
export const useUserLocale = () => {
4+
export const useUserLocale = (): {
5+
locale: any;
6+
isLoading: boolean;
7+
isError: boolean;
8+
error: unknown;
9+
} => {
510
const dataEngine = useDataEngine();
611

712
const { data, isLoading, isError, error } = useQuery(
@@ -16,7 +21,7 @@ export const useUserLocale = () => {
1621
}));
1722

1823
return {
19-
locale: data?.userSettings?.settings?.keyUiLocale,
24+
locale: (data as any)?.userSettings?.settings?.keyUiLocale,
2025
isLoading,
2126
isError,
2227
error,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// @flow
21
export { usePlacementDomNode } from './usePlacementDomNode';

src/core_modules/capture-core/utils/portal/usePlacementDomNode.js renamed to src/core_modules/capture-core/utils/portal/usePlacementDomNode.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// @flow
21
import { useState, useEffect, useRef } from 'react';
32

43
// Main use case is to get the placement DOM Node when using portals.
54
// The hook ensures a rerender after a reference to the DOMNode has been acquired.
65
export const usePlacementDomNode = () => {
7-
const domRef = useRef<?HTMLElement>();
8-
const [domNode, setDomNode] = useState();
6+
const domRef = useRef<HTMLDivElement>(null);
7+
const [domNode, setDomNode] = useState<HTMLElement>();
98
useEffect(() => {
109
if (domRef.current) {
1110
setDomNode(domRef.current);

0 commit comments

Comments
 (0)