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

Analytics updates #2326

Merged
merged 2 commits into from
Dec 11, 2024
Merged

Analytics updates #2326

merged 2 commits into from
Dec 11, 2024

Conversation

OchiengPaul442
Copy link
Contributor

@OchiengPaul442 OchiengPaul442 commented Dec 11, 2024

Summary of Changes (What does this PR do?)

  • fixed organization select issue by modifying customfield component

image

Summary by CodeRabbit

  • New Features

    • Introduced a new formatName function for improved name formatting.
    • Enhanced conditional formatting for selected options based on specific IDs.
  • Bug Fixes

    • Improved handling of input field values to ensure proper formatting.
  • Documentation

    • Updated prop types to enforce required properties and improve clarity on expected structures.

@OchiengPaul442 OchiengPaul442 self-assigned this Dec 11, 2024
Copy link

coderabbitai bot commented Dec 11, 2024

📝 Walkthrough

Walkthrough

The pull request introduces significant updates to the CustomFields component in CustomFields.jsx. It replaces the capitalize function with a new formatName function that formats names based on specified text case options. The handleSelect function has been modified to conditionally format names based on the id prop, particularly for the 'organization' ID. Additionally, prop types have been enhanced to enforce required properties and clarify the expected structure of the options and defaultOption props, improving type safety.

Changes

File Change Summary
platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx - Removed capitalize function
- Added formatName function with textFormat parameter
- Updated prop types to enforce required properties for title, id, and handleOptionSelect
- Defined options as an array of objects with required id and name fields

Possibly related PRs

Suggested labels

ready for review

Suggested reviewers

  • Baalmart
  • Codebmk

🎉 In the realm of code, changes take flight,
A new formatName shines ever so bright.
With props now required, clarity's the key,
CustomFields evolve, as smooth as can be!
So here's to the updates, let's give them a cheer,
For cleaner, safer code, we hold so dear! 🎊


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (3)
platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx (3)

7-17: Consider adding input validation for textFormat parameter

The formatName function looks solid, but we could make it more robust with a few tweaks.

Consider this enhanced implementation:

 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;
 };

44-61: Consider making the formatting rules configurable

The hardcoded check for id !== 'organization' makes the component less reusable. Consider making this more flexible.

A few approaches to consider:

  1. Add a skipFormatting prop to specify fields that should skip formatting
  2. Add a formattingRules prop to define custom formatting per field type

Example implementation:

// In props
skipFormatting: PropTypes.arrayOf(PropTypes.string)

// In handleSelect
const shouldFormat = !skipFormatting?.includes(id);

131-147: Excellent PropTypes enhancement!

The improved type definitions make the component more reliable and self-documenting. 👍

Consider adding defaultProps for optional values:

CustomFields.defaultProps = {
  field: false,
  options: [],
  edit: false,
  useCalendar: false,
  textFormat: 'lowercase'
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 48aaa77 and 9dc5f19.

📒 Files selected for processing (1)
  • platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx (3 hunks)
🔇 Additional comments (1)
platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx (1)

52-56: Verify fix for organization selection issue

The special handling for organization names looks correct, but let's verify the fix.

✅ Verification successful

Let me search for more context about the CustomFields component and organization name handling to verify this change properly.


I need to see the full implementation of these components to understand how the organization field is being handled and verify if skipping the formatting for organization names is the correct approach.


Special handling for organization names is correctly implemented

The code correctly handles organization names by skipping the formatting for the 'organization' field. This is the right approach because:

  1. Organization names are used as identifiers in API calls (fetchSitesSummary and download data requests)
  2. The original organization names are preserved in both the dropdown and form data
  3. The special case is consistently applied in both the handleSelect function and the input field rendering
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related organization field implementations
rg -l "CustomFields.*organization" --type js

# Look for any existing organization name formatting
rg "formatName.*organization" --type js

Length of output: 88


Script:

#!/bin/bash
# Search for CustomFields component and its usage
fd -e jsx -e js | xargs rg -l "CustomFields"

# Look for organization-related code in the modal components
fd -e jsx -e js | xargs rg "organization.*name" -A 2 -B 2

# Search for formatName function implementation
ast-grep --pattern 'function formatName($_) { $$$ }'

Length of output: 3450


Script:

#!/bin/bash
# Let's look at the CustomFields component implementation
cat platform/src/common/components/Modal/dataDownload/components/CustomFields.jsx

# And check the DataDownload component to understand the context
cat platform/src/common/components/Modal/dataDownload/modules/DataDownload.jsx

Length of output: 18418

Comment on lines +72 to +76
value={
id === 'organization'
? selectedOption.name
: formatName(selectedOption.name, textFormat)
}
Copy link

@coderabbitai coderabbitai bot Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Extract repeated formatting logic to avoid duplication

The formatting condition is duplicated across the component. Let's make it DRY.

Consider extracting the formatting logic:

+ const formatFieldValue = (value, fieldId) => {
+   return fieldId === 'organization' ? value : formatName(value, textFormat);
+ };

  // Then use it like:
  value={formatFieldValue(selectedOption.name, id)}

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @OchiengPaul442

  • please take note of this review comment.
  • But also please ensure that you maintain our earlier UPPER CASE only organisation name implementation. Please do NOT change it.
    cc: @Codebmk

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upper casing is still maintained @Baalmart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will push a commit on this comment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

New next-platform changes available for preview here

@Baalmart Baalmart merged commit de8088b into staging Dec 11, 2024
30 of 31 checks passed
@Baalmart Baalmart deleted the analytics-updates branch December 11, 2024 12:16
@Baalmart Baalmart mentioned this pull request Dec 11, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants