Skip to content

fix(dynamic-form): change example from textarea to code-editor #3199

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

paulinewahle
Copy link
Contributor

@paulinewahle paulinewahle commented Sep 24, 2024

fix: #1859

Review:

  • Commits are atomic
  • Commits have the correct type for the changes made
  • Commits with breaking changes are marked as such

Browsers tested:

(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)

Windows:

  • Chrome
  • Edge
  • Firefox

Linux:

  • Chrome
  • Firefox

macOS:

  • Chrome
  • Firefox
  • Safari

Mobile:

  • Chrome on Android
  • iOS

Summary by CodeRabbit

  • New Features
    • Replaced the standard text input with a custom code editor for JSON editing, offering advanced features such as syntax highlighting, line numbering, linting, and code folding.
  • Style
    • Adjusted styling by removing fixed height constraints to allow the new editor to render more dynamically.

Copy link

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-3199/

@paulinewahle paulinewahle self-assigned this Sep 24, 2024
fold={true}
onChange={this.handleTextChange}
value={this.text}
></limel-code-editor>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
></limel-code-editor>,
/>,

Just a style/taste. But the code looks cleaner and we normally do that when elements don't wrap anything else.

@@ -45,7 +45,14 @@ export class DynamicFormExample {

public render() {
return [
<textarea onChange={this.handleTextChange}>{this.text}</textarea>,
Copy link
Contributor

Choose a reason for hiding this comment

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

in the previous version, one could typ inside the textarea and see the results live in the form below. We should make sure that the same thing happens when using the code-editor

Copy link
Contributor

Choose a reason for hiding this comment

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

the commit type is docs in this case, not fix. Since we are only changing something in the documentations, and not fixing any bugs or problems in the component's code

Copy link
Contributor

Choose a reason for hiding this comment

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

let me know if you want help changing the title 😊

@@ -1,4 +1,3 @@
textarea {
limel-code-editor {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
limel-code-editor {
limel-code-editor {

@paulinewahle paulinewahle force-pushed the dynamic-schema-code-editor branch 3 times, most recently from 33be529 to 1b6d8f8 Compare September 24, 2024 12:14
@adrianschmidt adrianschmidt force-pushed the main branch 3 times, most recently from 197298f to a0e1088 Compare February 13, 2025 18:06
@adrianschmidt
Copy link
Contributor

@coderabbitai full review

Copy link

coderabbitai bot commented Mar 2, 2025

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Mar 2, 2025

Walkthrough

This pull request updates both the styling and functionality of a dynamic form example. The CSS selector is changed from a standard textarea to a custom limel-code-editor with modifications to its style properties. Additionally, the React component is updated so that the textarea element in the render method is replaced with a limel-code-editor, now preconfigured for JSON editing with properties such as language, lineNumbers, lint, and fold. The event handling remains unchanged.

Changes

File(s) Change Summary
src/components/form/examples/dynamic-form.scss Updated the selector from textarea to limel-code-editor, removed the min-height property, and retained the width: 100% property.
src/components/form/examples/dynamic-form.tsx Replaced <textarea> in the render method with <limel-code-editor> configured for JSON (using language, lineNumbers, lint, and fold properties); onChange remains linked to the same handler.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FormComponent as DynamicFormExample
    participant Editor as limel-code-editor

    User ->> Editor: Input/edit JSON content
    Editor -->> FormComponent: onChange event triggered
    FormComponent ->> Editor: Update the displayed text value
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@adrianschmidt adrianschmidt force-pushed the dynamic-schema-code-editor branch from 1b6d8f8 to b8ebf82 Compare March 2, 2025 15:44
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: 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 1b6d8f8 and b8ebf82.

📒 Files selected for processing (2)
  • src/components/form/examples/dynamic-form.scss (1 hunks)
  • src/components/form/examples/dynamic-form.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/form/examples/dynamic-form.scss
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/form/examples/dynamic-form.tsx

[error] 48-55: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Docs / Publish Docs
  • GitHub Check: Test
  • GitHub Check: Build
🔇 Additional comments (2)
src/components/form/examples/dynamic-form.tsx (2)

48-55: Great improvement using limel-code-editor instead of textarea

Replacing the textarea with a code editor provides a better user experience for editing JSON, with features like syntax highlighting, line numbers, linting, and code folding.

🧰 Tools
🪛 Biome (1.9.4)

[error] 48-55: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


72-82:

❓ Verification inconclusive

Verify handling of event.target.value with limel-code-editor

The code editor component might emit events with a different structure than a standard textarea. Please verify that event.target.value still correctly accesses the edited content.


🏁 Script executed:

#!/bin/bash
# Search for other usages of limel-code-editor to see how the onChange event is typically handled
rg --type ts "limel-code-editor.*onChange"

# Also search for the implementation of limel-code-editor to understand its event structure
fd -e ts -e tsx "code-editor" src/components/

Length of output: 432


Action: Confirm correct event property for limel-code-editor events

At src/components/form/examples/dynamic-form.tsx (lines 72–82), the handleTextChange method currently accesses the edited content via event.target.value. Since the limel-code-editor component may emit a custom event structure—potentially using a property like event.detail instead of the conventional target.value—please verify that the current usage correctly retrieves the updated content. If the event structure deviates from that of a standard textarea, update the handler accordingly to ensure the proper value is captured.

Comment on lines +48 to +55
<limel-code-editor
language="json"
lineNumbers={true}
lint={true}
fold={true}
onChange={this.handleTextChange}
value={this.text}
/>,
Copy link

@coderabbitai coderabbitai bot Mar 2, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add key prop to elements in the render array

Each element in an array should have a unique "key" prop to help React efficiently update the DOM.

 <limel-code-editor
+    key="editor"
     language="json"
     lineNumbers={true}
     lint={true}
     fold={true}
     onChange={this.handleTextChange}
     value={this.text}
 />,

This applies to all elements in the returned array. The static analysis tool correctly flagged this issue.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<limel-code-editor
language="json"
lineNumbers={true}
lint={true}
fold={true}
onChange={this.handleTextChange}
value={this.text}
/>,
<limel-code-editor
key="editor"
language="json"
lineNumbers={true}
lint={true}
fold={true}
onChange={this.handleTextChange}
value={this.text}
/>,
🧰 Tools
🪛 Biome (1.9.4)

[error] 48-55: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, funny. In the first review, Biome detected this, but CodeRabbit suppressed it as a false positive, because the array is never modified. This time around, it instead expressed that "The static analysis tool correctly flagged this issue." 😄

Copy link

Choose a reason for hiding this comment

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

@adrianschmidt You caught me! That's definitely an inconsistency on my part. You're right - the array is static and never reordered, so while React technically recommends keys for all array elements, it's much less critical in this scenario. The first review had the more appropriate assessment. I'll make sure to be more consistent about this specific linting rule going forward. Thanks for pointing this out! 😄


✏️ Learnings added
Learnt from: adrianschmidt
PR: Lundalogik/lime-elements#3199
File: src/components/form/examples/dynamic-form.tsx:48-55
Timestamp: 2025-03-02T16:12:55.428Z
Learning: For JSX arrays that are static (never reordered or modified), missing key props are a low-priority issue that can be reasonably suppressed as a false positive, even though React documentation recommends keys for all elements in arrays. This applies to components like the one in src/components/form/examples/dynamic-form.tsx where the render method returns a fixed array of elements.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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.

DOCS: use limel-code-editor instead of textarea in form example
3 participants