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

501 add repetition to hints #516

Merged
merged 6 commits into from
Jan 23, 2025
Merged

501 add repetition to hints #516

merged 6 commits into from
Jan 23, 2025

Conversation

MandeepPaul
Copy link
Collaborator

Describe your changes

Adde repetition field to hints. Updated tests, hint modal and migration.

Issue number

#501

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.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces a new repetitionType feature for hints, allowing users to control how often a hint is displayed. The changes span across multiple files in the backend and frontend, including database migrations, model definitions, configuration settings, and UI components. The implementation adds validation, updates test cases, and modifies the hint creation and management process to support two repetition types: "show only once" and "show every visit".

Changes

File Change Summary
backend/migrations/0006-1.0-hint.js Added repetitionType column, modified action and tooltipPlacement columns
backend/src/models/Hint.js Added repetitionType property with validation
backend/src/test/e2e/hint.test.mjs Updated test cases for repetitionType validation
backend/src/test/mocks/hint.mock.js Added repetitionType to hint mock and new builder methods
backend/src/utils/hint.helper.js Added validation rule for repetitionType
frontend/src/components/HintLeftContent.jsx Added dropdown for repetition type selection
frontend/src/scenes/hints/CreateHintPage.jsx Introduced buttonRepetition state and handling
backend/config/settings.js Added repetition configuration options

Possibly Related PRs

Suggested Reviewers

  • swoopertr
  • erenfn

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 641870b and 7c03a9b.

📒 Files selected for processing (1)
  • frontend/src/scenes/hints/CreateHintPage.jsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/scenes/hints/CreateHintPage.jsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)

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

🔭 Outside diff range comments (1)
backend/migrations/0006-1.0-hint.js (1)

Line range hint 3-3: Yo, we got some dead weight here! 🏋️‍♂️

The url import from 'inspector' is not used in this file.

- const { url } = require("inspector");
🧹 Nitpick comments (4)
backend/src/utils/hint.helper.js (1)

6-6: Yo, we need to keep it DRY! 🍝

The validation looks good, but the repetition options are duplicated across multiple files (model, helper, migration). Let's centralize these values in a shared constants file to maintain consistency.

Consider creating a shared constants file:

+ // backend/src/constants/hint.js
+ const HINT_CONSTANTS = {
+   REPETITION_TYPES: {
+     SHOW_ONCE: 'show only once',
+     SHOW_EVERY_VISIT: 'show every visit'
+   }
+ };
+ 
+ module.exports = HINT_CONSTANTS;

Then import and use it across all files:

- const validRepetitionOptions = ['show only once', 'show every visit'];
+ const { HINT_CONSTANTS } = require('../constants/hint');
+ const validRepetitionOptions = Object.values(HINT_CONSTANTS.REPETITION_TYPES);

Also applies to: 25-32

frontend/src/scenes/hints/CreateHintPage.jsx (1)

94-94: Consider aligning state variable name with API property

The state variable buttonRepetition is saved as repetitionType in the API. Consider renaming the state variable to match the API property name for better consistency.

-const [buttonRepetition, setButtonRepetition] = useState('Show only once');
+const [repetitionType, setRepetitionType] = useState('Show only once');
frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (2)

27-29: Add validation to the repetition handler

Consider adding validation to ensure only valid repetition types are set.

 const handleRepetitionChange = (newRepetitionType) => {
+  const validTypes = ['Show only once', 'Show every visit'];
+  if (!validTypes.includes(newRepetitionType)) {
+    console.warn(`Invalid repetition type: ${newRepetitionType}`);
+    return;
+  }
   setButtonRepetition(newRepetitionType);
 };

90-94: Extract repetition options to constants

Consider moving the repetition options to a constants file for better maintainability and reuse.

+const REPETITION_OPTIONS = ['Show only once', 'Show every visit'];
+
 <DropdownList
-  actions={['Show only once', 'Show every visit']}
+  actions={REPETITION_OPTIONS}
   onActionChange={handleRepetitionChange}
   selectedActionString={buttonRepetition}
 />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9cce0 and 5bed7ac.

📒 Files selected for processing (8)
  • backend/migrations/0006-1.0-hint.js (1 hunks)
  • backend/src/models/Hint.js (1 hunks)
  • backend/src/test/e2e/hint.test.mjs (1 hunks)
  • backend/src/test/mocks/hint.mock.js (2 hunks)
  • backend/src/test/unit/controllers/auth.test.js (1 hunks)
  • backend/src/utils/hint.helper.js (2 hunks)
  • frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (4 hunks)
  • frontend/src/scenes/hints/CreateHintPage.jsx (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • backend/src/test/unit/controllers/auth.test.js
🔇 Additional comments (4)
backend/src/test/mocks/hint.mock.js (1)

6-6: Yo dawg, these changes are straight fire! 🔥

The mock implementation is solid with proper test coverage for both missing and invalid repetition types. The default value matches the database migration.

Also applies to: 37-45

backend/migrations/0006-1.0-hint.js (1)

18-22: Clean migration, fam! 💯

The repetitionType column is properly defined with appropriate constraints and default value.

frontend/src/scenes/hints/CreateHintPage.jsx (2)

47-48: Yo, the repetition state management is on point!

The initialization and data fetching logic for buttonRepetition is well-implemented with proper default values and fallback handling.

Also applies to: 75-75


169-170: Props passing looks clean!

The repetition state and its setter are properly passed to the HintLeftContent component.

@MandeepPaul MandeepPaul force-pushed the 501-add-repetition-to-hints branch from eb1db69 to 641870b Compare January 23, 2025 10:14
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

🔭 Outside diff range comments (1)
frontend/src/scenes/hints/CreateHintPage.jsx (1)

Line range hint 94-109: There's vomit on his sweater already - we're missing validation!

The hintData construction needs validation before sending to the API, eh? Let's add some error checking.

+ import { hint as hintSettings } from '../../../backend/config/settings';

  const onSave = async () => {
+   const repetitionType = buttonRepetition.toLowerCase();
+   if (!hintSettings.repetition.includes(repetitionType)) {
+     toastEmitter.emit(
+       TOAST_EMITTER_KEY,
+       `Error: Invalid repetition type. Allowed values are: ${hintSettings.repetition.join(', ')}`
+     );
+     return;
+   }

    const hintData = {
-     repetitionType: buttonRepetition.toLowerCase(),
+     repetitionType,
      tooltipPlacement: tooltipPlacement.toLowerCase(),
      // ... rest of the properties
    };
🧹 Nitpick comments (2)
backend/config/settings.js (1)

46-46: Yo, the repetition values look solid, but let's keep our consistency game strong!

The new repetition values align well with the existing popup and banner configurations, eh? However, we should consider extracting these common repetition values into a shared constant to maintain consistency across different components.

+ const commonRepetition = ['show only once', 'show every visit'];

  module.exports = {
    // ... other config
    hint: {
      action: ['no action', 'open url', 'open url in a new tab'],
-     repetition: ['show only once', 'show every visit'],
+     repetition: [...commonRepetition],
    },
    popup: {
      action: ['no action', 'open url', 'open url in a new tab'],
-     repetition: ['show only once', 'show every visit'],
+     repetition: [...commonRepetition],
    },
    banner: {
-     repetition: ['show only once', 'show every visit'],
+     repetition: [...commonRepetition],
    },
  };
frontend/src/scenes/hints/CreateHintPage.jsx (1)

169-170: Lose yourself in the documentation - we need prop types!

The new props need proper TypeScript/PropTypes definitions to prevent future bugs.

HintLeftContent.propTypes = {
  buttonRepetition: PropTypes.string.isRequired,
  setButtonRepetition: PropTypes.func.isRequired,
  // ... other prop types
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eb1db69 and 641870b.

📒 Files selected for processing (8)
  • backend/config/settings.js (1 hunks)
  • backend/migrations/0006-1.0-hint.js (1 hunks)
  • backend/src/models/Hint.js (1 hunks)
  • backend/src/test/e2e/hint.test.mjs (2 hunks)
  • backend/src/test/mocks/hint.mock.js (2 hunks)
  • backend/src/utils/hint.helper.js (1 hunks)
  • frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (4 hunks)
  • frontend/src/scenes/hints/CreateHintPage.jsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • backend/src/utils/hint.helper.js
  • backend/src/models/Hint.js
  • backend/src/test/e2e/hint.test.mjs
  • backend/src/test/mocks/hint.mock.js
  • backend/migrations/0006-1.0-hint.js
  • frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (1)
frontend/src/scenes/hints/CreateHintPage.jsx (1)

67-75: Mom's spaghetti moment - we need better error handling here!

The data fetching logic needs to validate the repetitionType against allowed values from settings.js before setting the state.

@MandeepPaul MandeepPaul requested a review from erenfn January 23, 2025 16:34
@erenfn erenfn merged commit ab3bb40 into develop Jan 23, 2025
2 checks passed
@MandeepPaul MandeepPaul deleted the 501-add-repetition-to-hints branch January 24, 2025 13:36
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