Skip to content
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

fix(toolbar): fix toolbar rendering - hide empty button groups #972

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

dqunbp
Copy link
Contributor

@dqunbp dqunbp commented Feb 4, 2025

https://kontur.fibery.io/Tasks/Task/Hide-button-group-on-Toolbar-if-it's-empty-17352

Summary by CodeRabbit

  • Refactor
    • Optimized the toolbar’s rendering process for smoother, more responsive performance.
    • Improved filtering logic to display only sections with active controls, ensuring a cleaner interface.
    • Streamlined the overall toolbar structure for enhanced clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

This update refactors the toolbar content rendering within the ToolbarContent component. The computation of toolbar content is now optimized using a useMemo hook that aggregates toolbar sections and maps their controls into a structured array of button objects. The inline mapping was replaced with a cleaner, separated data preparation step that filters out sections without buttons. Additionally, new types such as ToolbarControlButton, alongside existing ControlState and ToolbarControlSettings, are introduced to improve type safety and code clarity.

Changes

File Path Change Summary
src/features/toolbar/.../ToolbarContent.tsx Introduced a useMemo hook for efficient computation of toolbar content, refactored rendering logic to map over the computed toolbarContent, filtered sections without buttons, and added/updated type definitions (ToolbarControlButton, ControlState, ToolbarControlSettings, and PrimitiveAtom import).

Sequence Diagram(s)

sequenceDiagram
    participant TC as ToolbarContent Component
    participant UM as useMemo Hook
    participant TS as Toolbar Settings
    participant RC as Render JSX

    TC->>UM: Compute toolbarContent
    UM->>TS: Iterate over sections and controls
    TS-->>UM: Return processed sections (filtered & mapped)
    UM->>TC: Supply computed toolbarContent
    TC->>RC: Map toolbarContent for rendering
Loading

Poem

I’m hopping through the lines of code, so spry,
Memoized magic makes the buttons fly.
Types and hooks dance in a neat display,
Filtering out the noise along the way.
With a twitch of my ears, I cheer with delight—
CodeRabbit’s world is ever so bright!
🐇💻🌟


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. (Beta)
  • @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

github-actions bot commented Feb 4, 2025

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

Copy link

github-actions bot commented Feb 4, 2025

Bundle size diff

Old size New size Diff
5.17 MB 5.17 MB 190 B (0.00%)

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9637565 and ca32dcd.

📒 Files selected for processing (1)
  • src/features/toolbar/components/ToolbarContent/ToolbarContent.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/features/toolbar/components/ToolbarContent/ToolbarContent.tsx

[error] 38-38: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
src/features/toolbar/components/ToolbarContent/ToolbarContent.tsx (3)

8-15: LGTM! Well-structured type definitions.

The new ToolbarControlButton type and its imports provide clear type safety for the toolbar button structure.


20-32: LGTM! Effective optimization and empty section filtering.

The useMemo implementation efficiently:

  • Caches the toolbar content computation
  • Correctly filters out empty sections
  • Maintains type safety with TypeScript

36-63: LGTM! Clean and efficient rendering logic.

The implementation effectively renders only non-empty sections with proper dividers, which aligns with the PR objectives.

🧰 Tools
🪛 Biome (1.9.4)

[error] 38-38: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 33 lines in your changes missing coverage. Please review.

Project coverage is 10.02%. Comparing base (9637565) to head (18699d9).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...olbar/components/ToolbarContent/ToolbarContent.tsx 0.00% 32 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (25.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (1.13%) is below the target coverage (15.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #972      +/-   ##
==========================================
- Coverage   10.02%   10.02%   -0.01%     
==========================================
  Files         669      669              
  Lines       29459    29467       +8     
  Branches     1236     1236              
==========================================
  Hits         2954     2954              
- Misses      25975    25983       +8     
  Partials      530      530              
Components Coverage Δ
UI Components 0.26% <ø> (ø)
Core Logic 17.81% <ø> (ø)
Features 1.13% <0.00%> (-0.01%) ⬇️
Utilities 45.49% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codecov bot commented Feb 4, 2025

Bundle Report

Changes will increase total bundle size by 278 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
konturio/disaster-ninja-fe-esm 5.42MB 278 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: konturio/disaster-ninja-fe-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-*.js 44 bytes 180.62kB 0.02%
assets/index-*.js 190 bytes 5.05kB 3.91%
assets/App-*.js 44 bytes 27.63kB 0.16%

Files in assets/index-*.js:

  • ./src/features/toolbar/components/ToolbarContent/ToolbarContent.tsx → Total Size: 1.77kB

@dqunbp dqunbp force-pushed the 17352-hide-button-group-on-toolbar-if-it-s-empty branch from ca32dcd to 18699d9 Compare February 4, 2025 00:39
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ca32dcd and 18699d9.

📒 Files selected for processing (1)
  • src/features/toolbar/components/ToolbarContent/ToolbarContent.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
src/features/toolbar/components/ToolbarContent/ToolbarContent.tsx (2)

1-15: LGTM! Well-structured type definitions.

The new type definitions and imports enhance type safety and code clarity.


20-32: LGTM! Efficient implementation of toolbar content processing.

The useMemo hook effectively optimizes the computation by caching the toolbar content and filtering out empty sections, which aligns with the PR objective.

@alesiahil alesiahil requested a review from a team February 4, 2025 08:52
@dqunbp dqunbp merged commit 9b4538c into main Feb 5, 2025
19 of 28 checks passed
@dqunbp dqunbp deleted the 17352-hide-button-group-on-toolbar-if-it-s-empty branch February 5, 2025 18:27
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.

2 participants