Skip to content

Commit 6ba8fd4

Browse files
authored
Merge pull request #1422 from navikt/attachment-values-update
Auto convert attachments values when loading component
2 parents 20dfd70 + f2432f6 commit 6ba8fd4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/shared-components/src/formio/components/core/attachment/default/DefaultAttachment.tsx

+40
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,46 @@ class DefaultAttachment extends BaseComponent {
2424
return defaultAttachmentBuilder();
2525
}
2626

27+
/**
28+
* If the component has values, we need to convert them to attachmentValues
29+
*
30+
* When we no longer need to support the old attachments with type radiopanel
31+
* and have none with type attachment and values, we can remove this.
32+
*/
33+
init() {
34+
super.init();
35+
36+
if (this.builderMode && !this.component?.attachmentValues && this.component?.values) {
37+
if (!this.component?.attachmentType) {
38+
this.component.attachmentType = this.component?.otherDocumentation ? 'other' : 'default';
39+
}
40+
41+
if (this.component.attachmentType === 'other') {
42+
this.component.attachmentValues = {
43+
leggerVedNaa: { enabled: true },
44+
nei: { enabled: true },
45+
};
46+
} else {
47+
this.component.attachmentValues = {};
48+
for (const objectValue of this.component.values) {
49+
if (
50+
objectValue.value === 'leggerVedNaa' ||
51+
objectValue.value === 'ettersender' ||
52+
objectValue.value === 'levertTidligere' ||
53+
objectValue.value === 'nei'
54+
) {
55+
this.component.attachmentValues[objectValue.value] = {
56+
enabled: !!objectValue.value,
57+
};
58+
}
59+
}
60+
}
61+
62+
this.component.otherDocumentation = undefined;
63+
this.component.values = undefined;
64+
}
65+
}
66+
2767
getAttachmentValues() {
2868
return this.component?.attachmentValues ? this.component?.attachmentValues : this.component?.values;
2969
}

0 commit comments

Comments
 (0)