Merge branch 'main' into perf/imagery-stale-thumbnail-cancellation-20260929

This commit is contained in:
German Khokhlov authored and GitHub committed 2026-11-18 17:25:46 +04:00
commit 5ed27a9131
9 files changed
+195 -102

No files matched your search

@@ -0,0 +1,3 @@
- Return the Mapped Installations status (site counts, Overpass retries) to the
voice analyst in English; the Layers panel, the nearby-search toast and the
awareness panel translate it where they show it (daikaginza, #1210).
+4 -2
View File
@@ -1128,7 +1128,8 @@
"src/i18n/locales/uk.json",
"src/i18n/locales/zh-CN.json",
"src/i18n/locales/zh-Hant.json",
"src/ui/layerNames.js"
"src/ui/layerNames.js",
"src/ui/statusText.js"
],
"external": []
},
@@ -3108,7 +3109,8 @@
"src/loadingFeedback.js",
"src/data/installationFeedback.js",
"src/ui/layerNames.js",
"src/render/cesium/zoomOutGuard.js"
"src/render/cesium/zoomOutGuard.js",
"src/ui/statusText.js"
],
"external": ["cesium", "kdbush"]
},
+3 -2
View File
@@ -1,6 +1,7 @@
import { msg } from '../i18n/marker.js';
// layers/installations/controls.js translates describeInstallationFeedback().
// installationFeedback() stays English for the analyst. ui/statusText.js and
// ui/shellFeedback.js (HUD) translate it: keep both in step with this wording.
const REASONS = Object.freeze({
rate_limited: msg('Overpass rate-limited'),
timeout: msg('Overpass timed out'),
@@ -19,7 +20,7 @@ const FALLBACK_REASON = msg('Overpass temporarily unavailable');
* @param {number} [now]
* @returns {{text: string, reason?: string, seconds?: number}|{count: number, km: ?number}}
*/
export function describeInstallationFeedback(stats = {}, now = Date.now()) {
function describeInstallationFeedback(stats = {}, now = Date.now()) {
const reason = REASONS[stats.failureReason] || FALLBACK_REASON;
if (stats.loading)
return {
+3 -7
View File
@@ -2,13 +2,9 @@ import {
formatAwarenessLabel,
AWARENESS_RADIUS_M,
} from '../../data/militaryAwarenessEngine.js';
import {
formatNumber,
onLocaleChange,
t,
translateKnown,
} from '../../i18n/index.js';
import { formatNumber, onLocaleChange, t } from '../../i18n/index.js';
import { sourceStatusLabel } from '../../ui/layerNames.js';
import { translateStatusMessage } from '../../ui/statusText.js';
import { formatQuantity } from '../../ui/unitLabels.js';
import { AWARENESS_PAGE_SIZE, AWARENESS_PAGE_ROTATE_MS } from './policy.js';
import { distanceParts } from '../../data/distanceFormat.js';
@@ -45,7 +41,7 @@ export function presentAwarenessDistance(meters) {
function presentAwarenessReason(summary = {}) {
return summary.reasonTemplate
? t(summary.reasonTemplate, summary.reasonValues)
: translateKnown(summary.reason || '');
: translateStatusMessage(summary.reason || '');
}
/**
+8 -35
View File
@@ -1,41 +1,15 @@
import { describeInstallationFeedback } from '../../data/installationFeedback.js';
import { installationFeedback } from '../../data/installationFeedback.js';
import {
LAYER_ID,
DISTANCE_PREFILTER_MARGIN_M,
ANCHOR_REFRESH_M,
} from './policy.js';
import { formatNumber, t, tn } from '../../i18n/index.js';
import { t } from '../../i18n/index.js';
import { fromDegrees, toCartographicRadians } from '../../geo/ellipsoid.js';
import { surfaceDistance } from '../../geo/geodesic.js';
import { toDegrees, toRadians } from '../../geo/vector.js';
import { cameraOf } from '../../render/rendererOf.js';
// installationFeedback.js is shared with the HUD (src/loadingFeedback.js) and
// hands back msg()-marked English plus values; getStats translates them here.
function localizeInstallationFeedback(feedback) {
if (feedback.text !== undefined) {
const values = {};
if (feedback.reason !== undefined) values.reason = t(feedback.reason);
if (feedback.seconds !== undefined) values.seconds = feedback.seconds;
return t(feedback.text, values);
}
const { count, km } = feedback;
if (km) {
const kmText = formatNumber(km);
return count === 0
? t('No mapped sites within {km} km of the contact', { km: kmText })
: tn(
count,
'{count} mapped site within {km} km of the contact',
'{count} mapped sites within {km} km of the contact',
{ km: kmText },
);
}
return count === 0
? t('No mapped sites in view')
: tn(count, '{count} mapped site in view', '{count} mapped sites in view');
}
export function createControls({ state: layerState, services, parts, source }) {
const methods = {
id: LAYER_ID,
@@ -285,13 +259,12 @@ export function createControls({ state: layerState, services, parts, source }) {
retryAt: layerState.retryAt,
retrying: layerState.loading && Boolean(layerState.failureReason),
failureReason: layerState.failureReason,
statusMessage: localizeInstallationFeedback(
describeInstallationFeedback({
...layerState,
count: layerState.lastUpdate ? mappedCount : undefined,
retrying: layerState.loading && Boolean(layerState.failureReason),
}),
),
// English: the analyst reads it as is; displays translate it.
statusMessage: installationFeedback({
...layerState,
count: layerState.lastUpdate ? mappedCount : undefined,
retrying: layerState.loading && Boolean(layerState.failureReason),
}),
loadingLabel: layerState.loading
? t('loading mapped installation context')
: '',
@@ -1,6 +1,8 @@
// statusMessage stays English (the analyst's empty note); displays translate it.
import test from 'node:test';
import assert from 'node:assert/strict';
import { setLocale, translateKnown } from '../../i18n/index.js';
import { setLocale, t, tn } from '../../i18n/index.js';
import { translateStatusMessage } from '../../ui/statusText.js';
import { createControls } from './controls.js';
function stats(state) {
@@ -13,67 +15,113 @@ function stats(state) {
}).methods.getStats();
}
for (const locale of ['es', 'ru']) {
test(`${locale}: installation feedback is in the UI language`, () => {
setLocale(locale);
const empty = stats({ status: 'empty', lastUpdate: 1 }).statusMessage;
assert.notEqual(empty, 'No mapped sites in view');
const found = stats({
function inLocale(locale, run) {
setLocale(locale);
try {
run();
} finally {
setLocale('en');
}
}
// A retry a minute out reads "60s" (rounded up).
const cases = [
[
{ status: 'empty', lastUpdate: 1 },
'No mapped sites in view',
() => t('No mapped sites in view'),
],
[
{ status: 'ready', lastUpdate: 1, records: [{ kind: 'installation' }] },
'1 mapped site in view',
() => tn(1, '{count} mapped site in view', '{count} mapped sites in view'),
],
[
{
status: 'ready',
lastUpdate: 1,
records: [{ kind: 'installation' }, { kind: 'installation' }],
}).statusMessage;
assert.notEqual(found, '2 mapped sites in view');
const tiles = stats({
status: 'unavailable',
failureReason: 'tiles_unavailable',
}).statusMessage;
assert.notEqual(tiles, 'Map tiles temporarily unavailable');
const retry = stats({
},
'2 mapped sites in view',
() => tn(2, '{count} mapped site in view', '{count} mapped sites in view'),
],
[
{
status: 'empty',
lastUpdate: 1,
wide: true,
coverage: { kind: 'subject', radiusM: 25000 },
},
'No mapped sites within 25 km of the contact',
() => t('No mapped sites within {km} km of the contact', { km: '25' }),
],
[
{
status: 'ready',
lastUpdate: 1,
wide: true,
coverage: { kind: 'subject', radiusM: 25000 },
records: [{ kind: 'installation' }],
},
'1 mapped site within 25 km of the contact',
() =>
tn(
1,
'{count} mapped site within {km} km of the contact',
'{count} mapped sites within {km} km of the contact',
{ km: '25' },
),
],
[
{ status: 'unavailable', failureReason: 'tiles_unavailable' },
'Map tiles temporarily unavailable',
() => t('Map tiles temporarily unavailable'),
],
[
{
status: 'unavailable',
failureReason: 'names_unavailable',
retryAt: Date.now() + 5000,
}).statusMessage;
assert.doesNotMatch(retry, /^Mapped names temporarily unavailable/);
for (const text of [
'Too many mapped sites in view to list them all',
'Installation context unavailable',
]) {
assert.notEqual(translateKnown(text), text);
}
get retryAt() {
return Date.now() + 60_000;
},
},
'Mapped names temporarily unavailable — retrying in 60s',
() =>
t('{reason} — retrying in {seconds}s', {
reason: t('Mapped names temporarily unavailable'),
seconds: 60,
}),
],
[
{ status: 'zoom-in' },
'Zoom in to search mapped installations',
() => t('Zoom in to search mapped installations'),
],
];
for (const locale of ['es', 'ru']) {
test(`${locale}: installation statusMessage stays English data`, () => {
inLocale(locale, () => {
for (const [state, english] of cases)
assert.equal(stats(state).statusMessage, english);
});
});
test(`${locale}: installation statusMessage is shown in the UI language`, () => {
inLocale(locale, () => {
for (const [state, english, shown] of cases) {
const shownText = translateStatusMessage(stats(state).statusMessage);
assert.notEqual(shownText, english);
assert.equal(shownText, shown());
}
});
});
}
test('en: installation feedback keeps its English wording', () => {
setLocale('en');
assert.equal(
stats({ status: 'empty', lastUpdate: 1 }).statusMessage,
'No mapped sites in view',
);
assert.equal(
stats({
status: 'ready',
lastUpdate: 1,
records: [{ kind: 'installation' }],
}).statusMessage,
'1 mapped site in view',
);
assert.equal(
stats({
status: 'ready',
lastUpdate: 1,
wide: true,
coverage: { kind: 'subject', radiusM: 25000 },
records: [{ kind: 'installation' }, { kind: 'installation' }],
}).statusMessage,
'2 mapped sites within 25 km of the contact',
);
assert.equal(
stats({
status: 'unavailable',
failureReason: 'names_unavailable',
retryAt: Date.now() + 5000,
}).statusMessage,
'Mapped names temporarily unavailable — retrying in 5s',
);
for (const [state, english] of cases) {
assert.equal(stats(state).statusMessage, english);
assert.equal(translateStatusMessage(english), english);
}
});
+2 -1
View File
@@ -1,5 +1,6 @@
import { t } from '../i18n/index.js';
import { spaceMissionsIndexFailure } from './contextActions.js';
import { translateStatusMessage } from './statusText.js';
import { shouldExpandGlobalContextPanel } from '../rightRailPolicy.js';
export function _initGlobalContextPanel() {
@@ -112,7 +113,7 @@ export function _initGlobalContextPanel() {
if (this.destroyed || searched === false) return false;
const stats = this.installations.getStats?.();
this.showToast(
stats?.statusMessage ||
(stats?.statusMessage && translateStatusMessage(stats.statusMessage)) ||
(stats?.status === 'zoom-in'
? t('Zoom in to search mapped installations')
: t('Nearby installations refreshed')),
+49 -1
View File
@@ -242,9 +242,57 @@ const STATUS_PIECE_PATTERNS = [
],
];
// Shapes of installationFeedback() (data/installationFeedback.js), which stays
// English for the analyst. Keep them in step with its wording.
const MAPPED_SITE_PATTERNS = [
[
/^(.+) — retrying in (\d+)s$/,
([, reason, seconds]) =>
t('{reason} — retrying in {seconds}s', {
reason: translateKnown(reason),
seconds,
}),
],
[
/^(.+) — retry pending$/,
([, reason]) =>
t('{reason} — retry pending', { reason: translateKnown(reason) }),
],
[/^No mapped sites in view$/, () => t('No mapped sites in view')],
[
/^(\d+) mapped sites? in view$/,
([, count]) =>
tn(
Number(count),
'{count} mapped site in view',
'{count} mapped sites in view',
),
],
[
/^No mapped sites within (\d+) km of the contact$/,
([, km]) =>
t('No mapped sites within {km} km of the contact', {
km: formatNumber(Number(km)),
}),
],
[
/^(\d+) mapped sites? within (\d+) km of the contact$/,
([, count, km]) =>
tn(
Number(count),
'{count} mapped site within {km} km of the contact',
'{count} mapped sites within {km} km of the contact',
{ km: formatNumber(Number(km)) },
),
],
];
// First match wins.
const STATUS_SHAPES = [...STATUS_PIECE_PATTERNS, ...MAPPED_SITE_PATTERNS];
/** A status piece by its shape in the UI language, or null. */
function statusPatternText(piece) {
for (const [pattern, format] of STATUS_PIECE_PATTERNS) {
for (const [pattern, format] of STATUS_SHAPES) {
const match = pattern.exec(piece);
if (match) return format(match);
}
+21
View File
@@ -74,6 +74,14 @@ const transitCoverage = [
'transit: No feed here yet · 12 regions available',
];
// Mapped Installations' statusMessage (data/installationFeedback.js).
const installationNotes = [
'military-installations: No mapped sites in view',
'military-installations: No mapped sites within 25 km of the contact',
'military-installations: Overpass timed out — retrying in 30s',
'military-installations: Zoom in to search mapped installations',
];
for (const locale of ['es', 'ru']) {
for (const [layerKey, caveat] of cases) {
test(`${locale}: analyst note "${caveat}" is translated`, () => {
@@ -85,6 +93,19 @@ for (const locale of ['es', 'ru']) {
});
}
test(`${locale}: Mapped Installations' empty note is translated on the analyst card`, () => {
inLocale(locale, () => {
for (const caveat of installationNotes) {
const notes = notesFor('military-installations', caveat);
assert.ok(notes.length > 0, 'the note is shown');
assert.doesNotMatch(
notes.join(' | '),
/mapped sites|retrying|Overpass timed out|Zoom in/,
);
}
});
});
test(`${locale}: Transit's empty note is translated on the analyst card`, () => {
inLocale(locale, () => {
for (const caveat of transitCoverage) {