Split the News panel into Conflicts and Local

Conflicts is the hotspots' significant news, on the map whenever the layer is
on. Local lists every report within 500 km of the view centre below 3,000 km,
and the map shows those instead while it is chosen. The section replaces the
"Include minor news" and "Show event cards" toggles: picture cards are always
on, and Local is what reads minor news. The Conflicts feed reads the same
whichever section is shown.
This commit is contained in:
Denis Groshev committed 2026-11-06 00:45:30 +01:00
1 parent 4817d2a648
commit f72f79f48b
20 files changed
+280 -189

No files matched your search

+55 -32
View File
@@ -22,6 +22,7 @@ import {
NEWS_FEED_PAGE,
NEWS_FOCUS_HEIGHT_M,
NEWS_IN_VIEW_MAX_HEIGHT_M,
NEWS_LOCAL_LIMIT,
NEWS_LAYER_ID,
NEWS_MAP_LIMIT,
NEWS_OVERLAY_SOURCE_ID,
@@ -47,6 +48,7 @@ import {
mergeFeedPage,
newsWindowChoices,
newsWindowMs,
localFilters,
normalizeFilters,
passesFilters,
reportMarkerPosition,
@@ -85,8 +87,9 @@ const emptyFeed = () => ({
loading: false,
error: null,
});
// Local: `active` while the camera is low enough to have a "near here";
// `minor` holds the day's reports with minor news included, read once while
// that filter is on; otherwise In view uses the map's own reports.
// the Local section is chosen.
const emptyInView = () => ({
active: false,
cell: null,
@@ -167,7 +170,26 @@ export function createNewsLayer({
inView.minor?.find((r) => r.id === id) ||
null;
const selected = () => (selectedId ? findReport(selectedId) : null);
const onMap = (report) => visibleOnMap(report, filters, now(), windowMs);
const local = () => filters.section === 'local';
// Local takes the map over only while there is a "near here" to show.
const localMode = () => local() && inView.active;
const onMap = (report) =>
visibleOnMap(
report,
localMode() ? localFilters(filters) : filters,
now(),
windowMs,
);
// The Local section's reports near the view centre, every severity.
const localReports = (limit) =>
reportsInView(
inView.minor || [],
inView.centre,
localFilters(filters),
now(),
limit,
windowMs,
);
const shownWindowMs = () =>
Math.min(maxWindowMs, (filters.hours ?? Infinity) * 3_600_000);
// The hours to ask the hotspot counts for, when shorter than the server's.
@@ -450,17 +472,14 @@ export function createNewsLayer({
}
}
// The big events stand as picture cards over their marker, unless the
// reader has turned them off; never two on top of each other. The clicked
// event shows its picture card either way, under its marker, with its text
// card above.
// The big events stand as picture cards over their marker, never two on
// top of each other. The clicked event shows its picture card under its
// marker, with its text card above.
function pictureCards(drawn, current, labels) {
const cardable = filters.cards
? cardEvents(
drawn.filter((r) => r.id !== selectedId && onMap(r)),
now(),
)
: [];
const cardable = cardEvents(
drawn.filter((r) => r.id !== selectedId && onMap(r)),
now(),
);
const pictured =
current?.pins.length &&
current.event?.size >= NEWS_CARD_MIN_SOURCES &&
@@ -582,9 +601,12 @@ export function createNewsLayer({
// A report picked in the feed or In view still gets its marker.
const current = selected();
const elsewhere = catchAllIds();
const shown = detail
? mapReports
: mapReports.filter((r) => elsewhere.has(r.hotspotId));
// Local: what is near the view centre instead of the hotspots' news.
const shown = localMode()
? localReports(NEWS_MAP_LIMIT)
: detail
? mapReports
: mapReports.filter((r) => elsewhere.has(r.hotspotId));
const drawn =
current && !shown.some((r) => r.id === current.id)
? [...shown, current]
@@ -888,6 +910,7 @@ export function createNewsLayer({
inViewRequest?.abort();
inViewRequest = null;
inView = emptyInView();
if (local()) render();
notify();
}
return;
@@ -897,7 +920,7 @@ export function createNewsLayer({
const cell = viewCell(centre);
if (!force && inView.active && cell === inView.cell) return;
inView = { ...inView, active: true, cell, centre };
if (!filters.includeMinor) {
if (!local()) {
inViewRequest?.abort();
inViewRequest = null;
inView = { ...inView, minor: null, loading: false, error: null };
@@ -905,6 +928,7 @@ export function createNewsLayer({
return;
}
if (!force && (inView.minor || inViewRequest)) {
render();
notify();
return;
}
@@ -942,7 +966,10 @@ export function createNewsLayer({
error: cause?.message || FEED_UNAVAILABLE,
};
} finally {
if (inViewRequest === controller) inViewRequest = null;
if (inViewRequest === controller) {
inViewRequest = null;
render();
}
notify();
}
}
@@ -1036,20 +1063,14 @@ export function createNewsLayer({
active: inView.active,
loading: inView.loading,
error: inView.error ? t(FEED_UNAVAILABLE) : null,
items: reportsInView(
filters.includeMinor ? inView.minor || [] : mapReports,
inView.centre,
filters,
at,
undefined,
windowMs,
).map((r) => feedCardView(r, at)),
items: localReports(NEWS_LOCAL_LIMIT).map((r) => feedCardView(r, at)),
},
selected:
report && withinNewsWindow(report, at, windowMs)
? feedCardView(report, at)
: null,
hasMore: Boolean(feed.nextBefore),
// Older pages are the Conflicts feed's; Local has none to scroll to.
hasMore: !local() && Boolean(feed.nextBefore),
loading: feed.loading || loading,
// Read failures are English data; the panel shows them translated.
error: error || feed.error ? t(error || feed.error) : null,
@@ -1211,11 +1232,11 @@ export function createNewsLayer({
}
if (params.filters && typeof params.filters === 'object') {
const next = normalizeFilters(params.filters, hotspots, filters);
// The severity floor and the cards change what is shown, not what is read.
const readKey = ({ hotspot, category, includeMinor }) =>
`${hotspot}|${category}|${includeMinor}`;
// The severity floor and the section change what is shown, not what
// the Conflicts feed reads.
const readKey = ({ hotspot, category }) => `${hotspot}|${category}`;
const reread = readKey(next) !== readKey(filters);
const minorChanged = next.includeMinor !== filters.includeMinor;
const sectionChanged = next.section !== filters.section;
filters = next;
const previousWindowMs = windowMs;
windowMs = shownWindowMs();
@@ -1230,7 +1251,7 @@ export function createNewsLayer({
if (reread) feed = emptyFeed();
render();
if (reread) void loadFeed('replace');
if (minorChanged) void refreshInView({ force: true });
if (sectionChanged) void refreshInView({ force: true });
// The hotspot counts are the server's, so a new window reads them again.
if (windowMs !== previousWindowMs) void layer.update(viewer);
notify();
@@ -1266,7 +1287,9 @@ export function createNewsLayer({
},
getStats() {
return {
count: mapReports.filter((r) => r.pins.length && onMap(r)).length,
count: (localMode() ? localReports(NEWS_MAP_LIMIT) : mapReports).filter(
(r) => r.pins.length && onMap(r),
).length,
lastUpdate,
loading,
error,
+65 -67
View File
@@ -96,7 +96,13 @@ function fixture(
const viewer = {
camera,
scene: { requestRender() {}, preRender: new Cesium.Event() },
dataSources: { add() {}, remove() {} },
added: [],
dataSources: {
add(source) {
viewer.added.push(source);
},
remove() {},
},
};
const layer = createNewsLayer({
source,
@@ -164,7 +170,7 @@ test('choosing a card selects it and flies straight down from 150 km; reduced mo
assert.equal(layer.getRowControls().feed.selected, null);
});
test('the card toggle and the severity floor change what is shown, not what is read', async (t) => {
test('the severity floor changes what is shown, not what is read', async (t) => {
const { layer, entries, calls } = fixture(t, { height: 500_000 });
layer.enable();
await layer.update();
@@ -174,105 +180,97 @@ test('the card toggle and the severity floor change what is shown, not what is r
assert.deepEqual(cards(), []);
await settle();
const reads = calls.feed.length;
layer.setParams({ filters: { cards: false, minSeverity: 0 } });
layer.setParams({ filters: { minSeverity: 0 } });
assert.equal(calls.feed.length, reads);
assert.equal(layer.getRowControls().feed.filters.cards, false);
assert.deepEqual(
layer.getRowControls().feed.items.map((item) => item.id),
['major', 'minor', 'far'],
);
});
test('In view places the held reports when the camera settles low, with no new read', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
let centre = { lat: 49, lon: 36 };
const { layer, camera, calls } = fixture(t, {
height: 1_000_000,
centre: () => centre,
});
layer.enable();
await layer.update();
const reads = calls.feed.length;
const view = layer.getRowControls().feed.inView;
assert.equal(view.active, true);
assert.equal(view.loading, false);
// Gaza is beyond 500 km of the view centre; the old report is past 24 h.
assert.deepEqual(
view.items.map((item) => item.id),
['major'],
);
// Panning to another cell (over Gaza) reads nothing: it reuses the map's
// reports, once the camera has settled.
centre = { lat: 31.5, lon: 34.4 };
camera.moveEnd.raiseEvent();
t.mock.timers.tick(799);
assert.deepEqual(
layer.getRowControls().feed.inView.items.map((item) => item.id),
['major'],
);
t.mock.timers.tick(1);
await Promise.resolve();
assert.deepEqual(
layer.getRowControls().feed.inView.items.map((item) => item.id),
['far'],
);
assert.equal(calls.feed.length, reads);
// Up above 3,000 km, In view goes away.
camera.positionCartographic.height = 5_000_000;
camera.moveEnd.raiseEvent();
t.mock.timers.tick(800);
assert.equal(layer.getRowControls().feed.inView.active, false);
});
test('In view with minor news reads once, not per pan; a failed read shows', async (t) => {
test('Local reads every report once, lists those near the view and takes the map over', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
let centre = { lat: 49, lon: 36 };
let fail = false;
const minorReads = [];
const { layer, camera } = fixture(t, {
const localReads = [];
const { layer, camera, viewer } = fixture(t, {
height: 1_000_000,
centre: () => centre,
source: {
getFeed: async (query) => {
if (query.relevance === '' && query.limit === 500) {
minorReads.push(query);
localReads.push(query);
if (fail) throw new Error('boom');
return {
reports: [report('broad', { severity: 2, relevance: 'minor' })],
reports: [
report('broad', { severity: 1, relevance: 'minor' }),
report('south', {
severity: 2,
pins: [{ lat: 31.5, lon: 34.4, place: 'Gaza', mappable: true }],
}),
],
nextBefore: null,
};
}
return { reports: [], nextBefore: null };
return {
reports: [report('major', { severity: 3 })],
nextBefore: null,
};
},
},
});
const markers = () =>
// The layer adds its outlines' source first, then its markers'.
viewer.added[1].entities.values
.map((entity) => String(entity.id))
.filter((id) => /~\d+$/.test(id))
.map((id) => id.replace(/^.*:/, '').replace(/~\d+$/, ''));
layer.enable();
await layer.update();
camera.moveEnd.raiseEvent();
t.mock.timers.tick(800);
await Promise.resolve();
assert.equal(minorReads.length, 0);
layer.setParams({ filters: { includeMinor: true } });
for (let i = 0; i < 4; i++) await Promise.resolve();
assert.equal(minorReads.length, 1);
// Conflicts: no read of minor news, the hotspots' news on the map.
assert.equal(localReads.length, 0);
assert.equal(layer.getRowControls().feed.inView.active, true);
assert.deepEqual(markers(), ['major']);
layer.setParams({ filters: { section: 'local' } });
for (let i = 0; i < 4; i++) await Promise.resolve();
assert.equal(localReads.length, 1);
let view = layer.getRowControls().feed;
// Every severity near the centre; Gaza is beyond 500 km; no older pages.
assert.deepEqual(
layer.getRowControls().feed.inView.items.map((item) => item.id),
view.inView.items.map((item) => item.id),
['broad'],
);
centre = { lat: 47, lon: 33 };
assert.equal(view.hasMore, false);
assert.deepEqual(markers(), ['broad']);
// A pan reads nothing more and follows the camera once it settles.
centre = { lat: 31.5, lon: 34.4 };
camera.moveEnd.raiseEvent();
t.mock.timers.tick(800);
await Promise.resolve();
assert.equal(minorReads.length, 1);
// Turned off and on again with the server failing: the error is shown.
layer.setParams({ filters: { includeMinor: false } });
assert.equal(localReads.length, 1);
assert.deepEqual(
layer.getRowControls().feed.inView.items.map((item) => item.id),
['south'],
);
assert.deepEqual(markers(), ['south']);
// Up above 3,000 km there is no "near here": the map shows conflicts again.
camera.positionCartographic.height = 5_000_000;
camera.moveEnd.raiseEvent();
t.mock.timers.tick(800);
view = layer.getRowControls().feed;
assert.equal(view.inView.active, false);
assert.ok(!markers().includes('south'));
// Back to Conflicts and to Local again with the server failing: it shows.
camera.positionCartographic.height = 1_000_000;
layer.setParams({ filters: { section: 'conflicts' } });
fail = true;
layer.setParams({ filters: { includeMinor: true } });
layer.setParams({ filters: { section: 'local' } });
for (let i = 0; i < 4; i++) await Promise.resolve();
assert.equal(minorReads.length, 2);
const view = layer.getRowControls().feed.inView;
assert.equal(view.error, 'News feed unavailable');
assert.deepEqual(view.items, []);
assert.equal(localReads.length, 2);
view = layer.getRowControls().feed;
assert.equal(view.inView.error, 'News feed unavailable');
assert.deepEqual(view.inView.items, []);
});
test('a shorter window narrows the feed and reads the hotspot counts for it', async (t) => {
+23 -5
View File
@@ -46,6 +46,14 @@ export const NEWS_DETAIL_MAX_HEIGHT_M = 2_500_000;
export const NEWS_IN_VIEW_MAX_HEIGHT_M = 3_000_000;
export const NEWS_IN_VIEW_RADIUS_KM = 500;
export const NEWS_IN_VIEW_LIMIT = 12;
/** The Local section lists at most this many reports near the view centre. */
export const NEWS_LOCAL_LIMIT = 40;
/**
* The News panel's sections: Conflicts (the hotspots' significant news, on the
* map whenever the layer is on) and Local (everything near the view centre,
* on the map while the section is chosen).
*/
export const NEWS_SECTIONS = Object.freeze(['conflicts', 'local']);
export const NEWS_SETTLE_MS = 800;
export const NEWS_CELL_DEG = 0.5;
/** A feed card's click flies the camera to this height over the event. */
@@ -625,9 +633,9 @@ export function normalizeFilters(next = {}, hotspots = [], previous = {}) {
hotspot,
category,
minSeverity,
includeMinor: merged.includeMinor === true,
// Event cards on the map; off leaves only the clicked event's card.
cards: merged.cards !== false,
section: NEWS_SECTIONS.includes(merged.section)
? merged.section
: 'conflicts',
// A shorter window than the server's; null shows all it serves.
hours: NEWS_WINDOW_CHOICES.includes(merged.hours) ? merged.hours : null,
};
@@ -661,12 +669,22 @@ export function visibleOnMap(
);
}
/** API query for the feed under the current filters: the window only. */
/**
* The filters Local applies: every hotspot and every severity, near the view
* centre; the category and the window still hold.
*/
export const localFilters = (filters) => ({
...filters,
hotspot: 'all',
minSeverity: 0,
});
/** API query for the Conflicts feed under the current filters: the window only. */
export function feedQueryFor(filters, extra = {}) {
return {
events: true,
today: true,
relevance: filters.includeMinor ? '' : NEWS_RELEVANT,
relevance: NEWS_RELEVANT,
hotspot: filters.hotspot,
category: filters.category === 'all' ? '' : filters.category,
limit: NEWS_FEED_PAGE,
+13 -7
View File
@@ -286,11 +286,17 @@ test('filters default to significant news and map to a last-24-hours query', ()
hotspot: 'ua',
category: 'all',
minSeverity: 2,
includeMinor: false,
cards: true,
section: 'conflicts',
hours: null,
});
assert.equal(normalizeFilters({ cards: false }, hotspots).cards, false);
assert.equal(
normalizeFilters({ section: 'local' }, hotspots).section,
'local',
);
assert.equal(
normalizeFilters({ section: 'nope' }, hotspots).section,
'conflicts',
);
assert.equal(normalizeFilters({ hours: 6 }, hotspots).hours, 6);
assert.equal(normalizeFilters({ hours: 5 }, hotspots).hours, null);
assert.equal(normalizeFilters({ minSeverity: 0 }, hotspots).minSeverity, 0);
@@ -301,10 +307,10 @@ test('filters default to significant news and map to a last-24-hours query', ()
),
'hotspot=ua&before=2026-10-28T08%3A00%3A00.000Z&limit=60&relevance=core%2Crelated&today=1&events=1',
);
// "Include minor news" drops the relevance filter.
assert.doesNotMatch(
newsFeedQuery(feedQueryFor({ ...filters, includeMinor: true })),
/relevance/,
// The Conflicts feed reads the same whichever section is chosen.
assert.equal(
newsFeedQuery(feedQueryFor({ ...filters, section: 'local' })),
newsFeedQuery(feedQueryFor(filters)),
);
});