fix(web): 将 MTR 终止标记放在主机信息旁

This commit is contained in:
tsosunchia committed 2026-08-14 21:20:39 +08:00
1 parent 9e7304992f
commit 043a667796
2 files changed
+50 -10

No files matched your search

+8 -8
View File
@@ -1327,6 +1327,14 @@ function renderMTRStats(stats) {
if (!hostParts.ip && !hostParts.host) {
hostCell.textContent = '--';
}
const marker = stat && stat.response && stat.response.kind === 'unreachable'
? String(stat.response.marker || '').trim() : '';
if (marker) {
const markerSpan = document.createElement('span');
markerSpan.className = 'mtr-response-marker';
markerSpan.textContent = ` ${marker}`;
hostCell.appendChild(markerSpan);
}
if (geoText) {
const geoDiv = document.createElement('div');
geoDiv.className = 'attempt__geo';
@@ -1339,14 +1347,6 @@ function renderMTRStats(stats) {
mplsDiv.textContent = mplsText;
hostCell.appendChild(mplsDiv);
}
const marker = stat && stat.response && stat.response.kind === 'unreachable'
? String(stat.response.marker || '').trim() : '';
if (marker) {
const markerSpan = document.createElement('span');
markerSpan.className = 'mtr-response-marker';
markerSpan.textContent = ` ${marker}`;
hostCell.appendChild(markerSpan);
}
tbody.appendChild(row);
});
+42 -2
View File
@@ -11,15 +11,23 @@ function loadAppRawIngestor() {
const classList = {add() {}, remove() {}, toggle() {}};
const element = () => ({
classList,
children: [],
dataset: {},
parentElement: {classList},
addEventListener() {},
appendChild(child) {
this.children.push(child);
return child;
},
});
const resultNode = element();
const context = vm.createContext({
console,
document: {
body: {classList},
getElementById: element,
createElement: element,
createTextNode: (text) => ({nodeType: 3, textContent: text}),
getElementById: (id) => id === 'result' ? resultNode : element(),
addEventListener() {},
},
window: {
@@ -30,7 +38,7 @@ function loadAppRawIngestor() {
const appPath = path.join(__dirname, 'app.js');
vm.runInContext(fs.readFileSync(appPath, 'utf8'), context, {filename: appPath});
return (records, summary) => {
const ingest = (records, summary) => {
context.__records = records;
context.__summary = summary;
vm.runInContext(`
@@ -42,6 +50,14 @@ function loadAppRawIngestor() {
`, context);
return JSON.parse(JSON.stringify(context.__rows));
};
ingest.render = (stats) => {
context.__stats = stats;
resultNode.children = [];
vm.runInContext('renderMTRStats(__stats);', context);
return resultNode;
};
return ingest;
}
const rows = [
@@ -102,3 +118,27 @@ test('unreachable marker follows the current path edge, not a stale raw response
});
assert.equal(responseForRow(row, {hop: 2, reason: 'destination_reached'}), undefined);
});
test('unreachable marker stays beside the host before block metadata', () => {
const app = loadAppRawIngestor();
const result = app.render([{
ttl: 2,
sent: 1,
received: 1,
loss_count: 0,
ip: '192.0.2.2',
host: 'router.example',
geo: {country: 'CN'},
mpls: ['L=100'],
response: {kind: 'unreachable', marker: '!H'},
}]);
const table = result.children[0];
const tbody = table.children[1];
const row = tbody.children[0];
const hostCell = row.children[6];
assert.deepEqual(
hostCell.children.map((child) => child.className).filter(Boolean),
['mtr-hostname', 'mtr-response-marker', 'attempt__geo', 'mtr-mpls'],
);
});