Skip to content

Commit 7db114c

Browse files
refactor: convert routing utils from Flow to TypeScript
- Convert buildUrlQueryString.js to TypeScript with proper parameter types - Convert getLocationQuery.js to TypeScript with any return type for compatibility - Convert useLocationQuery.js to TypeScript hook with any return type - Convert useNavigate.js to TypeScript hook with inferred parameter types - Convert index.js to TypeScript with updated exports - Remove all Flow type annotations and comments - Maintain minimal changes focused only on type conversion - All TypeScript compilation and linting checks pass Co-Authored-By: [email protected] <[email protected]>
1 parent 827b2da commit 7db114c

File tree

5 files changed

+4
-12
lines changed

5 files changed

+4
-12
lines changed

src/core_modules/capture-core/utils/routing/buildUrlQueryString.js renamed to src/core_modules/capture-core/utils/routing/buildUrlQueryString.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// @flow
2-
31
const LOCALE_EN = 'en';
42

5-
export const buildUrlQueryString = (queryArgs: $ReadOnly<{ [id: string]: ?string }>) =>
3+
export const buildUrlQueryString = (queryArgs: Readonly<Record<string, string | null | undefined>>) =>
64
Object
75
.entries(queryArgs)
86
.filter(([, value]) => value != null)
97
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB, LOCALE_EN))
108
.reduce((searchParams, [key, value]) => {
11-
// $FlowFixMe
129
value && searchParams.append(key, value);
1310
return searchParams;
1411
}, new URLSearchParams())

src/core_modules/capture-core/utils/routing/getLocationQuery.js renamed to src/core_modules/capture-core/utils/routing/getLocationQuery.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// @flow
2-
3-
export const getLocationQuery = (): {| [key: string]: string |} => {
1+
export const getLocationQuery = (): any => {
42
const urlSearchParamString = window.location.hash.split('?')[1];
53
return [...new URLSearchParams(urlSearchParamString).entries()].reduce((accParams, [key, value]) => {
64
accParams[key] = value;

src/core_modules/capture-core/utils/routing/index.js renamed to src/core_modules/capture-core/utils/routing/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
export { useLocationQuery } from './useLocationQuery';
32
export { getLocationQuery } from './getLocationQuery';
43
export { buildUrlQueryString } from './buildUrlQueryString';

src/core_modules/capture-core/utils/routing/useLocationQuery.js renamed to src/core_modules/capture-core/utils/routing/useLocationQuery.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// @flow
21
import { useMemo } from 'react';
32
import { useLocation } from 'react-router-dom';
43

5-
export const useLocationQuery = (): { [key: string]: string } => {
4+
export const useLocationQuery = (): any => {
65
const search = useLocation().search;
76
return useMemo(() => [...new URLSearchParams(search).entries()].reduce((accParams, entry) => {
87
accParams[entry[0]] = entry[1];

src/core_modules/capture-core/utils/routing/useNavigate.js renamed to src/core_modules/capture-core/utils/routing/useNavigate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// @flow
21
import { useHistory } from 'react-router-dom';
32

43
export const useNavigate = () => {
54
const history = useHistory();
65

7-
const navigate = (path: string, scrollToTop: boolean = true) => {
6+
const navigate = (path: string, scrollToTop = true) => {
87
history.push(path);
98
if (scrollToTop) {
109
window.scrollTo(0, 0);

0 commit comments

Comments
 (0)