Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/language/texts/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function en() {
'form_filler.file_uploader_delete_warning': 'Are you sure you want to delete this attachment?',
'form_filler.file_uploader_delete_button_confirm': 'Yes, delete attachment',
'form_filler.file_uploader_list_header_file_size': 'File size',
'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail',
'form_filler.file_uploader_list_header_name': 'Name',
'form_filler.file_uploader_list_header_status': 'Status',
'form_filler.file_uploader_list_header_delete_sr': 'Delete',
Expand Down
1 change: 1 addition & 0 deletions src/language/texts/nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function nb() {
'form_filler.file_uploader_delete_warning': 'Er du sikker på at du vil slette dette vedlegget?',
'form_filler.file_uploader_delete_button_confirm': 'Ja, slett vedlegg',
'form_filler.file_uploader_list_header_file_size': 'Filstørrelse',
'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use native Bokmål term for clarity

Consider "Miniatyrbilde" instead of the English "Thumbnail" for consistency with other localized strings.

-    'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail',
+    'form_filler.file_uploader_list_header_thumbnail': 'Miniatyrbilde',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail',
'form_filler.file_uploader_list_header_thumbnail': 'Miniatyrbilde',
🤖 Prompt for AI Agents
In src/language/texts/nb.ts around line 78, the localized label currently uses
the English word "Thumbnail"; replace its value with the native Bokmål term
"Miniatyrbilde" so the entry reads
'form_filler.file_uploader_list_header_thumbnail': 'Miniatyrbilde', ensuring
consistency with other Norwegian translations and preserving the same key.

'form_filler.file_uploader_list_header_name': 'Navn',
'form_filler.file_uploader_list_header_status': 'Status',
'form_filler.file_uploader_list_status_done': 'Ferdig lastet',
Expand Down
1 change: 1 addition & 0 deletions src/language/texts/nn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'form_filler.file_uploader_list_header_thumbnail': 'Thumbnail',
'form_filler.file_uploader_list_header_thumbnail': 'Miniatyrbilete',
🤖 Prompt for AI Agents
In src/language/texts/nn.ts around line 78, the value for
'form_filler.file_uploader_list_header_thumbnail' uses the English word
"Thumbnail"; replace it with the native Nynorsk term "Miniatyrbilete" (preserve
the same key, only change the string value) so the translation is consistent
with other Nynorsk entries.

'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',
Expand Down
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 src/layout/FileUpload/FileUploadTable/AttachmentThumbnail.tsx
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 (attachment as UploadedAttachment) is unnecessary because the type guard at line 22 already narrows attachment to UploadedAttachment. Additionally, the inline type { key: string; value: string } should be replaced with the IMetadata type from src/types/shared.ts.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
🤖 Prompt for AI Agents
In src/layout/FileUpload/FileUploadTable/AttachmentThumbnail.tsx around lines 27
to 30, remove the unnecessary (attachment as UploadedAttachment) cast and
replace the inline type annotation for metadata items with the shared IMetadata
type; use the already-established type guard (from line 22) so the code reads:
attachment.data.metadata.find((meta: IMetadata) => meta.key ===
'thumbnailLink')?.value ?? null. Also add an import for IMetadata from
src/types/shared.ts if it’s not already imported.


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>
);
};
Loading
Loading