Skip to content

Build your personal knowledge base with Trilium Notes

style(mind-map): bring unlinking out from under the link picker

Elian Doran871950393450
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
index 990d6cb374..2173a3370f 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
@@ -144,6 +144,19 @@
}
}
+/* The field takes what the unlinking button beside it leaves, as the picture's sizes do above. */
+.mind-map-node-panel .mind-map-node-link-row {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+
+ .mind-map-node-link {
+ flex: 1;
+ /* Without it a flex item refuses to shrink past its content, and there is nothing to cut. */
+ min-width: 0;
+ }
+}
+
/*
* The link takes the width of the panel and says what it points at, however long that runs: a title
* or an address is as long as it is, and cutting it short is kinder than letting it push the panel
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
index 6bd1d45dee..19140ad0ea 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
@@ -140,6 +140,11 @@ function chooseImage(container: HTMLElement, file: File) {
input.dispatchEvent(new Event("change", { bubbles: true }));
}
+/** The button beside the link field dropping what the selection points at, if it is offered at all. */
+function unlinkButton(container: HTMLElement) {
+ return section(container, LINK).querySelector<HTMLButtonElement>(".bx-unlink");
+}
+
function sizeButtons(container: HTMLElement) {
return Array.from(section(container, SIZE).querySelectorAll<HTMLElement>(".btn"));
}
@@ -671,6 +676,24 @@ describe("NodePanel", () => {
await vi.waitFor(() => expect(note?.textContent).toBe("Linked note"));
});
+ it("unlinks the selection from the button beside the field, which is only there to be unlinked", () => {
+ const linked = [
+ buildNode({ id: "a", hyperLink: "https://example.com" }),
+ buildNode({ id: "b", hyperLink: "https://example.com" })
+ ];
+ const { mind, reshapeNode } = buildMind(linked);
+
+ // Nothing to drop, nothing offering to: the field alone stands there.
+ expect(unlinkButton(renderInto(<NodePanel mind={buildMind([buildNode()]).mind} noteId="mapNote" nodes={[buildNode()]} />))).toBeNull();
+
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={linked} />);
+ unlinkButton(container)?.click();
+
+ // Blanked out rather than removed, Mind Elixir only ever assigning the properties it is given.
+ expect(reshapeNode).toHaveBeenNthCalledWith(1, mind.currentNodes[0], { hyperLink: "" });
+ expect(reshapeNode).toHaveBeenNthCalledWith(2, mind.currentNodes[1], { hyperLink: "" });
+ });
+
it("edits the tags of a single node, keeping the styling of the ones that stay", () => {
const styled = { text: "urgent", style: { color: "red" } };
const nodes = [buildNode({ tags: [styled, "later"] })];
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
index efdae10817..32be3cc4db 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
@@ -14,7 +14,6 @@ import ActionButton from "../../react/ActionButton";
import ColorPicker, { DEFAULT_COLOR_PALETTE } from "../../react/ColorPicker";
import Dropdown from "../../react/Dropdown";
import { FormFileUploadActionButton } from "../../react/FormFileUpload";
-import { FormListItem } from "../../react/FormList";
import { useNote, useNoteIcon, useNoteTitle } from "../../react/hooks";
import Icon from "../../react/Icon";
import IconPicker from "../../react/IconPicker";
@@ -564,6 +563,9 @@ const LINK_AUTOCOMPLETE_OPTIONS = { allowExternalLinks: true };
*
* The picker sits in a menu rather than in the panel itself: it is the field a note is picked
* through everywhere else in Trilium, and it wants more room than a panel this narrow can give it.
+ * Unlinking stands beside the field rather than at the foot of that menu, as it does for the picture
+ * above: dropping a link is not one more note to pick from, and offered among them it read as one —
+ * besides taking a menu opened on something else entirely to reach.
*/
function NodeLink({ currentValue, indeterminate, onChange }: {
currentValue: string | null;
@@ -590,45 +592,50 @@ function NodeLink({ currentValue, indeterminate, onChange }: {
}
return (
- <Dropdown
- className="mind-map-node-link"
- text={<NodeLinkFace link={currentValue} indeterminate={indeterminate} />}
- title={t("mind-map.choose-link")}
- dropdownRef={dropdownRef}
- dropdownContainerStyle={{ width: "360px" }}
- // The suggestions land inside the menu, so picking one is not the click outside that
- // would take the menu down before the pick is made.
- dropdownOptions={{ autoClose: "outside" }}
- // The panel scrolls, and the picker is wider than the panel is; hand the menu to the
- // page instead of leaving it to be clipped.
- portalToBody
- onShown={() => setPickerShown(true)}
- onHidden={() => setPickerShown(false)}
- >
- {pickerShown && (
- <div className="mind-map-node-link-picker" ref={pickerRef}>
- <NoteAutocomplete
- inputRef={inputRef}
- container={pickerRef}
- placeholder={t("mind-map.link-placeholder")}
- opts={LINK_AUTOCOMPLETE_OPTIONS}
- // Only a pick is worth taking: the field is also cleared as one types, and
- // the way back to no link at all is the one offered below.
- onChange={(suggestion) => {
- const link = linkFromSuggestion(suggestion);
- if (link) commit(link);
- }}
- />
-
- {(currentValue || indeterminate) && (
- <FormListItem
- icon="bx bx-unlink"
- onClick={() => commit(null)}
- >{t("mind-map.clear-link")}</FormListItem>
- )}
- </div>
+ <div className="mind-map-node-link-row">
+ <Dropdown
+ className="mind-map-node-link"
+ text={<NodeLinkFace link={currentValue} indeterminate={indeterminate} />}
+ title={t("mind-map.choose-link")}
+ dropdownRef={dropdownRef}
+ dropdownContainerStyle={{ width: "360px" }}
+ // The suggestions land inside the menu, so picking one is not the click outside that
+ // would take the menu down before the pick is made.
+ dropdownOptions={{ autoClose: "outside" }}
+ // The panel scrolls, and the picker is wider than the panel is; hand the menu to the
+ // page instead of leaving it to be clipped.
+ portalToBody
+ onShown={() => setPickerShown(true)}
+ onHidden={() => setPickerShown(false)}
+ >
+ {pickerShown && (
+ <div className="mind-map-node-link-picker" ref={pickerRef}>
+ <NoteAutocomplete
+ inputRef={inputRef}
+ container={pickerRef}
+ placeholder={t("mind-map.link-placeholder")}
+ opts={LINK_AUTOCOMPLETE_OPTIONS}
+ // Only a pick is worth taking: the field is also cleared as one types, and
+ // the way back to no link at all is the button beside the menu.
+ onChange={(suggestion) => {
+ const link = linkFromSuggestion(suggestion);
+ if (link) commit(link);
+ }}
+ />
+ </div>
+ )}
+ </Dropdown>
+
+ {/* Only where there is a link to drop — as with the picture, what acts on one is there
+ once there is something for it to act on. */}
+ {(currentValue || indeterminate) && (
+ <ActionButton
+ icon="bx bx-unlink"
+ text={t("mind-map.clear-link")}
+ onClick={() => onChange(null)}
+ />
)}
- </Dropdown>
+ </div>
);
}