Skip to content

Commit

Permalink
radiobuttoninline field: sort applicant type choices by value
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Nov 13, 2024
1 parent 4074030 commit 16381f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 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, getSectionApplicantType, getSectionTemplate, valueToApplicantType } from "@/application/helpers";
import { getApplicationAttachmentDownloadLink, getFieldFileIds, getRadioButtonInlineFieldChoicesSorted, 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: field.choices.map(choice => ({
options: getRadioButtonInlineFieldChoicesSorted(field, field.choices).map(choice => ({
label: choice.text,
value: choice.value,
field: choice.has_text_input ? <FormField name={`${fieldName}.extraValue`} fieldAttributes={{
Expand Down
13 changes: 10 additions & 3 deletions src/application/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { FormNames } from "@/enums";
import { ApplicantInfoCheckExternalTypes, ApplicantInfoCheckTypes, ApplicantTypes, TargetIdentifierTypes } from "@/application/enums";
import { getContentUser } from "@/users/helpers";
import createUrl from "@/api/createUrl";
import { APPLICANT_MAIN_IDENTIFIERS, APPLICANT_SECTION_IDENTIFIER, TARGET_SECTION_IDENTIFIER } from "@/application/constants";
import { APPLICANT_MAIN_IDENTIFIERS, APPLICANT_SECTION_IDENTIFIER, APPLICANT_TYPE_FIELD_IDENTIFIER, TARGET_SECTION_IDENTIFIER } from "@/application/constants";
import { store } from "@/index";
import { displayUIMessage } from "@/util/helpers";
import type { PlotSearch } from "@/plotSearch/types";
import type { RootState } from "@/root/types";
import type { ApplicationFormSection, Form, FormSection, PlotApplicationFormValue, SavedApplicationFormSection, UploadedFileMeta } from "@/application/types";
import type { ApplicationFormSection, Form, FormField, FormFieldChoice, FormSection, PlotApplicationFormValue, SavedApplicationFormSection, UploadedFileMeta } from "@/application/types";
export const transformTargetSectionTitle = (plotSearch: PlotSearch): (...args: Array<any>) => any => (title: string, section: FormSection, answer: SavedApplicationFormSection): string => {
if (section.identifier === TARGET_SECTION_IDENTIFIER && answer?.metadata?.identifier) {
const target = plotSearch?.plot_search_targets.find(target => target.id === answer.metadata?.identifier);
Expand Down Expand Up @@ -396,4 +396,11 @@ export const prepareApplicationForSubmission = (sections: Record<string, any>):
console.log(e);
return null;
}
};
};

export const getRadioButtonInlineFieldChoicesSorted = (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);
}
return choices;
}

0 comments on commit 16381f5

Please sign in to comment.