Skip to content

Conversation

@Srinath0916
Copy link
Contributor

@Srinath0916 Srinath0916 commented Dec 1, 2025

Made command status easier to read by adding colors - green for success, red for failed, and gray for in-progress. Also made the text bold so it stands out more.

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #812.

Description of Changes

Added color highlighting to command status in the device admin page to improve readability. The status field now displays with color coding and bold text:

  • Success: green + bold
  • Failed: red + bold
  • In-progress: gray + bold

This makes it easier to quickly scan command results when u read.

Screenshot

(
Screenshot 2025-12-02 at 3 25 54 AM

Screenshot 2025-12-02 at 3 26 23 AM

)

Summary by CodeRabbit

  • Improvements
    • Admin command entries now display a dedicated, localized status label alongside type, input/output, created and modified info.
    • Status labels are color-coded and bold for quick recognition: green = success, red = failed, gray = in-progress.

✏️ Tip: You can customize this high-level summary in your review settings.

Made command status easier to read by adding colors - green for
success, red for failed, and gray for in-progress. Also made the
text bold so it stands out more.
@Srinath0916 Srinath0916 force-pushed the issues/812-ui-command-highlight branch from 001fcc5 to da537d5 Compare December 2, 2025 08:41
@Srinath0916
Copy link
Contributor Author

Hi @pandafy, could you please review this, when u get time??

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Sorry for my late response, we're being flooded with PRs.
It looks good, can you please add a basic test for this?

@coderabbitai review


/* Command status highlighting */
.command-status-success {
color: #417927;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we have variables for this? We recently started using CSS variables more. It may be a good idea to define these colors in openwisp-utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nemesifier I'll keep the current approach for this PR. I haven't worked with openwisp-utils before, but I'd be happy to look into setting it up and creating CSS variables for these status colors as a follow-up if that would help with consistency across the project.

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

Introduces a status_display method in CommandInline to render command status with an HTML span using CSS classes and updates admin fields/readonly_fields to include it; adds three CSS classes to style statuses (success, failed, in-progress) in connection static CSS.

Changes

Cohort / File(s) Summary
Admin display logic
openwisp_controller/connection/admin.py
Added ClassVar typing for fields and readonly_fields, replaced status with status_display in their declarations, added status_display(self, obj) which returns HTML including a status-specific CSS class, and set status_display.short_description = _("status").
Status styling
openwisp_controller/connection/static/connection/css/command-inline.css
Added .command-status-success, .command-status-failed, and .command-status-in-progress classes to apply bold font weight and distinct colors for success (green), failed (red), and in-progress (gray).

Sequence Diagram(s)

(omitted — change is a UI/admin presentation addition without multi-component sequential flow)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I swapped a field and painted signs,
Green for triumph, red that whines,
Gray waits steady, bold and neat,
Status hops into the admin seat,
Little rabbit claps with tiny vines.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: adding color highlighting to command status in the UI, with a reference to the linked issue #812.
Description check ✅ Passed The description covers main requirements but lacks test updates and documentation updates as indicated by unchecked boxes in the template checklist.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #812 requirements: color coding applied (green for success, red for failed, gray for in-progress) and status text made bold.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #812: CSS styling for status colors and a new status_display method for rendering with styling. No unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings

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

Copy link

@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: 0

🧹 Nitpick comments (2)
openwisp_controller/connection/admin.py (1)

106-107: Consider adding ClassVar annotations for mutable class attributes.

The field definitions are correct and properly updated to use status_display. However, as flagged by static analysis, mutable class attributes in Django admin classes should be annotated with typing.ClassVar for better type safety and clarity.

🔎 Proposed refactor with ClassVar annotations

Add the import at the top of the file:

+from typing import ClassVar
 from datetime import timedelta

Then apply these annotations:

 class CommandInline(admin.StackedInline):
     model = Command
     verbose_name = _("Recent Commands")
     verbose_name_plural = verbose_name
-    fields = ["status_display", "type", "input_data", "output_data", "created", "modified"]
-    readonly_fields = ["status_display", "type", "input_data", "output_data", "created", "modified"]
+    fields: ClassVar = ["status_display", "type", "input_data", "output_data", "created", "modified"]
+    readonly_fields: ClassVar = ["status_display", "type", "input_data", "output_data", "created", "modified"]
     formset = LimitedCommandResults
openwisp_controller/connection/static/connection/css/command-inline.css (1)

235-249: Consider using CSS variables for consistency if they exist in openwisp-utils.

The implementation correctly applies the color coding specified in the PR objectives. While the project does use CSS variables from openwisp-utils elsewhere (e.g., --ow-color-fg-ghost in admin.css), the specific status colors (#417927, #ba2121, #666) do not appear to have CSS variable equivalents in the current setup. These colors are also used as hardcoded values elsewhere in the codebase (e.g., jsonschema-ui.css). If you plan to establish a consistent color palette for status indicators across the project, consider creating and using CSS variables for these colors; otherwise, the current implementation is acceptable and follows existing patterns.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 828dfb3 and 3b49672.

📒 Files selected for processing (2)
  • openwisp_controller/connection/admin.py
  • openwisp_controller/connection/static/connection/css/command-inline.css
🧰 Additional context used
🧬 Code graph analysis (1)
openwisp_controller/connection/admin.py (2)
openwisp_controller/config/base/device.py (1)
  • status (398-403)
openwisp_controller/connection/base/models.py (1)
  • input_data (638-642)
🪛 Ruff (0.14.10)
openwisp_controller/connection/admin.py

106-106: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


107-107: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)

🔇 Additional comments (1)
openwisp_controller/connection/admin.py (1)

136-147: No action required.

The implementation is correct. The Command model's status field choices ("in-progress", "success", "failed") match the CSS class names in command-inline.css exactly. The status field has a default value and is never null, so no None handling is needed. The use of format_html properly guards against XSS vulnerabilities.

- Add ClassVar annotations for fields and readonly_fields as suggested by reviewer
- Fix line length issues by properly formatting field lists
- Fix Black formatting for format_html call
- Address all CI formatting failures
@Srinath0916 Srinath0916 force-pushed the issues/812-ui-command-highlight branch from c5f5ee2 to 47ec5ad Compare December 31, 2025 02:03
Copy link

@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: 0

🧹 Nitpick comments (1)
openwisp_controller/connection/admin.py (1)

151-160: Consider adding tests for the new status_display method.

Per the PR checklist, tests have not been written. Consider adding unit tests to verify:

  • Correct CSS class generation for each status value (success, failed, in-progress)
  • Proper HTML output with format_html
  • Correct display text via get_status_display()
Example test structure
# In tests for connection admin
def test_command_inline_status_display_success(self):
    command = Command(status='success')
    inline = CommandInline(Command, admin_site)
    result = inline.status_display(command)
    assert 'command-status-success' in result
    assert 'Success' in result  # or whatever get_status_display() returns

def test_command_inline_status_display_failed(self):
    command = Command(status='failed')
    inline = CommandInline(Command, admin_site)
    result = inline.status_display(command)
    assert 'command-status-failed' in result
    
def test_command_inline_status_display_in_progress(self):
    command = Command(status='in-progress')
    inline = CommandInline(Command, admin_site)
    result = inline.status_display(command)
    assert 'command-status-in-progress' in result
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5f5ee2 and 47ec5ad.

📒 Files selected for processing (1)
  • openwisp_controller/connection/admin.py
🧰 Additional context used
🧬 Code graph analysis (1)
openwisp_controller/connection/admin.py (2)
openwisp_controller/config/base/device.py (1)
  • status (398-403)
openwisp_controller/connection/base/models.py (1)
  • input_data (638-642)
⏰ 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). (11)
  • GitHub Check: Python==3.12 | django~=5.2.0
  • GitHub Check: Python==3.11 | django~=5.2.0
  • GitHub Check: Python==3.12 | django~=4.2.0
  • GitHub Check: Python==3.13 | django~=5.1.0
  • GitHub Check: Python==3.12 | django~=5.1.0
  • GitHub Check: Python==3.10 | django~=5.2.0
  • GitHub Check: Python==3.13 | django~=5.2.0
  • GitHub Check: Python==3.10 | django~=4.2.0
  • GitHub Check: Python==3.11 | django~=4.2.0
  • GitHub Check: Python==3.10 | django~=5.1.0
  • GitHub Check: Python==3.11 | django~=5.1.0
🔇 Additional comments (4)
openwisp_controller/connection/admin.py (4)

2-2: LGTM: Good type annotation practice.

Adding ClassVar import to properly type-hint class-level attributes is a good practice that improves code clarity and IDE support.


107-122: LGTM: Field configuration is correct.

The conversion to ClassVar typing and replacement of status with status_display aligns with the custom status rendering implementation. All fields are appropriately marked as readonly for this read-only inline.


160-160: LGTM: Proper label configuration.

The short description is correctly set with translation support, consistent with other field labels in the inline.


151-156: No changes needed. The implementation correctly uses format_html for XSS safety and get_status_display() for human-readable text. Verification confirms:

  1. The CSS file (command-inline.css) exists in the correct Django static directory and is automatically served by Django's static file system
  2. All status values defined in AbstractCommand.STATUS_CHOICES ("in-progress", "success", "failed") have corresponding CSS classes (.command-status-in-progress, .command-status-success, .command-status-failed)

The code is production-ready.

@coveralls
Copy link

Coverage Status

coverage: 98.613% (+0.001%) from 98.612%
when pulling 47ec5ad on Srinath0916:issues/812-ui-command-highlight
into 828dfb3 on openwisp:master.

@Srinath0916
Copy link
Contributor Author

Hey, @nemesifier All feedback addressed and ready for merge!
Added ClassVar annotations as suggested
Fixed all the formatting issues (line lengths, Black formatting)
Updated commit message to follow the style guidelines
All QA checks are now passing! The color highlighting should work perfectly - green for success, red for failed, and gray for in-progress, all with bold text as requested.
This should be good to go,
Let me know if there's anything else is needed.

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.

[change:ui] Highlight color of command status result

3 participants