Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Mar 3, 2025

Add a new function taking an HTML content that will be used to display the description of the Story in a dedicated div.

Summary by CodeRabbit

  • New Features

    • Introduced a streamlined approach for constructing primary display areas, allowing content to be integrated directly within the main container.
  • Refactor

    • Simplified the UI component structure by removing redundant intermediary elements, resulting in a cleaner and more efficient presentation across several interactive views.

Add a new function taking an HTML content that will be used to display the description of the Story in a dedicated div.
@tbouffard tbouffard added the refactor Code refactoring label Mar 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2025

Walkthrough

This pull request streamlines the creation of main div elements across multiple story files. The changes update import statements in four story files to include a new function, createMainDiv, from the shared configuration module. In each story file, the code no longer creates and styles a separate divMessage element; instead, the inner HTML is passed directly into createMainDiv. Additionally, a new method, createMainDiv(htmlDescription: string): HTMLDivElement, is introduced in the shared module to encapsulate this functionality.

Changes

File(s) Change Summary
packages/html/stories/{CustomHandlesConfiguration, Events, Overlays, ShowRegion}.stories.ts Updated import statements to include createMainDiv and modified Template functions to remove separate divMessage creation by directly using createMainDiv with inner HTML.
packages/html/stories/.../shared/configure.js Added new method createMainDiv(htmlDescription: string): HTMLDivElement that creates a main div with a styled child div containing the provided HTML description.

Sequence Diagram(s)

sequenceDiagram
    participant Template
    participant GraphContainer as createGraphContainer
    participant MainDivCreator as createMainDiv
    Template->>GraphContainer: createGraphContainer(args)
    Template->>MainDivCreator: createMainDiv(innerHTML)
    MainDivCreator-->>Template: mainDiv element
    Template->>GraphContainer: append(mainDiv)
Loading

Possibly related PRs

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2025

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 (2)
packages/html/stories/shared/configure.js (1)

58-60: Consider adding a CSS class instead of inline styles

Using inline styles works, but for better maintainability, consider using a CSS class instead. This would allow for easier styling updates across all stories.

- divMessage.style.fontFamily = 'Arial,Helvetica,sans-serif';
- divMessage.style.marginBottom = '1rem';
+ divMessage.classList.add('story-description');

Then add the corresponding CSS class in a shared stylesheet.

packages/html/stories/Events.stories.ts (1)

68-74: Consider adding an ID to the main div for accessibility

For better accessibility and potential DOM references, consider adding an ID to the main div element in the createMainDiv function or as an optional parameter.

In configure.js, you could modify the function to accept an optional ID:

-export function createMainDiv(htmlDescription) {
+export function createMainDiv(htmlDescription, id = null) {
  const mainDiv = document.createElement('div');
+  if (id) mainDiv.id = id;
  // rest of the function remains the same

Then in the stories, you could optionally provide an ID when it might be useful:

-const div = createMainDiv(`
+const div = createMainDiv(`
  Creating a graph container and using interaction on the graph, including marquee selection, custom tooltips, context menu.
  <p>
  It also demonstrates how to use an edge style in the default stylesheet, and handle the double click on the adjustment point.
  <br>
   See also the <code>Overlays</code> Story for click event handling.
-  `);
+  `, 'events-description');
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b73fc2a and 52b8639.

📒 Files selected for processing (5)
  • packages/html/stories/CustomHandlesConfiguration.stories.ts (2 hunks)
  • packages/html/stories/Events.stories.ts (2 hunks)
  • packages/html/stories/Overlays.stories.ts (2 hunks)
  • packages/html/stories/ShowRegion.stories.ts (2 hunks)
  • packages/html/stories/shared/configure.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (9)
packages/html/stories/shared/configure.js (1)

46-63: Good implementation of shared functionality! ✅

This function nicely encapsulates the previously duplicated code for creating and styling description divs across story files. The documentation is clear and the implementation is straightforward.

packages/html/stories/Overlays.stories.ts (2)

35-39: Good import organization

The change to import createMainDiv alongside other configuration functions is well-organized and maintains code clarity.


56-63: Successfully simplified component creation

The refactoring successfully replaces the manual creation of div elements with the shared function, making the code more concise and consistent with other story files.

packages/html/stories/CustomHandlesConfiguration.stories.ts (2)

36-36: Clean import statement

The import statement is concise and properly includes the new shared function.


58-63: Improved code readability

The use of createMainDiv simplifies the Template function and removes duplication, making the code more readable and maintainable.

packages/html/stories/Events.stories.ts (2)

43-47: Consistent import pattern

The imports are organized consistently with other files, using a multi-line import statement for better readability.


68-74: Enhanced consistency across story files

The refactoring makes this file consistent with other story files by using the shared createMainDiv function, which improves maintainability and reduces duplication.

packages/html/stories/ShowRegion.stories.ts (2)

44-44: Good addition of the createMainDiv import.

The import statement correctly adds the new createMainDiv function alongside the existing createGraphContainer import.


63-65: Well-implemented refactoring of the description div creation.

This change successfully implements the shared code approach for managing story descriptions. Instead of manually creating and styling a div element, the code now uses the dedicated createMainDiv function, passing the HTML description directly as an argument. This refactoring:

  1. Centralizes the styling and structure of description divs
  2. Makes the code more maintainable
  3. Provides consistency across different story files

The HTML message content is preserved during this refactoring.

@tbouffard tbouffard merged commit 0620d6f into main Mar 3, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/stories_shared_code_for_description branch March 3, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant