Skip to content

Fix missing status_display, add format_status docs, refactor InstanceView initialization#8

Merged
tayyebi merged 3 commits intobetafrom
copilot/fix-instance-resize-status-display
Jan 7, 2026
Merged

Fix missing status_display, add format_status docs, refactor InstanceView initialization#8
tayyebi merged 3 commits intobetafrom
copilot/fix-instance-resize-status-display

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 7, 2026

Three code quality improvements identified in code review: missing status field formatting in resize handler, undocumented public function, and duplicated initialization logic.

Changes

  • Add missing status_display in resize handler - instance_resize_get now populates status_display with formatted status, matching behavior in instance_change_pass_get and instance_change_pass_post

  • Document format_status function - Added doc comment explaining transformation from API representation (e.g., "preparing_disk") to display format (e.g., "Preparing Disk")

  • Extract InstanceView initialization - Added InstanceView::new_with_defaults() method to eliminate duplicated initialization across 4 locations in handlers and services

// Before: Manual initialization duplicated in multiple locations
let mut instance = InstanceView { 
    id: instance_id.clone(), 
    hostname: "(no hostname)".into(), 
    region: "".into(), 
    main_ip: None, 
    main_ipv6: None, 
    status: "".into(), 
    status_display: "".into(), 
    vcpu_count_display: "—".into(), 
    ram_display: "—".into(), 
    disk_display: "—".into(), 
    os: None 
};

// After: Single method, consistent defaults
let mut instance = InstanceView::new_with_defaults(instance_id.clone());
Original prompt

Fix Remaining Code Review Issues

Please address the following issues found in the code review:

1. Missing status_display population in instance_resize_get function

File: src/handlers/instances.rs (around line 395)

In the instance_resize_get function, after retrieving the status from the API, we need to populate the status_display field with the formatted status value. This is currently done correctly in other handler functions like instance_change_pass_get and instance_change_pass_post, but is missing in the resize handler.

Fix needed: After line 395 where instance.status is set, add:

instance.status_display = crate::utils::format_status(&instance.status);

2. Add documentation for format_status function

File: src/utils/status_formatter.rs

The public format_status function lacks documentation. Add a doc comment explaining:

  • What the function does
  • The parameter it accepts
  • What it returns
  • Examples of transformations

Example documentation:

/// Formats a raw status string into a human-readable display format.
///
/// This function converts status values from their API representation (e.g., "preparing_disk")
/// into user-friendly display strings (e.g., "Preparing Disk").
///
/// # Arguments
///
/// * `status` - A string slice containing the raw status value
///
/// # Returns
///
/// A formatted String suitable for display to users. If the status is not recognized,
/// it returns the original status unchanged.
///
/// # Examples
///
/// ```
/// let formatted = format_status("preparing_disk");
/// assert_eq!(formatted, "Preparing Disk");
///
/// let formatted = format_status("active");
/// assert_eq!(formatted, "Active");
/// ```
pub fn format_status(status: &str) -> String {

3. Refactor duplicated InstanceView initialization

Files: src/handlers/instances.rs (lines 241, 279, 388) and src/services/instance_service.rs (line 73)

The default InstanceView initialization pattern is duplicated in multiple locations. Extract this into a helper method on the InstanceView struct or a standalone function to improve maintainability.

Suggested approach: Add a method to the InstanceView struct in src/models/instance_view.rs:

impl InstanceView {
    /// Creates a new InstanceView with default values for the given instance ID.
    pub fn new_with_defaults(instance_id: String) -> Self {
        Self {
            id: instance_id,
            hostname: "(no hostname)".into(),
            region: "".into(),
            main_ip: None,
            main_ipv6: None,
            status: "".into(),
            status_display: "".into(),
            vcpu_count_display: "—".into(),
            ram_display: "—".into(),
            disk_display: "—".into(),
            os: None,
        }
    }
}

Then replace all occurrences of the manual initialization with:

let mut instance = InstanceView::new_with_defaults(instance_id.clone());

Priority: High for issue #1, Medium for issues #2 and #3.

Testing: After making these changes, verify that:

  1. The resize page displays formatted status values correctly
  2. All existing functionality continues to work
  3. The code compiles without errors

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…or InstanceView initialization

Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
@tayyebi tayyebi requested a review from Copilot January 7, 2026 14:38
Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses three code quality and consistency issues identified during a previous code review. The changes ensure that status display formatting is consistently applied, improve code maintainability through refactoring, and enhance code documentation.

Key Changes:

  • Added missing status_display population in the instance_resize_get function to match the pattern used in other handler functions
  • Added comprehensive documentation to the format_status utility function with examples
  • Refactored duplicated InstanceView initialization code by introducing a new_with_defaults helper method

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/utils/status_formatter.rs Added comprehensive documentation for the format_status function including usage examples and parameter descriptions
src/models/instance_view.rs Added new_with_defaults helper method to eliminate code duplication when creating InstanceView instances with default values
src/handlers/instances.rs Refactored three handler functions to use new_with_defaults and added missing status_display population in instance_resize_get
src/services/instance_service.rs Refactored get_instance_for_action to use the new new_with_defaults helper method

Review Result: ✅ No issues found. All changes are correctly implemented and consistent with the codebase patterns. The PR successfully addresses all three objectives outlined in the description.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI changed the title [WIP] Fix missing status_display population in instance_resize_get function Fix missing status_display, add format_status docs, refactor InstanceView initialization Jan 7, 2026
Copilot AI requested a review from tayyebi January 7, 2026 14:44
@tayyebi tayyebi marked this pull request as ready for review January 7, 2026 14:46
@tayyebi tayyebi merged commit ed01ff3 into beta Jan 7, 2026
@tayyebi tayyebi deleted the copilot/fix-instance-resize-status-display branch January 7, 2026 15:01
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