-
Notifications
You must be signed in to change notification settings - Fork 93
NEW - allow the review page (panviewer) to render a pdf #11041
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
base: develop
Are you sure you want to change the base?
Changes from all commits
056b66b
8dcb396
332cafb
add7bd2
c6d8b0e
3b585fc
500f936
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,11 @@ | |
| * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
| */ | ||
| import * as React from 'react' | ||
| import { useIntl } from 'react-intl' | ||
| import { useState } from 'react' | ||
| import ReactPanZoom from './PanDraggable' | ||
| import { Button } from '../../Button' | ||
| import { Icon } from '../../Icon' | ||
| import styled from 'styled-components' | ||
|
|
||
| const StyledReactPanZoom = styled(ReactPanZoom)<{ | ||
|
|
@@ -39,9 +42,23 @@ interface IProps { | |
| } | ||
|
|
||
| const PanViewer: React.FC<IProps> = ({ image, zoom, rotation }) => { | ||
| const intl = useIntl() | ||
| const [dx] = useState(0) | ||
| const [dy] = useState(0) | ||
|
|
||
| const isPdf = image.endsWith('.pdf') | ||
|
|
||
| const handleOpenPdf = async () => { | ||
| try { | ||
| const res = await fetch(image, { cache: 'default' }) | ||
| const blob = await res.blob() | ||
| const blobUrl = URL.createObjectURL(blob) | ||
| window.open(blobUrl, '_blank') | ||
| } catch (err) { | ||
| console.error('Failed to open PDF', err) | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+51
to
+61
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the name of the component "pan viewer" it makes me think this might not be the right place for this logic. Pan viewer, if I'm not mistaken, is the component that makes it possible to zoom / pan the image that is previewed. Should this be one level up? @pankaj-pant @bvenceslas
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rikukissa you are right. It should be moved a level up. Although we have discovered internally that the PDF upload scope got accidentally introduced, and we are reverting back to image uploads for a cert that has been printed + signed + stamped (so a image taken with a phone/tablet). With that in mind, if this PR helps @tareq89 in the scope of this ticket #3613, please use the general gist of the fix. I think @euanmillar already updated in the issue 3613 the status of @bvenceslas's availability |
||
| return ( | ||
| <React.Fragment> | ||
| <StyledReactPanZoom | ||
|
|
@@ -51,11 +68,29 @@ const PanViewer: React.FC<IProps> = ({ image, zoom, rotation }) => { | |
| rotation={rotation} | ||
| key={dx} | ||
| > | ||
| <img | ||
| src={image} | ||
| alt="Supporting Document" | ||
| style={{ transform: `rotate(${rotation}deg)` }} | ||
| /> | ||
| {!isPdf ? ( | ||
| <img | ||
| src={image} | ||
| alt="Supporting Document" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs translation key |
||
| style={{ transform: `rotate(${rotation}deg)` }} | ||
| /> | ||
| ) : ( | ||
| <Button | ||
| id="preview_close" | ||
| aria-label="Preview PDF1970 | ||
| in new tab" | ||
| size="medium" | ||
| type="positive" | ||
| onClick={handleOpenPdf} | ||
| > | ||
| {intl.formatMessage({ | ||
| id: 'review.panViewer.openPDF', | ||
| defaultMessage: 'Open PDF in a new tab', | ||
| description: 'Label for open PDF button' | ||
| })} | ||
| <Icon name="ArrowSquareOut" size="medium" /> | ||
| </Button> | ||
| )} | ||
| </StyledReactPanZoom> | ||
| </React.Fragment> | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test case for this?