From a3df4438cd0af4f30e9f3702d58858328a5f8641 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Sun, 2 Feb 2025 10:04:56 +0100 Subject: [PATCH] fix: review comments --- .../QuickSelector/Program/EmptyPrograms.js | 10 +++++----- .../OverflowMenu/OverflowMenu.component.js | 7 +++---- src/core_modules/capture-core/flow/typeDeclarations.js | 2 +- src/store/getStore.js | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core_modules/capture-core/components/ScopeSelector/QuickSelector/Program/EmptyPrograms.js b/src/core_modules/capture-core/components/ScopeSelector/QuickSelector/Program/EmptyPrograms.js index 00fd557a79..248e118214 100644 --- a/src/core_modules/capture-core/components/ScopeSelector/QuickSelector/Program/EmptyPrograms.js +++ b/src/core_modules/capture-core/components/ScopeSelector/QuickSelector/Program/EmptyPrograms.js @@ -2,10 +2,10 @@ import React, { useEffect } from 'react'; import { Button, spacers, colors } from '@dhis2/ui'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; import { withStyles } from '@material-ui/core/styles'; import i18n from '@dhis2/d2-i18n'; -import { buildUrlQueryString, useLocationQuery } from '../../../../utils/routing'; +import { useNavigate, buildUrlQueryString, useLocationQuery } from '../../../../utils/routing'; type Props = { onResetOrgUnit: () => void, @@ -24,17 +24,17 @@ const styles = () => ({ }); const EmptyProgramsPlain = ({ onResetOrgUnit, classes }: Props) => { - const { push } = useHistory(); + const { navigate } = useNavigate(); const { pathname } = useLocation(); const { enrollmentId, teiId, orgUnitId } = useLocationQuery(); useEffect(() => { const navigateToEventRegistrationPage = () => { - push(`${pathname}?${buildUrlQueryString({ enrollmentId, teiId, orgUnitId })}`); + navigate(`${pathname}?${buildUrlQueryString({ enrollmentId, teiId, orgUnitId })}`); }; navigateToEventRegistrationPage(); - }, [push, pathname, enrollmentId, teiId, orgUnitId]); + }, [navigate, pathname, enrollmentId, teiId, orgUnitId]); return (
diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/OverflowMenu/OverflowMenu.component.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/OverflowMenu/OverflowMenu.component.js index df12185fec..ad43323159 100644 --- a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/OverflowMenu/OverflowMenu.component.js +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/OverflowMenu/OverflowMenu.component.js @@ -1,6 +1,5 @@ // @flow import React, { useState } from 'react'; -import { useHistory } from 'react-router-dom'; import { Divider, FlyoutMenu, @@ -14,7 +13,7 @@ import i18n from '@dhis2/d2-i18n'; import { ConditionalTooltip } from '../../Tooltips/ConditionalTooltip'; import { OverflowButton } from '../../Buttons'; import { UnlinkModal, UnlinkAndDeleteModal } from './Modal'; -import { buildUrlQueryString } from '../../../utils/routing'; +import { useNavigate, buildUrlQueryString } from '../../../utils/routing'; import type { Props } from './OverflowMenu.types'; import { useRelationshipTypeAccess } from '../hooks'; @@ -26,14 +25,14 @@ export const OverflowMenuComponent = ({ stageWriteAccess, relationshipType, }: Props) => { - const { push } = useHistory(); + const { navigate } = useNavigate(); const [isActionsOpen, setIsActionsOpen] = useState(false); const [isUnlinkModalOpen, setIsUnlinkModalOpen] = useState(false); const [isUnlinkAndDeleteModalOpen, setIsUnlinkAndDeleteModalOpen] = useState(false); const { relationshipTypeWriteAccess } = useRelationshipTypeAccess(relationshipType); const handleViewLinkedEvent = () => { - push(`/enrollmentEventEdit?${buildUrlQueryString({ eventId: linkedEvent.event, orgUnitId })}`); + navigate(`/enrollmentEventEdit?${buildUrlQueryString({ eventId: linkedEvent.event, orgUnitId })}`); setIsActionsOpen(false); }; diff --git a/src/core_modules/capture-core/flow/typeDeclarations.js b/src/core_modules/capture-core/flow/typeDeclarations.js index e9e8d4de10..70058382cd 100644 --- a/src/core_modules/capture-core/flow/typeDeclarations.js +++ b/src/core_modules/capture-core/flow/typeDeclarations.js @@ -210,5 +210,5 @@ declare type ApiUtils = {| mutate: DataEngineMutate, absoluteApiPath: string, serverVersion: { minor: number }, - navigate: (path: string) => void, + navigate: (path: string, scrollToTop?: boolean) => void, |}; diff --git a/src/store/getStore.js b/src/store/getStore.js index 9fdd9ed833..cc4573a26d 100644 --- a/src/store/getStore.js +++ b/src/store/getStore.js @@ -15,7 +15,7 @@ import { reducerDescriptions } from '../reducers/descriptions/trackerCapture.red import { epics } from '../epics/trackerCapture.epics'; export function getStore( - navigate: (path: string) => void, + navigate: (path: string, scrollToTop?: boolean) => void, apiUtils: ApiUtilsWithoutHistory, onRehydrated: () => void) { const reducersFromDescriptions = buildReducersFromDescriptions(reducerDescriptions);