Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions apps/web/src/page/kit/affected-chips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { V2SetupAuditCheck } from "@maple/domain/http/v2"
import { cn } from "@maple/ui/lib/utils"
import type { Html, HtmlBuilder } from "foldkit/html"
import { inlineCode, inlineCodeClassName } from "@maple/views/ui/inline-code"
import { hstack } from "@maple/views/ui/stack"
import { typography } from "@maple/views/ui/typography"
import { Array as Arr } from "effect"

type Entity = V2SetupAuditCheck["affected"][number]

const chipClassName = "text-2xs leading-4"

const affectedChip = <M>(h: HtmlBuilder<M>, entity: Entity, index: number): Html => {
const title = entity.note === null ? [] : [h.Title(entity.note)]
const key = h.Key(entity.id === null ? `index:${index}` : `id:${entity.kind}:${entity.id}`)
if (entity.kind === "service")
return h.a(
[key, h.Href(`/services/${encodeURIComponent(entity.name)}`), ...title],
[
inlineCode(
h,
{
className: cn(
chipClassName,
"text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground active:decoration-foreground",
),
},
[entity.name],
),
],
)
return h.code(
[
key,
...title,
h.Class(inlineCodeClassName("chip", cn(chipClassName, "text-muted-foreground"))),
h.DataAttribute("slot", "inline-code"),
],
[entity.name],
)
}

/** The entities a setup-health check names, as chips with a "+N more" for the rest past the cap.
* Renders nothing when the check names none; `className` is the caller's spacing. */
export const affectedChips = <M>(
h: HtmlBuilder<M>,
check: Pick<V2SetupAuditCheck, "affected" | "affected_count">,
options: Readonly<{ className?: string }> = {},
): ReadonlyArray<Html> =>
check.affected.length === 0
? []
: [
hstack(h, { gap: "1.5", wrap: true, className: options.className }, [
...Arr.map(check.affected, (entity, index) => affectedChip(h, entity, index)),
...(check.affected_count > check.affected.length
? [
typography(h, { size: "2xs", tone: "subtle" }, [
`+${check.affected_count - check.affected.length} more`,
]),
]
: []),
]),
]
66 changes: 66 additions & 0 deletions apps/web/src/page/settings/setup-health/setup-health.scene.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { describe, expect, test } from "vitest"
import { healthSegments, orderFindings, resolvedChecks, setupHealthAction } from "./derive"
import { Message } from "./model"
import { init, update } from "./update"
import { view } from "./view"
import type { HtmlBuilder } from "foldkit/html"
import { click, expect as expectView, given, role, scene, text } from "foldkit/scene"
import { Array as Arr, Result, Schema } from "effect"

const names = (commands: ReadonlyArray<{ readonly name: string }> | undefined) =>
Expand All @@ -21,6 +24,69 @@ const report = Schema.decodeSync(V2SetupAudit)({
})

describe("setup health", () => {
test("opening passing checks shows unavailable capability detail, entities and the capped remainder, but no skip detail", () => {
const audit = Schema.decodeSync(V2SetupAudit)({
...report,
summary: { ...report.summary, pass: 1, skip: 1 },
checks: [
{
object: "setup_audit_check",
id: "CFG-INTEG-02",
category: "integrations",
title: "Cloudflare datasets are collecting",
severity: "warn",
status: "pass",
detail: "2 unavailable (Cloudflare dataset settings deny collection).",
affected: [
{
kind: "integration",
id: null,
name: "firewall_events · example.com",
note: "unavailable",
},
],
affected_count: 2,
fix_hint: "Review Cloudflare settings.",
},
{
object: "setup_audit_check",
id: "TRC-01",
category: "traces",
title: "Traces have complete parents",
severity: "warn",
status: "skip",
detail: "Requires telemetry data, which is currently unavailable.",
affected: [],
affected_count: 0,
fix_hint: "Restore warehouse access.",
},
],
})
const model = update(
init().model,
Message.CompletedFetchAudit({ result: Result.succeed(audit) }),
).model
scene(
{
update,
view: (model, h: HtmlBuilder<Message>) =>
h.submodel({
slotId: "audit",
model,
view,
toParentMessage: (message) => message,
viewInputs: { nowMs: 0, timeZone: "UTC" },
}),
},
given(model),
click(role("button", { name: /Passing/ })),
expectView(text("2 unavailable (Cloudflare dataset settings deny collection).")).toExist(),
expectView(text("firewall_events · example.com")).toExist(),
expectView(text("+1 more")).toExist(),
expectView(text("Skipped")).toExist(),
expectView(text("Requires telemetry data, which is currently unavailable.")).not.toExist(),
)
})
test("entry runs the audit; Re-run keeps the report up and asks once while it re-runs", () => {
expect(names(init().commands)).toEqual(["FetchSetupAudit"])
const loaded = update(
Expand Down
69 changes: 16 additions & 53 deletions apps/web/src/page/settings/setup-health/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { badge } from "@maple/views/ui/display"
import { empty, emptyDescription, emptyHeader, emptyMedia, emptyTitle } from "@maple/views/ui/empty"
import { errorState } from "@maple/views/ui/error-state"
import { icon, type IconName } from "@maple/views/ui/icon"
import { inlineCode, inlineCodeClassName } from "@maple/views/ui/inline-code"
import { panel } from "@maple/views/ui/panel"
import { statusDot } from "@maple/views/ui/status-dot"
import { refreshButton } from "@maple/views/ui/refresh-button"
Expand All @@ -19,6 +18,7 @@ import { relativeTime } from "../../kit/relative-time"
import { docsLink } from "../../kit/signal-empty-state"
import { emptyActions } from "@maple/views/ui/signal-empty-state"
import { settingsSection, settingsSections } from "../../kit/settings-section"
import { affectedChips } from "../../kit/affected-chips"
import {
type HealthSegment,
healthSegments,
Expand Down Expand Up @@ -84,38 +84,6 @@ const actionButton = (h: H, action: SetupHealthAction): Html =>
[action.label, icon(h, "ArrowRightIcon", { size: 14 })],
)

const chipClassName = "text-2xs leading-4"

const affectedChip = (h: H, entity: V2SetupAuditCheck["affected"][number], index: number): Html => {
const title = entity.note === null ? [] : [h.Title(entity.note)]
const key = h.Key(entity.id === null ? `index:${index}` : `id:${entity.kind}:${entity.id}`)
if (entity.kind === "service")
return h.a(
[key, h.Href(`/services/${encodeURIComponent(entity.name)}`), ...title],
[
inlineCode(
h,
{
className: cn(
chipClassName,
"text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground active:decoration-foreground",
),
},
[entity.name],
),
],
)
return h.code(
[
key,
...title,
h.Class(inlineCodeClassName("chip", cn(chipClassName, "text-muted-foreground"))),
h.DataAttribute("slot", "inline-code"),
],
[entity.name],
)
}

const findingRow = (h: H, check: V2SetupAuditCheck): Html => {
const severity = SEVERITY[check.severity]
const action = setupHealthAction(check)
Expand Down Expand Up @@ -145,24 +113,7 @@ const findingRow = (h: H, check: V2SetupAuditCheck): Html => {
typography(h, { size: "xs", tone: "subtle", as: "p", className: "leading-relaxed" }, [
check.fix_hint,
]),
...(check.affected.length === 0
? []
: [
hstack(h, { gap: "1.5", align: "center", wrap: true, className: "pt-0.5" }, [
...Arr.map(check.affected, (entity, index) =>
affectedChip(h, entity, index),
),
...(check.affected_count > check.affected.length
? [
typography(h, { size: "2xs", tone: "subtle" }, [
"+",
String(check.affected_count - check.affected.length),
" more",
]),
]
: []),
]),
]),
...affectedChips(h, check, { className: "pt-0.5" }),
]),
]),
...(action === null ? [] : [h.div([h.Class("pl-7 sm:pl-0")], [actionButton(h, action)])]),
Expand Down Expand Up @@ -329,7 +280,7 @@ const passingDisclosure = (
h,
{
gap: "3",
align: "center",
align: "start",
as: "li",
className: "px-4 py-2.5",
attributes: [h.Key(check.id)],
Expand All @@ -344,7 +295,19 @@ const passingDisclosure = (
size: 14,
className: "text-foreground-subtle shrink-0",
}),
h.span([h.Class("min-w-0 flex-1 text-xs")], [check.title]),
vstack(h, { gap: "1.5", shrink: true, grow: true }, [
typography(h, { size: "xs" }, [check.title]),
...(check.detail === null || check.status === "skip"
? []
: [
typography(
h,
{ size: "xs", tone: "muted", as: "p" },
[check.detail],
),
]),
...affectedChips(h, check),
]),
...(check.status === "skip"
? [
badge(h, { variant: "secondary", size: "xs" }, [
Expand Down
Loading