diff --git a/platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx b/platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx index 14cb2b8868..9cba6d624f 100644 --- a/platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx +++ b/platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx @@ -4,20 +4,26 @@ import CheckIcon from '@/icons/tickIcon'; import CustomDropdown from '../../../Dropdowns/CustomDropdown'; import DatePicker from '../../../Calendar/DatePicker'; -const capitalize = (name) => { - if (typeof name !== 'string' || !name) return name; - return name.charAt(0).toUpperCase() + name.slice(1); -}; - +/** + * Formats the name based on the specified text format. + * Replaces underscores and hyphens with spaces. + * @param {string} name - The string to format. + * @param {string} textFormat - The desired text format ('uppercase' or 'lowercase'). + * @returns {string} - The formatted string. + */ const formatName = (name, textFormat = 'lowercase') => { if (typeof name !== 'string' || !name) return name; - return typeof name === 'string' - ? textFormat === 'uppercase' - ? name.toUpperCase().replace(/_/g, ' ').replace(/-/g, ' ') - : name.replace(/_/g, ' ').replace(/-/g, ' ') - : capitalize(name); + const formatted = name.replace(/[_-]/g, ' '); // Replace underscores and hyphens with spaces + return textFormat === 'uppercase' ? formatted.toUpperCase() : formatted; }; +/** + * CustomFields Component + * Renders different types of input fields based on props. + * + * @param {object} props - Component properties. + * @returns {JSX.Element} - Rendered component. + */ const CustomFields = ({ field = false, title, @@ -35,31 +41,46 @@ const CustomFields = ({ defaultOption || options[0], ); + /** + * Handles the selection of an option. + * Conditionally formats the name based on the field's ID. + * + * @param {object} option - The selected option object. + */ const handleSelect = useCallback( (option) => { + // Determine if formatting should be applied + const shouldFormat = id !== 'organization'; const formattedOption = { ...option, - name: formatName(option.name), + name: shouldFormat ? formatName(option.name, textFormat) : option.name, }; setSelectedOption(formattedOption); handleOptionSelect(id, formattedOption); }, - [id, handleOptionSelect], + [id, handleOptionSelect, textFormat], ); return (