Skip to content
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

Add translation to accordion component #1210

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
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') {
enstulen marked this conversation as resolved.
Show resolved Hide resolved
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,
enstulen marked this conversation as resolved.
Show resolved Hide resolved
});
}

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