Skip to content

[dashboard-controller] Move bages generation logic to internal dashboard component - #1567

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
dashboard-bages
Nov 4, 2025
Merged

[dashboard-controller] Move bages generation logic to internal dashboard component#1567
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
dashboard-bages

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Nov 1, 2025

Copy link
Copy Markdown
Member

Signed-off-by: Andrei Kvapil kvapss@gmail.com

What this PR does

Release note

[dashboard-controller] Move bages generation logic to internal dashboard component

Summary by CodeRabbit

  • Refactors
    • Dashboard badges now render with a unified ResourceBadge component across columns and headers.
    • Explicit badge size options removed; badges use simplified default sizing.
    • Badge payload simplified to a single value-driven field; abbreviation and rendering are handled by the badge component.
    • Stable per-kind color hashing removed; badges use streamlined, consistent styling with optional color overrides.
    • Column and header labels expanded to full descriptive names for clearer navigation.

@dosubot dosubot Bot added the size/L This PR changes 100-499 lines, ignoring generated files label Nov 1, 2025
@coderabbitai

coderabbitai Bot commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replace text/size/color-based badge creation with a Kind/value-based ResourceBadge across dashboard helpers and factories; remove stable color-hash utilities and badge size concepts; update related custom column builders and signatures to use badgeValue and optional style.

Changes

Cohort / File(s) Summary
Unified badge types & helpers
internal/controller/dashboard/unified_helpers.go
Removed BadgeSize and size constants; changed BadgeConfig to include Kind (kept Text/Color semantics); removed legacy color-getters; added createUnifiedBadge and createUnifiedBadgeFromKind; removed Size from UnifiedResourceConfig.
Badge rendering & header
internal/controller/dashboard/customcolumns.go
Replaced header badge component from "antdText" with "ResourceBadge" using value and optional style; removed local badgeText/badgeColor computation.
Factory calls & UI helpers
internal/controller/dashboard/factory.go, internal/controller/dashboard/ui_helpers.go
Removed explicit badge size usage; createBadgeFromKind/createHeaderBadge now call unified badge helpers without size param; removed Size init in Namespace config.
Static/custom column builders
internal/controller/dashboard/static_helpers.go, internal/controller/dashboard/static_refactored.go
Replaced inline/text-based badge blocks with ResourceBadge using badgeData (id, value, optional style); updated multiple createCustomColumn* signatures to accept badgeValue/badgeColor and removed title/size params; expanded some display labels.
Color & hashing removal
internal/controller/dashboard/helpers.go
Deleted stable color-generation helpers (initialsFromKind, hexColorForKind, hslToRGB, shortHashHex, numeric helpers) and removed related crypto/encoding imports.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Factory / Column Builder
    participant Unified as unified_helpers
    participant Renderer as UI renderer (ResourceBadge)

    rect `#F3F7FF`
    Note left of Caller: Previous flow (conceptual)
    Caller->>Unified: generateBadgeConfig(kind, text, color, title)
    Unified->>Unified: compute initials, stable hex color, attach Size
    Unified-->>Renderer: rendered/text badge payload
    end

    rect `#F7FFF3`
    Note left of Caller: New flow
    Caller->>Unified: createUnifiedBadgeFromKind(id, kind)
    Unified-->>Renderer: {type: "ResourceBadge", data: {id, value, style?}}
    Renderer-->>Caller: rendered ResourceBadge
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay attention to: unified_helpers.go (type/signature changes), cross-file updates to functions creating badges, and removed color/hash helpers that may be referenced elsewhere.

Possibly related PRs

Suggested reviewers

  • lllamnyp
  • nbykov0

Poem

🐇 I nibbled strings and trimmed the dye,
Badges now whisper their Kind, not try.
No hashes, no sizes — a cleaner band,
ResourceBadge hops, neat in my hand. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title contains a typo ('bages' instead of 'badges') and is somewhat vague about the scope of changes. While it references moving badge generation logic, the PR involves significant refactoring across multiple files including BadgeConfig restructuring, removal of color hashing logic, and API signature changes beyond just moving logic to a component. Correct the typo to 'badges' and clarify whether the primary change is moving logic to a component or refactoring the badge system architecture. Consider: '[dashboard-controller] Refactor badge generation with ResourceBadge' or '[dashboard-controller] Simplify badge creation and styling'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dashboard-bages

📜 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 ae8a54b and af460f1.

📒 Files selected for processing (7)
  • internal/controller/dashboard/customcolumns.go (1 hunks)
  • internal/controller/dashboard/factory.go (1 hunks)
  • internal/controller/dashboard/helpers.go (0 hunks)
  • internal/controller/dashboard/static_helpers.go (9 hunks)
  • internal/controller/dashboard/static_refactored.go (13 hunks)
  • internal/controller/dashboard/ui_helpers.go (1 hunks)
  • internal/controller/dashboard/unified_helpers.go (4 hunks)
💤 Files with no reviewable changes (1)
  • internal/controller/dashboard/helpers.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/controller/dashboard/factory.go
  • internal/controller/dashboard/ui_helpers.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (14)
internal/controller/dashboard/customcolumns.go (1)

60-67: LGTM! Clean migration to ResourceBadge component.

The header badge implementation correctly uses the ResourceBadge type with the kind value, delegating abbreviation and color generation to the frontend component. This simplifies the backend logic as intended by the refactor.

internal/controller/dashboard/static_refactored.go (3)

135-178: LGTM! Kind values correctly use PascalCase for ResourceBadge.

The updated custom column definitions correctly pass full resource Kind names (e.g., "Service", "Module", "WorkloadMonitor", "Secret") instead of abbreviated tokens. The empty string for the color parameter appropriately delegates color generation to the frontend ResourceBadge component.


271-286: LGTM! Consistent Kind value usage across ConfigMap and Namespace columns.

The custom column definitions for ConfigMaps and Namespaces correctly use full Kind names ("ConfigMap", "Namespace") in PascalCase, maintaining consistency with the refactor pattern.


1204-1204: LGTM! Correct usage of simplified createUnifiedBadgeFromKind signature.

The call correctly uses the updated two-parameter signature createUnifiedBadgeFromKind(id, kind), with "Namespace" as the proper PascalCase Kind value. This addresses the previous review feedback about the unused title parameter.

internal/controller/dashboard/static_helpers.go (5)

532-563: LGTM! Correct ResourceBadge implementation in createCustomColumn.

The function correctly constructs a ResourceBadge with the kind value and includes clear documentation about auto-generation of abbreviations. The structure properly nests the badge and link within an antdFlex container.


565-599: LGTM! Past review feedback addressed—title parameter removed.

The createCustomColumnWithBadge function now has a clean three-parameter signature (name, badgeValue, href), addressing the previous review comment about the unused title parameter. The implementation correctly uses ResourceBadge with auto-generated abbreviations.


601-642: LGTM! Clean optional color handling for ResourceBadge.

The function correctly implements optional color customization—when a color is provided, it's added to the badge style; when empty, the ResourceBadge component auto-generates the color. This provides flexibility while maintaining simplicity.


746-799: LGTM! Consistent badgeValue and optional color pattern.

Both createCustomColumnWithJsonPath and createCustomColumnWithoutJsonPath follow the same pattern—using badgeValue for the Kind and optional badgeColor for custom styling. The ResourceBadge implementation is consistent across these helpers.

Also applies to: 801-847


694-708: LGTM! Factory header correctly uses simplified badge helper.

The createFactoryHeader function correctly calls createUnifiedBadgeFromKind with two parameters (id, kind), consistent with the updated API that removed the unused title parameter.

internal/controller/dashboard/unified_helpers.go (5)

82-87: LGTM! Well-documented BadgeConfig structure.

The BadgeConfig struct is clearly documented with field-level comments explaining the purpose and expected format (e.g., PascalCase for Kind). The distinction between required (Kind) and optional (Text, Color) fields is clear and supports both auto-generation and customization use cases.


89-112: LGTM! Past review feedback properly addressed.

The createUnifiedBadge function correctly uses config.Kind for the ResourceBadge value field (line 93), addressing the previous review comment about using PascalCase Kind instead of Title. The optional Text and Color overrides provide flexibility without forcing explicit abbreviation generation, allowing the frontend ResourceBadge to auto-generate when overrides aren't specified.


114-125: LGTM! Simplified signature addresses past review feedback.

The createUnifiedBadgeFromKind function now has a clean two-parameter signature (id, kind), removing the unused title parameter mentioned in previous reviews. This provides a simple wrapper for the common case where no customization is needed, with clear documentation about auto-generation behavior.


138-158: LGTM! Minimal badge config initialization supports auto-generation.

The createResourceConfig function correctly initializes the BadgeConfig with only the Kind field (lines 147-149), leaving Text and Color as empty/zero values. This appropriately delegates abbreviation and color generation to the frontend ResourceBadge component.


221-273: LGTM! Flexible badge configuration in unified factory creation.

The createUnifiedFactory function correctly constructs a BadgeConfig from the UnifiedResourceConfig, allowing optional Text and Color customization (lines 227-231). This design provides flexibility for callers while maintaining the ability to rely on auto-generation when overrides aren't needed.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello Andrei Kvapil (@kvaps), I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the dashboard's badge generation mechanism by introducing a dedicated ResourceBadge component. This change centralizes the logic for creating resource badges, automatically handling abbreviations and color assignments based on the resource kind. The refactoring significantly streamlines the UI configuration for custom columns and factory headers, reducing code complexity and improving maintainability by abstracting styling and logic into a reusable component.

Highlights

  • Centralized Badge Logic: Badge generation logic, including abbreviation and color determination, has been migrated to a new ResourceBadge component, abstracting UI details.
  • Simplified UI Code: The dashboard UI code is simplified by replacing manual antdText badge configurations with the ResourceBadge component, reducing boilerplate and improving readability.
  • Removed Redundant Helpers: Several helper functions for badge styling, color generation (e.g., hexColorForKind, getColorForType), and badge sizing have been removed, streamlining the codebase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kvaps Andrei Kvapil (kvaps) changed the title [dashboard-controller] Migrate bages generation logic to internal dashboard component [dashboard-controller] Move bages generation logic to internal dashboard component Nov 1, 2025
@dosubot dosubot Bot added the kind/feature Categorizes issue or PR as related to a new feature label Nov 1, 2025

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request is a solid refactoring that migrates badge generation logic to a frontend ResourceBadge component. This is a great move for separation of concerns, simplifying the backend by removing styling and color generation logic. The changes are applied consistently across the codebase. I've identified a few areas for improvement: one bug where an incorrect value is passed to the new component, a couple of unused function parameters that can be cleaned up, and an opportunity to further delegate logic to the frontend for consistency.

Comment thread internal/controller/dashboard/unified_helpers.go Outdated
Comment thread internal/controller/dashboard/static_helpers.go Outdated
Comment thread internal/controller/dashboard/unified_helpers.go Outdated
Comment thread internal/controller/dashboard/unified_helpers.go Outdated

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/controller/dashboard/static_helpers.go (2)

534-563: Unused plural parameter breaks compilation

Go requires every parameter to be consumed. After the ResourceBadge refactor we never touch plural, so createCustomColumn now fails to build. Either remove the argument or mark it as intentionally ignored before merging.

-func createCustomColumn(name, kind, plural, href string) map[string]any {
+func createCustomColumn(name, kind string, _ string, href string) map[string]any {

568-599: Also fix unused title here

Same story: title is no longer referenced, so this helper won’t compile. Please drop it or turn it into a blank identifier.

-func createCustomColumnWithBadge(name, badgeValue, title, href string) map[string]any {
+func createCustomColumnWithBadge(name, badgeValue string, _ string, href string) map[string]any {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ac533f and 8f9f728.

📒 Files selected for processing (7)
  • internal/controller/dashboard/customcolumns.go (1 hunks)
  • internal/controller/dashboard/factory.go (1 hunks)
  • internal/controller/dashboard/helpers.go (0 hunks)
  • internal/controller/dashboard/static_helpers.go (9 hunks)
  • internal/controller/dashboard/static_refactored.go (13 hunks)
  • internal/controller/dashboard/ui_helpers.go (1 hunks)
  • internal/controller/dashboard/unified_helpers.go (3 hunks)
💤 Files with no reviewable changes (1)
  • internal/controller/dashboard/helpers.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

Comment thread internal/controller/dashboard/unified_helpers.go

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/controller/dashboard/static_helpers.go (1)

533-563: Fix compile error: use the plural argument

Go rejects unused parameters, so plural now triggers internal/controller/dashboard/static_helpers.go:536:2: plural declared but not used. We should either drop the parameter (and touch every caller) or, better, feed it into the unified badge helper so the signature stays intact.

 func createCustomColumn(name, kind, plural, href string) map[string]any {
 	link := antdLink("name-link", "{reqsJsonPath[0]['.metadata.name']['-']}", href)
+	badge := createUnifiedBadgeFromKind("header-badge", kind, plural)
 
 	return map[string]any{
 		"name": name,
 		"type": "factory",
 		"customProps": map[string]any{
@@
-				map[string]any{
-					"children": []any{
-						map[string]any{
-							"type": "ResourceBadge",
-							"data": map[string]any{
-								"id":    "header-badge",
-								"value": kind,
-								// abbreviation auto-generated by ResourceBadge from value
-							},
-						},
-						link,
-					},
+				map[string]any{
+					"children": []any{
+						badge,
+						link,
+					},
 					"type": "antdFlex",
 					"data": map[string]any{
 						"align": "center",
 						"gap":   float64(6),
 					},
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f9f728 and ae8a54b.

📒 Files selected for processing (7)
  • internal/controller/dashboard/customcolumns.go (1 hunks)
  • internal/controller/dashboard/factory.go (1 hunks)
  • internal/controller/dashboard/helpers.go (0 hunks)
  • internal/controller/dashboard/static_helpers.go (9 hunks)
  • internal/controller/dashboard/static_refactored.go (13 hunks)
  • internal/controller/dashboard/ui_helpers.go (1 hunks)
  • internal/controller/dashboard/unified_helpers.go (4 hunks)
💤 Files with no reviewable changes (1)
  • internal/controller/dashboard/helpers.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/controller/dashboard/customcolumns.go
  • internal/controller/dashboard/static_refactored.go
  • internal/controller/dashboard/factory.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

Comment thread internal/controller/dashboard/ui_helpers.go Outdated
@kvaps Andrei Kvapil (kvaps) added the backport Should change be backported on previous release label Nov 4, 2025
component

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@kvaps
Andrei Kvapil (kvaps) merged commit 19ed058 into main Nov 4, 2025
8 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the dashboard-bages branch November 4, 2025 16:36
@github-actions

github-actions Bot commented Nov 4, 2025

Copy link
Copy Markdown

Andrei Kvapil (kvaps) added a commit that referenced this pull request Nov 4, 2025
…logic to internal dashboard component (#1593)

# Description
Backport of #1567 to `release-0.37`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Should change be backported on previous release kind/feature Categorizes issue or PR as related to a new feature size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant