Skip to content

feat(html5/plugin): add support for custom svg for actions bar buttons - #22923

Merged
antobinary merged 6 commits into
bigbluebutton:v3.0.x-releasefrom
GuiLeme:plugin-sdk-issue-166
Apr 23, 2025
Merged

antobinary merged 6 commits into
bigbluebutton:v3.0.x-releasefrom
GuiLeme:plugin-sdk-issue-166

Conversation

@GuiLeme

@GuiLeme GuiLeme commented Apr 10, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

It adds support for a custom svg icon on an actions bar button.

Motivation

Add more flexibility for the plugin developer to choose an icon for that area. It can be extended for other areas as well in further PRs.

How to test:

I'd recommend to use the sample plugin sample-actions-bar-plugin. Or just add the following snippet to your own plugin:

new ActionsBarButton({
        icon: {
          svgContent: (
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-cctv-icon lucide-cctv">
              <path d="M16.75 12h3.632a1 1 0 0 1 .894 1.447l-2.034 4.069a1 1 0 0 1-1.708.134l-2.124-2.97" />
              <path d="M17.106 9.053a1 1 0 0 1 .447 1.341l-3.106 6.211a1 1 0 0 1-1.342.447L3.61 12.3a2.92 2.92 0 0 1-1.3-3.91L3.69 5.6a2.92 2.92 0 0 1 3.92-1.3z" />
              <path d="M2 19h3.76a2 2 0 0 0 1.8-1.1L9 15" />
              <path d="M2 21v-4" />
              <path d="M7 9h.01" />
            </svg>) as React.SVGProps<SVGSVGElement>,
        },
        tooltip: 'This will log on the console.',
        onClick: () => {
          pluginLogger.info('The actions bar button from plugin was clicked');
        },
        position: ActionsBarPosition.RIGHT,
      });

More

Closely related to PR bigbluebutton/bigbluebutton-html-plugin-sdk#167

See screenshot ahead:

image

@coderabbitai

coderabbitai Bot commented Apr 10, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The changes in this pull request refactor the ActionsBar component to enhance code readability and maintainability. The update introduces a buttonProps object that consolidates several properties (such as key, onClick, hideLabel, color, size, circle, and label) passed to the Button component. Additionally, conditional logic now determines the value for the icon property: if plugin.icon contains iconName, it is assigned directly to buttonProps.icon; otherwise, a custom icon is created using plugin.icon.svgContent. The properties are then passed to the Button component through the spread operator, simplifying the JSX structure without altering the component’s external behavior.

Sequence Diagram(s)

sequenceDiagram
    participant A as ActionsBar
    participant P as Plugin
    participant B as Button

    A->>A: Initialize buttonProps object
    alt plugin.icon contains iconName
        A->>A: Set icon using plugin.icon
    else
        A->>A: Set icon using custom icon
    end
    A->>B: Pass buttonProps (via spread operator)
Loading

"""


📜 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 9c87a30 and ec00e20.

⛔ Files ignored due to path filters (1)
  • bigbluebutton-html5/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1 hunks)
  • bigbluebutton-html5/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • bigbluebutton-html5/package.json
  • bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-webrtc)
  • GitHub Check: build-package (bbb-freeswitch)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-fsesl-akka)
  • GitHub Check: build-package (bbb-web)
  • GitHub Check: build-package (bbb-etherpad)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
  • GitHub Check: build-package (bbb-learning-dashboard)
  • GitHub Check: build-package (bbb-export-annotations)
  • GitHub Check: build-package (bbb-config)
  • GitHub Check: build-package (bbb-apps-akka)

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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1)

55-63: Custom SVG icon support works well but could be improved

The conditional logic for handling custom SVG icons is implemented correctly. However, consider these improvements:

  1. Add a fallback for when both plugin.icon and plugin.customIconSvg are null
  2. Using an <i> tag for SVG content is unusual - consider using a more semantic wrapper or no wrapper
if (plugin.icon === null) {
+  if (plugin.customIconSvg) {
     buttonProps.customIcon = (
-      <i>
+      <span className="custom-icon">
         {plugin.customIconSvg}
-      </i>
+      </span>
     );
+  } else {
+    // Fallback to a default icon or handle the case
+    buttonProps.icon = 'warning';
+  }
} else {
  buttonProps.icon = plugin.icon;
}

Does the Button component properly handle SVG content wrapped in an <i> tag? If there are styling concerns, a more appropriate wrapper might be needed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3811f5b and 52e8e9e.

📒 Files selected for processing (1)
  • bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1)
bigbluebutton-html5/imports/ui/components/presentation/styles.js (1)
  • Button (172-190)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (2)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (2)

43-43: Good refactoring of button properties!

Consolidating the button properties into a buttonProps object improves code readability and maintainability. This approach makes the code more organized and easier to understand.

Also applies to: 46-54


66-68: Clean JSX with spread operator

Using the spread operator to pass the properties to the Button component makes the JSX cleaner and more maintainable. Good choice!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1)

58-62: Consider using semantic markup for SVG icons

Using an <i> tag as a container for SVG content is not semantically correct. For better accessibility and semantics, consider using a more appropriate element like <span> with an appropriate ARIA role if needed.

                  buttonProps.customIcon = (
-                    <i>
+                    <span className="custom-svg-icon">
                       {plugin.icon.svgContent}
-                    </i>
+                    </span>
                  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be6a0d1 and c4a8192.

📒 Files selected for processing (1)
  • bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (1)
bigbluebutton-html5/imports/ui/components/presentation/styles.js (1)
  • Button (172-190)
🪛 Biome (1.9.4)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx

[error] 55-55: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)


[error] 57-57: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (3)
bigbluebutton-html5/imports/ui/components/actions-bar/component.jsx (3)

43-43: Good refactoring to improve code organization

Consolidating button properties into a buttonProps object makes the code more maintainable and easier to read. This is a positive change that follows good React practices and makes future modifications simpler.

Also applies to: 46-54


66-68: Good use of the spread operator for props

Using the spread operator to pass the properties to the Button component is a clean approach that improves code readability.


46-63:

Details

❓ Verification inconclusive

Verify custom SVG rendering behavior

The implementation successfully adds support for custom SVG icons as requested in the PR objectives. However, it's important to verify that SVG content renders properly in all supported browsers.


🌐 Web query:

Are there any browser compatibility issues with inline SVG content in React applications?

💡 Result:

Inline SVG content in React applications generally works well across modern browsers, but there are several compatibility considerations and potential issues to be aware of:

Core Compatibility

  • Modern browsers (Chrome, Firefox, Safari, Edge) fully support inline SVG rendering in React when using standard practices[1][4][7].
  • Internet Explorer 11 requires polyfills for fetch API and Number.isNaN when using libraries like react-inlinesvg[1][10].

Common Issues

  1. Attribute Handling

    • React requires camelCased SVG attributes (e.g., strokeWidth instead of stroke-width)[6][9]
    • Deprecated xlink:href should be replaced with href with proper namespace declarations[5][9]
  2. Styling Limitations

    // Incorrect in some browsers
    <svg style="fill: red"> 
    
    // Correct React syntax
    <svg style={{ fill: 'red' }}>

    Style objects must use React's syntax to avoid rendering issues[7][9].

  3. CORS Restrictions
    Remote SVGs require proper CORS headers, particularly when modifying SVG content dynamically[1][4].

  4. Namespace Issues
    Missing XML namespaces can break SVG rendering:

    // Problematic in older browsers
    <svg>
      <use href="#icon" />
    
    // Recommended
    <svg xmlns="http://www.w3.org/2000/svg" 
         xmlns:xlink="http://www.w3.org/1999/xlink">
      <use xlinkHref="#icon" />
    </svg>
    ```[5][6][9]

Optimization & Fallbacks

  • Polyfills: Required for IE11 support (fetch, Promise, Number.isNaN)[1][10]
  • Performance: Complex SVGs may require optimization with tools like SVGO[7][9]
  • Fallback strategies:
    <ReactSVG src="icon.svg">
      <img src="fallback.png" alt="Fallback" />
    </ReactSVG>
    ```[1][7]

Mobile Browser Considerations

Some mobile browsers have limited support for:

  • SVG filters and blend modes[7][9]
  • SMIL animations[4][9]
  • viewBox scaling calculations[5][7]

Developers should test extensively using tools like BrowserStack and implement feature detection where critical SVG functionality is required[7][9]. Using popular React SVG libraries like react-inlinesvg or @svgr/webpack helps abstract many compatibility concerns while providing caching and error handling[1][4][7].

Citations:


Custom SVG Rendering Verification – Please Ensure Cross-Browser Testing

The new implementation for custom SVG icons appears sound: when a plugin provides an SVG via its svgContent, it is wrapped and passed through as a custom icon. Based on current information, inline SVG content in React renders well in modern browsers (Chrome, Firefox, Safari, Edge). However, note the following:

  • Legacy Browser Support: If your application requires support for older browsers (e.g., Internet Explorer 11), additional testing is needed. IE11 may require polyfills (for features like fetch or Number.isNaN) and careful attention to SVG attribute naming (i.e., using camelCased properties in React).

  • Testing Recommendations:

    • Verify that the SVG markup provided in plugin.icon.svgContent is well-formed and renders correctly across all target browsers.
    • Confirm that using an <i> tag as a container does not interfere with the SVG’s accessibility or style. Consider whether a more semantically appropriate container (or directly rendering the <svg> element) is warranted based on your app’s design.

Overall, if your target browsers are primarily modern ones, this implementation should work as expected; otherwise, please double-check compatibility with legacy browsers.

🧰 Tools
🪛 Biome (1.9.4)

[error] 55-55: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)


[error] 57-57: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

@antobinary antobinary added this to the Release 3.0 milestone Apr 10, 2025
@ramonlsouza
ramonlsouza self-requested a review April 22, 2025 12:07

@ramonlsouza ramonlsouza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please check coderabbit comment about potential TypeError with optional chaining

…n adding a new icon to the actions bar button
@GuiLeme
GuiLeme requested a review from ramonlsouza April 22, 2025 20:41
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have 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.

3 participants