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(collections): warn when dropped archived notes stay hidden
Elian Doranf8e9d95dd801
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 773ad600e2..749daa282c 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1152,7 +1152,9 @@"book": {"no_children_help": "This collection doesn't have any child notes so there's nothing to display.","drag_locked_title": "Locked for editing",- "drag_locked_message": "Dragging not allowed since the collection is locked for editing."+ "drag_locked_message": "Dragging not allowed since the collection is locked for editing.",+ "archived_notes_hidden_one": "An archived note was copied here but stays hidden until you enable \"Show archived notes\".",+ "archived_notes_hidden_other": "{{count}} archived notes were copied here but stay hidden until you enable \"Show archived notes\"."},"editable_code": {"placeholder": "Type the content of your code note here..."diff --git a/apps/client/src/widgets/collections/dashboard/index.tsx b/apps/client/src/widgets/collections/dashboard/index.tsxindex 0a9a1a271a..8b6b35e38d 100644--- a/apps/client/src/widgets/collections/dashboard/index.tsx+++ b/apps/client/src/widgets/collections/dashboard/index.tsx@@ -12,7 +12,7 @@ import froca from "../../../services/froca";import { t } from "../../../services/i18n";import CollectionProperties from "../../note_bars/CollectionProperties";import ActionButton from "../../react/ActionButton";-import { useElementSize, useNoteLabelBoolean, useNoteTreeDrag, useSpacedUpdate } from "../../react/hooks";+import { useCollectionTreeDrag, useElementSize, useNoteLabelBoolean, useSpacedUpdate } from "../../react/hooks";import Icon from "../../react/Icon";import NoteLink from "../../react/NoteLink";import { ViewModeProps } from "../interface";@@ -39,7 +39,7 @@ export default function DashboardView({ note, noteIds, viewConfig, saveConfig, hconst notes = useDashboardNotes(noteIds);const isCollapsed = useIsCollapsed(containerRef);- const dropPositionsRef = useNoteTreeDropToDashboard(note, scrollContainerRef, containerRef, gridRef);+ const dropPositionsRef = useNoteTreeDropToDashboard(note, includeArchived, scrollContainerRef, containerRef, gridRef);useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, gridRef, dropPositionsRef, isCollapsed });return (@@ -264,22 +264,19 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g* the dashboard and the first one is positioned under the cursor. Returns a ref holding the drop* positions of the freshly cloned notes, which the reconcile effect consumes (once) when it* promotes them to grid widgets — kept out of savedWidgetsRef so persistLayout still saves them. */-function useNoteTreeDropToDashboard(note: FNote, dropAreaRef: RefObject<HTMLDivElement>, gridContainerRef: RefObject<HTMLDivElement>, gridRef: RefObject<GridStack | null>) {+function useNoteTreeDropToDashboard(note: FNote, includeArchived: boolean, dropAreaRef: RefObject<HTMLDivElement>, gridContainerRef: RefObject<HTMLDivElement>, gridRef: RefObject<GridStack | null>) {const dropPositionsRef = useRef<WidgetLayouts>({});- useNoteTreeDrag(dropAreaRef, {+ useCollectionTreeDrag(dropAreaRef, {dragEnabled: true,- dragNotEnabledMessage: {- icon: "bx bx-lock-alt",- title: t("book.drag_locked_title"),- message: t("book.drag_locked_message")- },+ includeArchived,async callback(treeData, e) {const grid = gridRef.current;const gridContainer = gridContainerRef.current;- if (!grid || !gridContainer) return;+ if (!grid || !gridContainer) return [];const dropCell = computeDropCell(grid, gridContainer, e);+ const addedNoteIds: string[] = [];let isFirstNewNote = true;for (const { noteId } of treeData) {const childNote = await froca.getNote(noteId, true);@@ -295,7 +292,9 @@ function useNoteTreeDropToDashboard(note: FNote, dropAreaRef: RefObject<HTMLDivE}isFirstNewNote = false;await branches.cloneNoteToParentNote(noteId, note.noteId);+ addedNoteIds.push(noteId);}+ return addedNoteIds;}});diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex 2dc2e54795..4d0f86b8c0 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -16,7 +16,7 @@ import { escapeHtml } from "../../../services/utils";import CollectionProperties from "../../note_bars/CollectionProperties";import ActionButton from "../../react/ActionButton";import { ButtonOrActionButton } from "../../react/Button";-import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";+import { useCollectionTreeDrag, useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";import { ViewModeProps } from "../interface";import { createNewNote, moveMarker } from "./api";import openContextMenu, { openMapContextMenu } from "./context_menu";@@ -47,6 +47,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMconst [ hasScale ] = useNoteLabelBoolean(note, "map:scale");const [ hideLabels ] = useNoteLabelBoolean(note, "map:hideLabels");const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");+ const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");const [ notes, setNotes ] = useState<FNote[]>([]);const layerData = useLayerData(note);const spacedUpdate = useSpacedUpdate(() => {@@ -104,16 +105,12 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM// Draggingconst containerRef = useRef<HTMLDivElement>(null);const apiRef = useRef<L.Map>(null);- useNoteTreeDrag(containerRef, {+ useCollectionTreeDrag(containerRef, {dragEnabled: !isReadOnly,- dragNotEnabledMessage: {- icon: "bx bx-lock-alt",- title: t("book.drag_locked_title"),- message: t("book.drag_locked_message")- },+ includeArchived,async callback(treeData, e) {const api = apiRef.current;- if (!note || !api || isReadOnly) return;+ if (!note || !api || isReadOnly) return [];const { noteId } = treeData[0];@@ -126,10 +123,12 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMconst parents = targetNote?.getParentNoteIds();if (parents?.includes(note.noteId)) {await moveMarker(noteId, latlng);- } else {- await branches.cloneNoteToParentNote(noteId, note.noteId);- await moveMarker(noteId, latlng);+ return [];}++ await branches.cloneNoteToParentNote(noteId, note.noteId);+ await moveMarker(noteId, latlng);+ return [ noteId ];}});diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex b36e77fac7..d0edb8b616 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -13,6 +13,7 @@ import FBlob from "../../entities/fblob";import FNote from "../../entities/fnote";import attributes from "../../services/attributes";import froca from "../../services/froca";+import { t } from "../../services/i18n";import keyboard_actions from "../../services/keyboard_actions";import { parseNavigationStateFromUrl, ViewScope } from "../../services/link";import options, { type OptionValue } from "../../services/options";@@ -1163,6 +1164,48 @@ export function useNoteTreeDrag(containerRef: MutableRef<HTMLElement | null | un}, [ containerRef, callback ]);}+/**+ * Collection-specific wrapper around {@link useNoteTreeDrag}. It standardizes the drag-locked+ * message shared by every collection view and, when the collection hides archived notes, warns the+ * user after a drop that any archived notes were cloned in but stay hidden until "Show archived+ * notes" is enabled (otherwise the note silently has no effect on the view).+ *+ * The `callback` should return the IDs of the notes it actually added (cloned) to the collection so+ * the warning only mentions newly-copied notes, not ones that were already present.+ */+export function useCollectionTreeDrag(containerRef: MutableRef<HTMLElement | null | undefined>, { dragEnabled, includeArchived, callback }: {+ dragEnabled: boolean,+ includeArchived: boolean,+ callback: (data: DragData[], e: DragEvent) => string[] | Promise<string[]>+}) {+ const wrappedCallback = useCallback(async (data: DragData[], e: DragEvent) => {+ const addedNoteIds = await callback(data, e);+ if (!includeArchived && addedNoteIds?.length) {+ await warnIfArchivedNotesHidden(addedNoteIds);+ }+ }, [ includeArchived, callback ]);++ useNoteTreeDrag(containerRef, {+ dragEnabled,+ dragNotEnabledMessage: {+ icon: "bx bx-lock-alt",+ title: t("book.drag_locked_title"),+ message: t("book.drag_locked_message")+ },+ callback: wrappedCallback+ });+}++/** Toast a heads-up when freshly cloned notes are archived and the collection hides them. */+async function warnIfArchivedNotesHidden(addedNoteIds: string[]) {+ const notes = await froca.getNotes(addedNoteIds);+ const archivedCount = notes.filter((note) => note.isArchived).length;+ if (!archivedCount) {+ return;+ }+ toast.showMessage(t("book.archived_notes_hidden", { count: archivedCount }), 5000, "bx bx-archive");+}+/*** Long-press + contextmenu handler bundle. `contextmenu` covers desktop right-click and* Android Chrome long-press; explicit touch handlers cover iOS/WKWebView where