-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
332 changed files
with
13,673 additions
and
907 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Cold chain | ||
|
||
### Overview | ||
|
||
Cold chain Domain | ||
|
||
### Intentions | ||
|
||
The intention is that this package is responsible for cold chain domain features: | ||
|
||
- Temperature logs | ||
- Monitoring | ||
- CCE | ||
|
||
### Tips & Things to keep in mind | ||
|
||
### Future considerations |
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,19 @@ | ||
{ | ||
"name": "@openmsupply-client/coldchain", | ||
"version": "0.0.0", | ||
"sideEffects": false, | ||
"private": true, | ||
"main": "./src/index.ts", | ||
"devDependencies": {}, | ||
"scripts": { | ||
"tsc": "tsc", | ||
"eslint": "eslint ./src" | ||
}, | ||
"dependencies": { | ||
"@openmsupply-client/common": "^0.0.1", | ||
"@openmsupply-client/config": "^0.0.0", | ||
"@openmsupply-client/system": "^0.0.0", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0" | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
client/packages/coldchain/src/ColdchainNotification.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,167 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import { | ||
BaseButton, | ||
Box, | ||
RouteBuilder, | ||
TemperatureBreachSortFieldInput, | ||
Typography, | ||
useMatch, | ||
useNavigate, | ||
useUrlQuery, | ||
} from '@openmsupply-client/common'; | ||
import { useFormatDateTime, useTranslation } from '@common/intl'; | ||
import { CircleAlertIcon } from '@common/icons'; | ||
import { alpha, useTheme } from '@common/styles'; | ||
import { AppRoute } from '@openmsupply-client/config'; | ||
import { | ||
TemperatureBreachFragment, | ||
useTemperatureBreach, | ||
} from './Monitoring/api/TemperatureBreach'; | ||
|
||
const Text: React.FC<PropsWithChildren> = ({ children }) => ( | ||
<Typography | ||
component="div" | ||
sx={{ | ||
fontSize: '14px', | ||
display: 'flex', | ||
alignContent: 'center', | ||
flexWrap: 'wrap', | ||
}} | ||
> | ||
{children} | ||
</Typography> | ||
); | ||
|
||
const Separator = () => ( | ||
<Text> | ||
<Typography paddingX={0.5}>|</Typography> | ||
</Text> | ||
); | ||
|
||
const DetailButton = ({ breach }: { breach: TemperatureBreachFragment }) => { | ||
const t = useTranslation('coldchain'); | ||
const navigate = useNavigate(); | ||
const { urlQuery } = useUrlQuery(); | ||
const currentTab = (urlQuery['tab'] as string) ?? ''; | ||
const isColdchain = useMatch( | ||
RouteBuilder.create(AppRoute.Coldchain).addWildCard().build() | ||
); | ||
|
||
if (isColdchain && currentTab === t('label.breaches')) return null; | ||
|
||
return ( | ||
<BaseButton | ||
variant="contained" | ||
style={{ height: 32 }} | ||
onClick={() => | ||
navigate( | ||
RouteBuilder.create(AppRoute.Coldchain) | ||
.addPart(AppRoute.Monitoring) | ||
.addQuery({ tab: t('label.breaches') }) | ||
.addQuery({ | ||
sort: TemperatureBreachSortFieldInput.StartDatetime, | ||
}) | ||
.addQuery({ acknowledged: false }) | ||
.addQuery({ 'sensor.name': breach.sensor?.name ?? '' }) | ||
.build() | ||
) | ||
} | ||
> | ||
{t('button.view-details')} | ||
</BaseButton> | ||
); | ||
}; | ||
const Location = ({ breach }: { breach: TemperatureBreachFragment }) => { | ||
const t = useTranslation('coldchain'); | ||
|
||
if (!breach?.location?.name) return null; | ||
return ( | ||
<> | ||
<Separator /> | ||
{!!breach?.location?.name && ( | ||
<Text> | ||
{t('message.location')} | ||
<b style={{ paddingLeft: 4 }}>{breach.location.name}</b> | ||
</Text> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export const ColdchainNotification = () => { | ||
const theme = useTheme(); | ||
const t = useTranslation('coldchain'); | ||
const { data: breaches } = useTemperatureBreach.document.notifications({ | ||
first: 1, | ||
offset: 0, | ||
sortBy: { key: 'startDatetime', direction: 'desc', isDesc: true }, | ||
filterBy: { acknowledged: false }, | ||
}); | ||
const { localisedDistanceToNow } = useFormatDateTime(); | ||
const breach = breaches?.nodes?.[0]; | ||
|
||
if (!breach) return null; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
borderBottom: '1px solid', | ||
borderBottomColor: 'primary.main', | ||
backgroundColor: alpha(theme.palette.primary.main, 0.075), | ||
flex: '0 0 54px', | ||
display: 'flex', | ||
paddingLeft: 2, | ||
alignContent: 'center', | ||
flexWrap: 'wrap', | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignContent: 'center', | ||
flexWrap: 'wrap', | ||
marginRight: 1, | ||
}} | ||
> | ||
<CircleAlertIcon | ||
fill={theme.palette.error.main} | ||
sx={{ | ||
color: 'background.white', | ||
}} | ||
width={27} | ||
height={27} | ||
/> | ||
</Box> | ||
<Text> | ||
<b> | ||
{t('message.notification-breach-detected', { | ||
time: localisedDistanceToNow(breach.startDatetime), | ||
})} | ||
</b> | ||
</Text> | ||
<Separator /> | ||
<Text> | ||
{t('message.last-temperature', { | ||
temperature: breach.maxOrMinTemperature, | ||
})} | ||
</Text> | ||
<Separator /> | ||
<Text> | ||
{t('message.device')} | ||
<b style={{ paddingLeft: 4 }}>{breach.sensor?.name}</b> | ||
</Text> | ||
<Location breach={breach} /> | ||
<Box | ||
sx={{ | ||
justifyContent: 'flex-end', | ||
display: 'flex', | ||
flex: 1, | ||
marginRight: 2, | ||
height: '32px', | ||
}} | ||
> | ||
<DetailButton breach={breach} /> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
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,19 @@ | ||
import React, { FC } from 'react'; | ||
import { RouteBuilder, Routes, Route } from '@openmsupply-client/common'; | ||
import { AppRoute } from '@openmsupply-client/config'; | ||
import { ListView } from './Sensor/ListView'; | ||
import { ListView as MonitoringListView } from './Monitoring/ListView'; | ||
|
||
export const ColdchainService: FC = () => { | ||
const monitoringRoute = RouteBuilder.create(AppRoute.Monitoring).build(); | ||
const sensorRoute = RouteBuilder.create(AppRoute.Sensors).build(); | ||
|
||
return ( | ||
<Routes> | ||
<Route path={monitoringRoute} element={<MonitoringListView />} /> | ||
<Route path={sensorRoute} element={<ListView />} /> | ||
</Routes> | ||
); | ||
}; | ||
|
||
export default ColdchainService; |
43 changes: 43 additions & 0 deletions
43
client/packages/coldchain/src/Monitoring/ListView/ListView.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,43 @@ | ||
import React, { FC } from 'react'; | ||
import { DetailTabs } from '@common/components'; | ||
import { TemperatureLogList } from './TemperatureLog'; | ||
import { useTranslation } from '@common/intl'; | ||
import { | ||
TemperatureBreachSortFieldInput, | ||
TemperatureLogSortFieldInput, | ||
} from '@openmsupply-client/common'; | ||
import { TemperatureBreachList } from './TemperatureBreach'; | ||
import { TemperatureChart } from './TemperatureChart'; | ||
|
||
export const ListView: FC = () => { | ||
const t = useTranslation('coldchain'); | ||
|
||
const tabs = [ | ||
{ | ||
Component: <TemperatureChart />, | ||
value: t('label.chart'), | ||
sort: { | ||
key: TemperatureLogSortFieldInput.Datetime, | ||
dir: 'desc' as 'desc' | 'asc', | ||
}, | ||
}, | ||
{ | ||
Component: <TemperatureBreachList />, | ||
value: t('label.breaches'), | ||
sort: { | ||
key: TemperatureBreachSortFieldInput.StartDatetime, | ||
dir: 'desc' as 'desc' | 'asc', | ||
}, | ||
}, | ||
{ | ||
Component: <TemperatureLogList />, | ||
value: t('label.log'), | ||
sort: { | ||
key: TemperatureLogSortFieldInput.Datetime, | ||
dir: 'desc' as 'desc' | 'asc', | ||
}, | ||
}, | ||
]; | ||
|
||
return <DetailTabs tabs={tabs} />; | ||
}; |
Oops, something went wrong.