Skip to content

fix: back button label updation and onboarding container layout#3868

Merged
jobenjada merged 2 commits intomainfrom
tweaks
Oct 24, 2024
Merged

fix: back button label updation and onboarding container layout#3868
jobenjada merged 2 commits intomainfrom
tweaks

Conversation

@Dhruwang
Copy link
Member

@Dhruwang Dhruwang commented Oct 18, 2024

What does this PR do?

Fixes #3835
Also fixes onboarding container layout

Screenshot 2024-10-18 at 10 58 28 AM

How should this be tested?

test back button label updation

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

  • New Features

    • Enhanced layout behavior in the Onboarding Options by adding responsive styling for better display.
    • Streamlined button label updating process in the Question Card for improved user experience.
  • Bug Fixes

    • Removed unnecessary logic related to back button labels in the Questions View, simplifying question management.

@vercel
Copy link

vercel bot commented Oct 18, 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) Visit Preview Oct 23, 2024 11:57pm
formbricks-docs ⬜️ Ignored (Inspect) Visit Preview Oct 23, 2024 11:57pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Warning

Rate limit exceeded

@jobenjada has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 960714e and 382578d.

Walkthrough

The pull request introduces modifications to three components: OnboardingOptionsContainer, QuestionCard, and QuestionsView. The OnboardingOptionsContainer component's layout behavior is adjusted by adding a flex-wrap class based on the number of options. The QuestionCard component's button label updating function is refactored for improved flexibility, while the QuestionsView component removes the management of the backButtonLabel, streamlining the question update logic.

Changes

File Change Summary
apps/web/app/(app)/(onboarding)/organizations/components/OnboardingOptionsContainer.tsx Added flex-wrap class to the className prop of a div based on options.length.
apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionCard.tsx Refactored updateEmptyNextButtonLabels to updateEmptyButtonLabels, adding labelKey and skipIndex parameters. Updated onBlur event handlers to reflect this change.
apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionsView.tsx Removed management of backButtonLabel, simplifying updateQuestion and addQuestion functions by eliminating related logic.

Assessment against linked issues

Objective Addressed Explanation
Ensure each "Back" Button Label maintains its own value (#3835)

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • jobenjada
  • gupta-piyush19

🐰 In the code we hop and play,
Flex-wrap here will save the day.
Labels change with a simple tweak,
Back button woes, now not so bleak!
With every edit, joy we find,
A smoother path for all mankind! 🐇


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 github-actions bot added the bug Something isn't working label Oct 18, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Oct 18, 2024

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

@Dhruwang Dhruwang requested a review from pandeymangg October 18, 2024 05:33
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: 0

🧹 Outside diff range and nitpick comments (4)
apps/web/app/(app)/(onboarding)/organizations/components/OnboardingOptionsContainer.tsx (1)

45-47: Approved: Improved layout responsiveness

The change effectively addresses the layout issue for the onboarding container by introducing conditional classes based on the number of options. This implementation provides a responsive design that adapts well to various screen sizes and option counts.

Consider extracting the class strings into variables for improved readability:

const commonClasses = "flex justify-center gap-8";
const wrapClasses = "w-5/6 flex-wrap lg:w-2/3";

// Then use them in the className prop
className={cn(commonClasses, {
  [wrapClasses]: options.length >= 3,
})}

This approach would make the class application more explicit and easier to maintain.

apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionsView.tsx (2)

Line range hint 232-252: LGTM: Simplified question update logic.

The removal of backButtonLabel handling and the consistent treatment of buttonLabel, upperLabel, and lowerLabel improve the code's clarity and address the reported issue. This change aligns well with the PR objectives.

Consider extracting the label handling logic into a separate function for better readability:

 const updateQuestion = (questionIdx: number, updatedAttributes: any) => {
   // ... existing code ...

   const attributesToCheck = ["buttonLabel", "upperLabel", "lowerLabel"];

+  const handleEmptyLabels = (question, attributes) => {
+    attributes.forEach((attribute) => {
+      if (Object.keys(updatedAttributes).includes(attribute)) {
+        const currentLabel = question[attribute];
+        if (currentLabel && Object.keys(currentLabel).length === 1 && currentLabel["default"].trim() === "") {
+          delete question[attribute];
+        }
+      }
+    });
+  };

-  attributesToCheck.forEach((attribute) => {
-    if (Object.keys(updatedAttributes).includes(attribute)) {
-      const currentLabel = updatedSurvey.questions[questionIdx][attribute];
-      if (currentLabel && Object.keys(currentLabel).length === 1 && currentLabel["default"].trim() === "") {
-        delete updatedSurvey.questions[questionIdx][attribute];
-      }
-    }
-  });
+  handleEmptyLabels(updatedSurvey.questions[questionIdx], attributesToCheck);

   setLocalSurvey(updatedSurvey);
   validateSurveyQuestion(updatedSurvey.questions[questionIdx]);
 };

This refactoring improves readability and makes the function more maintainable.


Issues Found: Incomplete Removal of backButtonLabel

While the backButtonLabel state management has been removed from QuestionsView.tsx, several references to backButtonLabel still exist in other files:

  • lib/validation.ts
  • components/EditorCardMenu.tsx
  • components/QuestionCard.tsx
  • components/CTAQuestionForm.tsx

These remaining references may lead to inconsistencies and potential bugs. Please ensure that backButtonLabel is fully removed from all related files to maintain codebase integrity.

🔗 Analysis chain

Line range hint 1-576: LGTM: Removed backButtonLabel state management.

The complete removal of backButtonLabel state management from the component is consistent with the PR objectives and addresses the reported issue. This change simplifies the component's logic and should resolve the problem of back button labels being incorrectly overridden.

To ensure that all references to backButtonLabel have been removed and that this change doesn't introduce any regressions, please run the following verification script:

This script will help verify that all backButtonLabel references have been removed from this file and related files, and check for any TODO comments that might be related to this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify complete removal of backButtonLabel and check for any remaining references

# Test 1: Check for any remaining backButtonLabel references in this file
echo "Checking for backButtonLabel references in QuestionsView.tsx:"
rg 'backButtonLabel' apps/web/app/\(app\)/\(survey-editor\)/environments/\[environmentId\]/surveys/\[surveyId\]/edit/components/QuestionsView.tsx

# Test 2: Check for backButtonLabel references in other files that might be affected
echo "Checking for backButtonLabel references in other related files:"
rg 'backButtonLabel' apps/web/app/\(app\)/\(survey-editor\)/environments/\[environmentId\]/surveys/\[surveyId\]/edit/

# Test 3: Check for any TODO comments related to this change
echo "Checking for related TODO comments:"
rg 'TODO.*back.*button' apps/web/app/\(app\)/\(survey-editor\)/environments/\[environmentId\]/surveys/\[surveyId\]/edit/

echo "Verification complete. Please review the results to ensure all backButtonLabel references have been properly removed."

Length of output: 3623

apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionCard.tsx (1)

474-481: Correct implementation of "Back" button label updates with minor improvement suggestion

The usage of updateEmptyButtonLabels for the "Back" button is well-implemented:

  1. It correctly uses "backButtonLabel" as the labelKey.
  2. The skipIndex is set to 0, preventing unnecessary updates to the first question's label.
  3. The translatedBackButtonLabel is properly constructed with the current language code.

This implementation ensures consistent "Back" button labels across the survey while respecting the first question's unique requirements.

For consistency with the "Next" button implementation, consider adding a check for the existence of question.backButtonLabel before updating:

 onBlur={(e) => {
   if (!question.backButtonLabel) return;
   let translatedBackButtonLabel = {
     ...question.backButtonLabel,
     [selectedLanguageCode]: e.target.value,
   };
+  if (questionIdx === 0) return;
   updateEmptyButtonLabels("backButtonLabel", translatedBackButtonLabel, 0);
 }}

This change ensures that the first question's back button label isn't unnecessarily updated, mirroring the logic used for the last question's next button.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4dad122 and 960714e.

📒 Files selected for processing (3)
  • apps/web/app/(app)/(onboarding)/organizations/components/OnboardingOptionsContainer.tsx (1 hunks)
  • apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionCard.tsx (3 hunks)
  • apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionsView.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
apps/web/app/(app)/(onboarding)/organizations/components/OnboardingOptionsContainer.tsx (1)

Line range hint 1-58: LGTM: Well-structured and flexible component

The OnboardingOptionsContainer component is well-implemented, providing a flexible and reusable solution for rendering onboarding options. It effectively handles various scenarios such as:

  1. Rendering options as links or regular cards
  2. Supporting loading states
  3. Displaying custom icons and icon text
  4. Adapting the layout based on the number of options

The use of the cn utility for conditional class names and the separation of the option card rendering logic into a separate function (getOptionCard) contribute to the component's maintainability.

apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionsView.tsx (3)

16-16: LGTM: Import statement updated correctly.

The addition of SetStateAction to the React import is appropriate. This type is commonly used for more precise typing of state setter functions, which can improve type safety in the component.


Line range hint 321-334: LGTM: Removed unnecessary backButtonLabel assignment.

The removal of the backButtonLabel assignment in the addQuestion function is consistent with the overall changes in this PR. This modification helps in addressing the reported issue with back button labels and simplifies the question addition process.


Line range hint 1-576: Summary: Effective resolution of back button label issue

The changes made to QuestionsView.tsx successfully address the reported issue with back button labels being incorrectly overridden. The removal of backButtonLabel state management and related logic simplifies the component and eliminates the source of the problem. These modifications are consistent throughout the file and align well with the PR objectives.

Key improvements:

  1. Removal of backButtonLabel handling in updateQuestion function.
  2. Consistent treatment of buttonLabel, upperLabel, and lowerLabel.
  3. Removal of backButtonLabel assignment in addQuestion function.
  4. Complete removal of backButtonLabel state management.

These changes should resolve the issue without introducing any negative side effects. The overall functionality of the component is maintained while improving its simplicity and reliability.

To ensure the completeness of these changes, please run the verification script provided in the previous comment to check for any remaining backButtonLabel references in this and related files.

apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/components/QuestionCard.tsx (3)

88-98: Improved flexibility and efficiency in button label updates

The refactoring of updateEmptyButtonLabels function is a significant improvement:

  1. It now handles both "Next" and "Back" button labels, increasing reusability.
  2. The skipIndex parameter allows excluding specific questions from updates, preventing unnecessary operations.
  3. The function is more efficient by only updating empty labels.

These changes align well with the DRY principle and improve the overall code quality.


451-455: Correct implementation of "Next" button label updates

The usage of updateEmptyButtonLabels for the "Next" button is well-implemented:

  1. It correctly uses "buttonLabel" as the labelKey.
  2. The skipIndex is set to the last question, preventing unnecessary updates to the final question's label.
  3. The translatedNextButtonLabel is properly constructed with the current language code.

This implementation ensures consistent "Next" button labels across the survey while respecting the last question's unique label requirements.


Line range hint 1-581: Summary: Effective resolution of back button label issue with improved code quality

The changes implemented in this file successfully address the issue described in #3835 regarding incorrect overwriting of back button labels. The refactoring of the updateEmptyButtonLabels function and its usage for both "Next" and "Back" buttons provide a more flexible and efficient solution.

Key improvements:

  1. Consistent handling of both "Next" and "Back" button labels.
  2. Prevention of unnecessary updates to the first and last questions' labels.
  3. Improved code reusability and maintainability.

These changes not only fix the reported issue but also enhance the overall quality of the code. The implementation aligns well with best practices and should provide a more robust solution for managing button labels in the survey editor.

@pandeymangg pandeymangg added this pull request to the merge queue Oct 18, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 18, 2024
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.

works well, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Back button label text gets overridden

3 participants