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(search): add an option to open all results (closes #5376)
Elian Doran524f8df8661e
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex c47debcdfe..af8a606f1c 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -806,7 +806,11 @@"board": "Board","presentation": "Presentation","include_archived_notes": "Show archived notes",- "hide_child_notes": "Hide child notes in tree"+ "hide_child_notes": "Hide child notes in tree",+ "open_all_in_tabs": "Open all",+ "open_all_in_tabs_tooltip": "Open all results in new tabs",+ "open_all_confirm": "This will open {{count}} notes in new tabs. Continue?",+ "open_all_too_many": "Too many results ({{count}}). Maximum is {{max}}."},"edited_notes": {"no_edited_notes_found": "No edited notes on this day yet...",diff --git a/apps/client/src/widgets/note_bars/CollectionProperties.tsx b/apps/client/src/widgets/note_bars/CollectionProperties.tsxindex 66bfb32c45..14f8685eaa 100644--- a/apps/client/src/widgets/note_bars/CollectionProperties.tsx+++ b/apps/client/src/widgets/note_bars/CollectionProperties.tsx@@ -2,10 +2,13 @@ import "./CollectionProperties.css";import { t } from "i18next";import { ComponentChildren } from "preact";-import { useRef } from "preact/hooks";+import { useRef, useState } from "preact/hooks";import FNote from "../../entities/fnote";+import appContext from "../../components/app_context";+import dialogService from "../../services/dialog";import { ViewTypeOptions } from "../collections/interface";+import ActionButton from "../react/ActionButton";import Dropdown from "../react/Dropdown";import { FormDropdownDivider, FormListItem } from "../react/FormList";import { useNoteProperty, useTriliumEvent } from "../react/hooks";@@ -24,6 +27,8 @@ export const ICON_MAPPINGS: Record<ViewTypeOptions, string> = {presentation: "bx bx-rectangle"};+const MAX_OPEN_TABS = 50;+export default function CollectionProperties({ note, centerChildren, rightChildren }: {note: FNote;centerChildren?: ComponentChildren;@@ -31,6 +36,7 @@ export default function CollectionProperties({ note, centerChildren, rightChildr}) {const [ viewType, setViewType ] = useViewType(note);const noteType = useNoteProperty(note, "type");+ const [ isOpening, setIsOpening ] = useState(false);return ([ "book", "search" ].includes(noteType ?? "") &&<div className="collection-properties">@@ -43,11 +49,59 @@ export default function CollectionProperties({ note, centerChildren, rightChildr</div><div className="right-container">{rightChildren}+ {noteType === "search" && (+ <OpenAllButton note={note} isOpening={isOpening} setIsOpening={setIsOpening} />+ )}</div></div>);}+function OpenAllButton({ note, isOpening, setIsOpening }: {+ note: FNote;+ isOpening: boolean;+ setIsOpening: (value: boolean) => void;+}) {+ const noteIds = note.getChildNoteIds();+ const count = noteIds.length;++ const handleOpenAll = async () => {+ if (count === 0) return;++ if (count > MAX_OPEN_TABS) {+ await dialogService.info(t("book_properties.open_all_too_many", { count, max: MAX_OPEN_TABS }));+ return;+ }++ if (count > 10) {+ const confirmed = await dialogService.confirm(t("book_properties.open_all_confirm", { count }));+ if (!confirmed) return;+ }++ setIsOpening(true);+ try {+ for (let i = 0; i < noteIds.length; i++) {+ const noteId = noteIds[i];+ const isLast = i === noteIds.length - 1;+ await appContext.tabManager.openTabWithNoteWithHoisting(noteId, {+ activate: isLast+ });+ }+ } finally {+ setIsOpening(false);+ }+ };++ return (+ <ActionButton+ icon={isOpening ? "bx bx-loader-alt bx-spin" : "bx bx-window-open"}+ text={t("book_properties.open_all_in_tabs_tooltip")}+ onClick={handleOpenAll}+ disabled={count === 0 || isOpening}+ />+ );+}+function ViewTypeSwitcher({ viewType, setViewType }: { viewType: ViewTypeOptions, setViewType: (newValue: ViewTypeOptions) => void }) {// Keyboard shortcutconst dropdownContainerRef = useRef<HTMLDivElement>(null);