Skip to content

fix: inconsistencies in survey summary #4032

Merged
gupta-piyush19 merged 7 commits intomainfrom
fix/survey-summary-multi-choice-calculation
Oct 25, 2024
Merged

fix: inconsistencies in survey summary #4032
gupta-piyush19 merged 7 commits intomainfrom
fix/survey-summary-multi-choice-calculation

Conversation

@gupta-piyush19
Copy link
Contributor

@gupta-piyush19 gupta-piyush19 commented Oct 25, 2024

What does this PR do?

fixes inconsistencies in survey summary

Fixes # (issue)

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Summary by CodeRabbit

Release Notes

  • New Features

    • Updated caution message in the Survey Menu Bar to clarify implications of changes after responses.
    • Enhanced user interface in Picture Choice Summary to display additional selection information.
  • Improvements

    • Increased decimal precision for various percentage displays across multiple summary components, providing more accurate data representation.
    • Improved layout and readability of the Open Text Summary response table.
  • Bug Fixes

    • Refined logic for calculating survey summaries to ensure accurate representation of selections versus responses.

@vercel
Copy link

vercel bot commented Oct 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Oct 25, 2024 4:43pm
formbricks-docs ⬜️ Ignored (Inspect) Oct 25, 2024 4:43pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request primarily involve modifications to various components related to survey management. Key updates include changes to caution messages, enhancements in decimal precision for percentage displays, and improvements in the handling of survey summaries and validations. The overall logic and control flow remain largely unchanged, focusing on cosmetic improvements and minor adjustments to enhance user experience and data accuracy.

Changes

File Change Summary
apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/SurveyMenuBar.tsx Modified cautionText from "This survey received responses" to "Changes will lead to inconsistencies".
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx Increased CTR percentage display precision from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CalSummary.tsx Increased percentage display precision for "Booked" and "Dismissed" from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ConsentSummary.tsx Increased percentage display precision from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx Updated selection count text to title case and increased percentage display precision from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/NPSSummary.tsx Increased percentage display precision for NPS groups from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx Added width attributes to TableCell components and modified text wrapping behavior.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/PictureChoiceSummary.tsx Introduced additionalInfo prop for multi-selection and updated percentage display precision from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/RankingSummary.tsx Increased average ranking display precision from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/RatingSummary.tsx Increased rating percentage display precision from 1 to 2 decimal places.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts Added totalSelectionCount variable for improved response calculations and refined error handling.
packages/types/surveys/types.ts Added selectionCount to ZSurveyQuestionSummaryPictureSelection and refined validation logic.

Possibly related PRs

Suggested labels

bug, enhancement, 🕹️ oss.gg, 🕹️ 150 points

Suggested reviewers

  • jobenjada

Poem

In the fields where surveys grow,
With caution texts that gently flow,
Percentages now shine so bright,
Two decimals bring more delight!
A rabbit hops with joy and cheer,
For clearer data, let’s all hear! 🐇✨


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 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 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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 25, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@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: 2

🧹 Outside diff range and nitpick comments (7)
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CalSummary.tsx (1)

45-45: Consider aligning variable naming with UI text.

While the precision change is good, there's an inconsistency between the variable name (skipped) and the UI text ("Dismissed"). This could cause confusion during maintenance.

Consider applying this change for better clarity:

-questionSummary.skipped.percentage
+questionSummary.dismissed.percentage

Note: This change would need to be coordinated with the corresponding type definition in TSurveyQuestionSummaryCal.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/PictureChoiceSummary.tsx (1)

42-49: LGTM! Consider adding aria-label for accessibility.

The additional info section for multi-select questions is well implemented. The visual indicator with InboxIcon provides good UX.

Consider adding an aria-label to improve accessibility:

-            <div className="flex items-center rounded-lg bg-slate-100 p-2">
+            <div className="flex items-center rounded-lg bg-slate-100 p-2" aria-label="Total selections count">
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/RatingSummary.tsx (2)

81-81: LGTM! Consider adding number formatting for consistency.

The change to display percentages with 2 decimal places aligns well with other summary components and improves precision.

Consider using the Intl.NumberFormat for consistent number formatting across the application:

-{convertFloatToNDecimal(result.percentage, 2)}%
+{new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(result.percentage)}%

Line range hint 42-90: Consider performance optimizations.

The component could benefit from some performance improvements:

  1. Memoize the click handler to prevent recreating it on each render:
const handleFilterClick = useCallback(
  (rating: number) => {
    setFilter(
      questionSummary.question.id,
      questionSummary.question.headline,
      questionSummary.question.type,
      "Is equal to",
      rating.toString()
    );
  },
  [questionSummary.question, setFilter]
);
  1. Memoize the percentage calculations:
const choices = useMemo(
  () => questionSummary.choices.map((result) => ({
    ...result,
    formattedPercentage: new Intl.NumberFormat('en-US', {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2
    }).format(result.percentage)
  })),
  [questionSummary.choices]
);
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx (1)

105-115: LGTM! Consider making the width responsive.

The changes improve readability by using break-normal and setting a fixed width. However, consider using responsive width classes for better mobile support.

-<TableCell width={180}>
+<TableCell className="w-[120px] md:w-[180px]">
apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/SurveyMenuBar.tsx (2)

64-64: LGTM! Consider making the warning message more specific.

The new warning message is more action-oriented, but could be more specific about the consequences, e.g., "Changes may affect survey response data consistency."

-  const cautionText = "Changes will lead to inconsistencies.";
+  const cautionText = "Changes may affect survey response data consistency.";

Line range hint 274-284: Consider enhancing the tooltip with more detailed guidance.

The tooltip could provide more context about which types of changes might lead to inconsistencies and how to handle them safely.

                 <TooltipContent side={"top"} className="lg:hidden">
-                  <p className="py-2 text-center text-xs text-slate-500 dark:text-slate-400">{cautionText}</p>
+                  <div className="max-w-xs py-2 text-center text-xs text-slate-500 dark:text-slate-400">
+                    <p>{cautionText}</p>
+                    <p className="mt-1">Modifying questions or response options may impact data analysis. Consider creating a new survey version instead.</p>
+                  </div>
                 </TooltipContent>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5c0b29e and c6eb506.

📒 Files selected for processing (12)
  • apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/SurveyMenuBar.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CalSummary.tsx (2 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ConsentSummary.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx (2 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/NPSSummary.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx (2 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/PictureChoiceSummary.tsx (3 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/RankingSummary.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/RatingSummary.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts (3 hunks)
  • packages/types/surveys/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ConsentSummary.tsx
🔇 Additional comments (17)
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx (1)

47-47: Verify decimal precision consistency across all summary components.

The change to display CTR with 2 decimal places looks good. Let's verify this is consistent across all summary components.

✅ Verification successful

Decimal precision is consistent across all summary components

The verification confirms that all summary components using convertFloatToNDecimal are consistently using 2 decimal places for percentage and numerical values, including:

  • CTASummary: CTR percentage
  • CalSummary: Booked and skipped percentages
  • PictureChoiceSummary: Result percentages
  • RankingSummary: Average rankings
  • NPSSummary: Group percentages
  • MultipleChoiceSummary: Result percentages
  • ConsentSummary: Summary percentages
  • RatingSummary: Result percentages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check decimal precision usage across all summary components
# Expected: All summary components should use 2 decimal places

# Search for convertFloatToNDecimal usage in summary components
rg "convertFloatToNDecimal\([^,]+,\s*\d+" -A 1 "apps/web/app/(app)/environments/[^/]+/surveys/[^/]+/(analysis)/summary/components/*Summary.tsx"

Length of output: 280


Script:

#!/bin/bash
# Let's try a different approach to find summary components and their decimal precision usage
# First, let's find all Summary.tsx files in the apps directory
fd "Summary\.tsx$" apps/web

# Then, let's search for convertFloatToNDecimal usage in these files
rg "convertFloatToNDecimal\([^,]+,\s*\d+" apps/web

Length of output: 3677

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/RankingSummary.tsx (1)

41-41: LGTM! Decimal precision standardization.

The change from 1 to 2 decimal places aligns with the broader effort to standardize numerical representations across survey summary components.

Let's verify the consistency across other summary components:

✅ Verification successful

Decimal precision standardization verified across all summary components

All summary components consistently use 2 decimal places with convertFloatToNDecimal:

  • RatingSummary: convertFloatToNDecimal(result.percentage, 2)
  • RankingSummary: convertFloatToNDecimal(result.avgRanking, 2)
  • PictureChoiceSummary: convertFloatToNDecimal(result.percentage, 2)
  • NPSSummary: convertFloatToNDecimal(questionSummary[group]?.percentage, 2)
  • MultipleChoiceSummary: convertFloatToNDecimal(result.percentage, 2)
  • ConsentSummary: convertFloatToNDecimal(summaryItem.percentage, 2)
  • CalSummary: convertFloatToNDecimal(questionSummary.*.percentage, 2)
  • CTASummary: convertFloatToNDecimal(questionSummary.ctr.percentage, 2)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify decimal precision consistency across summary components
# Expect: All summary components should use 2 decimal places

# Search for convertFloatToNDecimal usage in summary components
rg -A 1 "convertFloatToNDecimal" --glob "*Summary.tsx"

Length of output: 6039

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CalSummary.tsx (1)

29-29: LGTM! Consistent with precision standardization.

The increased decimal precision aligns with the standardization effort across summary components.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/PictureChoiceSummary.tsx (2)

78-78: LGTM! Consistent decimal precision.

The change to display percentages with 2 decimal places aligns with other summary components, fixing the inconsistency as intended in the PR objectives.


83-83: LGTM! More accurate terminology.

Good update to use "Selection/Selections" instead of "response/responses", which better reflects the action being counted.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/NPSSummary.tsx (1)

79-79: Verify consistent decimal precision across all survey components.

The change to 2 decimal places aligns with the PR's goal of fixing inconsistencies.

Let's verify the consistency across other summary components:

✅ Verification successful

Decimal precision is consistent across all survey summary components

All survey summary components (NPSSummary, PictureChoiceSummary, MultipleChoiceSummary, ConsentSummary, CTASummary, CalSummary, and RatingSummary) consistently use convertFloatToNDecimal with 2 decimal places for percentage display. The change aligns perfectly with the existing codebase standards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check decimal precision in all survey summary components
# Expected: All components should use convertFloatToNDecimal with 2 decimal places

rg -U "convertFloatToNDecimal.*percentage.*\d" --type tsx

Length of output: 87


Script:

#!/bin/bash
# Search for usage of convertFloatToNDecimal with percentage across all files
rg -U "convertFloatToNDecimal.*percentage" 

# Also search for the function definition to understand its usage
rg -U "function convertFloatToNDecimal|const convertFloatToNDecimal"

Length of output: 1816

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx (2)

Line range hint 117-122: LGTM! Consistent text wrapping behavior.

The change maintains visual consistency between anonymous and identified users.


127-127: LGTM! Verify time formatting across all locales.

The fixed width improves layout stability. However, let's verify the time formatting works well across different locales.

✅ Verification successful

Let me analyze the timeSince implementation to verify the formatting.


Time formatting is properly implemented and consistent across the application

The implementation uses date-fns's formatDistance function which:

  • Handles all locales correctly through its internal localization system
  • Provides relative time formatting (e.g., "2 hours ago")
  • Uses consistent formatting across all usages in the codebase
  • The 120px width allocation is sufficient for the formatted output
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of timeSince to ensure consistent formatting
rg "timeSince" -A 2

Length of output: 18907


Script:

#!/bin/bash
# Check the implementation of timeSince function
cat packages/lib/time.ts

Length of output: 3347

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx (4)

76-76: LGTM! Consistent with other summary components.

The capitalization of "Selections" aligns with the standardization effort across survey summary components.


104-104: LGTM! Enhanced precision in percentage display.

The change to display percentages with 2 decimal places improves consistency with other summary components and provides more precise data representation.


109-109: LGTM! Standardized selection count text.

The conditional text formatting for singular/plural cases ("Selection"/"Selections") maintains proper grammar while adhering to the new capitalization standard.


Line range hint 76-109: Verify consistent formatting across all summary components.

While the changes look good, let's verify that similar formatting is applied consistently across all survey summary components.

✅ Verification successful

Selection count and percentage formatting are consistent across summary components

Based on the search results, I can verify that:

  1. All summary components consistently use:
    • "Selection(s)" with proper capitalization and pluralization
    • convertFloatToNDecimal(value, 2) for percentage formatting with 2 decimal places

The formatting in MultipleChoiceSummary.tsx matches other summary components like PictureChoiceSummary.tsx, RatingSummary.tsx, etc., ensuring a consistent user experience across all question types.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for inconsistencies in selection count and percentage formatting across summary components
# Expected: All summary components should use:
# - Capitalized "Selection(s)"
# - 2 decimal places for percentages
# - Consistent conditional text formatting

# Search for selection-related text formatting
echo "Checking selection text formatting..."
rg -i "selection[s]?" --type tsx

# Search for percentage decimal formatting
echo "Checking percentage decimal formatting..."
rg "convertFloatToNDecimal" -A 1 --type tsx

Length of output: 312


Script:

#!/bin/bash
# Let's try without file type filtering since tsx is not recognized
# Search for selection-related text formatting
echo "Checking selection text formatting..."
rg -i "selection[s]?" 

# Search for percentage decimal formatting
echo "Checking percentage decimal formatting..."
rg "convertFloatToNDecimal" -A 1

Length of output: 35005

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts (4)

431-438: LGTM! Tracking total selections improves accuracy.

The addition of totalSelectionCount and its increment within the response loop is correct. This ensures accurate percentage calculations for multi-select picture questions.


450-451: LGTM! Percentage calculation now uses total selections.

The percentage calculation now correctly uses totalSelectionCount instead of totalResponseCount, which is more accurate for multi-select questions where each response can have multiple selections.


460-460: LGTM! Summary includes total selection count.

Adding selectionCount to the summary object provides valuable information about the total number of selections made across all responses.


Line range hint 431-460: Verify consistency with other multi-select question types.

The changes improve accuracy for PictureSelection questions. Let's verify if other multi-select question types use the same approach.

✅ Verification successful

Based on the extensive search results, I can now verify the consistency of multi-select question types. The codebase shows that:

  1. The PictureSelection question type follows the same pattern as other multi-select questions (MultipleChoiceMulti) for handling selections and calculating percentages:
  • Both use Array.isArray() to check responses
  • Both track totalSelectionCount and totalResponseCount
  • Both calculate percentages using the same formula with totalSelectionCount as denominator
  1. The logic handling is consistent across multi-select types:
  • Same operators available (equals, doesNotEqual, includesAll, includesOne)
  • Same array response handling
  • Same validation rules
  1. The UI components handle both types similarly:
  • Same filtering mechanisms
  • Same summary display logic
  • Same response processing

The implementation for PictureSelection questions is consistent with other multi-select question types, confirming the changes are properly aligned with the existing patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other question types that might need similar treatment
ast-grep --pattern 'case TSurveyQuestionTypeEnum.$_: {
  $$$
  totalSelectionCount
  $$$
}'

# Search for percentage calculations in the file
rg 'percentage.*totalSelectionCount' -A 2 -B 2

Length of output: 142


Script:

#!/bin/bash
# Let's try a different approach to find multi-select question handling
rg "Array\.isArray.*answer" -B 5 -A 10

# Also search for totalSelectionCount usage
rg "totalSelectionCount" -B 5 -A 5

# Look for question type enums to understand all possible types
rg "TSurveyQuestionTypeEnum" -B 2 -A 10

Length of output: 581908

packages/types/surveys/types.ts (1)

2139-2139: Ensure selectionCount is properly initialized and utilized

The addition of selectionCount to ZSurveyQuestionSummaryPictureSelection enhances the data captured for picture selection questions. Please verify that all instances where ZSurveyQuestionSummaryPictureSelection is created or manipulated are updated to include this new property to prevent potential runtime errors.

Run the following script to find all usages of ZSurveyQuestionSummaryPictureSelection and check for selectionCount handling:

<div>
<p className="rounded-lg bg-slate-100 px-2 text-slate-700">
{convertFloatToNDecimal(questionSummary.ctr.percentage, 1)}%
{convertFloatToNDecimal(questionSummary.ctr.percentage, 2)}%
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using number formatting utilities for better readability.

For better readability of percentages, especially in different locales, consider using Intl.NumberFormat.

-                {convertFloatToNDecimal(questionSummary.ctr.percentage, 2)}%
+                {new Intl.NumberFormat(undefined, {
+                  minimumFractionDigits: 2,
+                  maximumFractionDigits: 2,
+                  style: 'percent',
+                }).format(questionSummary.ctr.percentage / 100)}
📝 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.

Suggested change
{convertFloatToNDecimal(questionSummary.ctr.percentage, 2)}%
{new Intl.NumberFormat(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
style: 'percent',
}).format(questionSummary.ctr.percentage / 100)}

<div>
<p className="rounded-lg bg-slate-100 px-2 text-slate-700">
{convertFloatToNDecimal(questionSummary[group]?.percentage, 1)}%
{convertFloatToNDecimal(questionSummary[group]?.percentage, 2)}%
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider UX implications of showing 2 decimal places.

While more precise, showing 2 decimal places in percentages might not always improve readability. Consider:

  1. Using 1 decimal place for larger numbers (>10%)
  2. 2 decimal places only for small percentages (<10%)

Here's a more nuanced approach:

-                    {convertFloatToNDecimal(questionSummary[group]?.percentage, 2)}%
+                    {questionSummary[group]?.percentage >= 10 
+                      ? convertFloatToNDecimal(questionSummary[group]?.percentage, 1)
+                      : convertFloatToNDecimal(questionSummary[group]?.percentage, 2)}%
📝 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.

Suggested change
{convertFloatToNDecimal(questionSummary[group]?.percentage, 2)}%
{questionSummary[group]?.percentage >= 10
? convertFloatToNDecimal(questionSummary[group]?.percentage, 1)
: convertFloatToNDecimal(questionSummary[group]?.percentage, 2)}%

Copy link
Member

@jobenjada jobenjada left a comment

Choose a reason for hiding this comment

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

looks great!

@coderabbitai coderabbitai bot mentioned this pull request Apr 15, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants