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): pick the image coordinates with a segmented control
Elian Doranc15faaef49af
diff --git a/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx b/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsxindex 589b48ec1c..faa524cb6e 100644--- a/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx@@ -96,6 +96,24 @@ describe("GeoMapProperties", () => {act(() => item.click());}+ function coordinateButtons() {+ return [ ...document.querySelectorAll<HTMLButtonElement>(+ ".geo-map-properties-dialog .geo-map-coordinates .tn-segmented-choice button") ];+ }++ /** The coordinate modes, as their labels and whether each is the chosen one. */+ function coordinateModes() {+ return coordinateButtons()+ .map((button) => [ button.textContent?.trim(), button.classList.contains("active") ]);+ }++ function chooseCoordinateMode(label: string) {+ const button = coordinateButtons()+ .find((candidate) => candidate.textContent?.trim() === label);+ if (!button) throw new Error(`no ${label} button`);+ act(() => button.click());+ }+/** Types `value` into `input` and leaves it, which is when a number box commits. */function commit(input: HTMLInputElement | undefined, value: string) {if (!input) throw new Error("no such input");@@ -181,13 +199,10 @@ describe("GeoMapProperties", () => {]);expect(cornerInputs()).toHaveLength(0);- const mode = query<HTMLSelectElement>(".geo-map-coordinates select");- expect(mode?.value).toBe("pixels");- act(() => {- if (!mode) return;- mode.value = "custom";- mode.dispatchEvent(new Event("change"));- });+ expect(coordinateModes()).toEqual([+ [ "geo-map.coordinates-pixels", true ], [ "geo-map.coordinates-custom", false ]+ ]);+ chooseCoordinateMode("geo-map.coordinates-custom");expect(mocks.setLabel).toHaveBeenCalledWith(note.noteId, "map:imageBounds", "0,0 2048,1024");});@@ -209,13 +224,10 @@ describe("GeoMapProperties", () => {.toHaveBeenCalledWith(note.noteId, "map:imageBounds", "-512,512 1024.5,-512");expect(query(".geo-map-coordinates-error")).toBeNull();- const mode = query<HTMLSelectElement>(".geo-map-coordinates select");- expect(mode?.value).toBe("custom");- act(() => {- if (!mode) return;- mode.value = "pixels";- mode.dispatchEvent(new Event("change"));- });+ expect(coordinateModes()).toEqual([+ [ "geo-map.coordinates-pixels", false ], [ "geo-map.coordinates-custom", true ]+ ]);+ chooseCoordinateMode("geo-map.coordinates-pixels");expect(mocks.removeOwnedLabelByName).toHaveBeenCalledWith(note, "map:imageBounds");});diff --git a/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx b/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsxindex 39c51ee63e..7c4618f8b2 100644--- a/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx+++ b/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx@@ -12,12 +12,12 @@ import { bookPropertiesConfig } from "../../note_bars/collection-properties-confimport Admonition from "../../react/Admonition";import { Card, CardSection, OptionCardSection } from "../../react/Card";import FormDropdownList from "../../react/FormDropdownList";-import FormSelect from "../../react/FormSelect";import FormTextBox from "../../react/FormTextBox";import FormToggle from "../../react/FormToggle";import { useNoteLabel, useNoteLabelBoolean, useNoteRelation } from "../../react/hooks";import NoteAutocomplete from "../../react/NoteAutocomplete";import { type BookProperty, ViewPropertySection } from "../../react/NotePropertyMenu";+import SegmentedChoice from "../../react/SegmentedChoice";import { formatImageExtent, type ImageSize, parseImageExtent } from "./space";/** What the map knows of its image: none, loading, unusable, or loaded at its natural size. */@@ -234,7 +234,6 @@ function ImageCoordinates({ note, size }: { note: FNote; size: ImageSize | undefreturn (<OptionCardSectionclassName="geo-map-coordinates"- name="geo-map-coordinates"label={t("geo-map.coordinates")}description={t("geo-map.coordinates-description")}subSectionsVisible@@ -258,13 +257,11 @@ function ImageCoordinates({ note, size }: { note: FNote; size: ImageSize | undef)}</> : undefined}>- <FormSelect- values={[- { value: "pixels", title: t("geo-map.coordinates-pixels") },- { value: "custom", title: t("geo-map.coordinates-custom") }+ <SegmentedChoice+ options={[+ { value: "pixels", label: t("geo-map.coordinates-pixels") },+ { value: "custom", label: t("geo-map.coordinates-custom") }]}- keyProperty="value"- titleProperty="title"currentValue={isCustom ? "custom" : "pixels"}onChange={changeMode}/>