Skip to content

Commit 5662a80

Browse files
committed
Fix artifact table display
The table was broken because nightly has recently stopped shipping `libtest.so`, and one piece of the code was accessing `undefined` artifact data. This commit makes component handling more robust.
1 parent 8b21652 commit 5662a80

File tree

1 file changed

+49
-65
lines changed

1 file changed

+49
-65
lines changed

site/frontend/src/pages/compare/artifact-size/artifact-size-table.vue

Lines changed: 49 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,37 @@ const props = defineProps<{
1313
b: ArtifactDescription;
1414
}>();
1515
16+
interface ComponentSize {
17+
name: string;
18+
before: number;
19+
after: number;
20+
}
21+
22+
const allComponents: ComponentSize[] = [
23+
...new Set([
24+
...Object.keys(props.a.component_sizes),
25+
...Object.keys(props.b.component_sizes),
26+
]),
27+
].map((name) => {
28+
const before = props.a.component_sizes[name] ?? 0;
29+
const after = props.b.component_sizes[name] ?? 0;
30+
return {
31+
name,
32+
before,
33+
after,
34+
};
35+
});
36+
1637
// Sort binaries first, libraries later. Then within each category, sort alphabetically.
17-
const components = Object.keys(props.a.component_sizes).sort((a, b) => {
18-
const aLib = a.startsWith("lib");
19-
const bLib = b.startsWith("lib");
38+
const components = allComponents.sort((a, b) => {
39+
const aLib = isLibrary(a.name);
40+
const bLib = isLibrary(b.name);
2041
if (aLib && !bLib) {
2142
return 1;
2243
} else if (!aLib && bLib) {
2344
return -1;
2445
} else {
25-
return a.localeCompare(b);
46+
return a.name.localeCompare(b.name);
2647
}
2748
});
2849
@@ -37,27 +58,25 @@ function formatName(component: string): string {
3758
return component;
3859
}
3960
40-
function formatValue(value: number | undefined): string {
41-
if (!isValidValue(value)) {
61+
function formatValue(value: number): string {
62+
if (value === 0) {
4263
return "-";
4364
}
4465
return formatSize(value);
4566
}
4667
47-
function formatChangeTitle(
48-
a: number | undefined,
49-
b: number | undefined
50-
): string {
51-
if (!isValidValue(a) || !isValidValue(b)) {
52-
return "";
53-
}
68+
function formatChangeTitle(a: number, b: number): string {
5469
return (b - a).toLocaleString();
5570
}
5671
57-
function formatChange(a: number | undefined, b: number | undefined): string {
58-
if (!isValidValue(a) || !isValidValue(b)) {
59-
return "-";
72+
function formatTitle(value: number): string {
73+
if (value === 0) {
74+
return "Missing value";
6075
}
76+
return value.toLocaleString();
77+
}
78+
79+
function formatChange(a: number, b: number): string {
6180
const diff = b - a;
6281
const formatted = formatSize(Math.abs(diff));
6382
if (diff < 0) {
@@ -66,8 +85,8 @@ function formatChange(a: number | undefined, b: number | undefined): string {
6685
return formatted;
6786
}
6887
69-
function getClass(a: number | undefined, b: number | undefined): string {
70-
if (!isValidValue(a) || !isValidValue(b) || a == b) {
88+
function getClass(a: number, b: number): string {
89+
if (a === b) {
7190
return "";
7291
}
7392
return diffClass(b - a);
@@ -111,68 +130,33 @@ function generateTitle(component: string): string {
111130
<tbody>
112131
<tr v-for="component in components">
113132
<td class="component">
114-
{{ formatName(component) }}
115-
<Tooltip>{{ generateTitle(component) }}</Tooltip>
133+
{{ formatName(component.name) }}
134+
<Tooltip>{{ generateTitle(component.name) }}</Tooltip>
116135
</td>
117136
<td>
118-
{{ isLibrary(component) ? "Library" : "Binary" }}
137+
{{ isLibrary(component.name) ? "Library" : "Binary" }}
119138
</td>
120139
<td>
121-
<div
122-
class="aligned"
123-
:title="a.component_sizes[component].toLocaleString()"
124-
>
125-
{{ formatValue(a.component_sizes[component]) }}
140+
<div class="aligned" :title="formatTitle(component.before)">
141+
{{ formatValue(component.before) }}
126142
</div>
127143
</td>
128144
<td>
129-
<div
130-
class="aligned"
131-
:title="b.component_sizes[component].toLocaleString()"
132-
>
133-
{{ formatValue(b.component_sizes[component]) }}
145+
<div class="aligned" :title="formatTitle(component.after)">
146+
{{ formatValue(component.after) }}
134147
</div>
135148
</td>
136-
<td
137-
:class="
138-
getClass(
139-
a.component_sizes[component],
140-
b.component_sizes[component]
141-
)
142-
"
143-
>
149+
<td :class="getClass(component.before, component.after)">
144150
<div
145151
class="aligned"
146-
:title="
147-
formatChangeTitle(
148-
a.component_sizes[component],
149-
b.component_sizes[component]
150-
)
151-
"
152+
:title="formatChangeTitle(component.before, component.after)"
152153
>
153-
{{
154-
formatChange(
155-
a.component_sizes[component],
156-
b.component_sizes[component]
157-
)
158-
}}
154+
{{ formatChange(component.before, component.after) }}
159155
</div>
160156
</td>
161-
<td
162-
:class="
163-
getClass(
164-
a.component_sizes[component],
165-
b.component_sizes[component]
166-
)
167-
"
168-
>
157+
<td :class="getClass(component.before, component.after)">
169158
<div class="aligned">
170-
{{
171-
formatPercentChange(
172-
a.component_sizes[component],
173-
b.component_sizes[component]
174-
)
175-
}}
159+
{{ formatPercentChange(component.before, component.after) }}
176160
</div>
177161
</td>
178162
</tr>

0 commit comments

Comments
 (0)