-
Notifications
You must be signed in to change notification settings - Fork 31
feat/thumbnail #3898
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
Open
walldenfilippa
wants to merge
17
commits into
Altinn:main
Choose a base branch
from
walldenfilippa:feat/thumbnail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat/thumbnail #3898
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b52381f
Add and update files in FileUploadTable
walldenfilippa ff3a36e
Added texts thumbnail
walldenfilippa 4bba935
Update access metadata
walldenfilippa f444960
Merge branch 'main' into Feat/Thumbnail
tina-ahm 2b4472b
Add thumbnail header to file uploader list - en
walldenfilippa 42c8633
Add 'Thumbnail' header to file uploader list - nb
walldenfilippa 7672e60
Add 'Thumbnail' header to file uploader list
walldenfilippa 742b983
edits coderabbitai
67bec09
Merge branch 'main' of https://github.com/Altinn/app-frontend-react i…
86022a7
minor edit
11a48c8
added preview modal
walldenfilippa 3c81350
minor edits
walldenfilippa 621f569
minor edits styling
walldenfilippa 7f40679
fix pdf view + loading icon
walldenfilippa af26ff3
mobileview padding and gap
walldenfilippa e319806
change preview modal image to original image
walldenfilippa bc54e0f
fix width fileUpLoadWithTag
walldenfilippa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/layout/FileUpload/FileUploadTable/AttachmentThumbnail.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| .thumbnailContainer { | ||
| margin-top: 0.5rem; | ||
| margin-bottom: 0.5rem; | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .thumbnail { | ||
| max-width: 80px; | ||
| max-height: 56px; | ||
| object-fit: contain; | ||
| } | ||
|
|
||
| .thumbnailMobile { | ||
| max-width: 64px; | ||
| max-height: 48px; | ||
| object-fit: contain; | ||
| } | ||
|
|
||
| .previewBackdrop { | ||
| position: fixed; | ||
| top: 0; | ||
| left: 0; | ||
| right: 0; | ||
| bottom: 0; | ||
| background-color: rgba(0, 0, 0, 0.7); | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| z-index: 1000; | ||
| animation: fadeIn 0.3s ease-in-out; | ||
| } | ||
|
|
||
| .previewModal { | ||
| position: relative; | ||
| background-color: #fff; | ||
| border-radius: 8px; | ||
| box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); | ||
| max-width: 90vw; | ||
| max-height: 90vh; | ||
| overflow: auto; | ||
| padding: 0; | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| .previewHeader { | ||
| position: relative; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| padding: 16px 20px; | ||
| background-color: #fff; | ||
| border-radius: 8px 8px 0 0; | ||
| gap: 16px; | ||
| } | ||
|
|
||
| .previewHeaderMobile { | ||
| position: relative; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| padding: 8px 20px; | ||
| background-color: #fff; | ||
| border-radius: 8px 8px 0 0; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .fileName { | ||
| font-weight: 500; | ||
| color: #333; | ||
| flex: 1; | ||
| word-break: break-word; | ||
| font-size: 0.95rem; | ||
| } | ||
|
|
||
| .previewImage { | ||
| max-width: 100%; | ||
| max-height: calc(90vh - 100px); | ||
| object-fit: contain; | ||
| display: block; | ||
| padding: 0 20px 20px 20px; | ||
| background-color: #fff; | ||
| } | ||
|
|
||
| .previewImageMobile { | ||
| max-width: 100%; | ||
| max-height: calc(90vh - 100px); | ||
| object-fit: contain; | ||
| display: block; | ||
| padding: 0 10px 10px 10px; | ||
| background-color: #fff; | ||
| } | ||
|
|
||
| .closeButton { | ||
| position: relative; | ||
| background-color: transparent; | ||
| border: none; | ||
| font-size: 32px; | ||
| cursor: pointer; | ||
| color: var(--ds-color-text-subtle); | ||
| width: 40px; | ||
| height: 40px; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| border-radius: 4px; | ||
| transition: background-color 0.2s ease; | ||
| flex-shrink: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .closeButton:hover { | ||
| color: var(--ds-color-text-default); | ||
| background-color: var(--ds-color-surface-tinted); | ||
| } | ||
|
|
||
| .imageLoading { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| min-height: 200px; | ||
| } | ||
|
|
||
| @keyframes fadeIn { | ||
| from { | ||
| opacity: 0; | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
src/layout/FileUpload/FileUploadTable/AttachmentThumbnail.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { isAttachmentUploaded } from 'src/features/attachments'; | ||
| import { useInstanceDataElements, useLaxInstanceId } from 'src/features/instance/InstanceContext'; | ||
| import { useCurrentLanguage } from 'src/features/language/LanguageProvider'; | ||
| import classes from 'src/layout/FileUpload/FileUploadTable/AttachmentThumbnail.module.css'; | ||
| import { getDataElementUrl } from 'src/utils/urls/appUrlHelper'; | ||
| import { makeUrlRelativeIfSameDomain } from 'src/utils/urls/urlHelper'; | ||
| import type { IAttachment } from 'src/features/attachments'; | ||
|
|
||
| interface IAttachmentThumbnailProps { | ||
| attachment: IAttachment; | ||
| mobileView: boolean; | ||
| onThumbnailClick?: () => void; | ||
| } | ||
|
|
||
| export const AttachmentThumbnail = ({ attachment, mobileView, onThumbnailClick }: IAttachmentThumbnailProps) => { | ||
| const dataElements = useInstanceDataElements(undefined); | ||
| const instanceId = useLaxInstanceId(); | ||
| const language = useCurrentLanguage(); | ||
|
|
||
| // Only uploaded attachments can have thumbnails | ||
| if (!instanceId || !isAttachmentUploaded(attachment)) { | ||
| return ''; | ||
| } | ||
|
|
||
| const thumbnailLink = attachment.data.metadata?.find((meta) => meta.key === 'thumbnailLink')?.value; | ||
| if (!thumbnailLink) { | ||
| return ''; | ||
| } | ||
|
|
||
| const thumbnailDataElement = dataElements.find( | ||
| (el) => | ||
| el.dataType === 'thumbnail' && | ||
| el.metadata?.some((meta) => meta.key === 'attachmentLink' && meta.value === thumbnailLink), | ||
| ); | ||
|
|
||
| const url = thumbnailDataElement | ||
| ? makeUrlRelativeIfSameDomain(getDataElementUrl(instanceId, thumbnailDataElement.id, language)) | ||
| : undefined; | ||
|
|
||
| return ( | ||
| <div | ||
| className={classes.thumbnailContainer} | ||
| data-testid='attachment-thumbnail' | ||
| onClick={onThumbnailClick} | ||
| style={onThumbnailClick ? { cursor: 'pointer' } : {}} | ||
| role={onThumbnailClick ? 'button' : undefined} | ||
| tabIndex={onThumbnailClick ? 0 : undefined} | ||
| onKeyDown={onThumbnailClick ? (e) => e.key === 'Enter' && onThumbnailClick() : undefined} | ||
| > | ||
| <img | ||
| src={url} | ||
| alt={`Thumbnail for ${attachment.data.filename}`} | ||
| className={mobileView ? classes.thumbnailMobile : classes.thumbnail} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Improve accessibility and add safety check for image URL.
Two concerns:
Missing URL validation: The
urlcan beundefinedif nothumbnailDataElementis found, yet it's passed directly to theimgsrcattribute without validation. This could cause a broken image display.Accessibility pattern: Using a
divwith button-like behavior (role, tabIndex, onClick, onKeyDown) is non-standard. While functional, a native<button>element provides better accessibility and keyboard navigation out of the box.🔎 Proposed fixes
Add URL validation:
const url = thumbnailDataElement ? makeUrlRelativeIfSameDomain(getDataElementUrl(instanceId, thumbnailDataElement.id, language)) : undefined; + if (!url) { + return null; + } + return (Alternative: Use a button wrapper for better accessibility (optional, if styling allows):
Note: If using a button, you may need to add CSS to remove default button styling.
📝 Committable suggestion
🤖 Prompt for AI Agents