Compare commits

..

3 Commits

Author SHA1 Message Date
d944697f9c Update NewDocumentJob Component for Improved TemplatePreview Layout
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit
- Adjusted the sidebar div in the NewDocumentJob component to use a calculated height for better responsiveness.
- Ensured the sidebar maintains a minimum width, enhancing the overall layout and user experience of the TemplatePreview.
2026-08-22 13:19:57 +01:00
fb52a14dd0 Refactor TemplatePreview for Improved Layout and Responsiveness
- Replaced a div with a Flex component to enhance layout and alignment of the TemplatePreview.
- Adjusted styles to ensure minimum width and proper cursor behavior during panning.
- Streamlined iframe rendering within the new structure for better responsiveness and user experience.
2026-08-22 13:11:49 +01:00
47e4e60b86 Enhance TemplatePreview with Clear Iframe Contents Functionality
- Added a new function to clear iframe contents, improving resource management and preventing stale data display.
- Integrated the clearIframeContents function into the PDF preview type change handler, ensuring a clean slate when switching to PDF previews.
- Updated state management for iframe size and preview content to enhance user experience and maintain consistency.
2026-08-22 13:04:57 +01:00
2 changed files with 53 additions and 19 deletions

View File

@ -57,7 +57,13 @@ const NewDocumentJob = ({ onOk, defaultValues = {} }) => {
disabled={downloading} disabled={downloading}
sideBarGrow={true} sideBarGrow={true}
sideBar={ sideBar={
<div style={{ minHeight: '760px', flexGrow: 1 }}> <div
style={{
height: 'calc(100vh - 240px)',
flexGrow: 1,
minWidth: 0
}}
>
<TemplatePreview <TemplatePreview
objectData={objectData?.object} objectData={objectData?.object}
documentTemplate={objectData?.documentTemplate} documentTemplate={objectData?.documentTemplate}

View File

@ -171,6 +171,19 @@ const TemplatePreview = ({
setPreviewContentHTML(html) setPreviewContentHTML(html)
} }
const clearIframeContents = useCallback(() => {
iframeSizeObserverRef.current?.disconnect()
iframeSizeObserverRef.current = null
const iframe = iframeRef.current
if (iframe) {
iframe.srcdoc = ''
}
setPreviewContentHTML('')
setIframeSize({ width: '100%', height: 'auto' })
}, [])
const stopRenderProgressListener = useCallback(() => { const stopRenderProgressListener = useCallback(() => {
if (typeof renderUnsubscribeRef.current === 'function') { if (typeof renderUnsubscribeRef.current === 'function') {
renderUnsubscribeRef.current() renderUnsubscribeRef.current()
@ -541,10 +554,11 @@ const TemplatePreview = ({
disabled={loading || reloadLoading} disabled={loading || reloadLoading}
value={previewType} value={previewType}
onChange={(value) => { onChange={(value) => {
setPreviewType(value)
if (value == 'PDF') { if (value == 'PDF') {
clearIframeContents()
setPDFBlob(null) setPDFBlob(null)
} }
setPreviewType(value)
}} }}
/> />
) : null} ) : null}
@ -600,29 +614,43 @@ const TemplatePreview = ({
touchAction: panMode ? 'none' : undefined touchAction: panMode ? 'none' : undefined
}} }}
> >
<div <Flex
justify='center'
align='center'
style={{ style={{
minWidth: '100%',
width: iframeSize.width, width: iframeSize.width,
height: iframeSize.height, height: iframeSize.height
cursor: panMode ? (isPanning ? 'grabbing' : 'grab') : undefined
}} }}
> >
<iframe <div
ref={iframeRef}
srcDoc={previewContentHTML}
onLoad={handleIframeLoad}
scrolling='no'
frameBorder='0'
style={{ style={{
width: '100%', width: iframeSize.width,
height: iframeSize.height === 'auto' ? 150 : '100%', height: iframeSize.height,
display: 'block', cursor: panMode
border: 0, ? isPanning
overflow: 'hidden', ? 'grabbing'
pointerEvents: panMode ? 'none' : undefined : 'grab'
: undefined
}} }}
/> >
</div> <iframe
ref={iframeRef}
srcDoc={previewContentHTML}
onLoad={handleIframeLoad}
scrolling='no'
frameBorder='0'
style={{
width: '100%',
height: iframeSize.height === 'auto' ? 150 : '100%',
display: 'block',
border: 0,
overflow: 'hidden',
pointerEvents: panMode ? 'none' : undefined
}}
/>
</div>
</Flex>
</ScrollBox> </ScrollBox>
) : ( ) : (
<PDFViewer <PDFViewer