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

539 implement tours in extension #550

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

DeboraSerra
Copy link
Contributor

Describe your changes

Add the floating menu to the page with the possibility of selecting just one element for hint, or multiple elements for tours.
image

image

image

Issue number

#539

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 linked an issue Feb 20, 2025 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request enhances a web extension by introducing new UI elements and interactivity features. In extention/app.js, a floating menu with drag-and-drop capabilities and an improved sticky div have been added. New constants and functions support mode switching and dynamic element listing. Meanwhile, extention/background.js now includes an event listener for the Chrome action button, which invokes a setup function to initialise highlighting and user event listeners.

Changes

File Change Summary
extention/app.js Added constants (MENU_ID, TOUR_STEPS_CONTAINER_ID, TOUR_STEP_CLASS, AVAILABLE_MODES); introduced functions: createFloatingMenu (creates and adds a draggable UI menu), addDragEvent, and generateList; enhanced createStickyDiv, updateHighlight, and grabSelector for improved UI interactivity.
extention/background.js Added an event listener for the Chrome extension's action button click; implemented setup() function to initialise highlighting and register mouse and keydown event listeners for dynamic page interaction.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant FM as createFloatingMenu()
    participant GL as generateList()
    participant AD as addDragEvent()
    U->>FM: Initiate floating menu
    FM->>FM: Check if menu exists and create if not
    U->>FM: Click mode button ("tour")
    FM->>GL: Generate list for tour steps
    U->>AD: Drag tour steps to reorder
    AD->>FM: Update steps order
Loading
sequenceDiagram
    participant U as User
    participant AB as Action Button
    participant BG as setup()
    U->>AB: Click extension action button
    AB->>BG: Trigger setup in current tab
    BG->>BG: Initialise highlight and event listeners (mousemove, click, keydown)
Loading

Possibly related PRs

  • Onboard extention #547: Modifies extention/app.js with similar UI enhancements, particularly for interactive elements and highlighting features.

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

🔭 Outside diff range comments (1)
backend/.env (1)

9-14: ⚠️ Potential issue

Security: Email credentials exposed in version control.

Email credentials and app passwords should not be committed to the repository.

Move these sensitive values to a secure environment variable management system and use placeholders in the example file:

-[email protected]
-EMAIL_PASSWORD=passwor
-EMAIL_HOST=smtp.gmail.com
-EMAIL_PORT=465
-APP_PASSWORD=ukzwakckupguegiw
+[email protected]
+EMAIL_PASSWORD=your_email_password
+EMAIL_HOST=your_smtp_host
+EMAIL_PORT=your_smtp_port
+APP_PASSWORD=your_app_password
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 18c9d81 and 363bf56.

⛔ Files ignored due to path filters (1)
  • extention/icon.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • backend/.env (2 hunks)
  • extention/app.js (1 hunks)
  • extention/background.js (1 hunks)
  • extention/manifest.json (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
extention/app.js

[error] 460-460: This aliasing of this is unnecessary.

Arrow functions inherits this from their enclosing scope.
Safe fix: Use this instead of an alias.

(lint/complexity/noUselessThisAlias)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)

Copy link
Collaborator

@erenfn erenfn left a comment

Choose a reason for hiding this comment

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

  • There might be a problem with step naming -It follows the consecutive order no matter what. I think it would be better if we just use the target element names rather than Step counts.
  • Also I know you didn't do the copy button below, but can you change its color to 'guidefox purple'?
    image

Steps
Initial:
image
Add a step:
image
Move items:
image

@erenfn
Copy link
Collaborator

erenfn commented Feb 23, 2025

Also I sometimes get Uncaught ReferenceError: addHighlight is not defined since background.js may be loaded before app.js How can we solve this?

@DeboraSerra
Copy link
Contributor Author

  • There might be a problem with step naming -It follows the consecutive order no matter what. I think it would be better if we just use the target element names rather than Step counts.
    I did it like this at first, but sometimes the element selector is too long... It looks like this
    image
    I can limit the width of the text and hide the overflow, but it would look like this
    image

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

♻️ Duplicate comments (2)
extention/app.js (2)

332-336: ⚠️ Potential issue

Heads up! XSS vulnerability in HTML template.

The cardTemplate uses raw HTML which could be dangerous if step contains malicious content.

-const cardTemplate = `<i class="${dragClass}">&equiv;</i><span>{{step}}</span><i class="${trashClass}"><img src="https://cdn-icons-png.flaticon.com/512/860/860829.png" ald="Delete" width="16px" height="16px" /></i>`;
+const cardTemplate = document.createElement('div');
+const dragIcon = document.createElement('i');
+dragIcon.className = dragClass;
+dragIcon.textContent = '≡';
+const stepSpan = document.createElement('span');
+stepSpan.textContent = `${step}`;
+const trashIcon = document.createElement('i');
+trashIcon.className = trashClass;
+const img = document.createElement('img');
+img.src = 'https://cdn-icons-png.flaticon.com/512/860/860829.png';
+img.alt = 'Delete';
+img.width = 16;
+img.height = 16;

475-493: ⚠️ Potential issue

Yo! Memory leak and unnecessary this aliasing in throttle function.

The throttle function creates new DOM elements on every call and uses unnecessary this aliasing.

 function throttle(func, limit = 100) {
-  createStickyDiv();
-  createFloatingMenu();
   let inThrottle;
   let lastResult;
-  domSelected = false;
   return function () {
     const args = arguments;
-    const context = this;
     if (!inThrottle) {
       inThrottle = true;
       setTimeout(() => (inThrottle = false), limit);
-      lastResult = func.apply(context, args);
+      lastResult = func.apply(this, args);
     }
     return lastResult;
   };
 }
🧰 Tools
🪛 Biome (1.9.4)

[error] 483-483: This aliasing of this is unnecessary.

Arrow functions inherits this from their enclosing scope.
Safe fix: Use this instead of an alias.

(lint/complexity/noUselessThisAlias)

🧹 Nitpick comments (3)
extention/app.js (3)

1-12: Yo! Consider using an enum or object for modes.

Instead of using an array for AVAILABLE_MODES, consider using an enum or object to prevent typos and enable better IDE support.

-const AVAILABLE_MODES = ["hint", "tour"];
+const AVAILABLE_MODES = {
+  HINT: "hint",
+  TOUR: "tour"
+} as const;

301-322: Yo! Consider using ResizeObserver for dynamic updates.

The updateHighlight function might miss updates when elements change size dynamically.

+const resizeObserver = new ResizeObserver(entries => {
+  entries.forEach(entry => {
+    if (entry.target === lastHighlightTarget) {
+      updateHighlight({ target: lastHighlightTarget });
+    }
+  });
+});

 function updateHighlight({ target }) {
   if (
     !(target instanceof HTMLElement) ||
     target === lastHighlightTarget ||
     target.id.startsWith("bw-")
   ) {
     return;
   }
   lastHighlightTarget = target;
+  if (lastHighlightTarget) {
+    resizeObserver.observe(lastHighlightTarget);
+  }
   const { top, left, width, height } = target.getBoundingClientRect();

399-420: Yo! Consider adding error boundaries for tour mode.

The grabSelector function should handle errors gracefully in tour mode to prevent tour corruption.

   if (selectedMode === "tour") {
+    try {
       const selector = generateSelector(target);
+      if (!selector) {
+        console.warn('Failed to generate selector for element');
+        return;
+      }
       selectedElements.push({
         element: selector,
         step: selectedElements.length + 1,
       });
       generateList();
+    } catch (error) {
+      console.error('Failed to add tour step:', error);
+    }
     return;
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 363bf56 and 2de5e7f.

⛔ Files ignored due to path filters (1)
  • extention/trash.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • extention/app.js (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
extention/app.js

[error] 483-483: This aliasing of this is unnecessary.

Arrow functions inherits this from their enclosing scope.
Safe fix: Use this instead of an alias.

(lint/complexity/noUselessThisAlias)

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

272-282: ⚠️ Potential issue

Yo dawg! Duplicate event listeners on button.

The mouseenter, mouseleave, and click event listeners are duplicated for the button.

Remove the duplicate event listeners:

-  button.addEventListener("mouseenter", () => {
-    button.style.backgroundColor = "#6941C6";
-  });
-  button.addEventListener("mouseleave", () => {
-    button.style.backgroundColor = "#7F56D9";
-  });
-  button.addEventListener("click", async () => {
-    await navigator?.clipboard?.writeText(input.value);
-    //alert(`You entered: ${input.value}`);
-  });
-  stickyDiv.appendChild(button);

Likely an incorrect or invalid review comment.

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.

Implement Tours in Extension
2 participants