Skip to content

Commit

Permalink
Merge pull request #563 from CBIIT/CRDCDH-2008-hotfix
Browse files Browse the repository at this point in the history
CRDCDH-2008 Hotfix: Fix adding back abbreviation in program dropdown labels
  • Loading branch information
amattu2 authored Dec 13, 2024
2 parents 25eddce + b137219 commit ee3eb12
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/content/questionnaire/sections/B.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const FormSectionB: FC<FormSectionProps> = ({ SectionOption, refs }: FormSection
);
const [dbGaPPPHSNumber, setDbGaPPPHSNumber] = useState<string>(data.study?.dbGaPPPHSNumber);

const customProgramIds: string[] = [NotApplicableProgram._id, OtherProgram._id];
const programKeyRef = useRef(new Date().getTime());
const formContainerRef = useRef<HTMLDivElement>();
const formRef = useRef<HTMLFormElement>();
Expand Down Expand Up @@ -281,6 +282,25 @@ const FormSectionB: FC<FormSectionProps> = ({ 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]);
Expand All @@ -293,7 +313,6 @@ const FormSectionB: FC<FormSectionProps> = ({ SectionOption, refs }: FormSection
() => [NotApplicableProgram, ...programs, OtherProgram],
[NotApplicableProgram, OtherProgram, programs]
);
const customProgramIds: string[] = [NotApplicableProgram._id, OtherProgram._id];
const readOnlyProgram = readOnlyInputs || program?._id !== OtherProgram._id;

return (
Expand All @@ -308,7 +327,7 @@ const FormSectionB: FC<FormSectionProps> = ({ 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}
Expand Down

0 comments on commit ee3eb12

Please sign in to comment.