django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

feat: Add colorization based on health level for panels and toolbar

Open hunzlahmalik opened this issue 5 months ago • 3 comments

  • #1395

Description

This PR introduces a unified health/alert state for Django Debug Toolbar panels and updates the UI to reflect panel. The name health is debatable, but the alert was already taken by the panel.

Key Changes

  • Adds a ToolbarHealthLevel enum (NONE, WARNING, CRITICAL) for numeric health states.

  • Adds a health_level property to the base Panel class, allowing panels to report their health status.

  • Implements health_level in AlertsPanel and SQLPanel for alert and slow query detection.

  • The toolbar now computes the maximum health level across all panels and uses it to color the hidden toolbar handle.

  • UI Updates:

    • Panel buttons and the hidden toolbar handle use new CSS classes and colors based on health level.
    • Adds CSS variables and styles for warning and critical states.
Warning Warning on Hover Critical Critical on Hover
image image image image
Critical on Panel Warning on Panel
image image

Motivation

  • Improves user experience by visually highlighting issues in the toolbar.

Checklist:

  • [ ] I have added the relevant tests for this change.
  • [ ] I have added an item to the Pending section of docs/changes.rst.
  • [ ] Add to Documentation

hunzlahmalik avatar Aug 10 '25 20:08 hunzlahmalik

@matthiask @tim-schilling

I'll be writing the testcases for this. It would be great if you could take a look at it before testcases.

Thanks!

Edit: You can also suggest how to compute health(debatable name) across other panel profiling, time etc...

hunzlahmalik avatar Aug 10 '25 20:08 hunzlahmalik

@hunzlahmalik this is really neat! How does it work with the history panel? Does the color only show for the request that renders the button? If you switch to a request that has problems, does the color update? Last question, I promise, did you consider adding the health level to the history panel so a person can view the high level issues of all the requests in a summary-esque view? I personally think that would be a fantastic way to leverage this feature.

tim-schilling avatar Sep 20 '25 13:09 tim-schilling

For the panels that do define the health_level logic, after switching the request they should update the color too. Right now there are only two panels with health_level login, sqlpanel and alerts.

See this: image image

Regarding summary-esque view, what do you have in mind. We can colorize the rows in the history panel based on health, or do you want a separate some kind of filter/tab for it. I think coloring the rows looks good to me. Like if there is a request with health_level CRITICAL, then that row will be red, with warning, that row will be yellowish.

hunzlahmalik avatar Sep 23 '25 07:09 hunzlahmalik