Skip to content

Commit

Permalink
radiobuttoninline field: rename sort function and add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Nov 14, 2024
1 parent 1d14a64 commit 70b265b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/application/components/ApplicationSubsection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 ? <FormField name={`${fieldName}.extraValue`} fieldAttributes={{
Expand Down
8 changes: 7 additions & 1 deletion src/application/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,13 @@ export const prepareApplicationForSubmission = (sections: Record<string, any>):
}
};

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);
}
Expand Down

0 comments on commit 70b265b

Please sign in to comment.