-
Notifications
You must be signed in to change notification settings - Fork 31
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
Updated logic on custom field component #2331
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes in Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx (2)
Line range hint
8-14
: Clean implementation, but consider enhancing input validationThe formatName function is well-implemented with good edge case handling. However, we could make the textFormat validation more robust.
Consider adding validation for the textFormat parameter:
const formatName = (name, textFormat = 'lowercase') => { if (typeof name !== 'string' || !name) return name; + if (!['uppercase', 'lowercase'].includes(textFormat)) { + console.warn(`Invalid textFormat: ${textFormat}. Defaulting to lowercase.`); + textFormat = 'lowercase'; + } const formatted = name.replace(/[_-]/g, ' '); return textFormat === 'uppercase' ? formatted.toUpperCase() : formatted; };
Line range hint
134-134
: Add JSDoc for the textFormat propWhile the PropType validation is correct, adding documentation would improve maintainability.
Add JSDoc for the textFormat prop:
CustomFields.propTypes = { + /** + * Controls text case formatting. + * @default 'lowercase' + */ textFormat: PropTypes.oneOf(['uppercase', 'lowercase']),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx
(4 hunks)
🔇 Additional comments (1)
platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx (1)
70-70
: Consistent formatting implementation, verify impact
The formatting changes are consistently applied across both input and button text. However, we should verify the impact on existing data.
Also applies to: 95-95
* Handles the formatting logic for field values. | ||
* For the "organization" field ID, it retains hyphens in the selected value but displays without hyphens in uppercase. | ||
*/ | ||
const formatFieldValue = (value, fieldId, textFormat) => { | ||
const formatFieldValue = (value, fieldId, textFormat, display = false) => { | ||
if (fieldId === 'organization') { | ||
return value.toUpperCase(); | ||
return display ? formatName(value, 'uppercase') : value; | ||
} | ||
return formatName(value, textFormat); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider extracting field-specific formatting rules
The special case handling for 'organization' suggests this function might grow unwieldy as more field-specific rules are added.
Consider extracting field-specific formatting rules to a configuration object:
+const FIELD_FORMAT_RULES = {
+ organization: {
+ display: (value) => formatName(value, 'uppercase'),
+ store: (value) => value
+ },
+ default: {
+ display: (value, textFormat) => formatName(value, textFormat),
+ store: (value, textFormat) => formatName(value, textFormat)
+ }
+};
-const formatFieldValue = (value, fieldId, textFormat, display = false) => {
- if (fieldId === 'organization') {
- return display ? formatName(value, 'uppercase') : value;
- }
- return formatName(value, textFormat);
+const formatFieldValue = (value, fieldId, textFormat, display = false) => {
+ const rules = FIELD_FORMAT_RULES[fieldId] || FIELD_FORMAT_RULES.default;
+ return display ? rules.display(value, textFormat) : rules.store(value, textFormat);
};
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
* Handles the formatting logic for field values. | |
* For the "organization" field ID, it retains hyphens in the selected value but displays without hyphens in uppercase. | |
*/ | |
const formatFieldValue = (value, fieldId, textFormat) => { | |
const formatFieldValue = (value, fieldId, textFormat, display = false) => { | |
if (fieldId === 'organization') { | |
return value.toUpperCase(); | |
return display ? formatName(value, 'uppercase') : value; | |
} | |
return formatName(value, textFormat); | |
}; | |
/** | |
* Handles the formatting logic for field values. | |
* For the "organization" field ID, it retains hyphens in the selected value but displays without hyphens in uppercase. | |
*/ | |
const FIELD_FORMAT_RULES = { | |
organization: { | |
display: (value) => formatName(value, 'uppercase'), | |
store: (value) => value | |
}, | |
default: { | |
display: (value, textFormat) => formatName(value, textFormat), | |
store: (value, textFormat) => formatName(value, textFormat) | |
} | |
}; | |
const formatFieldValue = (value, fieldId, textFormat, display = false) => { | |
const rules = FIELD_FORMAT_RULES[fieldId] || FIELD_FORMAT_RULES.default; | |
return display ? rules.display(value, textFormat) : rules.store(value, textFormat); | |
}; |
New next-platform changes available for preview here |
New next-platform changes available for preview here |
Summary of Changes (What does this PR do?)
Summary by CodeRabbit
New Features
Bug Fixes