Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 9, 2025

Directly define the buttons in the page instead of using DomHelpers functions to simplify the implementation.
This also reduces the size of the application (about 3 kB).

Improve the script building all examples

  • list the size of all examples and add an option to only list size without building
  • move it to the scripts folder for consistency

Impact on the size of the examples

Example v0.19.0 With #806 With #809 With #822
js-example 475.30 kB 469.8 kB 470.56 kB 467.59 kB
js-example-selected-features 415.10 kB 410.18 kB 393.27 kB 390.40 kB
js-example-without-default 347.33 kB 342.69 kB 325.79 kB 325.44 kB
ts-example 438.64 kB 434.80 kB 435.46 kB 435.23 kB
ts-example-selected-features 380.70 kB 377.11 kB 369.30 kB 369.09 kB
ts-example-without-default 329.90 kB 326.43 kB 309.40 kB 309.18 kB

The very small decrease in all TS examples and js-example-without-default are due to other PR.

Summary by CodeRabbit

  • New Features
    • Added "View Original XML" and "Export XML" buttons below the graph in both example apps for easier access to XML viewing and exporting.
  • Style
    • Introduced a new .controls class to improve layout and spacing of control buttons in the UI.
  • Chores
    • Updated build scripts and workflow to improve automation and maintainability for building example projects.
  • Documentation
    • Improved clarity and formatting of code comments for better readability.

Directly define the buttons in the page instead of using DomHelpers functions to simplify the implementation.
This also reduces the size of the application.

Improve the script building all examples
- list the size of all examples and add an option to only list size without building
- move it to the scripts folder for consistency
@tbouffard tbouffard added the refactor Code refactoring label May 9, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 9, 2025

Walkthrough

This update relocates and enhances the example build script, updates workflow configuration to use the new script path, and modifies the HTML and JavaScript of two example projects to use static buttons for XML actions instead of dynamically creating them. Associated CSS is refactored for clearer structure and scoping of controls.

Changes

File(s) Change Summary
.github/workflows/build.yml Updated the build workflow to execute the example build script from ./scripts/build-all-examples.bash instead of the root directory. No other workflow steps changed.
build-all-examples.bash Deleted the original Bash script that built all example projects in packages/ts-example* and packages/js-example*.
scripts/build-all-examples.bash Added a new, enhanced Bash script for building all example projects. Supports an optional --list-size-only argument to skip builds and list output file sizes. Provides improved output and error handling.
packages/js-example/index.html
packages/js-example-selected-features/index.html
Added a <div class="controls"> containing two buttons ("View Original XML" and "Export XML") below the graph container. Buttons have IDs and aria-labels for accessibility.
packages/js-example/src/index.js
packages/js-example-selected-features/src/index.js
Removed dynamic button creation using DomHelpers. Now attaches click event listeners to pre-existing buttons in the DOM (identified by IDs). Removed import of DomHelpers. Functionality for XML popups remains unchanged.
packages/js-example/src/style.css
packages/js-example-selected-features/src/style.css
Introduced a .controls class with margin-top: 1.5rem. Moved or added button margin styling (margin-left: 0.5rem) inside .controls for scoped styling. Cleaned up and separated CSS rules for clarity.
packages/core/src/util/domHelpers.ts Reformatted and clarified the JSDoc comment for the button function. No code or API changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant index.js
    participant GraphModel

    User->>Browser: Clicks "View Original XML" button
    Browser->>index.js: Triggers click event
    index.js->>GraphModel: Retrieves original XML
    index.js->>Browser: Displays XML in popup

    User->>Browser: Clicks "Export XML" button
    Browser->>index.js: Triggers click event
    index.js->>GraphModel: Exports current model as XML
    index.js->>Browser: Displays exported XML in popup
Loading
sequenceDiagram
    participant GitHub Actions
    participant build-all-examples.bash (old)
    participant scripts/build-all-examples.bash (new)
    participant ExampleDirs

    GitHub Actions->>scripts/build-all-examples.bash (new): Run build script
    scripts/build-all-examples.bash (new)->>ExampleDirs: For each example dir, run npm build
    scripts/build-all-examples.bash (new)->>ExampleDirs: List JS file sizes in dist/
Loading

Possibly related PRs

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 4860885 and 36c1c0a.

📒 Files selected for processing (1)
  • scripts/build-all-examples.bash (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/build-all-examples.bash
✨ Finishing Touches
  • 📝 Generate Docstrings

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@tbouffard tbouffard marked this pull request as ready for review May 9, 2025 05:55
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 (4)
scripts/build-all-examples.bash (3)

9-12: Enhance argument parsing with usage and help option

Currently the script only handles --list-size-only and ignores any other flags silently. Consider switching to a case/getopts-based parser and adding a --help option to display usage information and exit on unknown arguments.


14-17: Clarify log message when skipping build

The message "Skip building examples..." is functional but could be more descriptive. For example:

- echo "Skip building examples..."
+ echo "Skipping build; listing example sizes only..."

43-47: Make file-size listing more robust against spaces

Parsing ls -l output can break on filenames with spaces. You can replace the ls + awk pipeline with find’s -printf for safer, more reliable output:

- find "$dir/dist" -name "*.js" -type f -exec ls -l {} \; | LC_NUMERIC=C awk '{
-   size_kb = $5 / 1000
-   printf "%.2f kB %s\n", size_kb, $9
- }'
+ find "$dir/dist" -name "*.js" -type f -printf '%s %p\n' | LC_NUMERIC=C awk '{
+   size_kb = $1 / 1000
+   printf "%.2f kB %s\n", size_kb, $2
+ }'
.github/workflows/build.yml (1)

59-59: Ensure the build script is executable in CI

The workflow invokes ./scripts/build-all-examples.bash directly. Please verify that the script has the executable bit set in the repo, or modify the step to invoke it via bash to avoid permission errors:

- run: ./scripts/build-all-examples.bash
+ run: bash scripts/build-all-examples.bash
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0728231 and 4860885.

📒 Files selected for processing (10)
  • .github/workflows/build.yml (1 hunks)
  • build-all-examples.bash (0 hunks)
  • packages/core/src/util/domHelpers.ts (1 hunks)
  • packages/js-example-selected-features/index.html (1 hunks)
  • packages/js-example-selected-features/src/index.js (1 hunks)
  • packages/js-example-selected-features/src/style.css (1 hunks)
  • packages/js-example/index.html (1 hunks)
  • packages/js-example/src/index.js (1 hunks)
  • packages/js-example/src/style.css (1 hunks)
  • scripts/build-all-examples.bash (1 hunks)
💤 Files with no reviewable changes (1)
  • build-all-examples.bash
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/js-example/src/index.js (2)
packages/js-example-selected-features/src/index.js (5)
  • popup (107-109)
  • xmlWithVerticesAndEdges (46-74)
  • xml (116-116)
  • graph (80-89)
  • graph (104-104)
packages/core/src/serialization/ModelXmlSerializer.ts (1)
  • ModelXmlSerializer (52-73)
🔇 Additional comments (7)
packages/core/src/util/domHelpers.ts (1)

114-124: JSDoc improvements enhance clarity and simplify example

The updated documentation for the button function now features a more concise description and a streamlined code example. The simplified single-line example better illustrates the typical usage pattern, which aligns with the PR's goal of simplifying button management.

packages/js-example-selected-features/index.html (1)

17-20: Good implementation of static buttons with proper accessibility attributes

Adding static buttons with descriptive aria-labels is a significant improvement over dynamically created buttons. This approach:

  1. Makes the UI structure more explicit in HTML
  2. Improves accessibility with proper aria-labels
  3. Separates concerns (HTML for structure, JS for behavior)
  4. Aligns with the PR goal of simplifying button management and reducing application size

The controls container provides a clean way to group related UI elements.

packages/js-example/index.html (1)

17-20: Well-structured static buttons with accessibility support

The addition of static buttons with descriptive aria-labels is an excellent improvement that:

  1. Enhances accessibility through proper HTML structure and aria-labels
  2. Makes the UI more maintainable by keeping structure in HTML
  3. Follows best practices by separating concerns
  4. Contributes to the PR's goal of reducing application size by ~3kB

The consistent implementation across example projects shows good attention to maintainability.

packages/js-example/src/style.css (1)

43-49: Better CSS organization with semantic class names

The CSS refactoring improves the structure by:

  1. Creating a semantic .controls class that clearly indicates its purpose
  2. Separating container spacing (margin-top) from element spacing (margin-left)
  3. Following CSS best practices with more specific selectors

This change complements the HTML structure updates and provides better styling organization.

packages/js-example-selected-features/src/index.js (1)

111-118: Cleaner approach using static HTML elements

This change effectively replaces dynamic button creation with event listeners attached to static HTML elements. The approach is more maintainable as it properly separates concerns between HTML structure and JavaScript behavior.

packages/js-example/src/index.js (1)

87-94: Good separation of concerns

The implementation now attaches event listeners to pre-existing HTML elements rather than creating buttons dynamically. This approach is consistent with the changes in the selected-features example and follows best practices by separating structure (HTML) from behavior (JavaScript).

packages/js-example-selected-features/src/style.css (1)

43-49: Improved CSS organization with proper scoping

The introduction of the .controls class with proper margin spacing and scoped button styling is a good improvement. This change supports the architectural shift to static HTML buttons while maintaining proper styling hierarchy.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 9, 2025

@tbouffard tbouffard merged commit c26d981 into main May 9, 2025
2 checks passed
@tbouffard tbouffard deleted the refactor/js-example_buttons_in_html_page branch May 9, 2025 10:04
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