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

refactor : ts integration : src/simulator/src/tutorials.ts #445

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ThatDeparted2061
Copy link
Contributor

@ThatDeparted2061 ThatDeparted2061 commented Jan 28, 2025

Fixes #414

@JoshVarga @Arnabdaz @niladrix719 @devartstar

Summary by CodeRabbit

  • Refactor
    • Refined the guided tutorial experience to deliver more consistent and reliable interactions.
  • Chores
    • Upgraded underlying data definitions and event handling for smoother, more robust tutorial operations.

Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request updates TypeScript usage in the simulator’s tutorial system. In the tutorials.ts file, explicit type annotations have been added for the tour constant and functions like tutorialWrapper and showTourGuide, ensuring improved type safety and clarity. The changes also include the use of optional chaining for DOM queries and the addition of the once event listener option. A new interface, TourStep, is defined in a separate types file to clearly outline the structure for tour steps.

Changes

File Changes Summary
src/simulator/src/tutorials.ts - Added explicit type annotations (TourStep[], void) for constants and functions.
- Used optional chaining for safe DOM element access.
- Updated event listener with the once option.
src/simulator/src/types/tutorial...ts - Introduced a new TourStep interface with required and optional properties to define tour steps and associated popover details.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant DOC as DOM
    participant TW as tutorialWrapper
    U->>DOC: Query for panelHeader element
    TW->>DOC: Attaches event listener (once)
    Note right of DOC: Listener triggers only once
Loading
sequenceDiagram
    participant TG as showTourGuide
    participant MB as MaximizeButton Element
    TG->>MB: Invokes click (if element exists via optional chaining)
Loading

Assessment against linked issues

Objective Addressed Explanation
Typescript Integration in /simulator/src files (#414)

Poem

I'm a bunny with a coding beat,
Hop-scotching through improved types so neat.
My whiskers twitch at each void and TourStep call,
With once-click events and safe selectors on the ball.
Cheers to the changes, carrots and code in a row 🥕✨!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ 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:

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

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.

Copy link

netlify bot commented Jan 28, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 175c53c
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/67a5cf591c14ac0008da1bba
😎 Deploy Preview https://deploy-preview-445--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (3)
src/simulator/src/types/tutorial.types.ts (1)

1-11: Add JSDoc documentation to improve code clarity.

The interface is well-structured, but adding JSDoc documentation would improve code clarity and maintainability.

Add documentation like this:

+/**
+ * Represents a step in the tutorial tour.
+ */
 export interface TourStep {
+    /** CSS selector for the element to highlight */
     element: string;
+    /** Optional CSS class to apply to the highlighted element */
     className?: string;
+    /** Configuration for the popover tooltip */
     popover: {
+        /** Optional CSS class to apply to the popover */
         className?: string;
+        /** Title text displayed in the popover */
         title: string;
+        /** Detailed description displayed in the popover */
         description: string;
+        /** Position of the popover relative to the highlighted element */
         position: 'left' | 'right' | 'top' | 'bottom';
+        /** Optional offset in pixels from the default position */
         offset?: number;
     };
 }
src/simulator/src/tutorials.ts (2)

84-104: Improve type assertions in event handler.

While the optional chaining is good, the type assertions in the click handler could be improved for better type safety.

Consider this improvement:

-    document.querySelector('.panelHeader')?.addEventListener('click', (e) => {
+    document.querySelector<HTMLElement>('.panelHeader')?.addEventListener('click', (e: MouseEvent) => {
         if (localStorage.tutorials === 'next') {
             panelHighlight.highlight({
                 element: '#guide_1',
                 popover: {
                     title: 'Here are the elements',
                     description: 'Select any element by clicking on it & then click anywhere on the grid to place the element.',
                     position: 'right',
-                    offset: ((e.target as HTMLElement).nextElementSibling as HTMLElement)?.offsetHeight + (e.target as HTMLElement).offsetTop - 45,
+                    offset: (e.currentTarget as HTMLElement).nextElementSibling?.offsetHeight + (e.currentTarget as HTMLElement).offsetTop - 45,
                 },
             });
             localStorage.setItem('tutorials', 'done');
         }
     }, { once: true });

Changes:

  1. Use querySelector<HTMLElement> to get better type inference
  2. Type the event parameter as MouseEvent
  3. Use currentTarget instead of target as it's more reliable in event delegation

113-118: Improve type assertion and localStorage consistency.

Two suggestions for improvement:

  1. Use querySelector<HTMLElement> for better type inference
  2. Consider using a constant for localStorage keys to maintain consistency

Consider these improvements:

+const STORAGE_KEYS = {
+    TUTORIAL_STATUS: 'tutorials',
+    TUTORIAL_TOUR_DONE: 'tutorials_tour_done'
+} as const;

 export function showTourGuide(): void {
-    (document.querySelector('.draggable-panel .maximize') as HTMLElement)?.click();
+    document.querySelector<HTMLElement>('.draggable-panel .maximize')?.click();
     animatedTourDriver.defineSteps(tour);
     animatedTourDriver.start();
-    localStorage.setItem('tutorials_tour_done', 'true');
+    localStorage.setItem(STORAGE_KEYS.TUTORIAL_TOUR_DONE, 'true');
 }

Update the tutorialWrapper function to use the constant:

-    if (localStorage.tutorials === 'next') {
+    if (localStorage.getItem(STORAGE_KEYS.TUTORIAL_STATUS) === 'next') {
         // ...
-        localStorage.setItem('tutorials', 'done');
+        localStorage.setItem(STORAGE_KEYS.TUTORIAL_STATUS, 'done');
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac9a470 and e15e359.

📒 Files selected for processing (2)
  • src/simulator/src/tutorials.ts (8 hunks)
  • src/simulator/src/types/tutorial.types.ts (1 hunks)
🔇 Additional comments (1)
src/simulator/src/tutorials.ts (1)

4-81: LGTM! Tour configuration is well-structured.

The tour configuration is properly typed as TourStep[] and the descriptions are clear and informative.

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.

Typescript Integration in /simulator/src files
1 participant