-
Notifications
You must be signed in to change notification settings - Fork 31
Feat/thumbnail #3797
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
Closed
Closed
Feat/thumbnail #3797
Changes from 7 commits
Commits
Show all changes
10 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
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
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
| .thumbnailContainer { | ||
| margin-top: 0.5rem; | ||
| margin-bottom: 0.5rem; | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .thumbnail { | ||
| max-width: 100px; | ||
| max-height: 70px; | ||
| object-fit: contain; | ||
| border-radius: 2px; | ||
| } | ||
|
|
||
| .thumbnailMobile { | ||
| max-width: 80px; | ||
| max-height: 60px; | ||
| object-fit: contain; | ||
| border-radius: 2px; | ||
| } |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
| 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, UploadedAttachment } from 'src/features/attachments'; | ||
| interface IAttachmentThumbnailProps { | ||
| attachment: IAttachment; | ||
| mobileView: boolean; | ||
| } | ||
|
|
||
| export const AttachmentThumbnail = ({ attachment, mobileView }: IAttachmentThumbnailProps) => { | ||
| // Get all data elements from the instance | ||
| const dataElements = useInstanceDataElements(undefined); | ||
| const instanceId = useLaxInstanceId(); | ||
| const language = useCurrentLanguage(); | ||
|
|
||
| // Only uploaded attachments can have thumbnails | ||
| if (!isAttachmentUploaded(attachment)) { | ||
| return null; | ||
| } | ||
|
|
||
| //Check for thumbnail metadata in the attachment | ||
| const thumbnailLink = | ||
| (attachment as UploadedAttachment)?.data?.metadata?.find( | ||
| (meta: { key: string; value: string }) => meta.key === 'thumbnailLink', | ||
| )?.value ?? null; | ||
walldenfilippa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!thumbnailLink) { | ||
| return null; | ||
| } | ||
|
|
||
| // Find the thumbnail data element | ||
| const thumbnailDataElement = dataElements.find( | ||
| (el) => | ||
| el.dataType === 'thumbnail' && | ||
| el.metadata?.some((meta) => meta.key === 'attachmentLink' && meta.value === thumbnailLink), | ||
| ); | ||
|
|
||
| if (!thumbnailDataElement?.id || !instanceId) { | ||
| return null; | ||
| } | ||
|
|
||
| const thumbnailUrl = makeUrlRelativeIfSameDomain(getDataElementUrl(instanceId, thumbnailDataElement.id, language)); | ||
|
|
||
| if (!thumbnailUrl) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={classes.thumbnailContainer} | ||
| data-testid='attachment-thumbnail' | ||
| > | ||
| <img | ||
| src={thumbnailUrl} | ||
| 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.
Uh oh!
There was an error while loading. Please reload this page.