Skip to content

Commit

Permalink
Merge branch 'alpha' into LIBS-514/memoize-passed-props
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Dec 20, 2023
2 parents 9c17206 + 0724236 commit 0ccae45
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 24 deletions.
33 changes: 32 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
# [3.10.0-alpha.6](https://github.com/dhis2/app-runtime/compare/v3.10.0-alpha.5...v3.10.0-alpha.6) (2023-10-09)


### Bug Fixes

* add back plugin service dependency [LIBS-583] ([ca10691](https://github.com/dhis2/app-runtime/commit/ca10691ba01be083379db54ea2ec29f1666955a8))
* add back plugin service dependency [LIBS-583] ([6d43ae3](https://github.com/dhis2/app-runtime/commit/6d43ae3688814ec3ae1f969123d63bd8e80146ce))

# [3.10.0-alpha.5](https://github.com/dhis2/app-runtime/compare/v3.10.0-alpha.4...v3.10.0-alpha.5) (2023-09-28)


### Bug Fixes

* merge issues ([496472a](https://github.com/dhis2/app-runtime/commit/496472a458f745d01890dec505d6ddb9259378d1))
* reset communication on either pluginSource or pluginShortName change ([3fdae5b](https://github.com/dhis2/app-runtime/commit/3fdae5becf3af038fef8ca5f0be7ecec44680600))
* trigger props resend when iframe src changes [LIBS-488] ([f4a6680](https://github.com/dhis2/app-runtime/commit/f4a668004fe2f97d77e3c74a6047246cf358ade4))
* trigger props resend when iframe src changes [LIBS-488] [#1344](https://github.com/dhis2/app-runtime/issues/1344) ([cea7600](https://github.com/dhis2/app-runtime/commit/cea760040d919508b1e13158dbf47ca9ed3686f6))

# [3.10.0-alpha.2](https://github.com/dhis2/app-runtime/compare/v3.10.0-alpha.1...v3.10.0-alpha.2) (2023-03-15)

### Bug Fixes

* add in plugin service in runtime package ([#1343](https://github.com/dhis2/app-runtime/issues/1343)) ([ed06a9f](https://github.com/dhis2/app-runtime/commit/ed06a9f4af7d3db40600ffd7e1b03cd095db36fc))

# [3.10.0-alpha.1](https://github.com/dhis2/app-runtime/compare/v3.9.0...v3.10.0-alpha.1) (2023-03-13)
# [3.10.0-alpha.4](https://github.com/dhis2/app-runtime/compare/v3.10.0-alpha.3...v3.10.0-alpha.4) (2023-09-28)


### Bug Fixes

* add width to plugin documentation [LIBS-487] ([b2c6273](https://github.com/dhis2/app-runtime/commit/b2c62732bf37e6d52b30f155b68c8b126068e8e5))
* clean up ([e53ecbd](https://github.com/dhis2/app-runtime/commit/e53ecbd0632e35681e135de9072169e6bfefe13c))
* temporarily disable failing test ([6664199](https://github.com/dhis2/app-runtime/commit/666419955d0f1f70c7b101a49d7440dcd33857a0))
* working autorsize width ([2991045](https://github.com/dhis2/app-runtime/commit/29910456aca9739848cac403c48a2ac4e64be1e3))


### Features

* add autoresizing for height ([dbb6e26](https://github.com/dhis2/app-runtime/commit/dbb6e265e0b3b01dfe975538703fcdde7c5f2b53))

# [3.10.0-alpha.3](https://github.com/dhis2/app-runtime/compare/v3.10.0-alpha.2...v3.10.0-alpha.3) (2023-08-22)

Expand Down
2 changes: 2 additions & 0 deletions docs/components/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const MyPlugin = (propsFromParent) => {
| **pluginSource** | _string_ (url) | _required_ if `pluginShortName` is not provided | The URL of the plugin. If this is not provided, `pluginShortName` must be provided. |
| **onError** | _Function_ | _optional_ | Callback function to be called when an error in the plugin triggers an error boundary. You can use this to pass an error back up to the app and create a custom handling/UX if errors occur in the plugin. In general, it is recommended that you use the plugin's built-in error boundaries |
| **showAlertsInPlugin** | _boolean_ | _optional_ | If `true`, any alerts within the plugin (defined with the `useAlert` hook) will be rendered within the iframe. By default, this is `false`. It is recommended, in general, that you do not override this and allow alerts to be hoisted up to the app level |
| **height** | _number_ | _optional_ | If a height is provided, the iframe will be fixed to the specified height. If no height is provided, the iframe will automatically resize based on its contents. |
| **width** | _number_ | _optional_ | If a width is provided, the iframe will be fixed to the specified width. If no width is provided, the iframe will automatically resize based on its contents. |

## Plugin Props (custom props)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"description": "A singular runtime dependency for applications on the DHIS2 platform",
"repository": "https://github.com/dhis2/app-runtime.git",
"author": "Austin McGee <austin@dhis2.org>",
Expand Down
11 changes: 6 additions & 5 deletions runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dhis2/app-runtime",
"description": "A singular runtime dependency for applications on the DHIS2 platform",
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "./build/types/index.d.ts",
Expand All @@ -23,10 +23,11 @@
"build/**"
],
"dependencies": {
"@dhis2/app-service-config": "3.10.0-alpha.3",
"@dhis2/app-service-data": "3.10.0-alpha.3",
"@dhis2/app-service-alerts": "3.10.0-alpha.3",
"@dhis2/app-service-offline": "3.10.0-alpha.3"
"@dhis2/app-service-config": "3.10.0-alpha.6",
"@dhis2/app-service-data": "3.10.0-alpha.6",
"@dhis2/app-service-alerts": "3.10.0-alpha.6",
"@dhis2/app-service-offline": "3.10.0-alpha.6",
"@dhis2/app-service-plugin": "3.10.0-alpha.6"
},
"peerDependencies": {
"prop-types": "^15.7.2",
Expand Down
2 changes: 1 addition & 1 deletion services/alerts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/app-service-alerts",
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "./build/types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion services/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/app-service-config",
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "build/types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions services/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/app-service-data",
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "build/types/index.d.ts",
Expand All @@ -22,7 +22,7 @@
"build/**"
],
"peerDependencies": {
"@dhis2/app-service-config": "3.10.0-alpha.3",
"@dhis2/app-service-config": "3.10.0-alpha.6",
"@dhis2/cli-app-scripts": "^7.1.1",
"prop-types": "^15.7.2",
"react": "^16.8",
Expand Down
4 changes: 2 additions & 2 deletions services/offline/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dhis2/app-service-offline",
"description": "A runtime service for online/offline detection and offline caching",
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "build/types/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
"coverage": "yarn test --coverage"
},
"peerDependencies": {
"@dhis2/app-service-config": "3.10.0-alpha.3",
"@dhis2/app-service-config": "3.10.0-alpha.6",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
Expand Down
6 changes: 3 additions & 3 deletions services/plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/app-service-plugin",
"version": "3.10.0-alpha.3",
"version": "3.10.0-alpha.6",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "build/types/index.d.ts",
Expand Down Expand Up @@ -28,8 +28,8 @@
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"@dhis2/app-service-alerts": "3.10.0-alpha.3",
"@dhis2/app-service-data": "3.10.0-alpha.3"
"@dhis2/app-service-alerts": "3.10.0-alpha.6",
"@dhis2/app-service-data": "3.10.0-alpha.6"
},
"devDependencies": {
"@types/post-robot": "^10.0.3"
Expand Down
45 changes: 37 additions & 8 deletions services/plugin/src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ const getPluginEntryPoint = ({
export const Plugin = ({
pluginSource,
pluginShortName,
...propsToPass
...propsToPassNonMemoized
}: {
pluginSource?: string
pluginShortName?: string
propsToPass: any
}): JSX.Element => {
const iframeRef = useRef<HTMLIFrameElement>(null)

// we do not know what is being sent in passed props, so for stable reference, memoize using JSON representation
const propsToPassNonMemoizedJSON = JSON.stringify(propsToPassNonMemoized)
const propsToPass: any = useMemo(
() => ({ ...propsToPassNonMemoized }),
// eslint-disable-next-line react-hooks/exhaustive-deps
[propsToPassNonMemoizedJSON]
)
const { height, width } = propsToPass

const { add: alertsAdd } = useContext(AlertsManagerContext)

const { data } = useDataQuery(appsInfoQuery)
Expand All @@ -51,6 +60,17 @@ export const Plugin = ({
useState<boolean>(false)

const [inErrorState, setInErrorState] = useState<boolean>(false)
const [pluginHeight, setPluginHeight] = useState<number>(150)
const [pluginWidth, setPluginWidth] = useState<number>(500)

useEffect(() => {
if (height) {
setPluginHeight(height)
}
if (width) {
setPluginWidth(width)
}
}, [height, width])

// since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop
const memoizedPropsToPass = useMemo(
Expand Down Expand Up @@ -80,6 +100,8 @@ export const Plugin = ({
const iframeProps = {
...memoizedPropsToPass,
alertsAdd,
setPluginHeight,
setPluginWidth,
setInErrorState,
setCommunicationReceived,
}
Expand Down Expand Up @@ -131,15 +153,22 @@ export const Plugin = ({

if (pluginEntryPoint) {
return (
<iframe
ref={iframeRef}
src={pluginSource}
<div
style={{
width: '100%',
height: '100%',
border: 'none',
height: `${pluginHeight}px`,
width: `${pluginWidth}px`,
}}
></iframe>
>
<iframe
ref={iframeRef}
src={pluginSource}
style={{
width: '100%',
height: '100%',
border: 'none',
}}
></iframe>
</div>
)
}

Expand Down

0 comments on commit 0ccae45

Please sign in to comment.