generated from METS-Programme/esm-ugandaemr-template-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jabahum/main
ft : add app menu items
- Loading branch information
Showing
57 changed files
with
7,045 additions
and
988 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const mockSession = { | ||
authenticated: true, | ||
user: { | ||
uuid: "82f18b44-6814-11e8-923f-e9a88dcb533f", | ||
display: "admin", | ||
username: "", | ||
systemId: "admin", | ||
userProperties: { | ||
defaultLocale: "en", | ||
loginAttempts: "0", | ||
}, | ||
person: { | ||
uuid: "5f87c042-6814-11e8-923f-e9a88dcb533f", | ||
display: "Super User", | ||
}, | ||
privileges: [], | ||
}, | ||
locale: "en", | ||
allowedLocales: ["en", "es", "fr", "km"], | ||
sessionLocation: { | ||
display: "Unknown Location", | ||
}, | ||
}; |
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,23 @@ | ||
export const mockUser = { | ||
authenticated: true, | ||
user: { | ||
uuid: "uuid", | ||
display: "admin", | ||
person: { uuid: "uuid", display: "Test User" }, | ||
privileges: [], | ||
roles: [{ uuid: "uuid", display: "System Developer" }], | ||
username: "testuser", | ||
userProperties: { | ||
defaultLocale: "fr", | ||
}, | ||
}, | ||
}; | ||
|
||
export const mockLoggedInUser = { | ||
uuid: "uuid", | ||
username: "Dr Healther Morgan", | ||
userProperties: {}, | ||
person: { | ||
display: "Dr Healther Morgan", | ||
}, | ||
}; |
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,38 @@ | ||
import React from "react"; | ||
import { of } from "rxjs"; | ||
|
||
export const useLayoutType = jest.fn(() => "tablet"); | ||
|
||
export function openmrsFetch() { | ||
return new Promise(() => { | ||
console.info("testing"); | ||
}); | ||
} | ||
|
||
export function useOnClickOutside() { | ||
return React.useRef(); | ||
} | ||
|
||
export function getCurrentUser() { | ||
return of({ authenticated: false }); | ||
} | ||
|
||
export function createErrorHandler() { | ||
return true; | ||
} | ||
|
||
export function refetchCurrentUser() { | ||
return Promise.resolve({}); | ||
} | ||
|
||
export const ComponentContext = React.createContext(null); | ||
|
||
export const openmrsComponentDecorator = jest | ||
.fn() | ||
.mockImplementation(() => (component) => component); | ||
|
||
export const Extension = jest.fn().mockImplementation((props: any) => { | ||
return <slot />; | ||
}); | ||
|
||
export const ExtensionSlot = ({ children }) => <>{children}</>; |
141 changes: 141 additions & 0 deletions
141
src/components/app-search-bar/app-search-bar.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import React, { useCallback, useMemo, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Search } from "@carbon/react"; | ||
import styles from "./app-search-bar.scss"; | ||
import MenuItems from "../../menu/menu.component"; | ||
import { | ||
Analytics, | ||
DocumentAdd, | ||
DocumentImport, | ||
Events, | ||
VolumeFileStorage, | ||
HospitalBed, | ||
Medication, | ||
User, | ||
Report, | ||
UserActivity, | ||
} from "@carbon/react/icons"; | ||
|
||
interface AppSearchBarProps { | ||
onChange?: (searchTerm) => void; | ||
onClear: () => void; | ||
onSubmit: (searchTerm) => void; | ||
small?: boolean; | ||
} | ||
|
||
const AppSearchBar = React.forwardRef< | ||
HTMLInputElement, | ||
React.PropsWithChildren<AppSearchBarProps> | ||
>(({ onChange, onClear, onSubmit, small }, ref) => { | ||
const { t } = useTranslation(); | ||
|
||
// items | ||
const openmrsSpaBase = window["getOpenmrsSpaBase"](); | ||
|
||
const initialItems = useMemo(() => { | ||
const items = [ | ||
{ | ||
app: "Data Visualiser", | ||
link: `${openmrsSpaBase}data-visualiser`, | ||
icon: <Analytics size={24} />, | ||
}, | ||
{ | ||
app: "Dispensing ", | ||
link: `${openmrsSpaBase}dispensing`, | ||
icon: <Medication size={24} />, | ||
}, | ||
{ | ||
app: "Stock Management ", | ||
link: `${openmrsSpaBase}stock-management`, | ||
icon: <Report size={24} />, | ||
}, | ||
{ | ||
app: "Bed Management ", | ||
link: `${openmrsSpaBase}bed-management`, | ||
icon: <HospitalBed size={24} />, | ||
}, | ||
{ | ||
app: "Form Builder ", | ||
link: `${openmrsSpaBase}form-builder`, | ||
icon: <DocumentAdd size={24} />, | ||
}, | ||
{ | ||
app: "Form Render Test ", | ||
link: `${openmrsSpaBase}form-render-test`, | ||
icon: <DocumentImport size={24} />, | ||
}, | ||
{ | ||
app: "Legacy Admin ", | ||
link: `/openmrs/admin/index.htm`, | ||
icon: <User size={24} />, | ||
}, | ||
{ | ||
app: "Cohort Builder ", | ||
link: `${openmrsSpaBase}cohort-builder`, | ||
icon: <Events size={24} />, | ||
}, | ||
{ | ||
app: "Theatre ", | ||
link: `${openmrsSpaBase}theatre`, | ||
icon: <UserActivity size={24} />, | ||
}, | ||
{ | ||
app: "System Info ", | ||
link: `${openmrsSpaBase}about`, | ||
icon: <VolumeFileStorage size={24} />, | ||
}, | ||
]; | ||
|
||
return items; | ||
}, [openmrsSpaBase]); | ||
|
||
const [searchTerm, setSearchTerm] = useState(""); | ||
const [items, setItems] = useState(initialItems); | ||
|
||
const handleChange = useCallback( | ||
(val) => { | ||
if (typeof onChange === "function") { | ||
onChange(val); | ||
} | ||
setSearchTerm(val); | ||
const filteredItems = initialItems.filter((item) => | ||
item.app.toLowerCase().includes(val) | ||
); | ||
setItems(filteredItems); | ||
}, | ||
[initialItems, onChange] | ||
); | ||
|
||
const handleSubmit = (evt) => { | ||
evt.preventDefault(); | ||
onSubmit(searchTerm); | ||
}; | ||
|
||
return ( | ||
<> | ||
<form onSubmit={handleSubmit} className={styles.searchArea}> | ||
<Search | ||
autoFocus | ||
className={styles.appSearchInput} | ||
closeButtonLabelText={t("clearSearch", "Clear")} | ||
labelText="" | ||
onChange={(event) => handleChange(event.target.value)} | ||
onClear={onClear} | ||
placeholder={t( | ||
"searchForApp", | ||
"Search for a application or module by name" | ||
)} | ||
size={small ? "sm" : "lg"} | ||
value={searchTerm} | ||
ref={ref} | ||
data-testid="appSearchBar" | ||
/> | ||
</form> | ||
<div className={styles.searchItems}> | ||
<MenuItems items={items} /> | ||
</div> | ||
</> | ||
); | ||
}); | ||
|
||
export default AppSearchBar; |
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,18 @@ | ||
@use '@carbon/styles/scss/colors'; | ||
@use '@carbon/styles/scss/spacing'; | ||
@import '~@openmrs/esm-styleguide/src/vars'; | ||
|
||
.searchArea { | ||
width: inherit; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.appSearchInput { | ||
border: none; | ||
} | ||
|
||
.searchItems { | ||
display: flex; | ||
} |
Oops, something went wrong.