Skip to content

Comments

Add Stimulus framework#6

Merged
jsolly merged 7 commits intojsolly:mainfrom
nbluis:stimulus
Jan 9, 2025
Merged

Add Stimulus framework#6
jsolly merged 7 commits intojsolly:mainfrom
nbluis:stimulus

Conversation

@nbluis
Copy link
Contributor

@nbluis nbluis commented Jan 7, 2025

Add Stimulus to framework list.

I just wasn't able to generate the stats correctly, as there seems to be some problem with the react container.

Summary by CodeRabbit

  • New Features

    • Added Stimulus.js framework support
    • Introduced a new checkbox group component with hierarchical selection
    • Integrated Stimulus framework into the application's framework selection
  • Dependencies

    • Added @hotwired/stimulus package version 3.2.2
  • Chores

    • Updated framework configuration and statistics
    • Enhanced framework rendering capabilities
    • Improved global context with a new Stimulus application property

@vercel
Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
checkboxes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 2:02pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2025

Warning

Rate limit exceeded

@nbluis has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 41d13f2 and bf9ac4c.

📒 Files selected for processing (1)
  • src/data/framework-stats.json (1 hunks)

Walkthrough

The pull request introduces support for the Stimulus JavaScript framework within the application. It adds the Stimulus library as a dependency, creates components for a checkbox group utilizing Stimulus functionality, updates configuration files to include Stimulus in the framework list, and modifies routing and rendering logic to accommodate the new framework. These changes enable users to interact with a Stimulus-based checkbox group component effectively.

Changes

File Change Summary
package.json Added @hotwired/stimulus dependency (version ^3.2.2)
src/components/stimulus/stimulus.astro Created checkbox group component with CheckboxGroupController
src/components/stimulus/stimulusContainer.astro Added container component for Stimulus framework display with <FrameworkContainer>, <Stimulus>, and <CodeBlock>
src/config/frameworks.ts Added Stimulus framework entry to FRAMEWORKS constant
src/data/framework-stats.json Added statistics for Stimulus framework
src/pages/index.astro Imported StimulusContainer and updated containerMap
src/pages/test/[framework].astro Added import and rendering support for Stimulus component
src/types/global.d.ts Added Stimulus: Application property to Window interface

Sequence Diagram

sequenceDiagram
    participant User
    participant ParentCheckbox
    participant ChildCheckboxes
    participant StimulusController

    User->>ParentCheckbox: Click
    ParentCheckbox->>StimulusController: Trigger parentToggle
    StimulusController->>ChildCheckboxes: Update all checkboxes
    
    User->>ChildCheckboxes: Click individual checkbox
    ChildCheckboxes->>StimulusController: Trigger childToggle
    StimulusController->>ParentCheckbox: Update parent checkbox state
Loading

Poem

🐰 A Stimulus Hop of Joy

Checkboxes dance with glee,
Parent and children in harmony,
A framework light and bright,
Bringing interaction's delight!

Hop, hop, hooray! 🎉

Finishing Touches

  • 📝 Generate Docstrings

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

@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)
package.json (1)

Line range hint 40-41: Critical: Invalid React version specified

The package.json specifies React version ^19.0.0, but React 19 hasn't been released yet. This explains the React-related issues mentioned in the PR description.

-    "react": "^19.0.0",
-    "react-dom": "^19.0.0",
+    "react": "^18.2.0",
+    "react-dom": "^18.2.0",
🧹 Nitpick comments (3)
src/components/stimulus/stimulus.astro (1)

33-39: Optimize child toggle logic and add error handling

The childToggle method can be optimized by caching the childTargets and adding error handling.

 childToggle() {
+  if (!this.hasParentTarget || this.childTargets.length === 0) return
+  const children = this.childTargets
-  const allChecked = this.childTargets.every(child => child.checked)
-  const someChecked = this.childTargets.some(child => child.checked)
+  const allChecked = children.every(child => child.checked)
+  const someChecked = !allChecked && children.some(child => child.checked)

   this.parentTarget.checked = allChecked || someChecked
   this.parentTarget.indeterminate = someChecked && !allChecked
 }
src/pages/test/[framework].astro (1)

Line range hint 32-38: Consider framework-specific initialization

The current 50ms delay is arbitrary and might not be sufficient for all frameworks. Consider implementing framework-specific initialization detection.

 window.addEventListener('load', () => {
-  // Give a small delay for frameworks to initialize
-  setTimeout(() => {
+  const framework = document.querySelector('[data-framework]').dataset.framework;
+  const delay = {
+    stimulus: 100, // Stimulus needs more time to initialize controllers
+    react: 50,
+    vue: 50,
+    // ... other frameworks
+    default: 50
+  }[framework] || 50;
+
+  setTimeout(() => {
     window.frameworkReady = true;
-  }, 50);
+  }, delay);
 });
src/pages/index.astro (1)

44-46: Consider removing unnecessary empty lines

The additional empty lines don't serve any functional purpose.

-
-
 <div
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between affd5be and f7a7eaa.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • src/assets/logos/stimulus.svg is excluded by !**/*.svg
📒 Files selected for processing (7)
  • package.json (1 hunks)
  • src/components/stimulus/stimulus.astro (1 hunks)
  • src/components/stimulus/stimulusContainer.astro (1 hunks)
  • src/config/frameworks.ts (1 hunks)
  • src/data/framework-stats.json (1 hunks)
  • src/pages/index.astro (10 hunks)
  • src/pages/test/[framework].astro (4 hunks)
🔇 Additional comments (7)
src/components/stimulus/stimulusContainer.astro (1)

1-16: LGTM! Implementation follows established patterns

The container component is well-structured and consistent with other framework implementations, properly utilizing shared components and following the project's architecture.

src/config/frameworks.ts (1)

34-37: LGTM! Framework configuration is correct

The Stimulus framework entry follows the established pattern and correctly sets clientFramework: null as Stimulus is a server-side framework, similar to Alpine.js and Hyperscript.

src/pages/test/[framework].astro (1)

Line range hint 41-54: LGTM! Framework rendering logic is consistent

The Stimulus framework integration follows the established pattern for conditional rendering.

src/pages/index.astro (3)

8-8: LGTM: StimulusContainer import follows project conventions

The import statement follows the established pattern for framework containers.


24-24: LGTM: Stimulus framework correctly added to containerMap

The integration follows the existing pattern for framework registration.


57-62: Verify React version compatibility

Given the PR description mentions issues with React version, let's verify the React-related imports and their compatibility.

package.json (1)

32-32: LGTM: Stimulus dependency added with appropriate version

The @hotwired/stimulus package is added with version ^3.2.2, which is the latest stable version.

@jsolly
Copy link
Owner

jsolly commented Jan 8, 2025

Hey @nbluis thanks for this! Looking great.

I pushed some recent refactoring changes that caused some conflicts. I will take a look tomorrow to see if I can resolve.

Is the pre-commit hook working for you? I am using Biome for linting and formatting.

I will add a GitHub action to flag formatting/linting issues.

Copy link

@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

🧹 Nitpick comments (1)
src/components/stimulus/stimulus.astro (1)

1-8: Consider using CSS nesting for better maintainability.

The styles could be organized more efficiently using CSS nesting:

 <style>
-  .stimulus-container { @apply px-3 py-2 }
-  .stimulus-parent { @apply p-2 rounded-lg }
-  .stimulus-children { @apply ml-8 rounded-lg }
-  .stimulus-checkbox { @apply p-1 flex items-center space-x-3 hover:bg-slate-100 transition-colors }
-  .stimulus-checkbox-input { @apply h-4 w-4 mt-0.5 text-blue-600 rounded border-slate-300 focus:ring-blue-500 }
-  .stimulus-checkbox-label { @apply text-slate-700 cursor-pointer text-sm font-medium }
+  .stimulus {
+    &-container { @apply px-3 py-2 }
+    &-parent { @apply p-2 rounded-lg }
+    &-children { @apply ml-8 rounded-lg }
+    &-checkbox {
+      @apply p-1 flex items-center space-x-3 hover:bg-slate-100 transition-colors;
+      &-input { @apply h-4 w-4 mt-0.5 text-blue-600 rounded border-slate-300 focus:ring-blue-500 }
+      &-label { @apply text-slate-700 cursor-pointer text-sm font-medium }
+    }
+  }
 </style>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f7a7eaa and 3b0b698.

📒 Files selected for processing (4)
  • src/components/stimulus/stimulus.astro (1 hunks)
  • src/config/frameworks.ts (1 hunks)
  • src/data/framework-stats.json (1 hunks)
  • src/pages/index.astro (10 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/config/frameworks.ts
  • src/data/framework-stats.json
  • src/pages/index.astro
🔇 Additional comments (2)
src/components/stimulus/stimulus.astro (2)

32-32: Avoid global window assignment

Storing the Stimulus application on the window object could lead to naming conflicts. Consider using a more isolated approach.


37-41: Add error handling for missing targets

The parentToggle method should handle cases where targets are missing to prevent runtime errors.

@nbluis
Copy link
Contributor Author

nbluis commented Jan 8, 2025

Hey @jsolly.

I've solved the conflicts, also make some refactorings in stimulus component.

The pre-commit hook not worked for me. I try to run manually but says alot of issues with other files of the codebase including other components.

@jsolly
Copy link
Owner

jsolly commented Jan 8, 2025

@nbluis Thanks for getting this set up!

I just updated main with better ignore rules for the linter. It was trying to lint files in the deployment directory.

Please pull latest and try pnpm astro check and pnpm lint There shouldn't be any errors in other components anymore!

Copy link

@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 (1)
src/components/stimulus/stimulus.astro (1)

1-8: Add dark mode support to enhance accessibility

Consider adding dark mode variants to improve accessibility and user experience.

-  .stimulus-checkbox-input { @apply h-4 w-4 mt-0.5 text-blue-600 rounded border-slate-300 focus:ring-blue-500 }
-  .stimulus-checkbox-label { @apply text-slate-700 cursor-pointer text-sm font-medium }
+  .stimulus-checkbox-input { @apply h-4 w-4 mt-0.5 text-blue-600 dark:text-blue-400 rounded border-slate-300 dark:border-slate-600 focus:ring-blue-500 dark:focus:ring-blue-400 }
+  .stimulus-checkbox-label { @apply text-slate-700 dark:text-slate-300 cursor-pointer text-sm font-medium }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0cba6de and 3eb9da8.

📒 Files selected for processing (3)
  • src/components/stimulus/stimulus.astro (1 hunks)
  • src/data/framework-stats.json (1 hunks)
  • src/types/global.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/data/framework-stats.json
🧰 Additional context used
📓 Learnings (2)
src/types/global.d.ts (1)
Learnt from: nbluis
PR: jsolly/checkboxes#6
File: src/components/stimulus/stimulus.astro:32-32
Timestamp: 2025-01-08T14:29:59.010Z
Learning: In Stimulus.js, when used without a build system, the framework should be initialized using `window.Stimulus = Application.start()` as per the official documentation. This is the recommended approach despite the global window assignment.
src/components/stimulus/stimulus.astro (1)
Learnt from: nbluis
PR: jsolly/checkboxes#6
File: src/components/stimulus/stimulus.astro:32-32
Timestamp: 2025-01-08T14:29:59.010Z
Learning: In Stimulus.js, when used without a build system, the framework should be initialized using `window.Stimulus = Application.start()` as per the official documentation. This is the recommended approach despite the global window assignment.
🔇 Additional comments (4)
src/types/global.d.ts (1)

1-7: LGTM! Type declaration is properly implemented.

The global type declaration for Stimulus is correctly implemented, properly extending the Window interface with the Application type from @hotwired/stimulus.

src/components/stimulus/stimulus.astro (3)

10-27: Well-structured and accessible HTML implementation!

The HTML implementation follows best practices with proper semantic structure and accessibility attributes:

  • Uses fieldset/legend for form grouping
  • Implements proper ARIA attributes
  • Maintains unique IDs for all inputs
  • Correctly associates labels with inputs

30-32: Correct Stimulus initialization approach

The initialization follows the official Stimulus documentation for non-build system usage, as confirmed by previous discussions.


34-53: 🛠️ Refactor suggestion

Enhance controller robustness and performance

Consider the following improvements to the controller implementation:

  1. Add error handling for missing targets
  2. Optimize performance by reducing DOM queries
 window.Stimulus.register("checkbox-group", class extends Controller {
   static targets = [ 'parent', 'child' ]

   declare readonly parentTarget: HTMLInputElement
   declare readonly childTargets: HTMLInputElement[]

+  connect() {
+    if (!this.hasParentTarget || this.childTargets.length === 0) {
+      console.warn('Checkbox group requires both parent and child targets')
+      return
+    }
+  }

   parentToggle() {
+    if (!this.hasParentTarget) return
     const checked = this.parentTarget.checked
     this.childTargets.forEach(child => child.checked = checked)
   }

   childToggle() {
+    if (!this.hasParentTarget || this.childTargets.length === 0) return
+    // Cache DOM queries
+    const { parentTarget, childTargets } = this
-    const allChecked = this.childTargets.every(child => child.checked)
-    const someChecked = this.childTargets.some(child => child.checked)
+    const allChecked = childTargets.every(child => child.checked)
+    const someChecked = !allChecked && childTargets.some(child => child.checked)

-    this.parentTarget.checked = allChecked || someChecked
-    this.parentTarget.indeterminate = someChecked && !allChecked
+    parentTarget.checked = allChecked
+    parentTarget.indeterminate = someChecked
   }
 })

Likely invalid or redundant comment.

@nbluis
Copy link
Contributor Author

nbluis commented Jan 9, 2025

@jsolly nice.

Lint issues fixed.

@jsolly
Copy link
Owner

jsolly commented Jan 9, 2025

Great! Will review this today or tomorrow! Thanks again.

@jsolly
Copy link
Owner

jsolly commented Jan 9, 2025

Amazing work. Merging!

I will update the stats for the framework on my machine since it looks like there was an issue generating the zscores. I made some improvements with that code anyway, so will be good for me to re-run the stats using my API key.

@jsolly jsolly merged commit 7c20705 into jsolly:main Jan 9, 2025
2 of 3 checks passed
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