From 2e94f7f2bcd4b060005c8585c8bbf94d71c2dde9 Mon Sep 17 00:00:00 2001 From: Dennis Kigen Date: Tue, 26 Nov 2024 23:35:32 +0300 Subject: [PATCH] (fix) Fix more react hooks exhaustive deps warnings I don't know why these didn't show up in #1380, but they're fixed now. --- .../date-and-time-of-death.component.tsx | 2 +- .../field/dob/dob.component.tsx | 2 +- .../field/name/name-field.component.tsx | 4 +- ...coded-person-attribute-field.component.tsx | 6 +- .../patient-registration-hooks.ts | 38 ++++++------- .../demographics-section.component.tsx | 6 +- .../relationships.resource.tsx | 56 +++++++++---------- .../compact-patient-search.component.tsx | 4 +- .../patient-search-button.component.tsx | 8 +-- .../patient-search.workspace.tsx | 15 +++-- .../src/patient-search.resource.tsx | 13 +++-- .../ward-patient-pending-transfer.tsx | 8 +-- .../src/ward-view/ward.component.tsx | 21 +++++-- .../admit-patient-form.workspace.tsx | 12 ++-- .../cancel-admission-request.workspace.tsx | 26 +++++---- .../patient-discharge.workspace.tsx | 19 ++++--- .../patient-bed-swap-form.component.tsx | 26 +++++---- ...atient-transfer-request-form.component.tsx | 43 +++++++------- .../form/notes-form.component.tsx | 53 ++++++++++-------- 19 files changed, 193 insertions(+), 169 deletions(-) diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx index 0a27740f4..95b04468c 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx @@ -35,7 +35,7 @@ function DeathDateField() { selectedDate ? dayjs(selectedDate).hour(0).minute(0).second(0).millisecond(0).toDate() : undefined, ); }, - [deathDate], + [setFieldValue], ); return ( diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/dob/dob.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/dob/dob.component.tsx index 6599103ec..efbaa6b9b 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/dob/dob.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/dob/dob.component.tsx @@ -41,7 +41,7 @@ export const DobField: React.FC = () => { setFieldValue('monthsEstimated', ''); setFieldTouched('birthdateEstimated', true, false); }, - [setFieldValue], + [setFieldTouched, setFieldValue], ); const onDateChange = useCallback( diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/name/name-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/name/name-field.component.tsx index f2b4e2147..8de9fe809 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/name/name-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/name/name-field.component.tsx @@ -3,9 +3,9 @@ import { useTranslation } from 'react-i18next'; import { ContentSwitcher, Switch } from '@carbon/react'; import { useField } from 'formik'; import { ExtensionSlot, useConfig } from '@openmrs/esm-framework'; +import { type RegistrationConfig } from '../../../config-schema'; import { Input } from '../../input/basic-input/input/input.component'; import { PatientRegistrationContext } from '../../patient-registration-context'; -import { type RegistrationConfig } from '../../../config-schema'; import styles from '../field.scss'; export const unidentifiedPatientAttributeTypeUuid = '8b56eac7-5c76-4b9c-8c6f-1deab8d3fc47'; @@ -51,7 +51,7 @@ export const NameField = () => { setFieldTouched('photo', true, false); } }, - [setCapturePhotoProps], + [setCapturePhotoProps, setFieldTouched], ); const toggleNameKnown = (e) => { diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx index e5b06a050..d72e935cd 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx @@ -3,10 +3,10 @@ import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { Field } from 'formik'; import { Layer, Select, SelectItem } from '@carbon/react'; +import { reportError } from '@openmrs/esm-framework'; import { type PersonAttributeTypeResponse } from '../../patient-registration.types'; import { useConceptAnswers } from '../field.resource'; import styles from './../field.scss'; -import { reportError } from '@openmrs/esm-framework'; export interface CodedPersonAttributeFieldProps { id: string; @@ -44,7 +44,7 @@ export function CodedPersonAttributeField({ ); setError(true); } - }, [answerConceptSetUuid, customConceptAnswers]); + }, [answerConceptSetUuid, customConceptAnswers, id, t]); useEffect(() => { if (!isLoadingConceptAnswers && !customConceptAnswers.length) { @@ -72,7 +72,7 @@ export function CodedPersonAttributeField({ setError(true); } } - }, [isLoadingConceptAnswers, conceptAnswers, customConceptAnswers]); + }, [isLoadingConceptAnswers, conceptAnswers, customConceptAnswers, t, id, answerConceptSetUuid]); const answers = useMemo(() => { if (customConceptAnswers.length) { diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts index ff50d4b20..b89aed9c6 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts @@ -1,14 +1,15 @@ +import { type Dispatch, useEffect, useMemo, useState } from 'react'; import { type FetchResponse, + type OpenmrsResource, getSynchronizationItems, openmrsFetch, - type OpenmrsResource, restBaseUrl, useConfig, usePatient, } from '@openmrs/esm-framework'; import camelCase from 'lodash-es/camelCase'; -import { type Dispatch, useEffect, useMemo, useState } from 'react'; +import dayjs from 'dayjs'; import useSWR from 'swr'; import { v4 } from 'uuid'; import { type RegistrationConfig } from '../config-schema'; @@ -29,7 +30,15 @@ import { latestFirstEncounter, } from './patient-registration-utils'; import { useInitialPatientRelationships } from './section/patient-relationships/relationships.resource'; -import dayjs from 'dayjs'; + +interface DeathInfoResults { + uuid: string; + display: string; + causeOfDeath: OpenmrsResource | null; + dead: boolean; + deathDate: string; + causeOfDeathNonCoded: string | null; +} export function useInitialFormValues(patientUuid: string): [FormValues, Dispatch] { const { freeTextFieldConceptUuid } = useConfig(); @@ -99,7 +108,7 @@ export function useInitialFormValues(patientUuid: string): [FormValues, Dispatch setInitialFormValues(registration._patientRegistrationData.formValues); } })(); - }, [isLoadingPatientToEdit, patientToEdit, patientUuid]); + }, [initialFormValues, isLoadingPatientToEdit, patientToEdit, patientUuid]); // Set initial patient death info useEffect(() => { @@ -118,7 +127,7 @@ export function useInitialFormValues(patientUuid: string): [FormValues, Dispatch nonCodedCauseOfDeath: deathInfo.causeOfDeathNonCoded, })); } - }, [isLoadingDeathInfo, deathInfo, setInitialFormValues]); + }, [isLoadingDeathInfo, deathInfo, setInitialFormValues, freeTextFieldConceptUuid]); // Set initial patient relationships useEffect(() => { @@ -187,7 +196,7 @@ export function useInitialAddressFieldValues(patientUuid: string, fallback = {}) setInitialAddressFieldValues(registration?._patientRegistrationData.initialAddressFieldValues ?? fallback); } })(); - }, [isLoading, patient, patientUuid]); + }, [fallback, initialAddressFieldValues, isLoading, patient, patientUuid]); return [initialAddressFieldValues, setInitialAddressFieldValues]; } @@ -208,7 +217,7 @@ export function usePatientUuidMap( setPatientUuidMap(registration?._patientRegistrationData.initialAddressFieldValues ?? fallback), ); } - }, [isLoadingPatientToEdit, patientToEdit, patientUuid]); + }, [fallback, isLoadingPatientToEdit, patientToEdit, patientUuid, patientUuidMap]); useEffect(() => { if (attributes) { @@ -263,7 +272,7 @@ export function useInitialPatientIdentifiers(patientUuid: string): { data: identifiers, isLoading, }; - }, [data, error]); + }, [data?.data?.results, isLoading]); return result; } @@ -299,19 +308,10 @@ function useInitialPersonAttributes(personUuid: string) { data: data?.data?.results, isLoading, }; - }, [data, error]); + }, [data?.data?.results, isLoading]); return result; } -interface DeathInfoResults { - uuid: string; - display: string; - causeOfDeath: OpenmrsResource | null; - dead: boolean; - deathDate: string; - causeOfDeathNonCoded: string | null; -} - function useInitialPersonDeathInfo(personUuid: string) { const { data, error, isLoading } = useSWR, Error>( !!personUuid @@ -325,7 +325,7 @@ function useInitialPersonDeathInfo(personUuid: string) { data: data?.data, isLoading, }; - }, [data, error]); + }, [data?.data, isLoading]); return result; } diff --git a/packages/esm-patient-registration-app/src/patient-registration/section/demographics/demographics-section.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/section/demographics/demographics-section.component.tsx index 3ab1adb22..cf2e9074e 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/section/demographics/demographics-section.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/section/demographics/demographics-section.component.tsx @@ -1,8 +1,8 @@ import React, { useContext, useEffect } from 'react'; -import styles from './../section.scss'; import { useField } from 'formik'; -import { PatientRegistrationContext } from '../../patient-registration-context'; import { Field } from '../../field/field.component'; +import { PatientRegistrationContext } from '../../patient-registration-context'; +import styles from './../section.scss'; export interface DemographicsSectionProps { fields: Array; @@ -18,7 +18,7 @@ export const DemographicsSection: React.FC = ({ fields setFieldValue('additionalMiddleName', ''); setFieldValue('additionalFamilyName', ''); } - }, [field.value, meta.touched]); + }, [field.value, meta.touched, setFieldValue]); return (
diff --git a/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx b/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx index 643639167..810f374ac 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx @@ -4,6 +4,33 @@ import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-fram import { type RelationshipValue } from '../../patient-registration.types'; import { personRelationshipRepresentation } from '../../../constants'; +export interface Relationship { + display: string; + uuid: string; + personA: { + age: number; + display: string; + birthdate: string; + uuid: string; + }; + personB: { + age: number; + display: string; + birthdate: string; + uuid: string; + }; + relationshipType: { + uuid: string; + display: string; + aIsToB: string; + bIsToA: string; + }; +} + +interface RelationshipsResponse { + results: Array; +} + export function useInitialPatientRelationships(patientUuid: string): { data: Array; isLoading: boolean; @@ -45,34 +72,7 @@ export function useInitialPatientRelationships(patientUuid: string): { error, isLoading, }; - }, [patientUuid, data, error]); + }, [data?.data?.results, error, isLoading, patientUuid]); return result; } - -export interface Relationship { - display: string; - uuid: string; - personA: { - age: number; - display: string; - birthdate: string; - uuid: string; - }; - personB: { - age: number; - display: string; - birthdate: string; - uuid: string; - }; - relationshipType: { - uuid: string; - display: string; - aIsToB: string; - bIsToA: string; - }; -} - -interface RelationshipsResponse { - results: Array; -} diff --git a/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.component.tsx b/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.component.tsx index 7973a5bc9..8e74237d2 100644 --- a/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.component.tsx +++ b/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.component.tsx @@ -96,7 +96,7 @@ const CompactPatientSearchComponent: React.FC = ({ }); } }, - [config.search.patientChartUrl, user, currentLocation], + [addViewedPatientAndCloseSearchResults, config.search.patientChartUrl], ); const focusedResult = useArrowNavigation( !recentPatients ? searchedPatients?.length ?? 0 : recentPatients?.length ?? 0, @@ -134,7 +134,7 @@ const CompactPatientSearchComponent: React.FC = ({ subtitle: errorFetchingUserProperties?.message, }); } - }, [fetchError, errorFetchingUserProperties]); + }, [fetchError, errorFetchingUserProperties, t]); const handleSubmit = useCallback( (debouncedSearchTerm) => { diff --git a/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.component.tsx b/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.component.tsx index 5382abad5..23f63176a 100644 --- a/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.component.tsx +++ b/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.component.tsx @@ -1,7 +1,7 @@ +import React, { useCallback, useEffect } from 'react'; import { Button } from '@carbon/react'; import { Search } from '@carbon/react/icons'; import { launchWorkspace } from '@openmrs/esm-framework'; -import React, { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { type PatientSearchWorkspaceProps } from '../patient-search-workspace/patient-search.workspace'; @@ -37,7 +37,7 @@ const PatientSearchButton: React.FC = ({ }) => { const { t } = useTranslation(); - const launchPatientSearchWorkspace = () => { + const launchPatientSearchWorkspace = useCallback(() => { const workspaceProps: PatientSearchWorkspaceProps = { handleSearchTermUpdated: searchQueryUpdatedAction, initialQuery: searchQuery, @@ -47,13 +47,13 @@ const PatientSearchButton: React.FC = ({ ...workspaceProps, workspaceTitle: overlayHeader, }); - }; + }, [overlayHeader, searchQuery, searchQueryUpdatedAction, selectPatientAction]); useEffect(() => { if (isOpen) { launchPatientSearchWorkspace(); } - }, [isOpen]); + }, [isOpen, launchPatientSearchWorkspace]); return (