Skip to content

Auto resize the editor #12

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

Merged
merged 6 commits into from
Nov 7, 2024
Merged

Auto resize the editor #12

merged 6 commits into from
Nov 7, 2024

Conversation

kamiazya
Copy link
Member

@kamiazya kamiazya commented Nov 7, 2024

This pull request includes changes to improve the user experience by enhancing the TSGraphvizLiveEditor component and updating documentation files. The most important changes include adding an auto-resize feature to the editor and removing the fixed height attribute from the documentation examples.

Enhancements to TSGraphvizLiveEditor component:

Updates to documentation files:

  • docs/ts-graphviz/02-core-features/index.mdx: Removed the fixed height attribute from the example code to improve flexibility.
  • i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx: Removed the fixed height attribute from the example code in the Japanese translation to improve flexibility.This pull request includes two commits. The first commit "Auto resize the editor to fit the content height" adds functionality to automatically resize the editor based on the content height. The second commit "Remove height prop" removes the height prop from the code. These changes improve the editor's usability and remove unnecessary code.

Summary by CodeRabbit

  • New Features

    • Introduced a "TypeScript-Friendly API" section in the documentation, highlighting TypeScript integration and providing examples.
    • Added a new section in Japanese documentation contrasting declarative and imperative APIs with examples.
    • Enhanced the TSGraphvizLiveEditor component to automatically resize based on content height for improved user experience.
  • Bug Fixes

    • Removed the height={150} property from the live editor component to improve rendering.

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Warning

Rate limit exceeded

@kamiazya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 30 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 2f68191 and a76f8ad.

Walkthrough

The pull request introduces enhancements to the documentation of the ts-graphviz library, specifically focusing on TypeScript integration and API distinctions. It adds a section on the TypeScript-Friendly API and elaborates on Object-Oriented Models, providing examples for class instantiation and manipulation. Additionally, it contrasts declarative and imperative APIs with illustrative examples. Changes to the TSGraphvizLiveEditor component include an updated onMount prop that dynamically adjusts the editor's height based on content. The modifications improve clarity and usability without altering public entity declarations.

Changes

File Path Change Summary
docs/ts-graphviz/02-core-features/index.mdx Added "TypeScript-Friendly API" section, detailed Object-Oriented Models, and clarified API styles.
i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx Added section on API understanding, contrasting declarative and imperative APIs, and removed height={150} from <TSGraphvizLiveEditor>.
src/components/TSGraphvizLiveEditor/index.tsx Updated onMount prop to include a default function for dynamic height adjustment based on content.

Possibly related PRs

Suggested labels

enhancement

Poem

In a world of graphs so bright,
TypeScript shines, a pure delight.
With nodes and edges, clear as day,
Our docs now guide you on your way.
So hop along, and take a look,
The ts-graphviz is in the book! 🐇📚


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 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
Contributor

coderabbitai bot commented Nov 7, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kamiazya
Copy link
Member Author

kamiazya commented Nov 7, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Outside diff range and nitpick comments (1)
src/components/TSGraphvizLiveEditor/index.tsx (1)

24-32: Consider enhancing the auto-resize implementation.

The auto-resize implementation is a good start, but could be improved in several ways:

  1. The hardcoded line height (20px) might not match all Monaco themes
  2. Missing min/max height constraints could lead to very tall or very short editors
  3. No debouncing for frequent content changes

Consider this enhanced implementation:

  onMount = (editor) => {
-   const contentHeight = editor.getModel().getLineCount() * 20;
+   const lineHeight = editor.getOption(monaco.editor.EditorOption.lineHeight);
+   const contentHeight = Math.min(
+     Math.max(
+       editor.getModel().getLineCount() * lineHeight,
+       100 // minimum height
+     ),
+     500 // maximum height
+   );
    const currentLayout = editor.getLayoutInfo();
    editor.layout({
      height: contentHeight,
      width: currentLayout.contentWidth,
    });
+   
+   // Auto-resize on content changes
+   let resizeTimeout: NodeJS.Timeout;
+   editor.getModel().onDidChangeContent(() => {
+     clearTimeout(resizeTimeout);
+     resizeTimeout = setTimeout(() => {
+       const newHeight = Math.min(
+         Math.max(
+           editor.getModel().getLineCount() * lineHeight,
+           100
+         ),
+         500
+       );
+       editor.layout({
+         height: newHeight,
+         width: currentLayout.contentWidth,
+       });
+     }, 100);
+   });
  },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c985f48 and a779681.

📒 Files selected for processing (3)
  • docs/ts-graphviz/02-core-features/index.mdx (0 hunks)
  • i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx (0 hunks)
  • src/components/TSGraphvizLiveEditor/index.tsx (1 hunks)
💤 Files with no reviewable changes (2)
  • docs/ts-graphviz/02-core-features/index.mdx
  • i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx
🔇 Additional comments (1)
src/components/TSGraphvizLiveEditor/index.tsx (1)

Line range hint 1-93: Overall implementation looks solid!

The auto-resize feature is well integrated with the existing component:

  • Proper TypeScript typing
  • Clean integration with Monaco editor
  • Maintains existing functionality (themes, TypeScript setup, readOnly support)

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

🧹 Outside diff range and nitpick comments (5)
i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx (1)

Line range hint 1-100: Consider enhancing the documentation with additional examples.

The documentation is well-structured and comprehensive. To make it even better, consider adding:

  1. Error handling examples showing how TypeScript's type system helps prevent common mistakes
  2. More interactive examples demonstrating different attribute combinations
  3. Examples of complex graph structures using subgraphs
src/components/TSGraphvizLiveEditor/index.tsx (2)

Line range hint 8-14: Update Props interface to match implementation

The Props interface still includes the monaco parameter in the onMount callback signature, but this parameter has been removed from the actual implementation. This mismatch could cause TypeScript compilation errors and confusion for consumers.

Apply this change to align the interface with the implementation:

interface Props {
  script: string;
  onMount?: (
-   editor: editor.IStandaloneCodeEditor,
-   monaco: typeof monaco_editor,
+   editor: editor.IStandaloneCodeEditor
  ) => void;
  readOnly?: boolean;
}

24-26: Enhance prop documentation

While the comment indicates auto-resizing, it would be helpful to document the specific behavior (min/max heights, resize triggers).

Consider updating the comment to:

- // Auto resize the editor to fit the content height
+ /**
+  * Callback when editor is mounted. Default implementation auto-resizes editor height:
+  * - Adjusts between 100px and 500px based on content
+  * - Updates on content changes (unless readOnly)
+  */
docs/ts-graphviz/02-core-features/index.mdx (2)

Line range hint 89-102: Consider adding error handling examples.

The object-oriented example could benefit from demonstrating proper error handling practices, especially for common scenarios like invalid node references or duplicate IDs.

Consider adding an example like this:

try {
  const G = new Digraph('G');
  const nodeA = new Node('A');
  // Attempting to add the same node twice
  G.addNode(nodeA);
  G.addNode(nodeA); // This should show how duplicates are handled
} catch (error) {
  console.error('Error creating graph:', error);
}

Line range hint 1-7: Document the auto-resize feature of TSGraphvizLiveEditor.

Since this documentation file includes usage of the TSGraphvizLiveEditor component, consider adding information about its auto-resize capability to help users understand this feature.

Add a note like:

 import TSGraphvizLiveEditor from '@site/src/components/TSGraphvizLiveEditor';
+
+:::tip
+The editor automatically adjusts its height based on the content, ensuring all code is visible without manual resizing.
+:::
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a779681 and 2f68191.

📒 Files selected for processing (3)
  • docs/ts-graphviz/02-core-features/index.mdx (1 hunks)
  • i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx (1 hunks)
  • src/components/TSGraphvizLiveEditor/index.tsx (4 hunks)
🔇 Additional comments (3)
i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx (1)

15-19: LGTM! The example effectively demonstrates the TypeScript-friendly API.

The code example is well-structured and shows proper usage of the digraph function with attributes. The removal of the fixed height property aligns with the auto-resize feature implementation.

Let's verify the TSGraphvizLiveEditor component's props:

✅ Verification successful

The example code correctly aligns with the component's implementation

The code example in the documentation correctly demonstrates the usage of the TSGraphvizLiveEditor component. The component implementation confirms:

  • The script prop is required and properly handled
  • The height property has been removed in favor of auto-resizing functionality
  • The component automatically adjusts its height based on content (100px min, 500px max)
  • The example shows the correct way to use attributes with the TypeScript-friendly API
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify TSGraphvizLiveEditor component implementation
# Expected: Find the component definition and verify onMount prop

# Search for the TSGraphvizLiveEditor component definition
ast-grep --pattern 'export default function TSGraphvizLiveEditor($_) {
  $$$
}'

Length of output: 81


Script:

#!/bin/bash
# Let's try a broader search for the component using ripgrep
rg -l "TSGraphvizLiveEditor" 

# Also search for any file containing LiveEditor to ensure we don't miss renamed components
rg -l "LiveEditor"

# Search for the actual implementation using a more flexible pattern
ast-grep --pattern 'function TSGraphvizLiveEditor'

# Try TypeScript/JavaScript specific component definition patterns
ast-grep --pattern 'const TSGraphvizLiveEditor = $_'

Length of output: 605


Script:

#!/bin/bash
# Let's examine the actual component implementation
cat src/components/TSGraphvizLiveEditor/index.tsx

# Also check the preview editor for any related props or patterns
cat src/components/TSGraphvizPreviewEditor/index.tsx

Length of output: 8940

src/components/TSGraphvizLiveEditor/index.tsx (1)

106-106: LGTM! Proper integration with Monaco editor options

The onMountCallback is correctly passed to Monaco's onMount prop, and the editor options (particularly scrollBeyondLastLine: false) are properly configured to support the auto-resize functionality.

docs/ts-graphviz/02-core-features/index.mdx (1)

16-22: LGTM! TSGraphvizLiveEditor implementation aligns with auto-resize feature.

The component usage correctly omits the fixed height property, allowing the new auto-resize functionality to work as intended.

@kamiazya kamiazya merged commit 4e7df17 into main Nov 7, 2024
4 checks passed
@kamiazya kamiazya deleted the auto-fit-height-on-editor branch November 7, 2024 14:37
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.

1 participant