From 70b265bbcfcfbc06bb50cdfcbf1122750b51c2e0 Mon Sep 17 00:00:00 2001 From: Jukka Ahonen Date: Thu, 14 Nov 2024 10:50:55 +0200 Subject: [PATCH] radiobuttoninline field: rename sort function and add docstring --- src/application/components/ApplicationSubsection.tsx | 4 ++-- src/application/helpers.ts | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/application/components/ApplicationSubsection.tsx b/src/application/components/ApplicationSubsection.tsx index fe8f93df..d459a0ef 100644 --- a/src/application/components/ApplicationSubsection.tsx +++ b/src/application/components/ApplicationSubsection.tsx @@ -17,7 +17,7 @@ import { formatDate, isFieldAllowedToRead } from "@/util/helpers"; import { ConfirmationModalTexts } from "@/enums"; import { ActionTypes, AppConsumer } from "@/app/AppContext"; import { ApplicantTypes } from "@/application/enums"; -import { getApplicationAttachmentDownloadLink, getFieldFileIds, getRadioButtonInlineFieldChoicesSorted, getSectionApplicantType, getSectionTemplate, valueToApplicantType } from "@/application/helpers"; +import { getApplicationAttachmentDownloadLink, getFieldChoicesSorted, getFieldFileIds, getSectionApplicantType, getSectionTemplate, valueToApplicantType } from "@/application/helpers"; import { getAttachmentAttributes, getAttachmentMethods, getExistingUploads, getFieldTypeMapping, getIsFetchingApplicationRelatedAttachments, getIsFetchingAttachmentAttributes, getIsFetchingPendingUploads, getIsPerformingFileOperation, getPendingUploads } from "@/application/selectors"; import { ApplicationSectionKeys } from "@/application/components/enums"; import { APPLICANT_MAIN_IDENTIFIERS, APPLICANT_SECTION_IDENTIFIER, APPLICANT_TYPE_FIELD_IDENTIFIER, EMAIL_FIELD_IDENTIFIER, TARGET_SECTION_IDENTIFIER } from "@/application/constants"; @@ -271,7 +271,7 @@ const ApplicationFormSubsectionFields = connect((state, props) => ({ type: 'radio-with-field' }; fieldOverrides = { - options: getRadioButtonInlineFieldChoicesSorted(field, field.choices || []).map(choice => ({ + options: getFieldChoicesSorted(field, field.choices || []).map(choice => ({ label: choice.text, value: choice.value, field: choice.has_text_input ? ): } }; -export const getRadioButtonInlineFieldChoicesSorted = (field: FormField, choices: FormFieldChoice[]): FormFieldChoice[] => { +/** + * Sorts the choices of a field based on the criteria specific to different field identifiers. + * @param {FormField} field + * @param {FormFieldChoice} choices + * @returns {FormFieldChoice[]} + */ +export const getFieldChoicesSorted = (field: FormField, choices: FormFieldChoice[]): FormFieldChoice[] => { if (field.identifier === APPLICANT_TYPE_FIELD_IDENTIFIER) { return choices.sort((a: FormFieldChoice, b: FormFieldChoice): number => parseInt(a.value) - parseInt(b.value) || 0); }