Skip to content

Add primary node customization hooks to ComponentDiagram#7

Merged
aretw0 merged 2 commits intomainfrom
copilot/implement-inversao-de-controle
Feb 15, 2026
Merged

Add primary node customization hooks to ComponentDiagram#7
aretw0 merged 2 commits intomainfrom
copilot/implement-inversao-de-controle

Conversation

Copy link
Contributor

Copilot AI commented Feb 15, 2026

Problem

ComponentDiagram primary nodes are hardcoded to use reflection on Enabled/Stopping/Stopped/Reason fields. This blocks lifecycle project migration which needs custom metadata display (signal counts) and CSS control (failure differentiation).

Changes

New customization hooks mirroring secondary node pattern:

type PrimaryNodeStyleFunc func(state any) (cssClass string)
type PrimaryNodeLabelFunc func(state any) string

type DiagramConfig struct {
    // ... existing fields ...
    PrimaryNodeStyler  PrimaryNodeStyleFunc
    PrimaryNodeLabeler PrimaryNodeLabelFunc
}

Default implementations encapsulate existing reflection logic:

  • defaultPrimaryNodeStyler - extracts Enabled/Stopping/Stopped → CSS class
  • defaultPrimaryNodeLabeler - extracts Reason → HTML label

Refactored renderGenericFragment to accept callbacks, falling back to defaults when nil (full backward compatibility).

Usage

// Custom state with domain-specific fields
type SignalState struct {
    Signal   string
    Received int
    Failed   bool
}

config := DefaultDiagramConfig()
config.PrimaryNodeStyler = func(state any) string {
    st := state.(SignalState)
    if st.Failed { return "failed" }
    if st.Signal == "SIGTERM" { return "stopping" }
    return "running"
}
config.PrimaryNodeLabeler = func(state any) string {
    st := state.(SignalState)
    return fmt.Sprintf("Signal: %s<br/>Received: %d", st.Signal, st.Received)
}

diagram := ComponentDiagram(signalState, processState, config)

Enables arbitrary state structures while maintaining zero-config defaults for legacy code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: aretw0 <14055273+aretw0@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement inversion of control for primary component in mermaid.go Add primary node customization hooks to ComponentDiagram Feb 15, 2026
Copilot AI requested a review from aretw0 February 15, 2026 07:37
@aretw0 aretw0 marked this pull request as ready for review February 15, 2026 07:38
@aretw0 aretw0 merged commit 4cd0582 into main Feb 15, 2026
1 check passed
@aretw0 aretw0 deleted the copilot/implement-inversao-de-controle branch February 15, 2026 07:40
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