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
fix(geomap): take the drawing rail off a map that may not be edited
Elian Doran8958a5a7f154
diff --git a/apps/client/src/widgets/collections/geomap/DrawToolbar.spec.tsx b/apps/client/src/widgets/collections/geomap/DrawToolbar.spec.tsxindex 0c62ec293f..368aad5854 100644--- a/apps/client/src/widgets/collections/geomap/DrawToolbar.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/DrawToolbar.spec.tsx@@ -1,7 +1,7 @@/*** The rail of drawing tools over a geo map (see DrawToolbar.tsx). What is checked is that every tool* is offered, that a press arms the map and a press on an armed one stands it down, that the armed- * tool is worn held down, and that a map that may not be edited refuses them all.+ * tool is worn held down, and that a map that may not be edited carries no rail at all.*/import { act } from "preact/test-utils";import { describe, expect, it, vi } from "vitest";@@ -67,13 +67,15 @@ describe("geo map DrawToolbar", () => {expect(buttons()).toHaveLength(DRAW_TOOL_ICONS.length);});- it("refuses every tool on a map that may not be edited", () => {- const { buttons } = renderRail({ isReadOnly: true });+ /**+ * Drawing is all the rail offers, so a map that may not be edited would carry four dead buttons+ * and nothing else. The editing bar shows its own refused, having somewhere to stand either way.+ */+ it("comes off a map that may not be edited rather than standing there refused", () => {+ const { group, buttons } = renderRail({ isReadOnly: true });- expect(buttons()).toHaveLength(DRAW_TOOL_ICONS.length);- for (const button of buttons()) {- expect(button.disabled).toBe(true);- }+ expect(group()).toBeNull();+ expect(buttons()).toHaveLength(0);});it("stands aside where there is no map at all", () => {diff --git a/apps/client/src/widgets/collections/geomap/DrawToolbar.tsx b/apps/client/src/widgets/collections/geomap/DrawToolbar.tsxindex dc4013813d..dd8904a4cb 100644--- a/apps/client/src/widgets/collections/geomap/DrawToolbar.tsx+++ b/apps/client/src/widgets/collections/geomap/DrawToolbar.tsx@@ -6,7 +6,7 @@ import type { DrawTool } from "./DrawShape";import { ParentMap } from "./map";interface DrawToolbarProps {- /** The map may not be edited, which is every tool refused at once. */+ /** The map may not be edited, which takes the rail off it entirely. */isReadOnly: boolean;/** The tool the map is armed to draw with, if any — its button worn held down. */drawingTool: DrawTool | null;@@ -29,8 +29,9 @@ interface DrawToolbarProps {export default function DrawToolbar({ isReadOnly, drawingTool, onToggleDrawing }: DrawToolbarProps) {const map = useContext(ParentMap);- // No rail over a map that could not be drawn (see the WebGL fallback in map.tsx).- if (!map) return null;+ // No rail over a map that could not be drawn (see the WebGL fallback in map.tsx), and none over+ // one that may not be edited: every button on it draws, so all four would be disabled at once.+ if (!map || isReadOnly) return null;return (<OverlayControlGroup className="geo-draw-toolbar" placement="middle-start" vertical overCanvas>@@ -40,7 +41,6 @@ export default function DrawToolbar({ isReadOnly, drawingTool, onToggleDrawing }title={drawingTool === tool ? t("geo-map.draw-cancel") : title()}icon={icon}active={drawingTool === tool}- disabled={isReadOnly}onClick={() => onToggleDrawing(tool)}/>))}