Skip to content

Conversation

@ShinichiShi
Copy link

@ShinichiShi ShinichiShi commented Oct 20, 2025

Fixes #661

Describe the changes you have made in this PR -

refactored tutorial.js and sequential.js to ts.

Screenshots of the changes (If any) -

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit

  • Refactor

    • Improved type safety and null-checks across the simulator and guided-tour flow, making tutorial interactions and clock toggling more robust.
  • Documentation

    • Clarified JSDoc/comments for tutorial and clock APIs; added explicit typings for tutorial steps and driver interfaces.

Note: No user-facing behavior or functionality was changed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

Adds TypeScript typings and null-safety to simulator tutorial code and one sequential helper: explicit parameter and return types, new tutorial interfaces, and additional guards. No control-flow or runtime behavior changes.

Changes

Cohort / File(s) Summary
Sequential function typing
src/simulator/src/sequential.ts
Changed export function changeClockEnable(val)export function changeClockEnable(val: boolean): void; added JSDoc @param and capitalization; implementation remains assignment-based.
Tutorial exports & flow
src/simulator/src/tutorials.ts
Added explicit types: tour: TourStep[], tutorialWrapper(): void, showTourGuide(): void; added null checks/type assertions, safer DOM/event handling, and store tutorial flag as 'true' string.
Tutorial types
src/simulator/src/types/tutorials.types.ts
Added interfaces TourStep, Popover, and DriverInstance describing tutorial step shape and driver API (start, defineSteps, highlight, reset).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "refactor: tutorial.js and sequential.js to typescript" directly and accurately describes the main change in the changeset. The title is specific about which files are being refactored (tutorial.js and sequential.js) and clearly identifies the purpose (conversion to TypeScript). The title is concise, uses clear language, and would allow a teammate scanning the repository history to immediately understand the primary objective of this change.
Linked Issues Check ✅ Passed The pull request successfully addresses all primary coding objectives from linked issue #661. The changes convert the JavaScript files (sequential.ts and tutorials.ts) to TypeScript with explicit type annotations and new type interfaces [#661]. The runtime logic remains unchanged—the changeClockEnable function body is identical, tutorial initialization flow is preserved, and only null checks and type guards are added for safety [#661]. Type safety is improved through new interface definitions (TourStep, Popover, DriverInstance) and explicit parameter/return type annotations on exported functions [#661]. The AI-assisted changes appear properly reviewed, with only type-level improvements and documentation enhancements introduced.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly within scope of converting JavaScript files to TypeScript and improving type safety. The modifications to sequential.ts and tutorials.ts add explicit type annotations and refactor for better type coverage without altering runtime behavior. The new tutorials.types.ts file introduces type-level declarations required for the TypeScript conversion. No extraneous refactoring, feature additions, or unrelated code changes are present. All alterations serve the stated objectives of the linked issue.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5798671 and 6496218.

📒 Files selected for processing (1)
  • src/simulator/src/types/tutorials.types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/simulator/src/types/tutorials.types.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Oct 20, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 6496218
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/68f68af17af899000866b65d
😎 Deploy Preview https://deploy-preview-665--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 45 (no change from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project 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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0921d26 and f45bb5e.

📒 Files selected for processing (3)
  • src/simulator/src/sequential.ts (1 hunks)
  • src/simulator/src/tutorials.ts (2 hunks)
  • src/simulator/src/types/tutorials.types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/simulator/src/tutorials.ts (1)
src/simulator/src/types/tutorials.types.ts (2)
  • TourStep (9-13)
  • DriverInstance (15-24)
🔇 Additional comments (4)
src/simulator/src/sequential.ts (1)

4-11: LGTM! Clean TypeScript conversion.

The type annotations are appropriate, and the JSDoc improvements enhance documentation clarity.

src/simulator/src/tutorials.ts (3)

2-4: LGTM! Proper type imports and annotations.

The import statement and tour type annotation correctly leverage the new type definitions.


92-133: Good defensive programming with null checks.

The null guards and event typing improve type safety. The double cast pattern (as unknown as DriverInstance) is acceptable for this TypeScript migration, though it indicates the custom DriverInstance interface may not perfectly align with driver.js's native types.


142-150: No behavior change detected—original concern invalid.

The change from storing boolean true to string 'true' does not affect functionality. In src/simulator/src/setup.js (line 157), the value is read using a truthy check (!localStorage.tutorials_tour_done), which works identically for both the old boolean (coerced to string "true" by localStorage) and the new explicit string. The code is correct as written.

Comment on lines 15 to 24
export interface DriverInstance {
highlight: (options: {
element: string
showButtons: boolean
popover: Popover
}) => void
defineSteps: (steps: TourStep[]) => void
start: () => void
reset: (clearHighlighted?: boolean) => void
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify interface matches driver.js API.

The DriverInstance interface appears well-structured. However, since this types a third-party library (driver.js), ensure the method signatures align with the actual library API to avoid runtime issues.


🌐 Web query:

driver.js library API documentation methods

💡 Result:

Here are the public methods on a driver.js instance (from the official API docs) with a short note for each: [1]

  1. drive([index]) — start the tour (optional start index). [1]
  2. moveNext() — go to next step. [1]
  3. movePrevious() — go to previous step. [1]
  4. moveTo(index) — go to a specific step. [1]
  5. hasNextStep() — returns whether a next step exists. [1]
  6. hasPreviousStep() — returns whether a previous step exists. [1]
  7. isFirstStep() — true if current step is first. [1]
  8. isLastStep() — true if current step is last. [1]
  9. getActiveIndex() — returns active step index. [1]
  10. getActiveStep() — returns active step configuration. [1]
  11. getPreviousStep() — returns previous step configuration. [1]
  12. getActiveElement() — returns currently highlighted DOM element. [1]
  13. getPreviousElement() — returns previously highlighted DOM element. [1]
  14. isActive() — whether a tour/highlight is currently active. [1]
  15. refresh() — recalc/redraw the highlight/popover. [1]
  16. getConfig() — get current config. [1]
  17. setConfig(config) — update configuration. [1]
  18. setSteps(steps) — set/replace the tour steps. [1]
  19. getState() — get driver state (see config/state docs). [1]
  20. highlight(step) — highlight a single element / show a popover. [1]
  21. destroy() — destroy the tour and cleanup. [1]

Source: driver.js API Reference. [1]

[1] https://driverjs.com/docs/api


Critical mismatches between DriverInstance interface and actual driver.js API.

The interface methods do not align with the official driver.js library:

  • highlight(options: {...}) — driver.js expects highlight(step), not an options object with element/showButtons/popover
  • defineSteps(steps) — actual method is setSteps(steps)
  • start() — actual method is drive([index])
  • reset(clearHighlighted?) — no such method; destroy() is the cleanup method

Update method names and signatures to match the actual driver.js API to prevent runtime errors.

🤖 Prompt for AI Agents
In src/simulator/src/types/tutorials.types.ts around lines 15 to 24, the
DriverInstance interface methods and signatures don't match driver.js: rename
and update signatures so they mirror the real API — replace
highlight(options:{...}) with highlight(step: TourStep), change
defineSteps(steps: TourStep[]) to setSteps(steps: TourStep[]), replace start()
with drive(index?: number) and remove reset(clearHighlighted?) in favor of
destroy(): void; ensure Popover/other types referenced align with TourStep
properties so the TypeScript types reflect driver.js usage.

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

♻️ Duplicate comments (1)
src/simulator/src/types/tutorials.types.ts (1)

21-30: Critical: DriverInstance interface still doesn't match driver.js API.

The interface methods remain misaligned with the actual driver.js library API, as previously flagged. This will cause runtime errors:

  • start() → should be drive(index?: number): void
  • defineSteps(steps: TourStep[]) → should be setSteps(steps: TourStep[]): void
  • reset(clearHighlighted?: boolean) → should be destroy(): void
  • highlight(options: {...}) → should be highlight(step: TourStep): void

Based on the previous review's web search results, update the interface to match the official driver.js API:

 export interface DriverInstance {
-    start(): void
-    defineSteps(steps: TourStep[]): void
-    highlight(options: {
-        element: string
-        popover: Popover
-        showButtons?: boolean
-    }): void 
-    reset(clearHighlighted?: boolean): void
+    drive(index?: number): void
+    setSteps(steps: TourStep[]): void
+    highlight(step: TourStep): void
+    destroy(): void
+    moveNext(): void
+    movePrevious(): void
+    isActive(): boolean
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f45bb5e and 5798671.

📒 Files selected for processing (1)
  • src/simulator/src/types/tutorials.types.ts (1 hunks)

Comment on lines 1 to 11
export interface TourStep {
element: string
className?: string
popover: {
className?: string
title: string
description: string
position: 'top' | 'bottom' | 'left' | 'right'
offset?: number
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify TourStep structure matches driver.js step configuration.

Ensure the TourStep interface aligns with driver.js's expected step configuration, particularly the element selector format and popover structure.


🌐 Web query:

driver.js step configuration structure

💡 Result:

A Driver.js "step" (DriveStep) is an object you pass in the driver config steps array or to highlight(). Main properties:

  • element: Element | string (CSS selector) | () => Element — target to highlight.
  • popover: object controlling the popover:
    • title?: string
    • description?: string
    • side?: "top" | "right" | "bottom" | "left"
    • align?: "start" | "center" | "end"
    • showButtons?: ("next" | "previous" | "close")[]
    • callbacks: onNextClick, onPrevClick, onCloseClick (per-popover).
  • disableActiveInteraction?: boolean — prevents interaction with target.
  • per-step hooks/callbacks: onDeselected, onHighlightStarted, onHighlighted (receive element, step, options).

Example:
const steps = [
{
element: '.page-header',
popover: {
title: 'Header',
description: 'This is the header.',
side: 'bottom',
align: 'center',
showButtons: ['next','close'],
onNextClick: () => { /* custom logic / }
},
disableActiveInteraction: false,
onHighlighted: (el, step, opts) => { /
... */ }
}
];

(Driver-level config and additional options like animate, overlay color, global hooks, and state access are also available.) [1][2]

Sources:
[1] Driver.js — Configuration (DriveStep & Popover types).
[2] Driver.js — Basic usage / steps example.


Critical: TourStep interface has multiple API mismatches with driver.js DriveStep structure.

The TourStep interface does not align with driver.js's actual step configuration. Key issues:

  • Property position should be side (valid values: "top" | "right" | "bottom" | "left")
  • Missing align property ("start" | "center" | "end")
  • Missing showButtons array for controlling button visibility
  • Missing disableActiveInteraction flag
  • Missing popover callbacks (onNextClick, onPrevClick, onCloseClick)
  • Missing step-level hooks (onHighlighted, onDeselected, onHighlightStarted)
  • element should accept Element | string | (() => Element), not just string
  • popover.title and description should be optional (?:), not required
  • Remove non-standard properties: className (both levels) and offset

Update the interface to match driver.js API specifications to prevent runtime errors and ensure proper type safety.

🤖 Prompt for AI Agents
In src/simulator/src/types/tutorials.types.ts around lines 1 to 11, the TourStep
interface does not match driver.js DriveStep; update it to: change property
position -> side with allowed values "top" | "right" | "bottom" | "left"; add
optional align?: "start" | "center" | "end"; add optional showButtons?: string[]
(or a typed enum/tuple matching driver.js buttons) and optional
disableActiveInteraction?: boolean; change element type to Element | string |
(() => Element); remove className and offset properties at both step and popover
levels; make popover.title? and popover.description? optional; add optional
popover callbacks onNextClick?, onPrevClick?, onCloseClick? and add optional
step-level hooks onHighlighted?, onDeselected?, onHighlightStarted? so the
interface matches driver.js API and avoids runtime type mismatches.

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.

Feature: Javascript to Typescript conversion in the src folder

1 participant