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

Creating hint in js agent and fixes #470

Merged
merged 13 commits into from
Jan 9, 2025
Merged

Conversation

swoopertr
Copy link
Contributor

@swoopertr swoopertr commented Jan 7, 2025

Describe your changes

Coding hint agent
-font fix for all available guides font-size :13px
-shadow fix for popup
-banner bottom position fix
-hint and popup button removed if the button action value is 'no action'

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

@swoopertr swoopertr added the enhancement New feature or request label Jan 7, 2025
@swoopertr swoopertr added this to the 1.0 milestone Jan 7, 2025
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

This pull request introduces a new JavaScript module bw.hint for managing tooltips on a webpage. The module provides functionality to dynamically generate and position tooltips based on configuration data. Additionally, modifications were made to the links.js file to remove a console log statement, and the main.js file was updated to conditionally load the hint script based on the onboard configuration. Changes to the popup.js file refine the modal's styling and improve event handling. The banner.js file also sees enhancements with a structured HTML template for banners.

Changes

File Change Summary
jsAgent/hint.js Added new bw.hint module with methods for tooltip generation, positioning, and interaction.
jsAgent/links.js Removed a console log statement in the putHtml method; updated font sizes in templates.
jsAgent/main.js Added BW_HINT_JS_URL constant and conditional script loading for hints based on configuration.
jsAgent/popup.js Updated modal styling and refined event handling for mouse interactions.
jsAgent/banner.js Removed console log and introduced a structured HTML template for banners with improved event handling.

Possibly Related PRs

  • added hints to get complete guides by url #431: This PR introduces enhancements to the hint functionality by adding a URL field to the hints, which is directly related to the tooltip management in the main PR that also deals with hints and their interactions.
  • fixed edit for hints #462: This PR modifies the Hint model to allow for longer content in the hintContent field, which is relevant to the tooltip functionality in the main PR that manages hints and their display.

Suggested Reviewers

  • erenfn

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

🧹 Nitpick comments (3)
jsAgent/hint.js (3)

1-1: Remove debug console.log statements.

Production code should not contain debug logging statements.

-console.log('hint.js is here!');
-            console.log(item);

Also applies to: 14-14


4-5: Consider encapsulating mouse tracking state.

The global state variables could be better encapsulated within a closure or class instance.

-    isMouseOverTooltip : false,
-    isMouseOverContainer : false,
+    _state: {
+        isMouseOverTooltip: false,
+        isMouseOverContainer: false
+    },

68-79: Extract magic numbers into named constants.

The positioning calculations use several magic numbers that should be extracted into named constants for better maintainability.

+    const TOOLTIP_POSITIONS = {
+        TOP: { y: -87, x: -27 },
+        BOTTOM: { y: 38, x: -27 },
+        LEFT: { y: -24, x: -172 },
+        RIGHT: { y: -24, x: 118 }
+    };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0fd8aa and fedc125.

📒 Files selected for processing (3)
  • jsAgent/hint.js (1 hunks)
  • jsAgent/links.js (1 hunks)
  • jsAgent/main.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (3)
jsAgent/main.js (1)

10-10: LGTM! Clean integration of hint functionality.

The changes follow the established pattern of conditional script loading and maintain consistency with the existing codebase.

Also applies to: 201-203

jsAgent/links.js (1)

41-41: LGTM! Removed debug logging.

Good cleanup, removing console.log statements before production deployment.

jsAgent/hint.js (1)

44-45: Clarify the TODO comment.

The comment "this can be delete later" needs clarification. If this code is temporary, please create a tracking issue.

Would you like me to create a GitHub issue to track this technical debt?

jsAgent/hint.js Show resolved Hide resolved
jsAgent/hint.js Outdated Show resolved Hide resolved
jsAgent/hint.js Outdated Show resolved Hide resolved
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: 5

🧹 Nitpick comments (1)
jsAgent/hint.js (1)

3-8: Let's drop some documentation beats! 📝

Add JSDoc documentation to describe the module and its initialization method.

+/**
+ * @namespace bw.hint
+ * @description Manages tooltip functionality for the application
+ */
 bw.hint = {
     isMouseOverTooltip : false,
     isMouseOverContainer : false,
+    /**
+     * @function init
+     * @description Initializes the hint system by generating tooltips
+     */
     init: function () {
         bw.hint.putHtml();
     },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fedc125 and a2a5c0e.

📒 Files selected for processing (3)
  • jsAgent/hint.js (1 hunks)
  • jsAgent/links.js (3 hunks)
  • jsAgent/popup.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • jsAgent/links.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (3)
jsAgent/popup.js (1)

54-54: Yo, these styling updates are fire! 🔥

The subtle border and box shadow changes make the modal look cleaner and more modern.

jsAgent/hint.js (2)

188-197: Still using string comparisons, my dude! 🎯

As previously suggested, refactor action handling using constants and a map for better maintainability.


211-214: Still missing that error handling, homie! 🛡️

As previously discussed, add error handling for cases where selectors don't match.

jsAgent/popup.js Outdated Show resolved Hide resolved
jsAgent/popup.js Outdated Show resolved Hide resolved
jsAgent/popup.js Outdated Show resolved Hide resolved
jsAgent/hint.js Outdated Show resolved Hide resolved
jsAgent/hint.js Outdated Show resolved Hide resolved
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: 3

🧹 Nitpick comments (1)
jsAgent/hint.js (1)

1-263: Yo, let's make this code bulletproof! 🎯

Consider implementing these architectural improvements:

  1. Add a proper cleanup method to remove tooltips and event listeners
  2. Use a tooltip manager to handle multiple tooltips
  3. Add support for keyboard navigation and accessibility
  4. Consider using a state management pattern for better control

Example tooltip manager:

class TooltipManager {
    constructor() {
        this.tooltips = new Map();
    }
    
    add(selector, config) {
        // Add tooltip with proper cleanup
    }
    
    remove(selector) {
        // Remove tooltip and cleanup
    }
    
    cleanup() {
        // Global cleanup
    }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed8e241 and 0cbc0f1.

📒 Files selected for processing (5)
  • jsAgent/banner.js (0 hunks)
  • jsAgent/hint.js (1 hunks)
  • jsAgent/links.js (3 hunks)
  • jsAgent/main.js (2 hunks)
  • jsAgent/popup.js (4 hunks)
💤 Files with no reviewable changes (1)
  • jsAgent/banner.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • jsAgent/main.js
  • jsAgent/links.js
  • jsAgent/popup.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (2)
jsAgent/hint.js (2)

42-101: Yo, these magic numbers are making me nervous! 😰

The positioning logic uses hardcoded values that should be constants. Also, this code is marked as temporary.


185-196: Lose yourself in the code, but not like this! 🎤

The action handling code was previously flagged. Let's use that refactor:

jsAgent/hint.js Outdated Show resolved Hide resolved
jsAgent/hint.js Outdated Show resolved Hide resolved
jsAgent/hint.js Outdated Show resolved Hide resolved
@swoopertr swoopertr changed the title Creating hint in js agent Creating hint in js agent and fixes Jan 8, 2025
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 comments (1)
jsAgent/banner.js (1)

Line range hint 24-29: Clean up those regex replacements, fam! 🧹

Replace RegExp constructor with regex literals for better readability and performance:

-            temp_html = temp_html.replace(new RegExp('{{position}}', 'g'), item.position);
-            temp_html = temp_html.replace(new RegExp('{{textColor}}', 'g'), item.fontColor);
-            temp_html = temp_html.replace(new RegExp('{{content}}', 'g'), item.bannerText);
+            temp_html = temp_html.replace(/{{position}}/g, item.position);
+            temp_html = temp_html.replace(/{{textColor}}/g, item.fontColor);
+            temp_html = temp_html.replace(/{{content}}/g, item.bannerText);
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 24-24: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 25-25: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 26-26: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 27-27: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)

🧹 Nitpick comments (1)
jsAgent/banner.js (1)

Line range hint 2-11: Yo dawg, let's clean up this style spaghetti! 🍝

The banner template has repeated dimensions and inline styles. Let's make it more maintainable:

+const BANNER_STYLES = {
+    dimensions: {
+        height: '50px',
+        width: '435px'
+    },
+    spacing: {
+        bottom: '50px',
+        padding: '0.7rem'
+    }
+};
+
 <div class="bw-banner" id="bw-banner-{{id}}" data-id="{{dataId}}" style="
-    position: fixed; {{position}}: 50px; z-index: 999999; height:50px; width:435px;
+    position: fixed; {{position}}: ${BANNER_STYLES.spacing.bottom}; 
+    z-index: 999999; 
+    height: ${BANNER_STYLES.dimensions.height}; 
+    width: ${BANNER_STYLES.dimensions.width};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0cbc0f1 and b3ef754.

📒 Files selected for processing (3)
  • jsAgent/banner.js (2 hunks)
  • jsAgent/hint.js (1 hunks)
  • jsAgent/popup.js (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • jsAgent/popup.js
🧰 Additional context used
🪛 Biome (1.9.4)
jsAgent/banner.js

[error] 24-24: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (6)
jsAgent/banner.js (1)

Line range hint 35-44: Event handling's looking fresh! 👌

Clean implementation of click events with proper data sending.

jsAgent/hint.js (5)

255-265: Animation's looking smooth as butter! 🧈

Clean implementation using the Web Animations API with proper timing values.


7-8: 🛠️ Refactor suggestion

Add some error handling to catch those edge cases! 🎣

Validate the hint data before processing:

     putHtml: function () {
         const hintData = window.bwonboarddata.hint;
+        if (!hintData || !Array.isArray(hintData)) {
+            console.warn('Invalid or missing hint data');
+            return;
+        }

Likely invalid or redundant comment.


204-213: 🛠️ Refactor suggestion

Refactor these string comparisons, eh! 🍁

Replace string comparisons with a more maintainable approach:

+    const ACTIONS = {
+        NO_ACTION: 'no action',
+        OPEN_URL: 'open url',
+        OPEN_URL_NEW_TAB: 'open url in a new tab'
+    };
+
+    const ACTION_HANDLERS = {
+        [ACTIONS.OPEN_URL]: (url) => location.href = url,
+        [ACTIONS.OPEN_URL_NEW_TAB]: (url) => window.open(url, '_blank')
+    };
+
-    if(btnEvent == 'no action'){
-    }
-    else if(btnEvent == 'open url'){
-        location.href = item.actionButtonUrl;
-    }
-    else if(btnEvent == 'open url in a new tab'){
-        window.open(item.actionButtonUrl, '_blank');
-    }
+    const handler = ACTION_HANDLERS[btnEvent];
+    if (handler) {
+        handler(item.actionButtonUrl);
+    }

Likely invalid or redundant comment.


49-83: 🛠️ Refactor suggestion

Yo, these magic numbers are making me nervous! 😰

The positioning logic uses many magic numbers. Consider:

  1. Extract these values into named constants
  2. If this is temporary code (as commented), create a ticket to track its replacement
+    // Position constants
+    const TOOLTIP_OFFSETS = {
+        TOP: -87,
+        BOTTOM: 38,
+        LEFT: -172,
+        RIGHT: 118
+    };

     if (tooltipPosition === 'top') {
-        tooltip.style.top = '-87px';
+        tooltip.style.top = `${TOOLTIP_OFFSETS.TOP}px`;

Likely invalid or redundant comment.


269-313: 🛠️ Refactor suggestion

Clean up those timeouts and event listeners! 🧹

Add proper cleanup and constants for better maintainability:

+    const TOOLTIP_DELAYS = {
+        SHOW: 500,
+        HIDE: 1500
+    };
+
+    let scrollHandler;
     element.addEventListener('mouseenter', function (e) {
         clearTimeout(tooltip.timer);
         clearTimeout(tooltip.positionTimer);
+        
+        // Update position on scroll
+        scrollHandler = () => updateTooltipPosition(e.target, tooltip);
+        window.addEventListener('scroll', scrollHandler);
     });

     element.addEventListener('mouseleave', function () {
+        if (scrollHandler) {
+            window.removeEventListener('scroll', scrollHandler);
+        }
         tooltip.timer = setTimeout(() => {
             tooltip.style.visibility = 'hidden';
-        }, 1500);
+        }, TOOLTIP_DELAYS.HIDE);
     });

Likely invalid or redundant comment.

@erenfn erenfn self-requested a review January 9, 2025 22:40
@swoopertr swoopertr merged commit 2cee75e into develop Jan 9, 2025
2 checks passed
@erenfn erenfn deleted the creating-hint-in-jsAgent branch January 16, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants