mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Say why Transit and Bike Share rows are empty outside coverage
Over a city with no feed or system (London, Tokyo) both rows read "ON · — · never", the same as a feed that never answered. Transit already computed a coverage note but put it only in `coverage`, which the row does not show; Bike Share reported nothing at all. Both layers now report a `zoom-in` guidance status with a `statusMessage`: "Fly below 3,000 km to a covered region" / "No feed here yet · N regions available" for Transit, and "Fly below 48 km to a covered city" / "No bike share here yet · N systems available" for Bike Share. A loading or failed Bike Share city keeps its own text. Leaving coverage clears the layer's last-update time, so the row no longer dates data it no longer draws. The coverage-note translations move from the voice card into `translateStatusMessage` (ui/statusText.js), which the Layers row and the voice card now share.
This commit is contained in:
1 parent
7d8b80db0a
commit
b6ad32009f
23 files changed
+459
-37
No files matched your search
@@ -11,14 +11,17 @@ import {
|
||||
} from './layerNames.js';
|
||||
export { localizeLayerName } from './layerNames.js';
|
||||
import { createWeatherPanel } from './weatherPanel.js';
|
||||
import { translateFeedError, translateStatusLine } from './statusText.js';
|
||||
import {
|
||||
translateFeedError,
|
||||
translateStatusLine,
|
||||
translateStatusMessage,
|
||||
} from './statusText.js';
|
||||
import {
|
||||
formatNumber,
|
||||
getLocale,
|
||||
msg,
|
||||
onLocaleChange,
|
||||
t,
|
||||
translateKnown,
|
||||
} from '../i18n/index.js';
|
||||
|
||||
// Feed-state values are machine ids (QA hooks, CSS feed-* classes); only the
|
||||
@@ -691,7 +694,7 @@ export class LayerPanel {
|
||||
typeof stats.statusMessage === 'string' &&
|
||||
stats.statusMessage.trim()
|
||||
) {
|
||||
return `${source} · ${translateKnown(stats.statusMessage.trim())}`;
|
||||
return `${source} · ${translateStatusMessage(stats.statusMessage.trim())}`;
|
||||
}
|
||||
const ago = stats.lastUpdate ? this._timeAgo(stats.lastUpdate) : t('never');
|
||||
if (stats.loading) {
|
||||
|
||||
@@ -431,3 +431,57 @@ test('without the Utilities list, Directions stays in Data Layers under Utilitie
|
||||
restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('a layer with no feed in view says why instead of "never"', async () => {
|
||||
const { LayerPanel, presentLayerCount, presentLayerToggle } =
|
||||
await import('./layerPanel.js');
|
||||
const { setLocale } = await import('../i18n/index.js');
|
||||
const panel = LayerPanel.prototype;
|
||||
const rows = [
|
||||
{
|
||||
id: 'transit',
|
||||
name: 'Transit',
|
||||
source: 'GTFS-RT',
|
||||
enabled: true,
|
||||
stats: {
|
||||
count: 0,
|
||||
lastUpdate: null,
|
||||
source: 'GTFS-RT',
|
||||
status: 'zoom-in',
|
||||
statusMessage: 'No feed here yet · 16 regions available',
|
||||
},
|
||||
meta: 'GTFS-RT · No feed here yet · 16 regions available',
|
||||
},
|
||||
{
|
||||
id: 'bikeshare',
|
||||
name: 'Bikeshare',
|
||||
source: 'GBFS',
|
||||
enabled: true,
|
||||
stats: {
|
||||
count: 0,
|
||||
lastUpdate: null,
|
||||
loading: false,
|
||||
status: 'zoom-in',
|
||||
statusMessage: 'Fly below 48 km to a covered city',
|
||||
},
|
||||
meta: 'GBFS · Fly below 48 km to a covered city',
|
||||
},
|
||||
];
|
||||
for (const layer of rows) {
|
||||
// Guidance is normal operation: the layer is on and nothing has failed.
|
||||
assert.equal(presentLayerToggle(layer).text, 'ON');
|
||||
assert.equal(presentLayerCount(layer.stats).empty, true);
|
||||
assert.equal(panel._buildMetaText(layer), layer.meta);
|
||||
}
|
||||
|
||||
setLocale('ru');
|
||||
try {
|
||||
for (const layer of rows) {
|
||||
const meta = panel._buildMetaText(layer);
|
||||
assert.doesNotMatch(meta, /never|Fly below|No feed|covered/, meta);
|
||||
assert.match(meta, /^(GTFS-RT|GBFS) · /, meta);
|
||||
}
|
||||
} finally {
|
||||
setLocale('en');
|
||||
}
|
||||
});
|
||||
@@ -265,3 +265,66 @@ export function translateStatusLine(text) {
|
||||
.map(translateStatusPiece)
|
||||
.join(STATUS_SEPARATOR);
|
||||
}
|
||||
|
||||
/** Thousands separators out of an English number ("3,000" → 3000). */
|
||||
const englishNumber = (text) => Number(text.replace(/,/g, ''));
|
||||
|
||||
// Coverage notes of a layer whose view has no feed, whole lines with a number
|
||||
// in them: transit (transit/queries.js) and bikeshare (bikeshare/controls.js).
|
||||
// Their " · " is part of one sentence, so they are matched before the line is
|
||||
// split into pieces. Keep these in step with the producers.
|
||||
const COVERAGE_NOTE_PATTERNS = [
|
||||
[
|
||||
/^Fly below ([\d,]+) km to a covered region$/,
|
||||
([, km]) =>
|
||||
t('Fly below {km} km to a covered region', {
|
||||
km: formatNumber(englishNumber(km)),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^No feed here yet · ([\d,]+) regions available$/,
|
||||
([, regions]) => {
|
||||
const count = englishNumber(regions);
|
||||
return tn(
|
||||
count,
|
||||
'No feed here yet · {n} region available',
|
||||
'No feed here yet · {n} regions available',
|
||||
{ n: formatNumber(count) },
|
||||
);
|
||||
},
|
||||
],
|
||||
[
|
||||
/^Fly below ([\d,]+) km to a covered city$/,
|
||||
([, km]) =>
|
||||
t('Fly below {km} km to a covered city', {
|
||||
km: formatNumber(englishNumber(km)),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^No bike share here yet · ([\d,]+) systems available$/,
|
||||
([, systems]) => {
|
||||
const count = englishNumber(systems);
|
||||
return tn(
|
||||
count,
|
||||
'No bike share here yet · {n} system available',
|
||||
'No bike share here yet · {n} systems available',
|
||||
{ n: formatNumber(count) },
|
||||
);
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* A layer's status message in the UI language: its catalog entry, a coverage
|
||||
* note by its shape, or a status line translated piece by piece.
|
||||
*/
|
||||
export function translateStatusMessage(text) {
|
||||
if (typeof text !== 'string') return text;
|
||||
const known = translateKnown(text);
|
||||
if (known !== text) return known;
|
||||
for (const [pattern, format] of COVERAGE_NOTE_PATTERNS) {
|
||||
const match = pattern.exec(text);
|
||||
if (match) return format(match);
|
||||
}
|
||||
return translateStatusLine(text);
|
||||
}
|
||||
@@ -3,7 +3,11 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { setLocale, t } from '../i18n/index.js';
|
||||
import { translateFeedError, translateStatusLine } from './statusText.js';
|
||||
import {
|
||||
translateFeedError,
|
||||
translateStatusLine,
|
||||
translateStatusMessage,
|
||||
} from './statusText.js';
|
||||
|
||||
function inLocale(locale, run) {
|
||||
setLocale(locale);
|
||||
@@ -75,3 +79,55 @@ for (const locale of ['es', 'ru']) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// A layer's coverage note when no feed covers the view: one sentence with a
|
||||
// " · " in it (transit/queries.js, bikeshare/controls.js).
|
||||
const COVERAGE_NOTES = [
|
||||
'Fly below 3,000 km to a covered region',
|
||||
'No feed here yet · 16 regions available',
|
||||
'Fly below 48 km to a covered city',
|
||||
'No bike share here yet · 61 systems available',
|
||||
];
|
||||
|
||||
test('en: coverage notes show as they came', () => {
|
||||
setLocale('en');
|
||||
for (const text of COVERAGE_NOTES)
|
||||
assert.equal(translateStatusMessage(text), text);
|
||||
assert.equal(
|
||||
translateStatusMessage('No bike share here yet · 1 systems available'),
|
||||
'No bike share here yet · 1 system available',
|
||||
);
|
||||
});
|
||||
|
||||
for (const locale of ['es', 'ru', 'ja']) {
|
||||
test(`${locale}: a coverage note translates whole, numbers kept`, () => {
|
||||
inLocale(locale, () => {
|
||||
for (const text of COVERAGE_NOTES) {
|
||||
const shown = translateStatusMessage(text);
|
||||
assert.doesNotMatch(
|
||||
shown,
|
||||
/\b(Fly|below|covered|feed|bike share|available)\b/,
|
||||
shown,
|
||||
);
|
||||
const number = /[\d,]+(?= km| regions| systems)/.exec(text)[0];
|
||||
assert.ok(
|
||||
shown.replace(/[^\d]/g, '').includes(number.replace(/,/g, '')),
|
||||
shown,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test(`${locale}: a status message without a coverage note keeps its other forms`, () => {
|
||||
inLocale(locale, () => {
|
||||
assert.equal(
|
||||
translateStatusMessage('Upstream response too large'),
|
||||
t('Upstream response too large'),
|
||||
);
|
||||
assert.equal(
|
||||
translateStatusMessage('2 feeds live · 14 heard'),
|
||||
translateStatusLine('2 feeds live · 14 heard'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user