Skip to content

Build your personal knowledge base with Trilium Notes

refactor(mind-map): take no picture in where the nodes carry different ones

Elian Doran63f59f1b7c84
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 32ec6b3f9d..c3a2a88dda 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3540,8 +3540,7 @@
"add-image": "Add an image",
"change-image": "Replace the image",
"remove-image": "Remove the image",
- "image-mixed": "Different images",
- "images-differ": "The selected nodes don't carry the same image.",
+ "images-differ": "The selected nodes don't carry the same image. To replace the images anyway, remove them first.",
"image-upload-failed": "Cannot upload image \"{{name}}\".",
"node-link": "Link",
"add-link": "Add a link",
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.css b/apps/client/src/widgets/type_widgets/MindMapNodePanel.css
index 67b8721125..8e18d42f10 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.css
+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.css
@@ -52,19 +52,6 @@
}
.mind-map-node-panel .mind-map-node-image {
- display: flex;
- flex-direction: column;
- gap: 8px;
-}
-
-/* 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;
- font-size: .9em;
- opacity: .7;
-}
-
-.mind-map-node-panel .mind-map-node-image-actions {
display: flex;
align-items: center;
gap: 4px;
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
index ed7c0c6691..48ea69a413 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
@@ -77,7 +77,7 @@ function activeImageWidth(container: HTMLElement) {
/** The button of the picture row wearing the given icon, if it is offered at all. */
function imageAction(container: HTMLElement, icon: string) {
- return section(container, IMAGE).querySelector<HTMLElement>(`.mind-map-node-image-actions .${icon}`);
+ return section(container, IMAGE).querySelector<HTMLButtonElement>(`.mind-map-node-image .${icon}`);
}
/** Hands a picture to the field behind the button, the way picking one from disk does. */
@@ -324,6 +324,7 @@ describe("MindMapNodePanel", () => {
// 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-repost")?.disabled).toBe(false);
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
@@ -354,7 +355,7 @@ describe("MindMapNodePanel", () => {
expect(reshapeNode).toHaveBeenNthCalledWith(2, mind.currentNodes[1], { image: undefined });
});
- it("says as much where the selection carries different pictures", () => {
+ it("takes no picture in where the selection carries different ones", () => {
const nodes = [
buildNode({ id: "a", image: { url: "a.png", width: 240, height: 180 } }),
buildNode({ id: "b", image: { url: "b.png", width: 120, height: 90 } })
@@ -362,10 +363,15 @@ describe("MindMapNodePanel", () => {
const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
- expect(section(container, IMAGE).querySelector(".mind-map-node-image-mixed")).toBeTruthy();
- // No width can be shown, but one can still be set for all of them.
- expect(activeImageWidth(container)).toBe(-1);
+ // One picture cannot take the place of them all — that is a removal in all but name. What
+ // it would take, removing them and taking one in, is what the row still offers. (The
+ // section carries the reason as its title, which no test can read: the panel's own strings
+ // resolve to nothing until i18next is initialized, which it is not here.)
+ expect(imageAction(container, "bx-repost")?.disabled).toBe(true);
expect(imageAction(container, "bx-trash")).toBeTruthy();
+ // No width can be shown either, but one can still be set for all of them.
+ expect(activeImageWidth(container)).toBe(-1);
+ expect(imageWidthButtons(container)).toHaveLength(3);
});
it("stores a chosen picture on the note and gives it to every selected node", async () => {
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx b/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
index 5fcd2f1dbe..f58155f0a5 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
@@ -373,7 +373,11 @@ function NodeIcon({ face, title, disabled, onSelect, onRemove }: {
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. */
+ /**
+ * The selected nodes carry different pictures. Nothing here shows which — the nodes do — and
+ * one cannot be put in the place of them all: that is a removal in all but name, and the way
+ * to it is to remove them and take one in, which the rest of the row offers plainly.
+ */
indeterminate: boolean;
/** The width they are drawn at, or `null` where the nodes disagree on one. */
width: number | null;
@@ -383,36 +387,33 @@ function NodeImage({ hasImage, indeterminate, width, onPick, onResize, onRemove
}) {
return (
<div className="mind-map-node-image">
- {indeterminate && <div className="mind-map-node-image-mixed">{t("mind-map.image-mixed")}</div>}
-
- <div className="mind-map-node-image-actions">
- {hasImage && (
- <SegmentedChoice
- options={buildImageWidthOptions()}
- // Nothing is highlighted where the nodes are drawn at different widths, or
- // where a map made elsewhere carries a width of its own.
- currentValue={width !== null ? String(nearestNodeImageWidth(width)) : ""}
- onChange={(width) => onResize(Number(width))}
- />
- )}
-
- <FormFileUploadActionButton
- icon={hasImage ? "bx bx-repost" : "bx bx-image-add"}
- text={hasImage ? t("mind-map.change-image") : t("mind-map.add-image")}
- onChange={(files) => {
- const file = files?.[0];
- if (file) onPick(file);
- }}
+ {hasImage && (
+ <SegmentedChoice
+ options={buildImageWidthOptions()}
+ // Nothing is highlighted where the nodes are drawn at different widths, or
+ // where a map made elsewhere carries a width of its own.
+ currentValue={width !== null ? String(nearestNodeImageWidth(width)) : ""}
+ onChange={(width) => onResize(Number(width))}
/>
+ )}
- {hasImage && (
- <ActionButton
- icon="bx bx-trash"
- text={t("mind-map.remove-image")}
- onClick={onRemove}
- />
- )}
- </div>
+ <FormFileUploadActionButton
+ icon={hasImage ? "bx bx-repost" : "bx bx-image-add"}
+ text={hasImage ? t("mind-map.change-image") : t("mind-map.add-image")}
+ disabled={indeterminate}
+ onChange={(files) => {
+ const file = files?.[0];
+ if (file) onPick(file);
+ }}
+ />
+
+ {hasImage && (
+ <ActionButton
+ icon="bx bx-trash"
+ text={t("mind-map.remove-image")}
+ onClick={onRemove}
+ />
+ )}
</div>
);
}