Skip to content

Commit

Permalink
chore(application-system): Making title an optional property on form …
Browse files Browse the repository at this point in the history
…fields (#17634)

* defaulting every title to empty

* chore: nx format:write update dirty files

* Adding a few more optionals to titles

---------

Co-authored-by: andes-it <[email protected]>
  • Loading branch information
HjorturJ and andes-it authored Jan 30, 2025
1 parent b617666 commit d46501c
Show file tree
Hide file tree
Showing 33 changed files with 70 additions and 66 deletions.
34 changes: 12 additions & 22 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const extractCommonFields = (
disabled = false,
doesNotRequireAnswer = false,
id,
title,
title = '',
dataTestId,
width = 'full',
nextButtonText,
Expand Down Expand Up @@ -504,7 +504,7 @@ export const buildKeyValueField = (data: {

export const buildSubmitField = (data: {
id: string
title: FormText
title?: FormText
placement?: 'footer' | 'screen'
marginBottom?: BoxProps['marginBottom']
marginTop?: BoxProps['marginTop']
Expand All @@ -514,7 +514,7 @@ export const buildSubmitField = (data: {
const {
id,
placement = 'footer',
title,
title = '',
actions,
refetchApplicationAfterSubmit,
marginTop,
Expand Down Expand Up @@ -562,11 +562,11 @@ export const buildFieldRequired = (

export const buildRedirectToServicePortalField = (data: {
id: string
title: FormText
title?: FormText
marginBottom?: BoxProps['marginBottom']
marginTop?: BoxProps['marginTop']
}): RedirectToServicePortalField => {
const { id, title, marginTop, marginBottom } = data
const { id, title = '', marginTop, marginBottom } = data
return {
children: undefined,
id,
Expand Down Expand Up @@ -595,12 +595,11 @@ export const buildPaymentPendingField = (data: {
export const buildMessageWithLinkButtonField = (
data: Omit<MessageWithLinkButtonField, 'type' | 'component' | 'children'>,
): MessageWithLinkButtonField => {
const { id, title, url, message, buttonTitle } = data
const { id, url, message, buttonTitle } = data
return {
...extractCommonFields(data),
children: undefined,
id,
title,
url,
message,
buttonTitle,
Expand All @@ -612,12 +611,11 @@ export const buildMessageWithLinkButtonField = (
export const buildExpandableDescriptionField = (
data: Omit<ExpandableDescriptionField, 'type' | 'component' | 'children'>,
): ExpandableDescriptionField => {
const { id, title, description, introText, startExpanded } = data
const { id, description, introText, startExpanded } = data
return {
...extractCommonFields(data),
children: undefined,
id,
title,
description,
introText,
startExpanded,
Expand Down Expand Up @@ -659,13 +657,11 @@ export const buildLinkField = (
export const buildPaymentChargeOverviewField = (
data: Omit<PaymentChargeOverviewField, 'type' | 'component' | 'children'>,
): PaymentChargeOverviewField => {
const { id, title, forPaymentLabel, totalLabel, getSelectedChargeItems } =
data
const { id, forPaymentLabel, totalLabel, getSelectedChargeItems } = data
return {
...extractCommonFields(data),
children: undefined,
id,
title,
forPaymentLabel,
totalLabel,
getSelectedChargeItems,
Expand All @@ -679,7 +675,6 @@ export const buildImageField = (
): ImageField => {
const {
id,
title,
image,
alt,
condition,
Expand All @@ -692,7 +687,6 @@ export const buildImageField = (
...extractCommonFields(data),
children: undefined,
id,
title,
image,
alt,
imageWidth,
Expand Down Expand Up @@ -894,7 +888,6 @@ export const buildFieldsRepeaterField = (
): FieldsRepeaterField => {
const {
fields,
title,
titleVariant,
formTitle,
formTitleVariant,
Expand All @@ -912,7 +905,6 @@ export const buildFieldsRepeaterField = (
type: FieldTypes.FIELDS_REPEATER,
component: FieldComponents.FIELDS_REPEATER,
fields,
title,
titleVariant,
formTitle,
formTitleVariant,
Expand Down Expand Up @@ -943,7 +935,7 @@ export const buildStaticTableField = (
header,
condition,
dataTestId,
title,
title = '',
description,
rows,
summary,
Expand Down Expand Up @@ -977,7 +969,7 @@ export const buildSliderField = (
): SliderField => {
const {
id,
title,
title = '',
titleVariant = 'h2',
condition,
min = 0,
Expand Down Expand Up @@ -1040,7 +1032,6 @@ export const buildDisplayField = (
data: Omit<DisplayField, 'type' | 'component' | 'children'>,
): DisplayField => {
const {
title,
titleVariant,
label,
variant,
Expand All @@ -1051,7 +1042,6 @@ export const buildDisplayField = (
} = data
return {
...extractCommonFields(data),
title,
titleVariant,
label,
variant,
Expand All @@ -1070,7 +1060,7 @@ export const buildAccordionField = (
): AccordionField => {
const {
accordionItems,
title,
title = '',
titleVariant,
id,
marginTop,
Expand All @@ -1093,7 +1083,7 @@ export const buildAccordionField = (
export const buildBankAccountField = (
data: Omit<BankAccountField, 'type' | 'component' | 'children'>,
): BankAccountField => {
const { title, id, marginBottom, marginTop, titleVariant } = data
const { title = '', id, marginBottom, marginTop, titleVariant } = data
return {
children: undefined,
id,
Expand Down
13 changes: 7 additions & 6 deletions libs/application/core/src/lib/formBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@ import {
} from '@island.is/application/types'

export const buildForm = (data: Omit<Form, 'type'>): Form => {
return { ...data, type: FormItemTypes.FORM }
return { ...data, title: data.title ?? '', type: FormItemTypes.FORM }
}

export const buildMultiField = (data: Omit<MultiField, 'type'>): MultiField => {
return { ...data, type: FormItemTypes.MULTI_FIELD }
return { ...data, title: data.title ?? '', type: FormItemTypes.MULTI_FIELD }
}

export const buildRepeater = (data: Omit<Repeater, 'type'>): Repeater => {
return { ...data, type: FormItemTypes.REPEATER }
return { ...data, title: data.title ?? '', type: FormItemTypes.REPEATER }
}

export const buildSection = (data: Omit<Section, 'type'>): Section => {
return { ...data, type: FormItemTypes.SECTION }
return { ...data, title: data.title ?? '', type: FormItemTypes.SECTION }
}

export const buildSubSection = (data: Omit<SubSection, 'type'>): SubSection => {
return { ...data, type: FormItemTypes.SUB_SECTION }
return { ...data, title: data.title ?? '', type: FormItemTypes.SUB_SECTION }
}

export const buildExternalDataProvider = (
data: Omit<ExternalDataProvider, 'type' | 'isPartOfRepeater' | 'children'>,
): ExternalDataProvider => {
return {
...data,
title: data.title ?? '',
isPartOfRepeater: false,
children: undefined,
type: FormItemTypes.EXTERNAL_DATA_PROVIDER,
Expand All @@ -49,7 +50,7 @@ export const buildDataProviderItem = (
id: data.provider?.externalDataId ?? data.provider?.action ?? '',
action: data.provider?.actionId,
order: data.provider?.order,
title: data.title,
title: data.title ?? '',
subTitle: data.subTitle,
pageTitle: data.pageTitle,
source: data.source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type PersonField = {
export const CommissionFieldRepeater: FC<
React.PropsWithChildren<FieldBaseProps>
> = ({ application, errors, field }) => {
const { id, title } = field
const { id, title = '' } = field
const { formatMessage, lang: locale } = useLocale()
const { fields, append, remove } = useFieldArray({ name: id })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const FieldLabel: FC<React.PropsWithChildren<FieldBaseProps>> = ({
application,
field,
}) => {
const { title } = field
const { title = '' } = field
const { formatMessage, lang: locale } = useLocale()

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const FieldTitle = ({ field, application }: Props) => {
marginBottom={field.description ? 1 : 0}
>
{formatTextWithLocale(
field.title,
field.title ?? '',
application,
locale as Locale,
formatMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const AdditionalOwnersOverview = ({
<Box marginBottom={3}>
<Text variant="h3" marginBottom={3}>
{formatTextWithLocale(
field.title,
field.title ?? '',
application,
locale as Locale,
formatMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SecondaryContact: FC<React.PropsWithChildren<FieldBaseProps>> = ({
}) => {
const { setValue, getValues } = useFormContext()
const { formatMessage, lang: locale } = useLocale()
const { id, title } = field
const { id, title = '' } = field
const isEnabled = getValues('hasSecondaryContact') === YES

const enableSecondaryContact = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const PropertyOverviewRepeater: FC<
React.PropsWithChildren<PropTypes>
> = ({ field, application }) => {
const { formatMessage, lang: locale } = useLocale()
const { title } = field
const { title = '' } = field
const { id } = field.props as { id: string }
const fields = getValueViaPath(application.answers, id) as Property[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const PropertyRepeater: FC<React.PropsWithChildren<FieldBaseProps>> = ({
errors,
}) => {
const { formatMessage, lang: locale } = useLocale()
const { id, title } = field
const { id, title = '' } = field
const { fields, append, remove } = useFieldArray({
name: `${id}`,
})
Expand Down
2 changes: 1 addition & 1 deletion libs/application/types/src/lib/Fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export interface SelectOption<T = string | number> {
export interface BaseField extends FormItem {
readonly id: string
readonly component: FieldComponents | string
readonly title: FormTextWithLocale
readonly title?: FormTextWithLocale
readonly description?: FormTextWithLocale
readonly children: undefined
disabled?: boolean
Expand Down
8 changes: 4 additions & 4 deletions libs/application/types/src/lib/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface Form {
mode?: FormModes
renderLastScreenBackButton?: boolean
renderLastScreenButton?: boolean
title: StaticText
title?: StaticText
type: FormItemTypes.FORM
}

Expand All @@ -102,7 +102,7 @@ export interface FormItem extends TestSupport {
readonly id?: string
condition?: Condition
readonly type: string
readonly title: FormTextWithLocale
readonly title?: FormTextWithLocale
readonly nextButtonText?: FormText
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export interface DataProviderItem {
readonly id: string
readonly action?: string
readonly order?: number
readonly title: FormText
readonly title?: FormText
readonly subTitle?: FormText
readonly pageTitle?: FormText
readonly source?: string //TODO see if we can remove this
Expand All @@ -162,7 +162,7 @@ export interface DataProviderItem {
export interface DataProviderBuilderItem {
id?: string
type?: string //TODO REMOVE THIS
title: FormText
title?: FormText
subTitle?: FormText
pageTitle?: FormText
source?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const AlertMessageFormField: FC<React.PropsWithChildren<Props>> = ({
<AlertMessage
type={field.alertType ?? 'default'}
title={formatTextWithLocale(
field.title,
field.title ?? '',
application,
locale as Locale,
formatMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const AsyncSelectFormField: FC<React.PropsWithChildren<Props>> = ({
}) => {
const {
id,
title,
title = '',
description,
loadOptions,
loadingError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const CheckboxFormField = ({
}: Props) => {
const {
id,
title,
title = '',
description,
options,
disabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const CompanySearchFormField: FC<React.PropsWithChildren<Props>> = ({
}) => {
const {
id,
title,
title = '',
placeholder,
setLabelToDataSchema = true,
shouldIncludeIsatNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DateFormField: FC<React.PropsWithChildren<Props>> = ({
const {
id,
disabled,
title,
title = '',
description,
required,
placeholder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DescriptionFormField: FC<
{showFieldName && (
<Text variant={field.titleVariant}>
{formatTextWithLocale(
field.title,
field.title ?? '',
application,
locale as Locale,
formatMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ExpandableDescriptionFormField: FC<
startExpanded={field.startExpanded}
id={`BulletPointFormField-${field.id}`}
label={formatTextWithLocale(
field.title,
field.title ?? '',
application,
locale as Locale,
formatMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const FieldsRepeaterFormField = ({
description,
marginTop = 6,
marginBottom,
title,
title = '',
titleVariant = 'h2',
formTitle,
formTitleVariant = 'h4',
Expand Down
Loading

0 comments on commit d46501c

Please sign in to comment.