Skip to content

Commit a139fd4

Browse files
clean and optimize code
1 parent 3900fce commit a139fd4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx

+18-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ const formatName = (name, textFormat = 'lowercase') => {
1414
};
1515

1616
/**
17-
* Handles the formatting logic for field values.
18-
* For the "organization" field ID, it retains hyphens in the selected value but displays without hyphens in uppercase.
17+
* Defines the rules for formatting the field value based on the field id.
18+
* Removes hyphens and formats in uppercase for display
19+
* Retains hyphens in the stored value
1920
*/
21+
const FIELD_FORMAT_RULES = {
22+
organization: {
23+
display: (value) => formatName(value.replace(/[_-]/g, ' '), 'uppercase'),
24+
store: (value) => value,
25+
},
26+
default: {
27+
display: (value, textFormat) => formatName(value, textFormat),
28+
store: (value, textFormat) => formatName(value, textFormat),
29+
},
30+
};
31+
2032
const formatFieldValue = (value, fieldId, textFormat, display = false) => {
21-
if (fieldId === 'organization') {
22-
return display ? formatName(value, 'uppercase') : value;
23-
}
24-
return formatName(value, textFormat);
33+
const rules = FIELD_FORMAT_RULES[fieldId] || FIELD_FORMAT_RULES.default;
34+
return display
35+
? rules.display(value, textFormat)
36+
: rules.store(value, textFormat);
2537
};
2638

2739
/**

0 commit comments

Comments
 (0)