Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(geomap): let a marker be moved from its own pane
Elian Doran791f1a6dcb47
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.cssindex 093031b0d4..45c45ed5d4 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.css+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css@@ -133,9 +133,11 @@align-items: center;gap: 4px;- /* The one thing in the row that writes rather than reads stands apart from the four being- reached for repeatedly, so the pointer cannot land on it by being a moment early. */- .geo-detail-pane-remove {+ /* The two that write rather than read stand apart from the four being reached for repeatedly, so+ the pointer cannot land on one of them by being a moment early. The gap falls before the first+ of the pair, which is the move: both are drawn together or not at all, a read-only map having+ neither. */+ .geo-detail-pane-move {margin-inline-start: auto;}}diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsxindex c2d8815426..1e1e372d34 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx@@ -112,6 +112,7 @@ describe("DetailPane", () => {openContextWithNote: async () => undefined};editorAskedToSave.mockClear();+ onRelocate.mockClear();});afterEach(() => {@@ -135,7 +136,7 @@ describe("DetailPane", () => {render(<ParentComponent.Provider value={mapComponent as Component}><ParentMap.Provider value={map as never}>- <DetailPane notes={notes} placing={placing} isReadOnly={isReadOnly} />+ <DetailPane notes={notes} placing={placing} isReadOnly={isReadOnly} onRelocate={onRelocate} /></ParentMap.Provider></ParentComponent.Provider>,container as HTMLElement@@ -143,6 +144,9 @@ describe("DetailPane", () => {});}+ /** Arming the map for the next click to be where the marker goes, which the map owns (index.tsx). */+ const onRelocate = vi.fn();+/** Lets the pane's note context resolve its path and announce the note it landed on. */async function settle() {await act(async () => {@@ -434,6 +438,47 @@ describe("DetailPane", () => {expect(pane()?.querySelector(".promoted-attribute-cell")).toBeNull();});+ describe("moving the marker", () => {+ function moveButton() {+ return container?.querySelector<HTMLButtonElement>(".geo-detail-pane-actions button.bx-move") ?? null;+ }++ /**+ * The map is armed rather than the marker dragged, and the pane goes away while it waits: the+ * click that names the new place has to land on the map, and the pane covers the part of it+ * nearest the marker.+ */+ it("arms the map for the next click and stands down", async () => {+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });+ const map = fakeMap();++ await mount([ note ], map);+ map.setUnderPointer([ markerFeature(note) ]);+ await act(async () => map.click());+ await settle();++ await act(async () => { moveButton()?.click(); });++ // The arming belongs to the map, which alone knows what the next click on it is for.+ expect(onRelocate).toHaveBeenCalledWith(note.noteId);+ expect(pane()).toBeNull();+ // Going away this way is still a close, so whatever was being written is saved first.+ expect(editorAskedToSave).toHaveBeenCalledWith({ ntxIds: [ "_geo-detail-pane" ] });+ });++ it("is not offered at all on a map that cannot be edited", async () => {+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });+ const map = fakeMap();++ await mount([ note ], map, false, true);+ map.setUnderPointer([ markerFeature(note) ]);+ await act(async () => map.click());++ expect(pane()).toBeTruthy();+ expect(moveButton()).toBeNull();+ });+ });+describe("taking the marker off the map", () => {function removeButton() {return container?.querySelector<HTMLButtonElement>(".geo-detail-pane-actions button.bx-trash") ?? null;diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsxindex 6cb0ec845f..864e371a33 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx@@ -27,12 +27,14 @@ import { LOCATION_ATTRIBUTE, MARKER_LAYER, parseLocation } from "./Markers";* pane outside it would leave the screen. It reads as a dock because the map keeps out of its way* (see {@link paneOffset}).*/-export default function DetailPane({ notes, placing, isReadOnly }: {+export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {notes: FNote[];/** A marker is being placed, which is what the next click on the map is for. */placing: boolean;/** The map may not be edited, which leaves the pane the ways of opening a note and no more. */isReadOnly: boolean;+ /** Arms this map for the selected marker to be put somewhere else, the next click being where. */+ onRelocate: (noteId: string) => void;}) {const map = useContext(ParentMap);const [ selectedNoteId, setSelectedNoteId ] = useState<string | null>(null);@@ -57,6 +59,20 @@ export default function DetailPane({ notes, placing, isReadOnly }: {setSelectedNoteId(null);}, [ paneComponent ]);+ /**+ * Arms the map for this marker to be put somewhere else, and stands the pane down while it waits.+ *+ * The pane goes because the click that names the new place has to land on the map, and the pane+ * covers the part of it nearest the marker — leaving it up would put the likeliest destinations+ * out of reach. What the map is waiting for is said by the instruction toast instead (see+ * index.tsx), which is where the same arming from the right-click menu says it too.+ */+ const relocate = useCallback(() => {+ if (!note) return;+ closePane();+ onRelocate(note.noteId);+ }, [ note, closePane, onRelocate ]);+// A note no longer on the map takes the pane with it. Its location may merely have been cleared// — which is all "remove from map" does — so the note being gone is not the only case.useEffect(() => {@@ -113,7 +129,7 @@ export default function DetailPane({ notes, placing, isReadOnly }: {// TitleRow), and answers to the pane's own component rather than the map's (see below).<ParentComponent.Provider value={paneComponent}><NoteContextContext.Provider value={noteContext}>- <MarkerDetails note={note} isReadOnly={isReadOnly} onClose={closePane} />+ <MarkerDetails note={note} isReadOnly={isReadOnly} onClose={closePane} onRelocate={relocate} /></NoteContextContext.Provider></ParentComponent.Provider>);@@ -147,7 +163,7 @@ function paneOffset(map: MapLibreGLMap): [number, number] {}/** The pane itself, for a marker there is one to draw. */-function MarkerDetails({ note, isReadOnly, onClose }: { note: FNote; isReadOnly: boolean; onClose(): void }) {+function MarkerDetails({ note, isReadOnly, onClose, onRelocate }: { note: FNote; isReadOnly: boolean; onClose(): void; onRelocate(): void }) {return (<OverlayPanelclassName="geo-detail-pane"@@ -155,7 +171,7 @@ function MarkerDetails({ note, isReadOnly, onClose }: { note: FNote; isReadOnly:close={{ text: t("geo-map.close-details"), onClick: onClose }}><OverlayPanelBody className="geo-detail-pane-body">- <MarkerActions note={note} isReadOnly={isReadOnly} />+ <MarkerActions note={note} isReadOnly={isReadOnly} onRelocate={onRelocate} />{/* Whatever fields the note's own definitions ask for, ahead of the note as the quickeditor puts them — a marker is often a note whose type says less about it than@@ -238,7 +254,7 @@ function usePaneNoteContext(note: FNote | undefined) {* The quick editor is deliberately absent: it is what a click on a marker used to raise, and the* pane took that click over — offering it here would put a modal back over the pane that replaced it.*/-function MarkerActions({ note, isReadOnly }: { note: FNote; isReadOnly: boolean }) {+function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOnly: boolean; onRelocate(): void }) {const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;// A path rather than an id: a note may hang in several places, and each of these opens a path.@@ -278,9 +294,19 @@ function MarkerActions({ note, isReadOnly }: { note: FNote; isReadOnly: booleandisabled={!latLng}/>- {/* Left out rather than disabled on a read-only map, as the right-click menu leaves it- out: everything else in the row reads the note, this alone writes it. */}- {!isReadOnly && (+ {/* Left out rather than disabled on a read-only map, as the right-click menu leaves them+ out: everything else in the row reads the note, these two alone write it. */}+ {!isReadOnly && <>+ <ActionButton+ className="geo-detail-pane-move"+ icon="bx bx-move"+ text={t("geo-map-context.move-marker")}+ // 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.+ onClick={onRelocate}+ />+<ActionButtonclassName="geo-detail-pane-remove"icon="bx bx-trash"@@ -292,7 +318,7 @@ function MarkerActions({ note, isReadOnly }: { note: FNote; isReadOnly: boolean// map would take the same note off in turn.onClick={() => void moveMarker(note.noteId, null)}/>- )}+ </>}</div>);}diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex 9ab18de176..c3521580fa 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -208,7 +208,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM><MapToolbar /><Tooltips />- <DetailPane notes={notes} placing={!!placement} isReadOnly={isReadOnly} />+ <DetailPane notes={notes} placing={!!placement} isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} /><ContextMenus note={note} isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} />{/* The pane above is what a click on a marker opens now, so the markers no longeropen the note themselves — the two would otherwise both answer the same click,