@seikika/astro-report 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +32 -2
- package/integration.d.mts +13 -0
- package/integration.mjs +44 -0
- package/package.json +57 -3
- package/src/ReportApp.vue +220 -0
- package/src/ReportContent.vue +13 -0
- package/src/ReportView.vue +88 -0
- package/src/layouts/DefaultLayout.astro +17 -0
- package/src/lib/bars.ts +290 -0
- package/src/lib/basis.ts +157 -0
- package/src/lib/campaigns.ts +410 -0
- package/src/lib/compare.ts +204 -0
- package/src/lib/dom.ts +43 -0
- package/src/lib/kinds.ts +84 -0
- package/src/lib/levels.ts +61 -0
- package/src/lib/rings.ts +244 -0
- package/src/lib/routes.ts +118 -0
- package/src/lib/rules.ts +143 -0
- package/src/lib/status.ts +150 -0
- package/src/lib/summary.ts +231 -0
- package/src/lib/text.ts +57 -0
- package/src/lib/tracks.ts +264 -0
- package/src/lib/words.ts +72 -0
- package/src/report-view.ts +37 -0
- package/src/report.astro +27 -0
- package/src/report.css +359 -0
- package/src/types.ts +141 -0
- package/src/views/campaigns.ts +265 -0
- package/src/views/catalog.ts +456 -0
- package/src/views/compare.ts +676 -0
- package/src/views/entity.ts +443 -0
- package/src/views/overview.ts +639 -0
- package/src/views/rule.ts +153 -0
- package/src/views/scorecards.ts +947 -0
- package/src/views/tracks.ts +294 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ReportViews } from "../report-view";
|
|
2
|
+
import type { Summary } from "../lib/summary";
|
|
3
|
+
import type { ReportData } from "../types";
|
|
4
|
+
import { badge, grow } from "../lib/bars";
|
|
5
|
+
import { BASIS, basisBadge, basisOf, refs } from "../lib/basis";
|
|
6
|
+
import { el, enc, link } from "../lib/dom";
|
|
7
|
+
import { fill, UNRUN } from "../lib/levels";
|
|
8
|
+
import { shortId, title } from "../lib/rings";
|
|
9
|
+
import { ruleTitle } from "../lib/rules";
|
|
10
|
+
import { isPassing } from "../lib/status";
|
|
11
|
+
import { rich } from "../lib/text";
|
|
12
|
+
import { fmt, plural } from "../lib/words";
|
|
13
|
+
|
|
14
|
+
export const ruleViews = {
|
|
15
|
+
rule(D: ReportData, S: Summary, scName, ruleName) {
|
|
16
|
+
var sc = D.scorecards[scName];
|
|
17
|
+
var def = sc.rules[ruleName];
|
|
18
|
+
var b = basisOf(def);
|
|
19
|
+
var scores = (D.scores || {})[scName] || {};
|
|
20
|
+
var tally = { pass: 0, waived: 0, fail: 0, unknown: 0 };
|
|
21
|
+
var failing: string[] = [];
|
|
22
|
+
Object.keys(scores).forEach(function (id) {
|
|
23
|
+
var row = scores[id];
|
|
24
|
+
var o = (row.rules || {})[ruleName];
|
|
25
|
+
if (!o || o === "skipped" || row.level === "skipped") return;
|
|
26
|
+
tally[o] = (tally[o] || 0) + 1;
|
|
27
|
+
if (!isPassing(o)) failing.push(id);
|
|
28
|
+
});
|
|
29
|
+
// A rule that measures how far off each entity is (lines over a limit, findings) lists the furthest first.
|
|
30
|
+
var measureOf = function (id) {
|
|
31
|
+
var m = (scores[id].measures || {})[ruleName];
|
|
32
|
+
return typeof m === "number" ? m : null;
|
|
33
|
+
};
|
|
34
|
+
var measured = failing.some(function (id) {
|
|
35
|
+
return measureOf(id) != null;
|
|
36
|
+
});
|
|
37
|
+
failing.sort(function (a, c) {
|
|
38
|
+
return (scores[a].rules[ruleName] === "fail" ? 0 : 1) - (scores[c].rules[ruleName] === "fail" ? 0 : 1) || (measureOf(c) || 0) - (measureOf(a) || 0) || a.localeCompare(c);
|
|
39
|
+
});
|
|
40
|
+
var allFail = failing.every(function (id) {
|
|
41
|
+
return scores[id].rules[ruleName] === "fail";
|
|
42
|
+
});
|
|
43
|
+
var all = tally.pass + tally.waived + tally.fail + tally.unknown;
|
|
44
|
+
// Worst on the left, as on every level bar.
|
|
45
|
+
var parts = [
|
|
46
|
+
{ k: "fail", n: tally.fail, c: "var(--fail)", t: "fail" },
|
|
47
|
+
{ k: "unknown", n: tally.unknown, c: UNRUN, t: "not run in this build" },
|
|
48
|
+
{ k: "pass", n: tally.pass + tally.waived, c: def.level ? fill(def.level) : "var(--pass)", t: def.level ? "pass, toward " + def.level : "pass" },
|
|
49
|
+
].filter(function (p) {
|
|
50
|
+
return p.n;
|
|
51
|
+
});
|
|
52
|
+
var spans = parts.map(function (p) {
|
|
53
|
+
return el("span", { style: "flex-grow:0;flex-basis:0;background:" + p.c, title: p.n + " " + p.t });
|
|
54
|
+
});
|
|
55
|
+
grow(
|
|
56
|
+
spans,
|
|
57
|
+
parts.map(function (p) {
|
|
58
|
+
return p.n;
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
var bar = el("div", { className: "bar lg" }, ...spans);
|
|
62
|
+
bar.setAttribute("role", "img");
|
|
63
|
+
bar.setAttribute(
|
|
64
|
+
"aria-label",
|
|
65
|
+
parts
|
|
66
|
+
.map(function (p) {
|
|
67
|
+
return p.n + " " + p.t;
|
|
68
|
+
})
|
|
69
|
+
.join(", "),
|
|
70
|
+
);
|
|
71
|
+
var list = el("div");
|
|
72
|
+
var limit = 40;
|
|
73
|
+
var drawList = function () {
|
|
74
|
+
list.replaceChildren(
|
|
75
|
+
...failing.slice(0, limit).map(function (id) {
|
|
76
|
+
var o = scores[id].rules[ruleName];
|
|
77
|
+
var ev = (scores[id].evidence || {})[ruleName];
|
|
78
|
+
var items = ev == null ? [] : Array.isArray(ev) ? ev : [ev];
|
|
79
|
+
return link("entity/" + enc(id), "erow", [
|
|
80
|
+
el("div", { className: "name" }, id.indexOf(":") > 0 ? id.slice(id.indexOf(":") + 1) : shortId(id), el("span", { className: "chev", ariaHidden: "true", textContent: "›" }), el("small", { textContent: items.length ? (typeof items[0] === "string" ? items[0] : JSON.stringify(items[0])) + (items.length > 1 ? " (+" + (items.length - 1) + ")" : "") : id })),
|
|
81
|
+
el("span", { className: "outcome " + o, textContent: o === "unknown" ? "not run in this build" : o }),
|
|
82
|
+
]);
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
if (failing.length > limit)
|
|
86
|
+
list.append(
|
|
87
|
+
el(
|
|
88
|
+
"div",
|
|
89
|
+
{ className: "more" },
|
|
90
|
+
el("button", {
|
|
91
|
+
className: "link",
|
|
92
|
+
textContent: "Show all " + failing.length,
|
|
93
|
+
onclick: function () {
|
|
94
|
+
limit = Infinity;
|
|
95
|
+
drawList();
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
drawList();
|
|
102
|
+
var section = el(
|
|
103
|
+
"section",
|
|
104
|
+
{},
|
|
105
|
+
el("nav", { className: "crumb", ariaLabel: "Breadcrumb" }, link("scorecards", "", "Scorecards"), " / ", link("scorecard/" + enc(scName), "", title(D, scName)), " / " + ruleTitle(scName, ruleName)),
|
|
106
|
+
el(
|
|
107
|
+
"div",
|
|
108
|
+
{ className: "ehead" },
|
|
109
|
+
el("div", {}, el("h2", { textContent: ruleTitle(scName, ruleName), tabIndex: -1 }), el("div", { className: "sub" }, el("code", { className: "rid", textContent: ruleName }), " · a rule of ", link("scorecard/" + enc(scName), "", title(D, scName)), def.level ? el("span", {}, " · needed for ", badge(def.level)) : null)),
|
|
110
|
+
basisBadge(b),
|
|
111
|
+
),
|
|
112
|
+
def.rationale || (def.links || []).length
|
|
113
|
+
? el(
|
|
114
|
+
"div",
|
|
115
|
+
{ className: "rationale" },
|
|
116
|
+
el("b", { textContent: "Why it exists" }),
|
|
117
|
+
def.rationale ? el("div", {}, ...rich(def.rationale)) : null,
|
|
118
|
+
refs(def.links),
|
|
119
|
+
!(def.links || []).length && (sc.links || []).length ? el("div", { className: "sub", style: "margin-top:6px" }, "Read more, from the ", link("scorecard/" + enc(scName), "", title(D, scName)), " scorecard:") : null,
|
|
120
|
+
!(def.links || []).length ? refs(sc.links) : null,
|
|
121
|
+
)
|
|
122
|
+
: el("p", { className: "sub", textContent: "This rule has no rationale yet." }),
|
|
123
|
+
el("h3", { textContent: "How it is decided" }),
|
|
124
|
+
el("p", { style: "margin:0" }, basisBadge(b), " ", BASIS[b].desc),
|
|
125
|
+
el("div", { className: "cel", textContent: def.check }),
|
|
126
|
+
def.fix ? el("h3", { textContent: "How to fix a failure" }) : null,
|
|
127
|
+
def.fix ? el("p", { style: "margin:0" }, ...rich(def.fix)) : null,
|
|
128
|
+
el("h3", { textContent: "Outcomes" }),
|
|
129
|
+
all && def.level ? el("p", { className: "sub", style: "margin:0 0 6px", textContent: "A pass is drawn in the colour of " + def.level + ", the level this rule belongs to, as on the scorecard's bars." }) : null,
|
|
130
|
+
all ? bar : el("p", { className: "empty", textContent: "No entity is in scope." }),
|
|
131
|
+
all
|
|
132
|
+
? el(
|
|
133
|
+
"div",
|
|
134
|
+
{ className: "legend" },
|
|
135
|
+
...parts.map(function (p) {
|
|
136
|
+
return el("span", {}, el("span", { className: "dot", style: "background:" + p.c }), el("b", { textContent: fmt(p.n) }), " " + p.t);
|
|
137
|
+
}),
|
|
138
|
+
)
|
|
139
|
+
: null,
|
|
140
|
+
);
|
|
141
|
+
section.dataset.focus = "";
|
|
142
|
+
return el(
|
|
143
|
+
"div",
|
|
144
|
+
{},
|
|
145
|
+
section,
|
|
146
|
+
failing.length
|
|
147
|
+
? el("section", {}, el("div", { className: "head" }, el("h2", { textContent: "Not passing" }), el("span", { className: "sub", textContent: plural(failing.length, "entity", "entities") + (measured ? ", furthest off first" : allFail ? "" : ", failures first") })), list)
|
|
148
|
+
: all
|
|
149
|
+
? el("section", {}, el("p", { className: "empty good", textContent: "✓ Every entity in scope passes this rule." }))
|
|
150
|
+
: null,
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
} satisfies ThisType<ReportViews>;
|