From b13721980dab6dc127e62b907270b20c62679096 Mon Sep 17 00:00:00 2001 From: Alejandro-Vega Date: Fri, 13 Dec 2024 09:47:41 -0500 Subject: [PATCH] Added back the abbreviation in the dropdown label --- src/content/questionnaire/sections/B.tsx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/content/questionnaire/sections/B.tsx b/src/content/questionnaire/sections/B.tsx index f24ad3e32..f6eaefba1 100644 --- a/src/content/questionnaire/sections/B.tsx +++ b/src/content/questionnaire/sections/B.tsx @@ -78,6 +78,7 @@ const FormSectionB: FC = ({ SectionOption, refs }: FormSection ); const [dbGaPPPHSNumber, setDbGaPPPHSNumber] = useState(data.study?.dbGaPPPHSNumber); + const customProgramIds: string[] = [NotApplicableProgram._id, OtherProgram._id]; const programKeyRef = useRef(new Date().getTime()); const formContainerRef = useRef(); const formRef = useRef(); @@ -281,6 +282,25 @@ const FormSectionB: FC = ({ SectionOption, refs }: FormSection setFundings(fundings.filter((f) => f.key !== key)); }; + /** + * Uses a form program to create a label + * + * @param program The form program that will be used to create the label + * @returns A label with the program name and abbreviation, if available. Otherwise an empty string. + */ + const formatProgramLabel = (program: ProgramInput) => { + if (!program) { + return ""; + } + if (customProgramIds.includes(program._id)) { + return program._id; + } + + return `${program.name || ""}${ + program.abbreviation ? ` (${program.abbreviation.toUpperCase()})` : "" + }`?.trim(); + }; + useEffect(() => { getFormObjectRef.current = getFormObject; }, [refs]); @@ -293,7 +313,6 @@ const FormSectionB: FC = ({ SectionOption, refs }: FormSection () => [NotApplicableProgram, ...programs, OtherProgram], [NotApplicableProgram, OtherProgram, programs] ); - const customProgramIds: string[] = [NotApplicableProgram._id, OtherProgram._id]; const readOnlyProgram = readOnlyInputs || program?._id !== OtherProgram._id; return ( @@ -308,7 +327,7 @@ const FormSectionB: FC = ({ SectionOption, refs }: FormSection label="Program" name="program[_id]" options={allProgramOptions.map((program) => ({ - label: customProgramIds.includes(program._id) ? program._id : program.name, + label: formatProgramLabel(program), value: program._id, }))} value={program?._id}