-
Couldn't load subscription status.
- 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
base: main
Are you sure you want to change the base?
Feat/thumbnail #3797
Changes from all commits
b52381f
ff3a36e
4bba935
f444960
2b4472b
42c8633
7672e60
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,6 +75,7 @@ export function nn() { | |||||
| 'form_filler.file_uploader_delete_warning': 'Er du sikker på at du vil sletta dette vedlegget?', | ||||||
| 'form_filler.file_uploader_delete_button_confirm': 'Ja, slett vedlegg', | ||||||
| 'form_filler.file_uploader_list_header_file_size': 'Filstorleik', | ||||||
| 'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail', | ||||||
|
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. Use native Nynorsk term for consistency Consider "Miniatyrbilete" instead of "Thumbnail". - 'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail',
+ 'form_filler.file_uploader_list_header_thumbnail': 'Miniatyrbilete',📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| 'form_filler.file_uploader_list_header_name': 'Namn', | ||||||
| 'form_filler.file_uploader_list_header_status': 'Status', | ||||||
| 'form_filler.file_uploader_list_status_done': 'Ferdig lasta', | ||||||
|
|
||||||
| 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; | ||
| } |
| 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; | ||||||||||||
|
Comment on lines
+27
to
+30
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. 🛠️ Refactor suggestion | 🟠 Major Remove unnecessary type cast and use proper type. The type cast As per coding guidelines. Apply this diff to improve type safety: - const thumbnailLink =
- (attachment as UploadedAttachment)?.data?.metadata?.find(
- (meta: { key: string; value: string }) => meta.key === 'thumbnailLink',
- )?.value ?? null;
+ const thumbnailLink = attachment.data.metadata?.find((meta) => meta.key === 'thumbnailLink')?.value ?? null;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| 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> | ||||||||||||
| ); | ||||||||||||
| }; | ||||||||||||
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.
Use native Bokmål term for clarity
Consider "Miniatyrbilde" instead of the English "Thumbnail" for consistency with other localized strings.
📝 Committable suggestion
🤖 Prompt for AI Agents