Skip to content

Commit

Permalink
feat: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Sep 6, 2024
1 parent b574425 commit 5868050
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
16 changes: 8 additions & 8 deletions docs/components/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ const MyPlugin = (propsFromParent) => {

## Plugin Props (reserved props)

| Name | Type | Required | Description |
| :--------------------: | :------------: | :---------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **pluginShortName** | _string_ | _required_ if `pluginSource` is not provided | The shortName of the app/plugin you wish to load (matching the result from api/apps). Used to look up the plugin entry point. If this is not provided, `pluginSource` must be provided. `pluginSource` will take precedence if provided. |
| **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 its height based on its contents. The value of `height` will not generally be passed to the plugin, as it is in an internal implementation detail. If you do need to also pass the height to the plugin, you can pass another variable (e.g. `pluginHeight`). |
| **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 its width based on its contents. The value of `width` will not generally be passed to the plugin, as it is in an internal implementation detail. If you do need to also pass the width to the plugin, you can pass another variable (e.g. `pluginWidth`). |
| Name | Type | Required | Description |
| :--------------------: | :------------: | :---------------------------------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **pluginShortName** | _string_ | _required_ if `pluginSource` is not provided | The shortName of the app/plugin you wish to load (matching the result from api/apps). Used to look up the plugin entry point. If this is not provided, `pluginSource` must be provided. `pluginSource` will take precedence if provided. |
| **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** | _string_ | _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 its height based on its contents. The value of `height` will not be passed to the plugin, as it is in an internal implementation detail. If you do need to also pass the height to the plugin, you can pass another variable (e.g. `pluginHeight`). |
| **width** | _string_ | _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 its width based on its contents. The value of `width` will not be passed to the plugin, as it is in an internal implementation detail. If you do need to also pass the width to the plugin, you can pass another variable (e.g. `pluginWidth`). |

## Plugin Props (custom props)

Expand Down
26 changes: 19 additions & 7 deletions services/plugin/src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ const getPluginEntryPoint = ({
)?.pluginLaunchUrl
}

const getIframeDimension = (dimension: string): string => {
if (!isNaN(Number(dimension))) {
return `${Number(dimension)}px`
}
return dimension
}

export const Plugin = ({
pluginSource,
pluginShortName,
height,
width,
...propsToPassNonMemoized
}: {
pluginSource?: string
pluginShortName?: string
height?: string
width?: string
propsToPass: any
height?: number
width?: number
}): JSX.Element => {
const iframeRef = useRef<HTMLIFrameElement>(null)

const { height, width } = propsToPassNonMemoized

const { add: alertsAdd } = useContext(AlertsManagerContext)

const { data } = useDataQuery(appsInfoQuery)
Expand Down Expand Up @@ -66,7 +73,6 @@ export const Plugin = ({
[
...Object.keys(propsToPassNonMemoized)
.sort()
.filter((k) => !['height', 'width'].includes(k))
.map((k) => (propsToPassNonMemoized as any)[k]),
]
/* eslint-enable react-hooks/exhaustive-deps */
Expand Down Expand Up @@ -145,8 +151,14 @@ export const Plugin = ({
ref={iframeRef}
src={pluginSource}
style={{
width: `${width ?? resizedWidth}px`,
height: `${height ?? resizedHeight}px`,
width: `${
width ? getIframeDimension(width) : resizedWidth + 'px'
}`,
height: `${
height
? getIframeDimension(height)
: resizedHeight + 'px'
}`,
border: 'none',
}}
></iframe>
Expand Down

0 comments on commit 5868050

Please sign in to comment.