mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(click): the card or label on top takes the click in every layer
Review fixes for #1781: - One rule for cards: the world-overlay host hands its hit test to the pick registry, and every click handler reads the topmost interactive card or label once per click (`clickCard`, `isUnderOtherCard` in src/data/pickRegistry.js), so all handlers agree in any listener order. A layer whose own card or label is on top acts on it whatever is drawn under it; a layer under another layer's card neither acts nor treats the click as empty space (a tracked aircraft stays tracked, a selection stays selected); Context names nothing under a card. A selected news card over a vessel no longer opens the link and selects the vessel. - With one rule, the per-owner arbitration options are no longer read and are removed: `passive`, `expanded` and `declinesClick` pick owners, `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds and `cardKeepsClick`. The dispatcher is unchanged from main. - A drag that ends on a quake disc, label or card does nothing; opening the USGS page or clearing the selection needs a clean click. - A click on the map under another layer's card opens no Street Level ground image. - A CCTV card that is going away is still not the scene under it. - Docs and changelog describe the new rule.
This commit is contained in:
1 parent
7312280817
commit
bb3bf9858b
87 files changed
+1398
-1775
No files matched your search
@@ -32,7 +32,12 @@ import aisLiveVesselsLayer from './aisLiveVessels.js';
|
||||
import { registerEntityContext, selectEntityContext } from './contextStore.js';
|
||||
import { WORLD_FOCUS_REQUEST_EVENT } from '../worldFocus.js';
|
||||
import { ensureGeoidReady, geoidHeight } from './geoid.js';
|
||||
import { registerPickOwner, unregisterPickOwner } from './pickRegistry.js';
|
||||
import {
|
||||
isUnderOtherCard,
|
||||
registerPickOwner,
|
||||
setClickCardHitTest,
|
||||
unregisterPickOwner,
|
||||
} from './pickRegistry.js';
|
||||
import { applyVesselOverlayPolicy } from './vesselLabels.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import { layerFeedState } from './manager.js';
|
||||
@@ -490,7 +495,7 @@ test('first accepted position ends grace and warm data survives later open silen
|
||||
const clock = makeFakeAisRuntime(7000);
|
||||
const record = makeRecord();
|
||||
_setAisRuntimeForTest(clock.runtime);
|
||||
_setVesselOverlayHostForTest({
|
||||
useVesselHost({
|
||||
setEntries() {},
|
||||
setVisible() {},
|
||||
clearSource() {},
|
||||
@@ -540,7 +545,7 @@ test('first accepted position ends grace and warm data survives later open silen
|
||||
assert.equal(feed.error, 'awaiting usable AIS positions…');
|
||||
} finally {
|
||||
_setVesselStateForTest({ enabled: false });
|
||||
_setVesselOverlayHostForTest();
|
||||
useVesselHost();
|
||||
_setAisRuntimeForTest();
|
||||
}
|
||||
});
|
||||
@@ -1643,7 +1648,7 @@ test('vessel host publication preserves the shipped grid winner and separation s
|
||||
},
|
||||
},
|
||||
});
|
||||
_setVesselOverlayHostForTest({
|
||||
useVesselHost({
|
||||
setEntries(sourceId, entries, options) {
|
||||
publications.push({ sourceId, entries, options });
|
||||
},
|
||||
@@ -1667,7 +1672,7 @@ test('vessel host publication preserves the shipped grid winner and separation s
|
||||
} finally {
|
||||
unbind();
|
||||
_setVesselStateForTest({ enabled: false });
|
||||
_setVesselOverlayHostForTest();
|
||||
useVesselHost();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1694,7 +1699,7 @@ test('vessel real layer lifecycle publishes protected selection and leaves no st
|
||||
globalThis.window.addEventListener('gev:world-request-focus', (event) => {
|
||||
focusRequests.push(event.detail);
|
||||
});
|
||||
_setVesselOverlayHostForTest(host);
|
||||
useVesselHost(host);
|
||||
_setVesselStateForTest({
|
||||
viewer: {
|
||||
get canvas() {
|
||||
@@ -1743,7 +1748,7 @@ test('vessel real layer lifecycle publishes protected selection and leaves no st
|
||||
);
|
||||
} finally {
|
||||
_setVesselStateForTest({ enabled: false });
|
||||
_setVesselOverlayHostForTest();
|
||||
useVesselHost();
|
||||
if (hadWindow) globalThis.window = priorWindow;
|
||||
else delete globalThis.window;
|
||||
globalThis.document = priorDocument;
|
||||
@@ -1849,6 +1854,15 @@ test('vessel interaction wire: a vessel with an id and no MMSI is selected by cl
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Hand the vessel layer an overlay host, and answer the pick registry's
|
||||
* card-on-top question from the same host, as the application does.
|
||||
*/
|
||||
function useVesselHost(host) {
|
||||
_setVesselOverlayHostForTest(host);
|
||||
setClickCardHitTest(host ? (x, y) => host.hitTest(x, y) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overlay-host recorder whose hitTest answers with one card id. The real host
|
||||
* only publishes rects for `interactive` entries, so a stub returning a hit is
|
||||
@@ -1880,9 +1894,7 @@ test('vessel interaction wire: clicking a card selects and transfers, like the s
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
useVesselHost(hostWithCardHit(`vessel:${harness.record.mmsi}`));
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(
|
||||
@@ -1893,7 +1905,7 @@ test('vessel interaction wire: clicking a card selects and transfers, like the s
|
||||
assert.equal(requests[0].kind, 'vessel');
|
||||
assert.equal(requests[0].id, harness.record.mmsi);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -1908,9 +1920,7 @@ test('vessel interaction wire: clicking the selected vessel card refocuses exact
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
useVesselHost(hostWithCardHit(`vessel:${harness.record.mmsi}`));
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(
|
||||
@@ -1921,29 +1931,31 @@ test('vessel interaction wire: clicking the selected vessel card refocuses exact
|
||||
assert.equal(requests[0].id, harness.record.mmsi);
|
||||
assert.equal(harness.trail.clearCalls, 0);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('vessel interaction wire: a covered card yields while a real vessel pick still focuses', () => {
|
||||
// Another layer's card on top takes the click from the vessel card under it
|
||||
// and from a vessel icon under it alike.
|
||||
test('vessel interaction wire: a covered card and a covered vessel pick both yield', () => {
|
||||
for (const ownPick of [false, true]) {
|
||||
const harness = installWireHarness(ownPick ? { id: makeRecord().mmsi } : null);
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
useVesselHost(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`, {
|
||||
sourceId: 'earthquakes', entryId: 'quake:cover',
|
||||
}),
|
||||
);
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(requests.length, ownPick ? 1 : 0);
|
||||
assert.equal(requests.length, 0, `own pick: ${ownPick}`);
|
||||
assert.equal(aisLiveVesselsLayer.getSelectedInfo()?.mmsi, harness.record.mmsi);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
@@ -1960,7 +1972,7 @@ test('vessel interaction wire: an unknown card id preserves selection and never
|
||||
requests.push(event.detail),
|
||||
);
|
||||
// An evicted vessel's card id resolves to no live record.
|
||||
_setVesselOverlayHostForTest(hostWithCardHit('vessel:999999999'));
|
||||
useVesselHost(hostWithCardHit('vessel:999999999'));
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(
|
||||
@@ -1969,52 +1981,47 @@ test('vessel interaction wire: an unknown card id preserves selection and never
|
||||
);
|
||||
assert.equal(requests.length, 0);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('vessel interaction wire: a sibling-owned pick wins without selection mutation', () => {
|
||||
// Another layer is already acting on this click; two camera commands is the
|
||||
// worse failure, so the card is not consulted.
|
||||
test('vessel interaction wire: the vessel card on top wins over a sibling-owned pick', () => {
|
||||
// The card painted on top takes the click; the sibling (an aircraft)
|
||||
// stands aside under it, so there is one camera command, not two.
|
||||
registerPickOwner('flights', (pickedId) => pickedId === 'a1b2c3');
|
||||
const harness = installWireHarness({ id: 'a1b2c3' });
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
useVesselHost(hostWithCardHit(`vessel:${harness.record.mmsi}`));
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi,
|
||||
harness.record.mmsi,
|
||||
);
|
||||
assert.equal(requests.length, 0);
|
||||
assert.equal(requests.length, 1);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
unregisterPickOwner('flights');
|
||||
}
|
||||
});
|
||||
|
||||
// The aircraft layer runs first and starts tracking the plane under the
|
||||
// vessel's card, making it passive. The card reads the owners that acted
|
||||
// when the click resolved, so it still yields: one action.
|
||||
test('vessel interaction wire: a card yields to an aircraft that starts tracking in the same click', (t) => {
|
||||
// The aircraft layer runs first. Under the vessel's card it stands aside, so
|
||||
// the card takes the click: one action.
|
||||
test('vessel interaction wire: a card over an aircraft takes the click; the aircraft does not track', (t) => {
|
||||
let tracked = null;
|
||||
registerPickOwner('test-planes', (pickedId) => pickedId === 'plane:9', {
|
||||
expanded: true,
|
||||
passive: (pickedId) => pickedId === tracked,
|
||||
});
|
||||
registerPickOwner('test-planes', (pickedId) => pickedId === 'plane:9');
|
||||
t.after(() => unregisterPickOwner('test-planes'));
|
||||
const harness = installWireHarness(
|
||||
{ id: 'plane:9' },
|
||||
{ selectedRecord: null },
|
||||
{},
|
||||
(event) => {
|
||||
if (isUnderOtherCard(event)) return;
|
||||
if (event.hit?.id === 'plane:9') tracked = 'plane:9';
|
||||
},
|
||||
);
|
||||
@@ -2022,16 +2029,17 @@ test('vessel interaction wire: a card yields to an aircraft that starts tracking
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
useVesselHost(hostWithCardHit(`vessel:${harness.record.mmsi}`));
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(tracked, 'plane:9', 'the aircraft starts tracking');
|
||||
assert.equal(requests.length, 0, 'the vessel card yields');
|
||||
assert.equal(aisLiveVesselsLayer.getSelectedInfo()?.mmsi ?? null, null);
|
||||
assert.equal(tracked, null, 'the aircraft does not track');
|
||||
assert.equal(requests.length, 1, 'the vessel card acts');
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi,
|
||||
harness.record.mmsi,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -2048,7 +2056,7 @@ test('vessel interaction wire: a card over a trail selects; a bare trail is a no
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
useVesselHost(
|
||||
hostWithCardHit(carded ? `vessel:${harness.record.mmsi}` : null),
|
||||
);
|
||||
try {
|
||||
@@ -2059,16 +2067,15 @@ test('vessel interaction wire: a card over a trail selects; a bare trail is a no
|
||||
carded ? harness.record.mmsi : null,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// A coarse tap on the vessel's card finds a fire nearby through the shared
|
||||
// touch contact. The fire layer acts only on exact hits, so the card keeps the
|
||||
// tap; an exact fire pick under the card still belongs to the fire.
|
||||
test('vessel interaction wire: a coarse near miss of an exact-only item keeps the card tap', (t) => {
|
||||
// A coarse tap on the vessel's card over a fire, nearby or exact: the card on
|
||||
// top keeps the tap.
|
||||
test('vessel interaction wire: the card keeps a tap over a nearby or exact fire', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
@@ -2088,18 +2095,16 @@ test('vessel interaction wire: a coarse near miss of an exact-only item keeps th
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
useVesselHost(hostWithCardHit(`vessel:${harness.record.mmsi}`));
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(requests.length, exact ? 0 : 1, `exact fire: ${exact}`);
|
||||
assert.equal(requests.length, 1, `exact fire: ${exact}`);
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi ?? null,
|
||||
exact ? null : harness.record.mmsi,
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi,
|
||||
harness.record.mmsi,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
@@ -2130,7 +2135,7 @@ for (const card of ['live', 'stale', 'absent', 'covered']) {
|
||||
);
|
||||
return { sourceId: 'cctv', entryId: 'vessel:999999999' };
|
||||
};
|
||||
_setVesselOverlayHostForTest(host);
|
||||
useVesselHost(host);
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(
|
||||
@@ -2139,7 +2144,7 @@ for (const card of ['live', 'stale', 'absent', 'covered']) {
|
||||
);
|
||||
assert.equal(requests.length, card === 'live' ? 1 : 0);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
useVesselHost(null);
|
||||
harness.cleanup();
|
||||
unregisterPickOwner('weather-cyclones');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user