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: plugin sizing updates #902

Merged
merged 21 commits into from
Jan 23, 2025
Merged

feat: plugin sizing updates #902

merged 21 commits into from
Jan 23, 2025

Conversation

KaiVandivier
Copy link
Contributor

@KaiVandivier KaiVandivier commented Dec 17, 2024

Address LIBS-723

Requires app-runtime changes (dhis2/app-runtime#1398)

  • By default, stretches the plugin width to behave (mostly) like a regular div with default width: auto
    • iframes can't actually do width: auto, so width: 100% is currently used -- margins don't work as expected in this case though
    • width: auto behavior could work with a <div> around the iframe, where the div uses the auto width and the iframe uses width: 100% to match that size
      • I tried this built in to the Plugin component's JSX, but it messes with flex styles, so I wrote up some guidance on how to get the right margin behavior instead
  • Adds and uses a className prop to <Plugin> and the underlying iframe
  • If a contentWidth prop is used on the Plugin component, then the width of the iframe will be based off the contents inside
  • The animation loop to check the content width and send that to the parent is removed
  • Removes 20px bottom padding in iframe, since offsetHeight should measure a scrollbar height

I used patch-package to make it easier to test this out with app-runtime changes. I made 6 test cases in a component in the simple app to use:

  1. Default "width: auto" behavior
  2. Using height: 100%
  3. Using fixed heights and widths
  4. Using content-driven sizing
  5. Flexing horizontally
  6. Flexing vertically
Screen.Recording.2024-12-17.at.14.20.12.mov

To do and known issues
Before review:

  • Resizing stops working if the plugin hits its internal error boundary (observers and callbacks probably need to be set up again). Update: actually, I'm unable to reproduce this -- seems to be working 🤷
  • Try out div around iframe to get default 'auto' width of divs (and iframe has width(/height?) 100% by default). Update: tried this out, and it makes the right behavior for width: auto, but breaks other height behaviors. I don't think it's worth doing
  • Add code comments to explain sizing control flow what's going on
  • Write docs and guidance ⭐ (it's in the app-runtime repo)

After review:

  • Remove test components in the simple example app
  • Remove console logs
  • Remove patch package

@KaiVandivier KaiVandivier requested a review from a team January 13, 2025 16:43
Comment on lines 110 to 112
const [resizePluginHeight, setResizePluginHeight] = useState(null)
const [resizePluginWidth, setResizePluginWidth] = useState(null)
const [pluginClientWidth, setPluginClientWidth] = useState(null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add comments explaining the difference between clientWidth, resizePluginWidth, and pluginClientWidth? The names are a bit confusing if you don't have much context

@KaiVandivier KaiVandivier merged commit 1136e0d into master Jan 23, 2025
8 checks passed
@KaiVandivier KaiVandivier deleted the plugin-sizing-updates branch January 23, 2025 08:38
dhis2-bot added a commit that referenced this pull request Jan 23, 2025
# [12.1.0](v12.0.0...v12.1.0) (2025-01-23)

### Features

* plugin sizing updates ([#902](#902)) ([1136e0d](1136e0d))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 12.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

KaiVandivier added a commit that referenced this pull request Jan 23, 2025
Supports easier-to-use plugin sizing and improves performance.
Should be paired with app-runtime >=3.13.0.
See https://dhis2.atlassian.net/browse/LIBS-723

* feat(plugin): simpler sizing; content-driven size without animation loop

* fix(plugins): remove scrollbar padding

* fix: resize dif references
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants