-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(refactor) O3-3326 Patient Search - migrate to use workspace
- Loading branch information
Showing
11 changed files
with
143 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 22 additions & 26 deletions
48
...es/esm-patient-search-app/src/patient-search-overlay/patient-search-overlay.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
packages/esm-patient-search-app/src/patient-search-page/patient-search-page.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/esm-patient-search-app/src/patient-search-workspace/patient-search.workspace.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useConfig, useDebounce } from '@openmrs/esm-framework'; | ||
import React, { useCallback, useState } from 'react'; | ||
import { type PatientSearchConfig } from '../config-schema'; | ||
import PatientSearchBar from '../patient-search-bar/patient-search-bar.component'; | ||
import { PatientSearchContext, type PatientSearchContextProps } from '../patient-search-context'; | ||
import AdvancedPatientSearchComponent from '../patient-search-page/advanced-patient-search.component'; | ||
|
||
export interface PatientSearchWorkspaceProps extends PatientSearchContextProps { | ||
initialQuery?: string; | ||
handleSearchTermUpdated?: (value: string) => void; | ||
} | ||
|
||
/** | ||
* The workspace allows other apps to include patient search functionality. | ||
*/ | ||
const PatientSearchWorkspace: React.FC<PatientSearchWorkspaceProps> = ({ | ||
initialQuery = '', | ||
handleSearchTermUpdated, | ||
nonNavigationSelectPatientAction, | ||
patientClickSideEffect, | ||
}) => { | ||
const { | ||
search: { disableTabletSearchOnKeyUp }, | ||
} = useConfig<PatientSearchConfig>(); | ||
const [searchTerm, setSearchTerm] = useState(initialQuery); | ||
const showSearchResults = Boolean(searchTerm?.trim()); | ||
const debouncedSearchTerm = useDebounce(searchTerm); | ||
|
||
const handleClearSearchTerm = useCallback(() => setSearchTerm(''), [setSearchTerm]); | ||
|
||
const onSearchTermChange = useCallback((value: string) => { | ||
setSearchTerm(value); | ||
handleSearchTermUpdated && handleSearchTermUpdated(value); | ||
}, []); | ||
|
||
return ( | ||
<PatientSearchContext.Provider value={{ nonNavigationSelectPatientAction, patientClickSideEffect }}> | ||
<PatientSearchBar | ||
initialSearchTerm={initialQuery} | ||
onChange={(value) => !disableTabletSearchOnKeyUp && onSearchTermChange(value)} | ||
onClear={handleClearSearchTerm} | ||
onSubmit={onSearchTermChange} | ||
/> | ||
{showSearchResults && <AdvancedPatientSearchComponent query={debouncedSearchTerm} inTabletOrOverlay />} | ||
</PatientSearchContext.Provider> | ||
); | ||
}; | ||
|
||
export default PatientSearchWorkspace; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters