module HealthHelper
View helpers that render the table health breakdown view, mapping evaluator ratios to labels, operations, and severity styling.
Constants
- COMPONENT_META
-
Which maintenance operation fixes each component. Labels and explanations live in the locale, so the UI language stays with the rest of the app.
Public Instance Methods
# File app/helpers/health_helper.rb, line 27 def health_component_rows(evaluation) details = evaluation[:details] || {} evaluation.fetch(:components, {}).map do |key, ratio| meta = COMPONENT_META.fetch(key) { label: t("health.component_labels.#{key}"), explains: t("health.component_explains.#{key}"), operation: meta[:operation], ratio: ratio, has_data: !ratio.nil?, # A row with no data still reports 0 so the view can render the track # at a fixed width with an empty fill, instead of a shorter row. pct: ratio.nil? ? 0 : (ratio * 100).round, severity: severity_for(ratio), detail: component_detail(key, details) } end end
Rows ready for the breakdown view.
detail is the human number behind the ratio, read from the evaluation’s own details - the evaluator normalises to 0..1 and loses the unit, so it emits the measured values alongside. Taking them from the evaluation rather than from a separately-built extractor keeps the panel describing ONE evaluation, which is what makes a persisted read and a fresh evaluation render identically (see #215).
Every row has the same shape whether or not it has data, so the view can render an identical structure per row and the columns line up (see #219).
@param evaluation [Hash] the health evaluator result (persisted or fresh). @return [Array<Hash>] one hash per component with label, ratio, and severity.
# File app/helpers/health_helper.rb, line 50 def severity_fill_class(severity) case severity when :ok then "bg-ok-DEFAULT" when :warning then "bg-warn-DEFAULT" when :critical then "bg-red-DEFAULT" else "bg-cosmos-line" end end
Maps a severity to the background colour class used for its bar. @param severity [Symbol] the severity, one of :ok, :warning, or :critical. @return [String] the background CSS class for the severity.