Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support plugin wrappers [LIBS-397] #823

Merged
merged 28 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7fd0605
feat: plugin error handling
tomzemp Feb 6, 2023
7ee8ed6
feat: plugin handling
tomzemp Feb 9, 2023
ac10119
chore: move plugin wrapper logic to app-platform
tomzemp Feb 17, 2023
d40dfba
fix: simplify error reset logic
tomzemp Feb 20, 2023
bd4dccb
fix: pass props with spread operator
tomzemp Feb 24, 2023
5c637c0
fix: merge in master branch of app-platform
tomzemp Mar 8, 2023
d5e17e1
fix: style adapter package file
tomzemp Mar 9, 2023
d4f1ee2
feat: implement plugin wrapper (receiver in plugin) (alpha) (#786)
tomzemp Mar 13, 2023
15ecf4d
chore(release): cut 10.4.0-alpha.1 [skip release]
dhis2-bot Mar 13, 2023
74bbe00
feat: auto resizing for height
tomzemp Mar 29, 2023
a80ea56
fix: auto width adjustment
tomzemp May 16, 2023
3433129
fix: update app-runtime dependencies
tomzemp Jun 16, 2023
78598d4
Merge pull request #810 from dhis2/alpha-update-runtime-deps
tomzemp Jun 16, 2023
b0f4732
chore(release): cut 10.4.0-alpha.2 [skip release]
dhis2-bot Jun 16, 2023
90fef9f
Merge branch 'master' into chore-catch-up-with-master
KaiVandivier Aug 10, 2023
4f5dae9
Merge pull request #813 from dhis2/chore-catch-up-with-master
KaiVandivier Aug 10, 2023
5a7cd50
chore(release): cut 10.4.0-alpha.3 [skip release]
dhis2-bot Aug 10, 2023
9863ae0
fix: clean up dependencies
tomzemp Aug 21, 2023
f6c07cf
fix: use useRef for previous width
tomzemp Aug 22, 2023
6733572
Merge branch 'alpha' into alpha-update
tomzemp Aug 22, 2023
ca24fcc
chore: update alpha branch (#815)
amcgee Aug 22, 2023
bb26b38
chore(release): cut 10.4.0-alpha.4 [skip release]
dhis2-bot Aug 22, 2023
e5c66b8
Merge pull request #814 from dhis2/LIBS-487/auto-dimensions
tomzemp Sep 28, 2023
d3220f0
chore(release): cut 10.4.0-alpha.5 [skip release]
dhis2-bot Sep 28, 2023
16b1a6b
Merge branch 'master' into update-alpha
tomzemp Dec 20, 2023
ec772f6
fix: update alpha [skip release]
tomzemp Dec 20, 2023
e66a8ea
fix: update alpha
tomzemp Dec 21, 2023
da28835
chore(release): cut 10.4.0-alpha.6 [skip release]
dhis2-bot Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
# [10.4.0-alpha.6](https://github.com/dhis2/app-platform/compare/v10.4.0-alpha.5...v10.4.0-alpha.6) (2023-12-21)


### Bug Fixes

* don't open browser for plugins on start [LIBS-503] ([#821](https://github.com/dhis2/app-platform/issues/821)) ([7db7a69](https://github.com/dhis2/app-platform/commit/7db7a69b55d88f681e14e49d4b774e75d7289776))
* update alpha ([e66a8ea](https://github.com/dhis2/app-platform/commit/e66a8ea62c7b30c929f7b5cebab08df3fa4cbf62))
* update alpha [skip release] ([ec772f6](https://github.com/dhis2/app-platform/commit/ec772f655f3160446ab74f523e147d3e129b94a9))

## [10.3.11](https://github.com/dhis2/app-platform/compare/v10.3.10...v10.3.11) (2023-12-11)


### Bug Fixes

* don't open browser for plugins on start [LIBS-503] ([#821](https://github.com/dhis2/app-platform/issues/821)) ([7db7a69](https://github.com/dhis2/app-platform/commit/7db7a69b55d88f681e14e49d4b774e75d7289776))

## [10.3.10](https://github.com/dhis2/app-platform/compare/v10.3.9...v10.3.10) (2023-08-21)
# [10.4.0-alpha.5](https://github.com/dhis2/app-platform/compare/v10.4.0-alpha.4...v10.4.0-alpha.5) (2023-09-28)


### Bug Fixes

* auto width adjustment ([a80ea56](https://github.com/dhis2/app-platform/commit/a80ea56f1cd887e3458af8b6995f3136017fa9c2))
* clean up dependencies ([9863ae0](https://github.com/dhis2/app-platform/commit/9863ae09c72b65e11ce69ba03034ecd2737dacb3))
* use useRef for previous width ([f6c07cf](https://github.com/dhis2/app-platform/commit/f6c07cf222254379c5e7574087a9364507e9cdd1))


### Features

* auto resizing for height ([74bbe00](https://github.com/dhis2/app-platform/commit/74bbe00c0f64364b96b2b5b4fb68830b1d91a016))

# [10.4.0-alpha.4](https://github.com/dhis2/app-platform/compare/v10.4.0-alpha.3...v10.4.0-alpha.4) (2023-08-22)


### Bug Fixes

* support yarn.lock discovery on non-unix ([#811](https://github.com/dhis2/app-platform/issues/811)) ([22a6863](https://github.com/dhis2/app-platform/commit/22a6863c1b4a5d9c6c026c502a1b77dded318be7))

# [10.4.0-alpha.3](https://github.com/dhis2/app-platform/compare/v10.4.0-alpha.2...v10.4.0-alpha.3) (2023-08-10)


### Bug Fixes

* support yarn.lock discovery on non-unix ([#811](https://github.com/dhis2/app-platform/issues/811)) ([22a6863](https://github.com/dhis2/app-platform/commit/22a6863c1b4a5d9c6c026c502a1b77dded318be7))
* move precache route to reenable navigation handler on login redirects [LIBS-473] ([#809](https://github.com/dhis2/app-platform/issues/809)) ([1ff29b6](https://github.com/dhis2/app-platform/commit/1ff29b645ec07e0bcce76efedbc08f1b76014a42))
* **pwa:** avoid crashing when SW is not available [LIBS-499] ([#807](https://github.com/dhis2/app-platform/issues/807)) ([b681022](https://github.com/dhis2/app-platform/commit/b68102248fad98303dd2c01d954f4430b1934a25))
* omit `moment-locales` from precache ([#806](https://github.com/dhis2/app-platform/issues/806)) ([c8d5494](https://github.com/dhis2/app-platform/commit/c8d5494c5eaf6a2f021166d208a1cc289701a47a))
* **cli:** fix envs to fix plugins in dev ([#799](https://github.com/dhis2/app-platform/issues/799)) ([ba29cea](https://github.com/dhis2/app-platform/commit/ba29ceacfe5a25d42a406f80a9896ccbc7bc82f8))
* **plugins:** omit launch paths when unused [LIBS-477] ([#791](https://github.com/dhis2/app-platform/issues/791)) ([e49a51f](https://github.com/dhis2/app-platform/commit/e49a51fec39a323350c71d4e09caff836aab2262))
* **pwa:** bump ui version for headerbar connection status [LIBS-315] ([#797](https://github.com/dhis2/app-platform/issues/797)) ([61ff0a4](https://github.com/dhis2/app-platform/commit/61ff0a49e63189d892403db8df24c57e170dac0a))
* make loading placeholders transparent ([#795](https://github.com/dhis2/app-platform/issues/795)) ([6e64756](https://github.com/dhis2/app-platform/commit/6e64756325b366b413acbdce8dd0d6b70632d118))
* **plugins:** inject precache manifest correctly ([#792](https://github.com/dhis2/app-platform/issues/792)) ([c0d172e](https://github.com/dhis2/app-platform/commit/c0d172ec362182ce978e43b16e9c411ec61e5039))
* **pwa:** add config option to omit files from precache [LIBS-482] ([#793](https://github.com/dhis2/app-platform/issues/793)) ([d089dda](https://github.com/dhis2/app-platform/commit/d089dda25433ca52f84c42c9369fce95419e4f83))

## [10.3.9](https://github.com/dhis2/app-platform/compare/v10.3.8...v10.3.9) (2023-05-16)


Expand Down
10 changes: 5 additions & 5 deletions adapter/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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: 2022-09-22T19:11:17.660Z\n"
"PO-Revision-Date: 2022-09-22T19:11:17.660Z\n"
"POT-Creation-Date: 2023-02-08T14:36:41.461Z\n"
"PO-Revision-Date: 2023-02-08T14:36:41.461Z\n"

msgid "Save your data"
msgstr "Save your data"
Expand Down Expand Up @@ -39,12 +39,12 @@ 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 "Something went wrong"

msgid "Try again"
msgstr "Try again"

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

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

Expand Down
8 changes: 4 additions & 4 deletions adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/app-adapter",
"version": "10.3.11",
"version": "10.4.0-alpha.6",
"repository": {
"type": "git",
"url": "https://github.com/amcgee/dhis2-app-platform",
Expand All @@ -21,11 +21,11 @@
"build"
],
"dependencies": {
"@dhis2/pwa": "10.3.11",
"@dhis2/pwa": "10.4.0-alpha.6",
"moment": "^2.24.0"
},
"devDependencies": {
"@dhis2/cli-app-scripts": "10.3.11",
"@dhis2/cli-app-scripts": "10.4.0-alpha.6",
"@testing-library/react": "^12.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
Expand All @@ -37,7 +37,7 @@
"test": "d2-app-scripts test"
},
"peerDependencies": {
"@dhis2/app-runtime": "^3.5",
"@dhis2/app-runtime": "^3.10.0-alpha.2",
"@dhis2/d2-i18n": "^1",
"@dhis2/ui": ">=8.5",
"classnames": "^2",
Expand Down
29 changes: 27 additions & 2 deletions adapter/src/components/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,39 @@ import { ErrorBoundary } from './ErrorBoundary.js'
import { LoadingMask } from './LoadingMask.js'
import { styles } from './styles/AppWrapper.style.js'

export const AppWrapper = ({ children, plugin }) => {
const AppWrapper = ({ children, plugin, onPluginError, clearPluginError }) => {
const { loading: localeLoading } = useCurrentUserLocale()
const { loading: latestUserLoading } = useVerifyLatestUser()

if (localeLoading || latestUserLoading) {
return <LoadingMask />
}

if (plugin) {
return (
<div className="app-shell-adapter">
<style jsx>{styles}</style>
<div className="app-shell-app">
<ErrorBoundary
plugin={true}
onPluginError={onPluginError}
onRetry={() => {
clearPluginError()
window.location.reload()
}}
>
{children}
</ErrorBoundary>
</div>
<Alerts />
</div>
)
}

return (
<div className="app-shell-adapter">
<style jsx>{styles}</style>
{!plugin && <ConnectedHeaderBar />}
<ConnectedHeaderBar />
<div className="app-shell-app">
<ErrorBoundary onRetry={() => window.location.reload()}>
{children}
Expand All @@ -32,5 +53,9 @@ export const AppWrapper = ({ children, plugin }) => {

AppWrapper.propTypes = {
children: PropTypes.node,
clearPluginError: PropTypes.func,
plugin: PropTypes.bool,
onPluginError: PropTypes.func,
}

export { AppWrapper }
25 changes: 25 additions & 0 deletions adapter/src/components/ErrorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class ErrorBoundary extends Component {
}

componentDidCatch(error, errorInfo) {
if (this.props.plugin) {
if (this.props.onPluginError) {
console.error(error)
this.props.onPluginError(error)
}
}
this.setState({
error,
errorInfo,
Expand All @@ -58,6 +64,23 @@ export class ErrorBoundary extends Component {
render() {
const { children, fullscreen, onRetry } = this.props
if (this.state.error) {
if (this.props.plugin) {
return (
<>
<style jsx>{styles}</style>
<div className="pluginBoundary">
<span>I am the default plugin boundary</span>
{onRetry && (
<div className="retry">
<UIButton onClick={onRetry}>
{i18n.t('Try again')}
</UIButton>
</div>
)}
</div>
</>
)
}
return (
<div className={cx('mask', { fullscreen })}>
<style jsx>{styles}</style>
Expand Down Expand Up @@ -119,5 +142,7 @@ export class ErrorBoundary extends Component {
ErrorBoundary.propTypes = {
children: PropTypes.node.isRequired,
fullscreen: PropTypes.bool,
plugin: PropTypes.bool,
onPluginError: PropTypes.func,
onRetry: PropTypes.func,
}
9 changes: 9 additions & 0 deletions adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const ServerVersionProvider = ({
url, // url from env vars
apiVersion,
pwaEnabled,
plugin,
parentAlertsAdd,
showAlertsInPlugin,
children,
}) => {
const offlineInterface = useOfflineInterface()
Expand Down Expand Up @@ -160,6 +163,9 @@ export const ServerVersionProvider = ({
pwaEnabled,
}}
offlineInterface={offlineInterface}
plugin={plugin}
parentAlertsAdd={parentAlertsAdd}
showAlertsInPlugin={showAlertsInPlugin}
>
{children}
</Provider>
Expand All @@ -171,6 +177,9 @@ ServerVersionProvider.propTypes = {
appVersion: PropTypes.string.isRequired,
apiVersion: PropTypes.number,
children: PropTypes.element,
parentAlertsAdd: PropTypes.func,
plugin: PropTypes.bool,
pwaEnabled: PropTypes.bool,
showAlertsInPlugin: PropTypes.bool,
url: PropTypes.string,
}
11 changes: 10 additions & 1 deletion adapter/src/components/styles/ErrorBoundary.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const bgColor = '#F4F6F8',
primaryTextColor = '#000000',
secondaryTextColor = '#494949',
errorColor = '#D32F2F',
grey050 = '#FBFCFD'
grey050 = '#FBFCFD',
red200 = '#ffcdd2'

export default css`
.mask {
Expand Down Expand Up @@ -100,4 +101,12 @@ export default css`
color: ${errorColor};
font-family: Menlo, Courier, monospace !important;
}

.pluginBoundary {
background-color: ${red200};
}

.pluginBoundary span {
display: inline-block;
}
`
25 changes: 23 additions & 2 deletions adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ const AppAdapter = ({
apiVersion,
pwaEnabled,
plugin,
parentAlertsAdd,
showAlertsInPlugin,
onPluginError,
clearPluginError,
children,
}) => (
<ErrorBoundary fullscreen onRetry={checkForSWUpdateAndReload}>
<ErrorBoundary
plugin={plugin}
fullscreen
onRetry={checkForSWUpdateAndReload}
>
<OfflineInterfaceProvider>
<PWALoadingBoundary>
<ServerVersionProvider
Expand All @@ -25,8 +33,17 @@ const AppAdapter = ({
url={url}
apiVersion={apiVersion}
pwaEnabled={pwaEnabled}
plugin={plugin}
parentAlertsAdd={parentAlertsAdd}
showAlertsInPlugin={showAlertsInPlugin}
>
<AppWrapper plugin={plugin}>{children}</AppWrapper>
<AppWrapper
plugin={plugin}
onPluginError={onPluginError}
clearPluginError={clearPluginError}
>
{children}
</AppWrapper>
</ServerVersionProvider>
</PWALoadingBoundary>
</OfflineInterfaceProvider>
Expand All @@ -38,9 +55,13 @@ AppAdapter.propTypes = {
appVersion: PropTypes.string.isRequired,
apiVersion: PropTypes.number,
children: PropTypes.element,
clearPluginError: PropTypes.func,
parentAlertsAdd: PropTypes.func,
plugin: PropTypes.bool,
pwaEnabled: PropTypes.bool,
showAlertsInPlugin: PropTypes.func,
url: PropTypes.string,
onPluginError: PropTypes.func,
}

export default AppAdapter
1 change: 1 addition & 0 deletions cli/config/plugin.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = ({ env: webpackEnv, config, paths }) => {

const shellEnv = getShellEnv({
plugin: 'true',
requiredProps: config.requiredProps ? config.requiredProps.join() : '',
name: config.title,
...getPWAEnvVars(config),
})
Expand Down
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/cli-app-scripts",
"version": "10.3.11",
"version": "10.4.0-alpha.6",
"engines": {
"node": ">=14"
},
Expand Down Expand Up @@ -28,7 +28,7 @@
"@babel/preset-env": "^7.14.7",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.6.0",
"@dhis2/app-shell": "10.3.11",
"@dhis2/app-shell": "10.4.0-alpha.6",
"@dhis2/cli-helpers-engine": "^3.2.0",
"@jest/core": "^27.0.6",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
Expand Down
4 changes: 2 additions & 2 deletions examples/pwa-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pwa-app",
"version": "10.3.11",
"version": "10.4.0-alpha.6",
"description": "",
"license": "BSD-3-Clause",
"private": true,
Expand All @@ -13,7 +13,7 @@
"demo": "yarn build --force --standalone --debug && yarn serve"
},
"peerDependencies": {
"@dhis2/app-runtime": "*",
"@dhis2/app-runtime": "^3.10.0-alpha.2",
"@dhis2/d2-i18n": "*",
"react": "^16.8",
"react-dom": "^16.8"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-app",
"version": "10.3.11",
"version": "10.4.0-alpha.6",
"repository": "https://github.com/amcgee/dhis2-app-platform",
"author": "Austin McGee <[email protected]>",
"license": "BSD-3-Clause",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "root",
"version": "10.3.11",
"version": "10.4.0-alpha.6",
"private": true,
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/pwa",
"version": "10.3.11",
"version": "10.4.0-alpha.6",
"description": "",
"license": "BSD-3-Clause",
"publishConfig": {
Expand All @@ -13,7 +13,7 @@
"deploy": "d2-app-scripts deploy"
},
"devDependencies": {
"@dhis2/cli-app-scripts": "10.3.11"
"@dhis2/cli-app-scripts": "10.4.0-alpha.6"
},
"dependencies": {
"idb": "^6.0.0",
Expand Down
Loading
Loading