Altinn / app-frontend-react

Altinn application React frontend
BSD 3-Clause "New" or "Revised" License
14 stars 24 forks source link

Make map marker visible in PDF and readyForPrint more robust #2048

Closed bjosttveit closed 3 weeks ago

bjosttveit commented 3 weeks ago

Description

There were a few issues with the Map component in PDF

  1. The map marker from leaflet has role=button and would therefore get hidden in the PDF. This was solved by overriding styling in the MapComponentSummary
  2. The map fades in from opacity 0 on load, meaning that when app-frontend thinks everything is loaded the Map is not 100% visible yet. This was also fixed by overriding styling in MapComponentSummary, setting tiles to always have opacity 1.
  3. The waiting-for-images-to-load part of ReadyForPrint turned out to not be very robust, as in most cases none of the map tiles had time to load before print happened. One problem seems to be that it first looks for all of the image elements, and adds promises for the ones that have not loaded yet. But most of the time it would not find any image elements at that time, and therefore add no promises, and so it would be completely unpredictable whether the images are actually loaded or not.

Adding this simple check revealed that when using a Map component, most of the images were not in fact finished loading by the time ReadyForPrint was rendered past the assetsLoaded check. At least when doing a hard refresh (Ctrl+Shift+R), when allowing the browser to use its cache it would often load them all in time.

bilde bilde

To resolve the last issue I added the waitForImages function, which will wait for a couple of animation frames before checking for new image elements, then awaiting those promises, and repeating, until there are no more images that are not loaded.

I have not added any tests for this, not sure exactly how I would detect this in cypress, but I have tested manually and it has never failed me so far

bilde

Related Issue(s)

Verification/QA

sonarcloud[bot] commented 3 weeks ago

Quality Gate Failed Quality Gate failed

Failed conditions
50.0% Condition Coverage on New Code (required ≥ 65%)

See analysis details on SonarCloud