Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRDCDH-2008 Hotfix: Fix adding back abbreviation in program dropdown labels #563

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading