[MDS-7015] red boundary box not showing in pdf viewer for permit conditions - #3991
Conversation
alazar-aot
left a comment
There was a problem hiding this comment.
Requesting a few small tweaks to make things a bit tighter, but great work overall!
| useEffect(() => { | ||
| setIsDocumentLoaded(false); | ||
| hasDrawnAnnotationRef.current = false; | ||
| }, [documentPath]); | ||
|
|
||
| const { pageNumber, boundingBox } = annotationLocation ?? {}; | ||
| const { top, right, bottom, left } = boundingBox ?? {}; | ||
|
|
||
| useEffect(() => { | ||
| if (!isDocumentLoaded || !pdfViewerRef.current) { | ||
| return; | ||
| } | ||
|
|
||
| if (annotationLocation) { | ||
| hasDrawnAnnotationRef.current = true; | ||
| addAnnotationToPDFViewer(pdfViewerRef.current, pageNumber, boundingBox); | ||
| } else if (hasDrawnAnnotationRef.current) { | ||
| pdfViewerRef.current.annotation.clear(); | ||
| } | ||
| }, [isDocumentLoaded, pageNumber, top, right, bottom, left]); |
There was a problem hiding this comment.
If documentPath and annotationLocation both change in the same render then I think it's possible that we end up drawing the annotation on the old/reloading PDF. Might be better to make isDocumentLoaded only true when pdfViewerRef.current corresponds to the currently loaded documentPath, or add documentPath to the annotation's useEffect dependency array directly (and re-check load state against it before calling addAnnotationToPDFViewer)
There was a problem hiding this comment.
This has been changed as well now
|
|
|
alazar-aot
left a comment
There was a problem hiding this comment.
Looks great, thank you!



Objective
MDS-7015
The "Open Permit in Document Viewer" side-by-side PDF view in the permit conditions page wasn't scrolling to or highlighting the selected condition. The cause of this was the highlight/scroll logic only ran inside the PDF's one-time
documentLoadevent, so it fired at most once per viewer open and never updated as you clicked through different conditions. It also only worked if you had selected a condition before you clicked "Open Permit In Document Viewer" button.The highlight/page-navigation now re-runs whenever the selected condition's page or bounding box actually changes, not just on the PDF's initial load.
The change also always clears the previous highlight before drawing the next one so there aren't any leftover bounding boxes just sticking around
Also locked the bounding boxes so the user can't drag them boxes around