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
refactor(client): remove the ribbon's attribute tabs
Elian Doran66c9ddb8e268
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex dd1cbbdfa6..b219dece60 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1342,7 +1342,6 @@},"inherited_attribute_list": {"title": "Inherited Attributes",- "no_inherited_attributes": "No inherited attributes.","none": "none"},"note_info_widget": {@@ -1388,9 +1387,6 @@"this_note_was_originally_taken_from": "This note was originally taken from:","info": "Info"},- "owned_attribute_list": {- "owned_attributes": "Owned Attributes"- },"promoted_attributes": {"promoted_attributes": "Promoted Attributes","create_attribute": "Create a new attribute",diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.css b/apps/client/src/widgets/attribute_widgets/AttributeEditor.csssimilarity index 100%rename from apps/client/src/widgets/ribbon/components/AttributeEditor.cssrename to apps/client/src/widgets/attribute_widgets/AttributeEditor.cssdiff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.spec.tsx b/apps/client/src/widgets/attribute_widgets/AttributeEditor.spec.tsxsimilarity index 100%rename from apps/client/src/widgets/ribbon/components/AttributeEditor.spec.tsxrename to apps/client/src/widgets/attribute_widgets/AttributeEditor.spec.tsxdiff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/attribute_widgets/AttributeEditor.tsxsimilarity index 94%rename from apps/client/src/widgets/ribbon/components/AttributeEditor.tsxrename to apps/client/src/widgets/attribute_widgets/AttributeEditor.tsxindex 28ebe92566..1042a147f7 100644--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx+++ b/apps/client/src/widgets/attribute_widgets/AttributeEditor.tsx@@ -6,26 +6,26 @@ import clsx from "clsx";import { createPortal, RefObject } from "preact";import { useEffect, useImperativeHandle, useMemo, useRef, useState } from "preact/hooks";-import type { CommandData, FilteredCommandNames } from "../../../components/app_context";-import FAttribute from "../../../entities/fattribute";-import FNote from "../../../entities/fnote";-import contextMenu from "../../../menus/context_menu";-import attribute_parser, { Attribute } from "../../../services/attribute_parser";-import attribute_renderer from "../../../services/attribute_renderer";-import attributes from "../../../services/attributes";-import froca from "../../../services/froca";-import { t } from "../../../services/i18n";-import { ATTRIBUTE_HELP_PAGE } from "../../../services/in_app_help";-import link from "../../../services/link";-import server from "../../../services/server";-import { isIMEComposing } from "../../../services/shortcuts";-import { escapeQuotes, getErrorMessage } from "../../../services/utils";-import AttributeDetailWidget, { AttributeNameSuggestion, fetchAttributeNames } from "../../attribute_widgets/attribute_detail";-import ActionButton from "../../react/ActionButton";-import CKEditor, { CKEditorApi } from "../../react/CKEditor";-import HelpDropdown from "../../react/HelpDropdown";-import { useLegacyImperativeHandlers, useLegacyWidget, useTriliumEvent } from "../../react/hooks";-import { createAutocompleteMentionList, createNoteMentionList } from "../../type_widgets/text/mention_list_view";+import type { CommandData, FilteredCommandNames } from "../../components/app_context";+import FAttribute from "../../entities/fattribute";+import FNote from "../../entities/fnote";+import contextMenu from "../../menus/context_menu";+import attribute_parser, { Attribute } from "../../services/attribute_parser";+import attribute_renderer from "../../services/attribute_renderer";+import attributes from "../../services/attributes";+import froca from "../../services/froca";+import { t } from "../../services/i18n";+import { ATTRIBUTE_HELP_PAGE } from "../../services/in_app_help";+import link from "../../services/link";+import server from "../../services/server";+import { isIMEComposing } from "../../services/shortcuts";+import { escapeQuotes, getErrorMessage } from "../../services/utils";+import ActionButton from "../react/ActionButton";+import CKEditor, { CKEditorApi } from "../react/CKEditor";+import HelpDropdown from "../react/HelpDropdown";+import { useLegacyImperativeHandlers, useLegacyWidget, useTriliumEvent } from "../react/hooks";+import { createAutocompleteMentionList, createNoteMentionList } from "../type_widgets/text/mention_list_view";+import AttributeDetailWidget, { AttributeNameSuggestion, fetchAttributeNames } from "./attribute_detail";import AttributeHelp from "./AttributeHelp";type AttributeCommandNames = FilteredCommandNames<CommandData>;diff --git a/apps/client/src/widgets/ribbon/components/AttributeHelp.css b/apps/client/src/widgets/attribute_widgets/AttributeHelp.csssimilarity index 100%rename from apps/client/src/widgets/ribbon/components/AttributeHelp.cssrename to apps/client/src/widgets/attribute_widgets/AttributeHelp.cssdiff --git a/apps/client/src/widgets/ribbon/components/AttributeHelp.tsx b/apps/client/src/widgets/attribute_widgets/AttributeHelp.tsxsimilarity index 85%rename from apps/client/src/widgets/ribbon/components/AttributeHelp.tsxrename to apps/client/src/widgets/attribute_widgets/AttributeHelp.tsxindex bfea90dba5..8481a484c2 100644--- a/apps/client/src/widgets/ribbon/components/AttributeHelp.tsx+++ b/apps/client/src/widgets/attribute_widgets/AttributeHelp.tsx@@ -1,7 +1,7 @@import "./AttributeHelp.css";-import { t } from "../../../services/i18n";-import { RawHtmlBlock } from "../../react/RawHtml";+import { t } from "../../services/i18n";+import { RawHtmlBlock } from "../react/RawHtml";/*** Quick reference on how to type attributes into the attribute editor. Rendered inside adiff --git a/apps/client/src/widgets/ribbon/InheritedAttributesTab.css b/apps/client/src/widgets/attribute_widgets/InheritedAttributes.csssimilarity index 100%rename from apps/client/src/widgets/ribbon/InheritedAttributesTab.cssrename to apps/client/src/widgets/attribute_widgets/InheritedAttributes.cssdiff --git a/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx b/apps/client/src/widgets/attribute_widgets/InheritedAttributes.tsxsimilarity index 89%rename from apps/client/src/widgets/ribbon/InheritedAttributesTab.tsxrename to apps/client/src/widgets/attribute_widgets/InheritedAttributes.tsxindex cc55637ced..c5cdc6a3d6 100644--- a/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx+++ b/apps/client/src/widgets/attribute_widgets/InheritedAttributes.tsx@@ -1,23 +1,24 @@-import "./InheritedAttributesTab.css";+import "./InheritedAttributes.css";import { createPortal } from "preact";import { useEffect, useRef, useState } from "preact/hooks";import FAttribute from "../../entities/fattribute";+import FNote from "../../entities/fnote";import attribute_renderer from "../../services/attribute_renderer";import attributes from "../../services/attributes";import { t } from "../../services/i18n";-import { AttributeDetail, AttributeDetailOpts } from "../attribute_widgets/attribute_detail";import { useTriliumEvent } from "../react/hooks";import RawHtml from "../react/RawHtml";import { joinElements } from "../react/react_utils";-import { TabContext } from "./ribbon-interface";+import { AttributeDetail, AttributeDetailOpts } from "./attribute_detail";-type InheritedAttributesTabArgs = Pick<TabContext, "note" | "componentId"> & {- emptyListString?: string;-};+interface InheritedAttributesProps {+ note: FNote | null | undefined;+ componentId: string;+}-export default function InheritedAttributesTab({ note, componentId, emptyListString }: InheritedAttributesTabArgs) {+export default function InheritedAttributes({ note, componentId }: InheritedAttributesProps) {const [ inheritedAttributes, setInheritedAttributes ] = useState<FAttribute[]>();const containerRef = useRef<HTMLDivElement>(null);const [ detailOpts, setDetailOpts ] = useState<AttributeDetailOpts | null>(null);@@ -84,7 +85,7 @@ export default function InheritedAttributesTab({ note, componentId, emptyListStr/>)), " ")) : (- <>{t(emptyListString ?? "inherited_attribute_list.no_inherited_attributes")}</>+ <>{t("inherited_attribute_list.none")}</>)}</div>diff --git a/apps/client/src/widgets/layout/StatusBar.spec.tsx b/apps/client/src/widgets/layout/StatusBar.spec.tsxindex 4b75066b63..f49afef82a 100644--- a/apps/client/src/widgets/layout/StatusBar.spec.tsx+++ b/apps/client/src/widgets/layout/StatusBar.spec.tsx@@ -18,7 +18,7 @@ vi.mock("../react/hooks", async (importOriginal) => ({// The attributes panel builds its editor on CKEditor, which is a legacy widget wanting a real parent// component to be a child of. What the panel is here is a panel that is up or is not.-vi.mock("../ribbon/components/AttributeEditor", async () => {+vi.mock("../attribute_widgets/AttributeEditor", async () => {const { h } = await import("preact");return { default: () => h("div", { class: "attribute-editor-stub" }) };diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsxindex 11db339014..c18e0861db 100644--- a/apps/client/src/widgets/layout/StatusBar.tsx+++ b/apps/client/src/widgets/layout/StatusBar.tsx@@ -16,6 +16,9 @@ import { NOTE_TYPES } from "../../services/note_types";import server from "../../services/server";import { openInAppHelpFromUrl } from "../../services/utils";import { formatDateTime } from "../../utils/formatters";+import AttributeEditor, { AttributeEditorImperativeHandlers } from "../attribute_widgets/AttributeEditor";+import AttributeHelp from "../attribute_widgets/AttributeHelp";+import InheritedAttributes from "../attribute_widgets/InheritedAttributes";import { ContentLanguagesModal, useLanguageSwitcher } from "../dialogs/content_languages";import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";import Dropdown, { type DropdownHandle, DropdownPanel, type DropdownPanelProps } from "../react/Dropdown";@@ -25,9 +28,6 @@ import { useActiveNoteContext, useLegacyImperativeHandlers, useNoteLabel, useNotimport Icon from "../react/Icon";import LinkButton from "../react/LinkButton";import { ParentComponent } from "../react/react_utils";-import AttributeEditor, { AttributeEditorImperativeHandlers } from "../ribbon/components/AttributeEditor";-import AttributeHelp from "../ribbon/components/AttributeHelp";-import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";import SimilarNotesTab from "../ribbon/SimilarNotesTab";@@ -453,7 +453,7 @@ function AttributesPane({ note, noteContext, attributesShown, setAttributesShownhelpContent={<AttributeHelp />}><span class="attributes-panel-label">{t("inherited_attribute_list.title")}</span>- <InheritedAttributesTab {...context} emptyListString="inherited_attribute_list.none" />+ <InheritedAttributes {...context} />{editorMounted && <AttributeEditor{...context}diff --git a/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsx b/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsxdeleted file mode 100644index b80d748b57..0000000000--- a/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsx+++ /dev/null@@ -1,30 +0,0 @@-import { useMemo, useRef } from "preact/hooks";--import { useLegacyImperativeHandlers, useTriliumEvents } from "../react/hooks";-import AttributeEditor, { AttributeEditorImperativeHandlers } from "./components/AttributeEditor";-import { TabContext } from "./ribbon-interface";--export default function OwnedAttributesTab({ note, hidden, activate, ntxId, ...restProps }: TabContext) {- const api = useRef<AttributeEditorImperativeHandlers>(null);-- useTriliumEvents([ "addNewLabel", "addNewRelation" ], ({ ntxId: eventNtxId }) => {- if (ntxId === eventNtxId) {- activate();- }- });-- // Interaction with the attribute editor.- useLegacyImperativeHandlers(useMemo(() => ({- saveAttributesCommand: () => api.current?.save(),- reloadAttributesCommand: () => api.current?.refresh(),- updateAttributeListCommand: ({ attributes }) => api.current?.renderOwnedAttributes(attributes)- }), [ api ]));-- return (- <div className="attribute-list">- { note && (- <AttributeEditor api={api} ntxId={ntxId} note={note} {...restProps} hidden={hidden} />- )}- </div>- );-}diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsxindex b84f21969e..c282be24f7 100644--- a/apps/client/src/widgets/ribbon/Ribbon.tsx+++ b/apps/client/src/widgets/ribbon/Ribbon.tsx@@ -95,7 +95,7 @@ export default function Ribbon() {<div className="ribbon-body-container">{computedTabs && computedTabs.map(tab => {const isActive = tab.index === activeTabIndex;- if (!isActive && !tab.stayInDom) {+ if (!isActive) {return;}diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.tsindex 93b282cb10..ae42990610 100644--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts@@ -3,12 +3,10 @@ import options from "../../services/options";import EditedNotesTab from "./EditedNotesTab";import FilePropertiesTab from "./FilePropertiesTab";import ImagePropertiesTab from "./ImagePropertiesTab";-import InheritedAttributesTab from "./InheritedAttributesTab";import NoteInfoTab from "./NoteInfoTab";import NoteMapTab from "./NoteMapTab";import NotePathsTab from "./NotePathsTab";import NotePropertiesTab from "./NotePropertiesTab";-import OwnedAttributesTab from "./OwnedAttributesTab";import { TabConfiguration } from "./ribbon-interface";import ScriptTab from "./ScriptTab";import SearchDefinitionTab from "./SearchDefinitionTab";@@ -61,21 +59,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [toggleCommand: "toggleRibbonTabImageProperties",activate: true,},- {- title: t("owned_attribute_list.owned_attributes"),- icon: "bx bx-list-check",- content: OwnedAttributesTab,- show: ({note}) => !note?.isLaunchBarConfig(),- toggleCommand: "toggleRibbonTabOwnedAttributes",- stayInDom: true- },- {- title: t("inherited_attribute_list.title"),- icon: "bx bx-list-plus",- content: InheritedAttributesTab,- show: ({note}) => !note?.isLaunchBarConfig(),- toggleCommand: "toggleRibbonTabInheritedAttributes"- },{title: t("note_paths.title"),icon: "bx bx-collection",diff --git a/apps/client/src/widgets/ribbon/ribbon-interface.ts b/apps/client/src/widgets/ribbon/ribbon-interface.tsindex b6407b7506..7e8365ead2 100644--- a/apps/client/src/widgets/ribbon/ribbon-interface.ts+++ b/apps/client/src/widgets/ribbon/ribbon-interface.ts@@ -27,10 +27,6 @@ export interface TabConfiguration {show: boolean | ((context: TitleContext) => Promise<boolean | null | undefined> | boolean | null | undefined);toggleCommand?: KeyboardActionNames;activate?: boolean | ((context: TitleContext) => boolean);- /**- * By default the tab content will not be rendered unless the tab is active (i.e. selected by the user). Setting to `true` will ensure that the tab is rendered even when inactive, for cases where the tab needs to be accessible at all times (e.g. for the detached editor toolbar) or if event handling is needed.- */- stayInDom?: boolean;}export async function shouldShowTab(showConfig: TabConfiguration["show"], context: TitleContext) {