Skip to content

Commit

Permalink
Merge pull request #2308 from airqo-platform/hotfix-data-export
Browse files Browse the repository at this point in the history
[Analytics] Format organisation dropdown text to uppercase
  • Loading branch information
Baalmart authored Dec 10, 2024
2 parents f84eb15 + 06938fd commit 7960367
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@ const formatGroupName = (name) => {
const trimmedName = name.trim();
if (!trimmedName) return 'Unknown';

return trimmedName.toLowerCase() === 'airqo'
? 'AirQo'
: trimmedName
.replace(/_/g, ' ')
.split(' ')
.map(
(word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
)
.join(' ');
// make name upper case and replace _ or - with space
return trimmedName.toUpperCase().replace(/_/g, ' ').replace(/-/g, ' ');
};

const getAbbreviation = (name) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import CheckIcon from '@/icons/tickIcon';
import CustomDropdown from '../../../Dropdowns/CustomDropdown';
import DatePicker from '../../../Calendar/DatePicker';

const formatName = (name) => {
if (typeof name === 'string' && name.toLowerCase() === 'airqo') {
return 'AirQo';
}
return name;
const capitalize = (name) => {
if (typeof name !== 'string' || !name) return name;
return name.charAt(0).toUpperCase() + name.slice(1);
};

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 CustomFields = ({
Expand All @@ -22,6 +29,7 @@ const CustomFields = ({
useCalendar = false,
handleOptionSelect,
defaultOption,
textFormat = 'lowercase',
}) => {
const [selectedOption, setSelectedOption] = useState(
defaultOption || options[0],
Expand Down Expand Up @@ -65,9 +73,13 @@ const CustomFields = ({
tabStyle="w-full bg-white px-3 py-2"
dropdown
tabIcon={icon}
btnText={btnText || formatName(selectedOption.name)}
btnText={
formatName(btnText, textFormat) ||
formatName(selectedOption.name, textFormat)
}
customPopperStyle={{ left: '-7px' }}
dropDownClass="w-full"
textFormat={textFormat}
>
{options.map((option) => (
<span
Expand All @@ -77,8 +89,8 @@ const CustomFields = ({
selectedOption.id === option.id ? 'bg-[#EBF5FF] rounded-md' : ''
}`}
>
<span className="flex items-center capitalize space-x-2">
<span>{formatName(option.name)}</span>
<span className="flex items-center space-x-2">
<span>{formatName(option.name, textFormat)}</span>
</span>
{selectedOption.id === option.id && (
<CheckIcon fill={'#145FFF'} />
Expand All @@ -102,6 +114,7 @@ CustomFields.propTypes = {
useCalendar: PropTypes.bool,
handleOptionSelect: PropTypes.func,
defaultOption: PropTypes.object,
textFormat: PropTypes.oneOf(['uppercase', 'lowercase']),
};

export default CustomFields;
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ const DataDownload = ({ onClose }) => {
icon={<WorldIcon width={16} height={16} fill="#000" />}
defaultOption={formData.network}
handleOptionSelect={handleOptionSelect}
textFormat="uppercase"
/>
<CustomFields
title="Data type"
Expand Down

0 comments on commit 7960367

Please sign in to comment.