Skip to content

Commit

Permalink
Merge pull request #627 from dhis2/alpha
Browse files Browse the repository at this point in the history
feat: add PWA capabilities
  • Loading branch information
KaiVandivier authored Aug 31, 2021
2 parents 655d9c0 + d2ad1dd commit f4d00b6
Show file tree
Hide file tree
Showing 58 changed files with 17,592 additions and 1,080 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# [7.6.0-alpha.1](https://github.com/dhis2/app-platform/compare/v7.5.1...v7.6.0-alpha.1) (2021-08-31)


### Bug Fixes

* catch errors in completeRecording ([e67ae82](https://github.com/dhis2/app-platform/commit/e67ae821b33990435f3846f3ce933362105520bb))
* check whole URL against filter patterns ([5468114](https://github.com/dhis2/app-platform/commit/5468114e8631610d4e70f6c54a288a62cc7f28c2))
* only return sections with cached data from getCachedSections ([f6242d1](https://github.com/dhis2/app-platform/commit/f6242d1b6b25268f3a0c441060264d584d023afe))
* reopen indexedDB if global state resets ([0aded68](https://github.com/dhis2/app-platform/commit/0aded6846b1f9abc567e44144006cb516516e8b3))
* return true if either cache or idb entry is removed ([43d8001](https://github.com/dhis2/app-platform/commit/43d8001ab2aa6077bb0dc3fbaecb2228399a26e4))
* simplify message payload to be compatible with firefox ([5e5a633](https://github.com/dhis2/app-platform/commit/5e5a633440e1b103669dae3d0b1e8786cde9f96b))


### Features

* add service worker and pwa capabilities ([#550](https://github.com/dhis2/app-platform/issues/550)) ([225069e](https://github.com/dhis2/app-platform/commit/225069e11d924734c5ac2e257af7d5e9185c612a)), closes [#580](https://github.com/dhis2/app-platform/issues/580) [#582](https://github.com/dhis2/app-platform/issues/582) [#592](https://github.com/dhis2/app-platform/issues/592)
* allow RegEx for filter patterns in d2.config.js ([9699330](https://github.com/dhis2/app-platform/commit/96993301f1d3ba4eec719bd2ecf93b72995653ba))
* use new headerbar with online status indicator ([#626](https://github.com/dhis2/app-platform/issues/626)) ([3bd7d37](https://github.com/dhis2/app-platform/commit/3bd7d37d0776dfd44ab583a95ad47734c1302f84))

## [7.5.1](https://github.com/dhis2/app-platform/compare/v7.5.0...v7.5.1) (2021-08-25)


Expand Down
34 changes: 20 additions & 14 deletions adapter/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,44 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-10-08T15:51:57.880Z\n"
"PO-Revision-Date: 2020-10-08T15:51:57.880Z\n"
"POT-Creation-Date: 2021-07-16T13:22:12.456Z\n"
"PO-Revision-Date: 2021-07-16T13:22:12.456Z\n"

msgid "An error occurred in the DHIS2 application."
msgstr ""
msgstr "An error occurred in the DHIS2 application."

msgid "Technical details copied to clipboard"
msgstr "Technical details copied to clipboard"

msgid "Something went wrong"
msgstr ""
msgstr "Something went wrong"

msgid "Refresh to try again"
msgstr ""
msgid "Try again"
msgstr "Try again"

msgid "Hide technical details"
msgstr ""
msgstr "Hide technical details"

msgid "Show technical details"
msgstr ""
msgstr "Show technical details"

msgid "The following information may be requested by technical support."
msgstr ""
msgstr "The following information may be requested by technical support."

msgid "Copy technical details to clipboard"
msgstr "Copy technical details to clipboard"

msgid "Please sign in"
msgstr ""
msgstr "Please sign in"

msgid "Server"
msgstr ""
msgstr "Server"

msgid "Username"
msgstr ""
msgstr "Username"

msgid "Password"
msgstr ""
msgstr "Password"

msgid "Sign in"
msgstr ""
msgstr "Sign in"
5 changes: 3 additions & 2 deletions adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/app-adapter",
"version": "7.5.1",
"version": "7.6.0-alpha.1",
"repository": {
"type": "git",
"url": "https://github.com/amcgee/dhis2-app-platform",
Expand All @@ -21,10 +21,11 @@
"build"
],
"dependencies": {
"@dhis2/pwa": "7.6.0-alpha.1",
"moment": "^2.24.0"
},
"devDependencies": {
"@dhis2/cli-app-scripts": "7.5.1",
"@dhis2/cli-app-scripts": "7.6.0-alpha.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"react": "^16.8",
Expand Down
7 changes: 6 additions & 1 deletion adapter/src/components/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import { useCurrentUserLocale } from '../utils/useLocale.js'
import { Alerts } from './Alerts.js'
import { ErrorBoundary } from './ErrorBoundary.js'
import { LoadingMask } from './LoadingMask.js'
import { styles } from './styles/AppWrapper.style.js'

Expand All @@ -17,7 +18,11 @@ export const AppWrapper = ({ appName, children }) => {
<div className="app-shell-adapter">
<style jsx>{styles}</style>
<HeaderBar appName={appName} />
<div className="app-shell-app">{children}</div>
<div className="app-shell-app">
<ErrorBoundary onRetry={() => window.location.reload()}>
{children}
</ErrorBoundary>
</div>
<Alerts />
</div>
)
Expand Down
123 changes: 123 additions & 0 deletions adapter/src/components/ErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import i18n from '@dhis2/d2-i18n'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import buttonStyles from './styles/Button.style'
import styles from './styles/ErrorBoundary.style'

// In order to avoid using @dhis2/ui components in the error boundary - as anything
// that breaks within it will not be caught properly - we define a component
// with the same styles as Button
const UIButton = ({ children, onClick }) => (
<>
<style jsx>{buttonStyles}</style>
<button onClick={onClick}>{children}</button>
</>
)

UIButton.propTypes = {
children: PropTypes.node.isRequired,
onClick: PropTypes.func.isRequired,
}

const translatedErrorHeading = i18n.t(
'An error occurred in the DHIS2 application.'
)

export class ErrorBoundary extends Component {
constructor(props) {
super(props)
this.state = {
error: null,
errorInfo: null,
drawerOpen: false,
}
this.errorDetailsRef = React.createRef()
}

componentDidCatch(error, errorInfo) {
this.setState({
error,
errorInfo,
})
}

toggleTechInfoDrawer = () => {
this.setState({
drawerOpen: !this.state.drawerOpen,
})
}

handleCopyErrorDetails = () => {
const errorDetails = this.errorDetailsRef.current.textContent
navigator.clipboard.writeText(errorDetails).then(() => {
alert(i18n.t('Technical details copied to clipboard'))
})
}

render() {
const { children, fullscreen, onRetry } = this.props
if (this.state.error) {
return (
<div className={cx('mask', { fullscreen })}>
<style jsx>{styles}</style>
<div className="container">
<h1 className="message">
{i18n.t('Something went wrong')}
</h1>
{onRetry && (
<div className="retry">
<UIButton onClick={onRetry}>
{i18n.t('Try again')}
</UIButton>
</div>
)}
<button
className="drawerToggle"
onClick={this.toggleTechInfoDrawer}
>
{this.state.drawerOpen
? i18n.t('Hide technical details')
: i18n.t('Show technical details')}
</button>
<div
className={cx('drawer', {
hidden: !this.state.drawerOpen,
})}
>
<div className="errorIntro">
<p>{translatedErrorHeading}</p>
<p>
{i18n.t(
'The following information may be requested by technical support.'
)}
</p>
<UIButton onClick={this.handleCopyErrorDetails}>
{i18n.t(
'Copy technical details to clipboard'
)}
</UIButton>
</div>
<pre
className="errorDetails"
ref={this.errorDetailsRef}
>
{`${this.state.error}\n`}
{this.state.error.stack}
{this.state.errorInfo.componentStack}
</pre>
</div>
</div>
</div>
)
}

return children
}
}

ErrorBoundary.propTypes = {
children: PropTypes.node.isRequired,
fullscreen: PropTypes.bool,
onRetry: PropTypes.func,
}
98 changes: 0 additions & 98 deletions adapter/src/components/FatalErrorBoundary.js

This file was deleted.

12 changes: 11 additions & 1 deletion adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { parseServerVersion } from '../utils/parseServerVersion.js'
import { LoadingMask } from './LoadingMask.js'
import { LoginModal } from './LoginModal.js'

export const ServerVersionProvider = ({ url, apiVersion, children }) => {
export const ServerVersionProvider = ({
url,
apiVersion,
offlineInterface,
pwaEnabled,
children,
}) => {
const [{ loading, error, systemInfo }, setState] = useState({
loading: true,
})
Expand Down Expand Up @@ -50,7 +56,9 @@ export const ServerVersionProvider = ({ url, apiVersion, children }) => {
apiVersion: apiVersion || realApiVersion,
serverVersion,
systemInfo,
pwaEnabled,
}}
offlineInterface={offlineInterface}
>
{children}
</Provider>
Expand All @@ -60,5 +68,7 @@ export const ServerVersionProvider = ({ url, apiVersion, children }) => {
ServerVersionProvider.propTypes = {
apiVersion: PropTypes.number,
children: PropTypes.element,
offlineInterface: PropTypes.shape({}),
pwaEnabled: PropTypes.bool,
url: PropTypes.string,
}
Loading

0 comments on commit f4d00b6

Please sign in to comment.