Skip to content

Commit

Permalink
Merge pull request #1210 from navikt/bugfix/translate-accordion
Browse files Browse the repository at this point in the history
Add translation to accordion component
  • Loading branch information
enstulen authored Jun 12, 2024
2 parents 06749a2 + 7336c62 commit 4acdb79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/bygger/src/translations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from '@navikt/skjemadigitalisering-shared-components';

import {
AccordionSettingValue,
AccordionSettingValues,
AttachmentSettingValue,
AttachmentSettingValues,
Component,
Expand Down Expand Up @@ -133,6 +135,7 @@ const getTranslatablePropertiesFromForm = (form: NavFormType) =>
addAnother,
removeAnother,
attachmentValues,
accordionValues,
}) => ({
title,
label: getLabel(label, type, !!hideLabel),
Expand All @@ -150,6 +153,7 @@ const getTranslatablePropertiesFromForm = (form: NavFormType) =>
addAnother: getTextFromComponentProperty(addAnother),
removeAnother: getTextFromComponentProperty(removeAnother),
attachmentValues: getAttachmentTexts(attachmentValues),
accordionValues: getAccordionTexts(accordionValues),
}),
);

Expand All @@ -164,6 +168,16 @@ const textObject = (withInputType: boolean, value: string): TextObjectType => {
};
};

const getAccordionTexts = (accordionValues?: AccordionSettingValues): undefined | string[] => {
if (!accordionValues) {
return undefined;
}

return accordionValues.flatMap((value: AccordionSettingValue) => {
return [value.title, value.content];
});
};

const getAttachmentTexts = (attachmentValues?: AttachmentSettingValues): undefined | string[] => {
if (!attachmentValues) {
return undefined;
Expand Down Expand Up @@ -193,7 +207,7 @@ const getFormTexts = (form?: NavFormType, withInputType = false): TextObjectType
Object.keys(component)
.filter((key) => component[key] !== undefined && key !== 'attachmentValues')
.flatMap((key) => {
if (key === 'values' || key === 'data') {
if (key === 'values' || key === 'data' || key === 'accordionValues') {
return component[key]
.filter((value) => value !== '')
.map((value) => textObject(withInputType, value)) as TextObjectType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Accordion extends BaseComponent {
label: 'Trekkspill',
type: 'accordion',
key: 'accordion',
hideLabel: true,
});
}

Expand All @@ -34,9 +35,9 @@ class Accordion extends BaseComponent {
<NavAccordion id={this.getId()} ref={(ref) => this.setReactInstance(ref)} headingSize={this.getTitleSize()}>
{this.getAccordionValues()?.map((item, index) => (
<NavAccordion.Item key={index} defaultOpen={item.defaultOpen}>
<NavAccordion.Header>{item.title}</NavAccordion.Header>
<NavAccordion.Header>{this.translate(item.title)}</NavAccordion.Header>
<NavAccordion.Content>
<InnerHtml content={item.content} />
<InnerHtml content={this.translate(item.content)} />
</NavAccordion.Content>
</NavAccordion.Item>
))}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared-domain/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccordionSettingValue, AccordionSettingValues } from './accordion';
import attachmentUtils, {
AttachmentSettingValue,
AttachmentSettingValues,
Expand Down Expand Up @@ -125,6 +126,8 @@ export {
validatorUtils,
};
export type {
AccordionSettingValue,
AccordionSettingValues,
AktivitetPeriode,
AktivitetVedtaksinformasjon,
AttachmentSettingValue,
Expand Down

0 comments on commit 4acdb79

Please sign in to comment.