Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager: refactor, add placeholder for the new Space Usage tool

Adorian Doranb5c0eb2d8b6a
diff --git a/apps/client/src/services/content_manager.spec.ts b/apps/client/src/services/active_content.spec.ts
similarity index 99%
rename from apps/client/src/services/content_manager.spec.ts
rename to apps/client/src/services/active_content.spec.ts
index 833c19aeae..085f2c20b3 100644
--- a/apps/client/src/services/content_manager.spec.ts
+++ b/apps/client/src/services/active_content.spec.ts
@@ -2,7 +2,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import FBranch from "../entities/fbranch";
import { buildNote } from "../test/easy-froca";
-import attributeService from "./attributes";
import {
buildCategoryQuery,
buildLocationTree,
@@ -16,7 +15,8 @@ import {
parseFilterTriggers,
resolveProperties,
setCategoryEnabled
-} from "./content_manager";
+} from "./active_content";
+import attributeService from "./attributes";
import froca from "./froca";
import searchService from "./search";
diff --git a/apps/client/src/services/content_manager.ts b/apps/client/src/services/active_content.ts
similarity index 100%
rename from apps/client/src/services/content_manager.ts
rename to apps/client/src/services/active_content.ts
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 63d73e203b..a656785079 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2659,7 +2659,12 @@
"sort_by_title": "Title",
"sort_by_date_created": "Creation date",
"no_items": "No active content found.",
- "no_items_hint": "Scripts, themes, templates and snippets you create will be listed here."
+ "no_items_hint": "Scripts, themes, templates and snippets you create will be listed here.",
+ "section_active_content": "Active Content",
+ "section_space_usage": "Space Usage"
+ },
+ "space_usage": {
+ "coming_soon": "Space Usage is coming soon."
},
"note_language": {
"not_set": "No language set",
diff --git a/apps/client/src/widgets/react/SegmentedChoice.tsx b/apps/client/src/widgets/react/SegmentedChoice.tsx
new file mode 100644
index 0000000000..d61d0095e3
--- /dev/null
+++ b/apps/client/src/widgets/react/SegmentedChoice.tsx
@@ -0,0 +1,33 @@
+import clsx from "clsx";
+
+import Button, { ButtonGroup } from "./Button";
+
+interface SegmentedChoiceProps<T extends string> {
+ options: { value: T, label: string }[];
+ /**
+ * Kept a plain string rather than {@link T}: callers routinely hold the value as a raw option
+ * string, and a value outside the options simply highlights nothing.
+ */
+ currentValue: string;
+ onChange: (newValue: T) => void;
+}
+
+/**
+ * A row of buttons acting as one exclusive choice, the current one highlighted — for switching
+ * between a few named views or sections where a dropdown would hide the alternatives.
+ */
+export default function SegmentedChoice<T extends string>({ options, currentValue, onChange }: SegmentedChoiceProps<T>) {
+ return (
+ <ButtonGroup size="sm">
+ {options.map(({ value, label }) => (
+ <Button
+ key={value}
+ text={label}
+ size="small"
+ className={clsx(currentValue === value && "active")}
+ onClick={() => onChange(value)}
+ />
+ ))}
+ </ButtonGroup>
+ );
+}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.css b/apps/client/src/widgets/type_widgets/options/content_manager/active_content.css
similarity index 79%
rename from apps/client/src/widgets/type_widgets/options/content_manager.css
rename to apps/client/src/widgets/type_widgets/options/content_manager/active_content.css
index 06dc319b2c..9562c616f0 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager.css
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/active_content.css
@@ -1,28 +1,28 @@
/* Lives in the sticky page header, which supplies its own spacing. */
-.content-manager-toolbar {
+.active-content-toolbar {
display: flex;
align-items: center;
gap: 0.75em;
}
/* Space out the per-category lists, which bring no bottom margin of their own. */
-.content-manager-list .note-list.list-view {
+.active-content-list .note-list.list-view {
margin-bottom: 2em;
}
-.content-manager-filter {
+.active-content-filter {
flex-grow: 1;
max-width: 25em;
}
-.content-manager-toolbar-label {
+.active-content-toolbar-label {
/* Pushes the sort control to the trailing edge, leaving the filter box on the leading one. */
margin-inline-start: auto;
white-space: nowrap;
}
/* Values sit on the item's own line, so a row stays one line tall. */
-.content-manager-properties {
+.active-content-properties {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
@@ -32,29 +32,29 @@
/* `Badge` paints its background from `--color`. The selector repeats `.ext-badge` so the text colour
outranks the component's own `color: white`, which is unreadable on this light fill. */
-.ext-badge.content-manager-badge {
+.ext-badge.active-content-badge {
--color: var(--more-accented-background-color);
color: var(--main-text-color);
}
/* Free-form values (a path, an icon prefix) stay plain text, where the name gives them meaning. */
-.content-manager-property {
+.active-content-property {
font-size: .75em;
opacity: .75;
}
/* A note in several categories gets a strip each; the extra gap keeps them from reading as one run. */
-.content-manager-item-strip {
+.active-content-item-strip {
display: flex;
align-items: center;
gap: 0.5em;
}
-.content-manager-item-strip + .content-manager-item-strip {
+.active-content-item-strip + .active-content-item-strip {
margin-inline-start: 0.75em;
}
-.content-manager-item-count {
+.active-content-item-count {
flex-shrink: 0;
white-space: nowrap;
}
@@ -62,11 +62,11 @@
/* The item menu is portaled to <body> (so an open menu isn't counted as hovering its row), which
drops it below Bootstrap's modal when the page is opened in the settings dialog. Raised the same
way as the body-appended tooltips in style.css. */
-.content-manager-item-menu .dropdown-menu {
+.active-content-item-menu .dropdown-menu {
z-index: 32767;
}
-.content-manager-loading {
+.active-content-loading {
opacity: 0.7;
}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx
similarity index 88%
rename from apps/client/src/widgets/type_widgets/options/content_manager.tsx
rename to apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx
index 5d56c11742..7e551a90f3 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx
@@ -1,12 +1,9 @@
-import "./content_manager.css";
+import "./active_content.css";
-import clsx from "clsx";
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
-import appContext from "../../../components/app_context";
-import type FNote from "../../../entities/fnote";
-import attributeService from "../../../services/attributes";
-import branches from "../../../services/branches";
+import appContext from "../../../../components/app_context";
+import type FNote from "../../../../entities/fnote";
import {
buildLocationTree,
CONTENT_CATEGORIES,
@@ -18,21 +15,23 @@ import {
type LocationNode,
resolveProperties,
setCategoryEnabled
-} from "../../../services/content_manager";
-import debounce from "../../../services/debounce";
-import { t } from "../../../services/i18n";
-import { isMobile } from "../../../services/utils";
-import { ListView, type ListViewOptions } from "../../collections/legacy/ListOrGridView";
-import { Badge } from "../../react/Badge";
-import Button, { ButtonGroup } from "../../react/Button";
-import Dropdown from "../../react/Dropdown";
-import { FormListItem } from "../../react/FormList";
-import FormTextBox from "../../react/FormTextBox";
-import FormToggle from "../../react/FormToggle";
-import { useTriliumEvent, useTriliumOption } from "../../react/hooks";
-import NoItems from "../../react/NoItems";
-import type { TypeWidgetProps } from "../type_widget";
-import OptionsPageHeader from "./components/OptionsPageHeader";
+} from "../../../../services/active_content";
+import attributeService from "../../../../services/attributes";
+import branches from "../../../../services/branches";
+import debounce from "../../../../services/debounce";
+import { t } from "../../../../services/i18n";
+import { isMobile } from "../../../../services/utils";
+import { ListView, type ListViewOptions } from "../../../collections/legacy/ListOrGridView";
+import { Badge } from "../../../react/Badge";
+import Dropdown from "../../../react/Dropdown";
+import { FormListItem } from "../../../react/FormList";
+import FormTextBox from "../../../react/FormTextBox";
+import FormToggle from "../../../react/FormToggle";
+import { useTriliumEvent, useTriliumOption } from "../../../react/hooks";
+import NoItems from "../../../react/NoItems";
+import SegmentedChoice from "../../../react/SegmentedChoice";
+import OptionsPageHeader from "../components/OptionsPageHeader";
+import type { ContentManagerSectionProps } from "./index";
const NOOP = () => {};
@@ -46,7 +45,7 @@ const FILTER_DEBOUNCE_MS = 300;
function ContentItemMenu({ note }: { note: FNote }) {
return (
<Dropdown
- className="content-manager-item-menu"
+ className="active-content-item-menu"
buttonClassName="note-book-item-menu bx bx-dots-vertical-rounded"
hideToggleArrow noSelectButtonStyle noDropdownListStyle iconAction
// Out of the row and into the body: nested, the open menu would still count as hovering
@@ -91,10 +90,10 @@ function ItemDetail({ note, category, showCategory }: {
showCategory?: boolean
}) {
return (
- <span className="content-manager-properties">
+ <span className="active-content-properties">
{showCategory && (
<Badge
- className="content-manager-badge"
+ className="active-content-badge"
text={t(category.titleKey)}
tooltip={t("content_manager.property_category")}
/>
@@ -122,13 +121,13 @@ function ContentProperties({ note, category }: { note: FNote, category: ContentC
? values.map((value, index) => (
<Badge
key={`${titleKey}-${index}`}
- className="content-manager-badge"
+ className="active-content-badge"
text={value.titleKey ? t(value.titleKey) : value.text}
tooltip={t(titleKey)}
/>
))
: (
- <span key={titleKey} className="content-manager-property">
+ <span key={titleKey} className="active-content-property">
<strong>{t(titleKey)}:</strong>
{" "}
{values.map((value) => value.titleKey ? t(value.titleKey) : value.text).join(", ")}
@@ -183,7 +182,7 @@ const LIST_OPTIONS: ListViewOptions = {
pageSize: 50
};
-export default function ContentManagerSettings({ note }: TypeWidgetProps) {
+export default function ActiveContent({ note, sectionSwitcher }: ContentManagerSectionProps) {
const [ sortOrder, setSortOrder ] = useTriliumOption("contentManagerSortOrder");
const [ viewMode, setViewMode ] = useTriliumOption("contentManagerViewMode");
const [ typedFilter, setTypedFilter ] = useState("");
@@ -215,9 +214,9 @@ export default function ContentManagerSettings({ note }: TypeWidgetProps) {
<>
{/* In the header's own row rather than the page body, so the controls stay put as the
list scrolls beneath them. */}
- <OptionsPageHeader below={
- <div className="content-manager-toolbar">
- <div className="input-group content-manager-filter">
+ <OptionsPageHeader actions={sectionSwitcher} below={
+ <div className="active-content-toolbar">
+ <div className="input-group active-content-filter">
<FormTextBox
inputRef={filterRef}
placeholder={t("content_manager.filter_placeholder")}
@@ -234,7 +233,7 @@ export default function ContentManagerSettings({ note }: TypeWidgetProps) {
onClick={clearFilter}
/>
</div>
- <span className="content-manager-toolbar-label">{t("content_manager.view_mode")}</span>
+ <span className="active-content-toolbar-label">{t("content_manager.view_mode")}</span>
<SegmentedChoice
options={VIEW_MODES}
currentValue={viewMode}
@@ -244,7 +243,7 @@ export default function ContentManagerSettings({ note }: TypeWidgetProps) {
</div>
} />
- <div className="content-manager-list">
+ <div className="active-content-list">
<ContentList
pageNote={note}
categories={categories}
@@ -307,7 +306,7 @@ function LocationList({ pageNote, categories, highlightedTokens }: CategoryListP
if (!item) {
return (
- <span className="content-manager-property content-manager-item-count">
+ <span className="active-content-property active-content-item-count">
{t("content_manager.item_count", { count: itemCountByNoteId.get(note.noteId) ?? 0 })}
</span>
);
@@ -318,7 +317,7 @@ function LocationList({ pageNote, categories, highlightedTokens }: CategoryListP
// the user did not touch. The category is named here because the headings that
// would otherwise say it are gone.
return item.categories.map((category) => (
- <span key={category.id} className="content-manager-item-strip">
+ <span key={category.id} className="active-content-item-strip">
<ItemDetail note={note} category={category} showCategory />
<ContentToggle note={note} category={category} />
</span>
@@ -376,7 +375,7 @@ function ContentList({ pageNote, categories, highlightedTokens, viewMode }: {
viewMode: string
}) {
if (!categories) {
- return <p className="content-manager-loading">{t("content_manager.loading")}</p>;
+ return <p className="active-content-loading">{t("content_manager.loading")}</p>;
}
const populated = categories.filter(({ notes }) => notes.length > 0);
@@ -429,26 +428,6 @@ function CategoryList({ pageNote, categories, highlightedTokens }: CategoryListP
);
}
-function SegmentedChoice({ options, currentValue, onChange }: {
- options: { value: string, label: string }[];
- currentValue: string;
- onChange: (newValue: string) => void;
-}) {
- return (
- <ButtonGroup size="sm">
- {options.map(({ value, label }) => (
- <Button
- key={value}
- text={label}
- size="small"
- className={clsx(currentValue === value && "active")}
- onClick={() => onChange(value)}
- />
- ))}
- </ButtonGroup>
- );
-}
-
/** A single icon rather than a labelled pair of buttons, the order being set rarely. */
function SortOrderMenu({ currentValue, onChange }: { currentValue: string, onChange: (newValue: string) => void }) {
return (
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx
new file mode 100644
index 0000000000..a2bc1ef969
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx
@@ -0,0 +1,40 @@
+import type { ComponentChildren } from "preact";
+import { useState } from "preact/hooks";
+
+import { t } from "../../../../services/i18n";
+import SegmentedChoice from "../../../react/SegmentedChoice";
+import type { TypeWidgetProps } from "../../type_widget";
+import ActiveContent from "./active_content";
+import SpaceUsage from "./space_usage";
+
+type ContentManagerSection = "activeContent" | "spaceUsage";
+
+/** What the shell hands each section: the page's own props plus the switcher between sections. */
+export interface ContentManagerSectionProps extends TypeWidgetProps {
+ /**
+ * Rendered by the section inside its own header's title row, so the choice stays visible while
+ * the section's content scrolls beneath it.
+ */
+ sectionSwitcher: ComponentChildren;
+}
+
+/**
+ * The Content Manager page: a shell hosting the Active Content listing and the Space Usage tooling,
+ * switched by a segmented button. Each section owns its header and toolbar — the shell holds nothing
+ * but the choice, which starts over on Active Content each time the page opens.
+ */
+export default function ContentManagerSettings(props: TypeWidgetProps) {
+ const [ section, setSection ] = useState<ContentManagerSection>("activeContent");
+ const sectionSwitcher = (
+ <SegmentedChoice options={SECTIONS} currentValue={section} onChange={setSection} />
+ );
+
+ return section === "spaceUsage"
+ ? <SpaceUsage {...props} sectionSwitcher={sectionSwitcher} />
+ : <ActiveContent {...props} sectionSwitcher={sectionSwitcher} />;
+}
+
+const SECTIONS: { value: ContentManagerSection, label: string }[] = [
+ { value: "activeContent", label: t("content_manager.section_active_content") },
+ { value: "spaceUsage", label: t("content_manager.section_space_usage") }
+];
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage.tsx
new file mode 100644
index 0000000000..d6ef429b53
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage.tsx
@@ -0,0 +1,14 @@
+import { t } from "../../../../services/i18n";
+import NoItems from "../../../react/NoItems";
+import OptionsPageHeader from "../components/OptionsPageHeader";
+import type { ContentManagerSectionProps } from "./index";
+
+/** Placeholder section until the Space Usage views (overview treemap, browse charts) land. */
+export default function SpaceUsage({ sectionSwitcher }: ContentManagerSectionProps) {
+ return (
+ <>
+ <OptionsPageHeader actions={sectionSwitcher} />
+ <NoItems icon="bx bx-pie-chart-alt-2" text={t("space_usage.coming_soon")} />
+ </>
+ );
+}