Skip to content

Build your personal knowledge base with Trilium Notes

refactor(mind-map): let the node show its picture, not the panel

Elian Dorand0aff19020d4
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.css b/apps/client/src/widgets/type_widgets/MindMapNodePanel.css
index 8f129697dc..67b8721125 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.css
+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.css
@@ -51,30 +51,15 @@
}
}
-/* The picture stands above the row of what can be done with it. */
.mind-map-node-panel .mind-map-node-image {
display: flex;
flex-direction: column;
gap: 8px;
}
-/*
- * Shown as it will read on a node, only smaller — enough to tell which picture it is. Left to keep
- * its proportions inside that, and read against the panel as it will be read against the map, so
- * that a picture with transparent parts shows them as such rather than on a plate of its own.
- */
-.mind-map-node-panel .mind-map-node-image-preview {
- align-self: center;
- max-width: 100%;
- max-height: 90px;
- object-fit: contain;
- border-radius: 4px;
-}
-
-/* Where the selection carries different pictures, said in the room one would have taken. */
+/* Where the selection carries different pictures, said above the row rather than beside it. */
.mind-map-node-panel .mind-map-node-image-mixed {
align-self: center;
- padding: 12px 0;
font-size: .9em;
opacity: .7;
}
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
index 02ee5dd623..ed7c0c6691 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
@@ -67,10 +67,6 @@ function iconFaces(container: HTMLElement) {
[ ...button.classList ].filter((name) => name.startsWith("bx")).join(" "));
}
-function imagePreview(container: HTMLElement) {
- return section(container, IMAGE).querySelector<HTMLImageElement>(".mind-map-node-image-preview");
-}
-
function imageWidthButtons(container: HTMLElement) {
return Array.from(section(container, IMAGE).querySelectorAll<HTMLElement>(".btn-group .btn"));
}
@@ -320,19 +316,19 @@ describe("MindMapNodePanel", () => {
expect(iconButtons(container).every((button) => button.disabled)).toBe(true);
});
- it("shows the picture the selection carries and what can be done with it, nothing more", () => {
+ it("offers what can be done with the picture a node carries, and only takes one in without", () => {
const nodes = [buildNode({ image: { url: "api/attachments/att1/image/a.png", width: 240, height: 180 } })];
const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
- expect(imagePreview(container)?.getAttribute("src")).toBe("api/attachments/att1/image/a.png");
+ // The picture is on the node itself; the row says how large it is drawn and offers the way
+ // to another one or to none.
expect(activeImageWidth(container)).toBe(1);
expect(imageAction(container, "bx-trash")).toBeTruthy();
// A node carrying none offers to take one in, and nothing else: there is no size to set and
// nothing to remove.
const empty = renderInto(<MindMapNodePanel mind={buildMind([buildNode()]).mind} noteId="mapNote" nodes={[buildNode()]} />);
- expect(imagePreview(empty)).toBeNull();
expect(imageWidthButtons(empty)).toHaveLength(0);
expect(imageAction(empty, "bx-trash")).toBeNull();
expect(imageAction(empty, "bx-image-add")).toBeTruthy();
@@ -366,9 +362,8 @@ describe("MindMapNodePanel", () => {
const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
- expect(imagePreview(container)).toBeNull();
expect(section(container, IMAGE).querySelector(".mind-map-node-image-mixed")).toBeTruthy();
- // Neither the picture nor the width can be shown, but both can still be set for all of them.
+ // No width can be shown, but one can still be set for all of them.
expect(activeImageWidth(container)).toBe(-1);
expect(imageAction(container, "bx-trash")).toBeTruthy();
});
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx b/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
index 1ea7fc6ae2..5fcd2f1dbe 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
@@ -135,7 +135,7 @@ export default function MindMapNodePanel({ mind, noteId, nodes }: MindMapNodePan
title={image === MIXED ? t("mind-map.images-differ") : undefined}
>
<NodeImage
- url={image !== MIXED ? image : null}
+ hasImage={!!image}
indeterminate={image === MIXED}
width={imageWidth !== MIXED && imageWidth ? Number(imageWidth) : null}
// A node carries one picture, so what is taken in takes the place of what was
@@ -363,15 +363,17 @@ function NodeIcon({ face, title, disabled, onSelect, onRemove }: {
}
/**
- * The picture a node carries: what it looks like, how large it is drawn, and the way to another one
- * or to none at all.
+ * The picture a node carries: how large it is drawn, and the way to another one or to none at all.
*
- * A node holds one picture, so the button offering one stands alone until there is a picture to
- * show, and turns into the way to replace it once there is — the same shape the icons row takes.
+ * The picture itself is not shown again here — it is on the node, at the very size these buttons
+ * set, a hand's width from the panel. What the row says instead is whether there is one: a node
+ * carrying none offers the one button that takes a picture in, and every other is only there once
+ * there is something for it to act on.
*/
-function NodeImage({ url, indeterminate, width, onPick, onResize, onRemove }: {
- url: string | null;
- /** The selected nodes carry different pictures, so none of them can be shown. */
+function NodeImage({ hasImage, indeterminate, width, onPick, onResize, onRemove }: {
+ /** Whether the selection carries a picture at all, which is what the row offers to do with. */
+ hasImage: boolean;
+ /** The selected nodes carry different pictures, which is why no width is shown. */
indeterminate: boolean;
/** The width they are drawn at, or `null` where the nodes disagree on one. */
width: number | null;
@@ -379,13 +381,9 @@ function NodeImage({ url, indeterminate, width, onPick, onResize, onRemove }: {
onResize(width: number): void;
onRemove(): void;
}) {
- const hasImage = !!url || indeterminate;
-
return (
<div className="mind-map-node-image">
- {indeterminate
- ? <div className="mind-map-node-image-mixed">{t("mind-map.image-mixed")}</div>
- : url && <img className="mind-map-node-image-preview" src={url} alt="" />}
+ {indeterminate && <div className="mind-map-node-image-mixed">{t("mind-map.image-mixed")}</div>}
<div className="mind-map-node-image-actions">
{hasImage && (