Skip to content

Build your personal knowledge base with Trilium Notes

fix(geomap): stop offering to move a track that has no marker to move

Elian Doran1b05fd2c5705
diff --git a/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx b/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx
index a4a71a919d..3d5f037b9f 100644
--- a/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx
@@ -15,6 +15,7 @@ import type { MenuCommandItem, MenuItem } from "../../../menus/context_menu";
import { buildNote } from "../../../test/easy-froca";
import { renderInto } from "../../../test/render";
import ContextMenus from "./ContextMenus";
+import { GPX_MIME } from "./GpxTrack";
import { ParentMap } from "./map";
import { MARKER_LAYER } from "./Markers";
@@ -132,7 +133,7 @@ describe("ContextMenus", () => {
});
it("opens the note of a GPX track that was clicked, not the map's own menu", async () => {
- const track = buildNote({ title: "A Sunday ride" });
+ const track = buildNote({ title: "A Sunday ride", mime: GPX_MIME });
const { items } = await openMenu(fakeMap(undefined, track));
// The note's menu rather than the map's: a track is a note, so what it offers is what a
@@ -141,9 +142,21 @@ describe("ContextMenus", () => {
expect(items).toContainEqual(expect.objectContaining({ title: "geo-map-context.remove-from-map" }));
});
+ /**
+ * A track has no marker to put somewhere else: it is on the map by being drawn across it, and
+ * its place is the line its file holds. The offer used to be made and only wrote a location onto
+ * the note — planting a stray pin elsewhere while the line stayed where it was.
+ */
+ it("does not offer to move a GPX track, which has no marker to move", async () => {
+ const track = buildNote({ title: "A Sunday ride", mime: GPX_MIME });
+ const { items } = await openMenu(fakeMap(undefined, track));
+
+ expect(moveItem(items)).toBeUndefined();
+ });
+
it("prefers the marker to the track it stands on, both being under the pointer", async () => {
const marker = buildNote({ title: "Where I stopped", "#geolocation": "1,2" });
- const track = buildNote({ title: "A Sunday ride" });
+ const track = buildNote({ title: "A Sunday ride", mime: GPX_MIME });
const { items, onRelocate } = await openMenu(fakeMap(marker, track));
// Aiming at a pin standing on its own track has to mean the pin: it is the smaller target,
diff --git a/apps/client/src/widgets/collections/geomap/ContextMenus.ts b/apps/client/src/widgets/collections/geomap/ContextMenus.ts
index aa2e3e4715..b6ec2da3ec 100644
--- a/apps/client/src/widgets/collections/geomap/ContextMenus.ts
+++ b/apps/client/src/widgets/collections/geomap/ContextMenus.ts
@@ -6,9 +6,10 @@ import contextMenu, { type MenuItem } from "../../../menus/context_menu.js";
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker.jsx";
import linkContextMenu from "../../../menus/link_context_menu.js";
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
+import froca from "../../../services/froca.js";
import { t } from "../../../services/i18n.js";
import link from "../../../services/link.js";
-import { trackHitLayers } from "./GpxTrack.js";
+import { GPX_MIME, trackHitLayers } from "./GpxTrack.js";
import { type GeoMouseEvent, ParentMap, toGeoMouseEvent } from "./map.js";
import { formatLocation, MARKER_LAYER } from "./Markers.js";
@@ -75,10 +76,7 @@ export function openContextMenu(noteId: string, e: GeoMouseEvent, isEditable: bo
items = [
...items,
{ kind: "separator" },
- // The marker is put somewhere else by being placed again rather than dragged: the notes
- // are drawn into one symbol layer, not an element apiece, so there is nothing on the map
- // to take hold of.
- { title: t("geo-map-context.move-marker"), handler: () => onRelocate(noteId), uiIcon: "bx bx-move" },
+ ...buildRelocateItem(noteId, onRelocate),
{ title: t("geo-map-context.remove-from-map"), command: "deleteFromMap", uiIcon: "bx bx-trash" },
{ kind: "separator"},
{
@@ -134,6 +132,27 @@ export function openMapContextMenu(e: GeoMouseEvent, isEditable: boolean, onCrea
});
}
+/**
+ * The offer to put a marker somewhere else, where the note has a marker to put.
+ *
+ * The marker is moved by being placed again rather than dragged: the notes are drawn into one symbol
+ * layer, not an element apiece, so there is nothing on the map to take hold of.
+ *
+ * A GPX track is offered nothing, which is why this is a list and not an item. A track is on the map
+ * by being drawn across it — its place is the line its file holds, which no click can pick up. What
+ * the offer did was write a location onto the note, planting a stray pin somewhere else while the
+ * line stayed exactly where it was. The detail pane leaves the button out for the same reason.
+ */
+function buildRelocateItem(noteId: string, onRelocate: (noteId: string) => void): MenuItem<keyof CommandMappings>[] {
+ if (froca.getNoteFromCache(noteId)?.mime === GPX_MIME) {
+ return [];
+ }
+
+ return [
+ { title: t("geo-map-context.move-marker"), handler: () => onRelocate(noteId), uiIcon: "bx bx-move" }
+ ];
+}
+
function buildGeoLocationItem(e: GeoMouseEvent) {
const coordinates: [number, number] = [ e.latlng.lng, e.latlng.lat ];
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index a5f0b288e0..33feb3d831 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -893,6 +893,27 @@ describe("DetailPane", () => {
expect(pane()).toBeTruthy();
expect(moveButton()).toBeNull();
});
+
+ /**
+ * A track has no marker to put somewhere else: it is on the map by being drawn across it,
+ * and its place is the line its file holds. The button used to be offered and only wrote a
+ * location onto the note, planting a stray pin while the line stayed where it was.
+ */
+ it("is not offered for a GPX track, which has no marker to move", async () => {
+ buildNote({ id: "root", title: "root", children: [ { id: "hikemove", title: "A hike", mime: GPX_MIME } ] });
+ const note = froca.notes["hikemove"];
+ const map = fakeMap();
+
+ await mount([ note ], map);
+ map.setUnderPointer([ trackFeature(note) ]);
+ await act(async () => map.click());
+ await settle();
+
+ // The rest of the row stands: only the one offer that cannot mean anything is gone.
+ expect(pane()).toBeTruthy();
+ expect(container?.querySelector(".geo-detail-pane-actions button.bx-log-in")).toBeTruthy();
+ expect(moveButton()).toBeNull();
+ });
});
describe("taking the marker off the map", () => {
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index 292ded75a2..ab4ae3dab0 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -280,8 +280,11 @@ const PANE_WIDTH = 380;
/** Must agree with `--geo-map-inset` in index.css. */
const PANE_INSET = 20;
-/** How far into the map the pane reaches: its width plus the gap, which it also covers. */
-const PANE_REACH = PANE_WIDTH + PANE_INSET;
+/** How far into the map the pane reaches: its width plus the gap, which it also covers. Exported
+ * because everything the map places has to keep out from under the pane — the camera holds the
+ * selected marker clear of it (below), and the marker previews slide clear of it too (see
+ * {@link Tooltips}). */
+export const PANE_REACH = PANE_WIDTH + PANE_INSET;
/**
* How far off centre to hold a marker so the pane does not cover it.
@@ -625,7 +628,10 @@ function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOn
<NoteColorPicker note={note} />
</Dropdown>
- <ActionButton
+ {/* A track is offered nothing here: it is on the map by being drawn across it, and
+ its place is the line its file holds rather than a location that could be
+ written somewhere else. The right-click menu leaves it out for the same reason. */}
+ {note.mime !== GPX_MIME && <ActionButton
className="geo-detail-pane-move"
icon="bx bx-move"
text={t("geo-map-context.move-marker")}
@@ -633,7 +639,7 @@ function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOn
// notes are drawn into one symbol layer, not an element apiece, so there is
// nothing on the map to take hold of.
onClick={onRelocate}
- />
+ />}
<ActionButton
className="geo-detail-pane-remove"