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

521 hint values arent being updated #522

Merged
merged 3 commits into from
Jan 27, 2025

Conversation

DeboraSerra
Copy link
Contributor

Describe your changes

Changed migrations to prevent breaking the flow.
Changed behaviour of Formik to update the fields when data is updated

image

Issue number

#521

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

@DeboraSerra DeboraSerra requested a review from erenfn January 26, 2025 23:28
@DeboraSerra DeboraSerra linked an issue Jan 26, 2025 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Jan 26, 2025

Walkthrough

This pull request introduces significant refactoring across backend migration scripts and frontend components, focusing on state management and database schema improvements. The changes primarily involve consolidating state in React components, updating migration scripts with enhanced error handling and type annotations, and modifying how hint-related properties are managed. The modifications aim to improve code organization and data integrity across the application.

Changes

File Change Summary
backend/migrations/0006-1.0-hint.js Added JSDoc comments, replaced multiple column modification calls with changeColumn, introduced ENUM types for action, tooltipPlacement, and repetitionType
backend/migrations/0009-1.0-guidelog.js Added JSDoc comments, introduced try-catch block for index creation error handling
frontend/src/components/HintLeftContent/HintLeftContent.jsx Refactored props from multiple individual props to a single data object and setState function
frontend/src/scenes/hints/CreateHintPage.jsx Consolidated multiple state variables into a single leftContent state object

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • erenfn
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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. (Beta)
  • @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.

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
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: 1

🧹 Nitpick comments (5)
frontend/src/scenes/hints/CreateHintPage.jsx (3)

47-57: Clean up those commented state variables, fam! 🧹

Remove the commented-out state variables since they've been replaced by the leftContent object.


59-79: Let's make those default values reusable! 🎮

Extract the default values into a constant object for reusability and maintainability.

+const DEFAULT_LEFT_CONTENT = {
+  buttonRepetition: 'show only once',
+  url: 'https://',
+  actionButtonUrl: 'https://',
+  actionButtonText: 'Take me to subscription page',
+  action: 'No action',
+  targetElement: '.element',
+  tooltipPlacement: 'Top',
+  isHintIconVisible: true,
+};

-const [leftContent, setLeftContent] = useState({
-  buttonRepetition: 'show only once',
-  url: 'https://',
-  actionButtonUrl: 'https://',
-  actionButtonText: 'Take me to subscription page',
-  action: 'No action',
-  targetElement: '.element',
-  tooltipPlacement: 'Top',
-  isHintIconVisible: true,
-});
+const [leftContent, setLeftContent] = useState(DEFAULT_LEFT_CONTENT);

Line range hint 91-117: Error handling could use more specifics! 🎯

Consider providing more specific error messages for different failure scenarios.

 } catch (error) {
-  emitToastError(error);
+  const errorMessage = error.response?.data?.message
+    ? `Failed to fetch hint data: ${error.response.data.message}`
+    : 'Failed to fetch hint data. Please try again.';
+  emitToastError(errorMessage);
 }
frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (2)

210-223: Prop types could be more strict! 🔒

Consider adding:

  • Required flags
  • Specific string literals for enums
  • Default props
 HintLeftContent.propTypes = {
   data: PropTypes.shape({
-    buttonRepetition: PropTypes.string,
+    buttonRepetition: PropTypes.oneOf(['show only once', 'show every visit']).isRequired,
-    action: PropTypes.string,
+    action: PropTypes.oneOf(['No action', 'Open URL', 'Open URL in a new tab']).isRequired,
-    tooltipPlacement: PropTypes.string,
+    tooltipPlacement: PropTypes.oneOf(['Top', 'Right', 'Bottom', 'Left']).isRequired,
     // ... other props
-  }),
+  }).isRequired,
-  setState: PropTypes.func,
+  setState: PropTypes.func.isRequired,
   onSave: PropTypes.func,
 };

41-45: Form validation could be more robust! 💪

Consider enabling validation on blur for better user experience.

 <Formik
   initialValues={data}
   validationSchema={newHintSchema}
   enableReinitialize={true}
   validateOnMount={false}
-  validateOnBlur={false}
+  validateOnBlur={true}
 >
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 456b5f7 and d21c795.

📒 Files selected for processing (4)
  • backend/migrations/0006-1.0-hint.js (4 hunks)
  • backend/migrations/0009-1.0-guidelog.js (2 hunks)
  • frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (9 hunks)
  • frontend/src/scenes/hints/CreateHintPage.jsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (4)
backend/migrations/0009-1.0-guidelog.js (2)

6-47: Yo, this table creation is straight fire! 🔥

Clean implementation with proper:

  • Type annotations
  • Transaction handling
  • Column constraints
  • Nullable flags

Line range hint 66-88: Transaction handling is on point! 💯

Solid implementation with:

  • Proper commit on success
  • Rollback on failure
  • Error propagation
backend/migrations/0006-1.0-hint.js (2)

Line range hint 6-96: Table creation is looking clean! 🧼

Solid implementation with:

  • Type annotations
  • Proper foreign key references
  • Appropriate column constraints

Line range hint 97-130: Heads up about case sensitivity in ENUM types! 🎯

The ENUM types are case-sensitive, which could cause issues when comparing values. Consider normalizing case in the application layer.

Run this script to check for case mismatches in existing data:

@erenfn erenfn merged commit 74ed81c into develop Jan 27, 2025
2 checks passed
@erenfn erenfn deleted the 521-hint-values-arent-being-updated branch March 5, 2025 21:08
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.

Hint values aren't being updated
2 participants