Skip to content

Standardize Panel Return Types #44

@lowhung

Description

@lowhung

Description

Panel functions have inconsistent return types. Standardize on a result struct pattern.

Current State

fn draw_filter_panel(...) -> bool                    // Returns changed flag
fn draw_details_panel(...) -> DetailsPanelResult     // Returns struct
fn draw_legend(...)                                  // Returns nothing
fn draw_group_panel(...)                             // Returns nothing

Proposed Solution

Create a unified PanelResult type:

/// Result from drawing a panel, indicating any user actions.
#[derive(Default)]
pub struct PanelResult {
    /// Whether panel state was modified (requires graph update, etc.)
    pub changed: bool,
    /// User action to be handled by the app
    pub action: Option<PanelAction>,
}

/// Actions that can be triggered from panels.
pub enum PanelAction {
    SelectNode(String),
    SelectEdge(SelectedEdge),
    ClearSelection,
}

impl PanelResult {
    pub fn unchanged() -> Self {
        Self::default()
    }
    
    pub fn changed() -> Self {
        Self { changed: true, action: None }
    }
    
    pub fn with_action(action: PanelAction) -> Self {
        Self { changed: false, action: Some(action) }
    }
}

Update all panel functions:

pub fn draw_filter_panel(...) -> PanelResult
pub fn draw_details_panel(...) -> PanelResult
pub fn draw_legend(...) -> PanelResult  // Returns unchanged()
pub fn draw_group_panel(...) -> PanelResult
pub fn draw_group_legend(...) -> PanelResult

Acceptance Criteria

  • Create PanelResult and PanelAction types
  • Update all panel functions to return PanelResult
  • Update app.rs to handle unified result type
  • All tests pass

Files Affected

  • src/ui/panels.rs
  • src/ui/types.rs (add new types)
  • src/ui/app.rs (update panel result handling)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions