Skip to content

Commit 709065a

Browse files
committed
fix(webapp): a delta arrow without a magnitude renders nothing
1 parent 6fcf1cf commit 709065a

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

apps/webapp/app/presenters/v3/reports/report-layout.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,52 @@ const livenessFinding = {
2929
metricIds: ["liveness"],
3030
};
3131

32+
function vmWithMetric(metric: LayoutViewModel["metrics"][number]): LayoutViewModel {
33+
return {
34+
title: "health",
35+
scope: "prod",
36+
period: "last 60 min",
37+
windowMinutes: 60,
38+
summary: { severity: "warn", statements: [] },
39+
findings: [{ type: "queue", severity: "warn", reason: "backlog", metricIds: [metric.id] }],
40+
metrics: [metric],
41+
footer: [],
42+
};
43+
}
44+
45+
function heroDelta(metric: LayoutViewModel["metrics"][number]) {
46+
const layout = buildReportLayout(vmWithMetric(metric), reportMessages("health"));
47+
return layout.hero?.metrics.find((m) => m.id === metric.id)?.delta;
48+
}
49+
50+
describe("buildReportLayout metric deltas", () => {
51+
it("renders no delta when a metric collapsed to nothing", () => {
52+
expect(
53+
heroDelta({
54+
id: "pending",
55+
value: 0,
56+
unit: "count",
57+
severity: "warn",
58+
normal: 40,
59+
delta: { dir: "down", mult: 0 },
60+
})
61+
).toBeUndefined();
62+
});
63+
64+
it("still renders a multiplier for a genuine fall", () => {
65+
expect(
66+
heroDelta({
67+
id: "pending",
68+
value: 10,
69+
unit: "count",
70+
severity: "warn",
71+
normal: 40,
72+
delta: { dir: "down", mult: 0 },
73+
})
74+
).toEqual({ text: "↓ 4×", dir: "down" });
75+
});
76+
});
77+
3278
describe("buildReportLayout self-evident findings", () => {
3379
it("drops the metric row of a non-hero finding whose only metric is its own line", () => {
3480
const layout = buildReportLayout(

apps/webapp/app/presenters/v3/reports/report-layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ function metricDelta(metric: LayoutMetricInput): LayoutDelta | undefined {
574574
// A fall's own multiplier rounds to 0 or 1, so measure how far it fell instead.
575575
if (delta?.dir === "down") {
576576
const fall = fallMultiplier(metric);
577-
if (fall === null) return { text: REPORT_GLYPH.down, dir: "down" };
577+
// An arrow with no multiplier behind it says nothing the sparkline hasn't.
578+
if (fall === null) return undefined;
578579
if (fall !== undefined) return { text: `${REPORT_GLYPH.down} ${fall}×`, dir: "down" };
579580
}
580581
if (delta && delta.mult !== undefined && delta.mult > 1 && delta.dir !== "flat") {

0 commit comments

Comments
 (0)