Skip to content

Build your personal knowledge base with Trilium Notes

refactor(collections): remove the redundant Collection Properties ribbon tab

Elian Doranc22863025070
diff --git a/apps/client/src/widgets/note_bars/CollectionProperties.tsx b/apps/client/src/widgets/note_bars/CollectionProperties.tsx
index 110c42c1f4..d012e5d7bc 100644
--- a/apps/client/src/widgets/note_bars/CollectionProperties.tsx
+++ b/apps/client/src/widgets/note_bars/CollectionProperties.tsx
@@ -12,11 +12,10 @@ 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";
+import { useNoteLabel, useNoteProperty, useTriliumEvent } from "../react/hooks";
import Icon from "../react/Icon";
import { CheckBoxProperty, ViewProperty } from "../react/NotePropertyMenu";
import { bookPropertiesConfig } from "../ribbon/collection-properties-config";
-import { useViewType, VIEW_TYPE_MAPPINGS } from "../ribbon/CollectionPropertiesTab";
export const ICON_MAPPINGS: Record<ViewTypeOptions, string> = {
grid: "bx bxs-grid",
@@ -29,6 +28,17 @@ export const ICON_MAPPINGS: Record<ViewTypeOptions, string> = {
dashboard: "bx bxs-dashboard"
};
+export const VIEW_TYPE_MAPPINGS: Record<ViewTypeOptions, string> = {
+ grid: t("book_properties.grid"),
+ list: t("book_properties.list"),
+ calendar: t("book_properties.calendar"),
+ table: t("book_properties.table"),
+ geoMap: t("book_properties.geo-map"),
+ board: t("book_properties.board"),
+ presentation: t("book_properties.presentation"),
+ dashboard: t("book_properties.dashboard")
+};
+
const MAX_OPEN_TABS = 50;
export default function CollectionProperties({ note, centerChildren, rightChildren }: {
@@ -104,6 +114,13 @@ function OpenAllButton({ note, isOpening, setIsOpening }: {
);
}
+export function useViewType(note: FNote | null | undefined) {
+ const [ viewType, setViewType ] = useNoteLabel(note, "viewType");
+ const defaultViewType = (note?.type === "search" ? "list" : "grid");
+ const viewTypeWithDefault = (viewType ?? defaultViewType) as ViewTypeOptions;
+ return [ viewTypeWithDefault, setViewType ] as const;
+}
+
function ViewTypeSwitcher({ viewType, setViewType }: { viewType: ViewTypeOptions, setViewType: (newValue: ViewTypeOptions) => void }) {
// Keyboard shortcut
const dropdownContainerRef = useRef<HTMLDivElement>(null);
diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.css b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.css
deleted file mode 100644
index d3088992ff..0000000000
--- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.css
+++ /dev/null
@@ -1,29 +0,0 @@
-.book-properties-widget {
- padding: 12px 12px 6px 12px;
- display: flex;
- flex-wrap: wrap;
- gap: 15px;
- overflow: visible;
- align-items: center;
-}
-
-.book-properties-widget > * {
- flex-shrink: 0;
-}
-
-.book-properties-widget > .type-number > label {
- display: flex;
- align-items: baseline;
-}
-
-.book-properties-widget input[type="checkbox"] {
- margin-inline-end: 5px;
-}
-
-.book-properties-widget label {
- display: flex;
- justify-content: center;
- align-items: center;
- text-overflow: clip;
- white-space: nowrap;
-}
diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx
deleted file mode 100644
index b4ba72fd1b..0000000000
--- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx
+++ /dev/null
@@ -1,220 +0,0 @@
-import "./CollectionPropertiesTab.css";
-
-import { ComponentChildren, Fragment } from "preact";
-import { useContext, useMemo } from "preact/hooks";
-
-import FNote from "../../entities/fnote";
-import { isExperimentalFeatureEnabled } from "../../services/experimental_features";
-import { t } from "../../services/i18n";
-import { mapToKeyValueArray } from "../../services/utils";
-import { ViewTypeOptions } from "../collections/interface";
-import Button, { SplitButton } from "../react/Button";
-import FormCheckbox from "../react/FormCheckbox";
-import FormSelect, { FormSelectWithGroups } from "../react/FormSelect";
-import FormTextBox from "../react/FormTextBox";
-import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks";
-import { BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxGroup, ComboBoxItem, ComboBoxProperty, isPropertyVisible, NumberProperty, OptionGroupProperty, SplitButtonProperty } from "../react/NotePropertyMenu";
-import { ParentComponent } from "../react/react_utils";
-import { bookPropertiesConfig } from "./collection-properties-config";
-import { TabContext } from "./ribbon-interface";
-
-export const VIEW_TYPE_MAPPINGS: Record<ViewTypeOptions, string> = {
- grid: t("book_properties.grid"),
- list: t("book_properties.list"),
- calendar: t("book_properties.calendar"),
- table: t("book_properties.table"),
- geoMap: t("book_properties.geo-map"),
- board: t("book_properties.board"),
- presentation: t("book_properties.presentation"),
- dashboard: t("book_properties.dashboard")
-};
-
-const isNewLayout = isExperimentalFeatureEnabled("new-layout");
-
-export default function CollectionPropertiesTab({ note }: TabContext) {
- const [viewType, setViewType] = useViewType(note);
- const properties = bookPropertiesConfig[viewType].properties;
-
- return (
- <div className="book-properties-widget">
- {note && (
- <>
- {!isNewLayout && <CollectionTypeSwitcher viewType={viewType} setViewType={setViewType} />}
- <BookProperties viewType={viewType} note={note} properties={properties} />
- </>
- )}
- </div>
- );
-}
-
-export function useViewType(note: FNote | null | undefined) {
- const [ viewType, setViewType ] = useNoteLabel(note, "viewType");
- const defaultViewType = (note?.type === "search" ? "list" : "grid");
- const viewTypeWithDefault = (viewType ?? defaultViewType) as ViewTypeOptions;
- return [ viewTypeWithDefault, setViewType ] as const;
-}
-
-function CollectionTypeSwitcher({ viewType, setViewType }: { viewType: string, setViewType: (newValue: string) => void }) {
- const collectionTypes = useMemo(() => mapToKeyValueArray(VIEW_TYPE_MAPPINGS), []);
-
- return (
- <div style={{ display: "flex", alignItems: "baseline" }}>
- <span style={{ whiteSpace: "nowrap" }}>{t("book_properties.view_type")}:&nbsp; &nbsp;</span>
- <FormSelect
- currentValue={viewType ?? "grid"} onChange={setViewType}
- values={collectionTypes}
- keyProperty="key" titleProperty="value"
- />
- </div>
- );
-}
-
-function BookProperties({ note, properties }: { viewType: ViewTypeOptions, note: FNote, properties: BookProperty[] }) {
- return (
- <>
- {properties.filter((property) => isPropertyVisible(property, note)).map((property, index) => (
- <div key={index} className={`type-${property}`}>
- {mapPropertyView({ note, property })}
- </div>
- ))}
-
- <CheckboxPropertyView
- note={note} property={{
- bindToLabel: "includeArchived",
- label: t("book_properties.include_archived_notes"),
- type: "checkbox"
- }}
- />
- </>
- );
-}
-
-function mapPropertyView({ note, property }: { note: FNote, property: BookProperty }) {
- switch (property.type) {
- case "button":
- return <ButtonPropertyView note={note} property={property} />;
- case "split-button":
- return <SplitButtonPropertyView note={note} property={property} />;
- case "checkbox":
- return <CheckboxPropertyView note={note} property={property} />;
- case "number":
- return <NumberPropertyView note={note} property={property} />;
- case "combobox":
- return <ComboBoxPropertyView note={note} property={property} />;
- case "option-group":
- return <OptionGroupPropertyView note={note} property={property} />;
- case "submenu":
- // The ribbon is a flat strip, so a submenu is flattened to its (visible) children inline.
- return (
- <>
- {property.children.filter((child) => isPropertyVisible(child, note)).map((child, index) => (
- <Fragment key={index}>{mapPropertyView({ note, property: child })}</Fragment>
- ))}
- </>
- );
- }
-}
-
-function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) {
- const parentComponent = useContext(ParentComponent);
-
- return <Button
- text={property.label}
- title={property.title}
- icon={property.icon}
- onClick={() => {
- if (!parentComponent) return;
- property.onClick({
- note,
- triggerCommand: parentComponent.triggerCommand.bind(parentComponent)
- });
- }}
- />;
-}
-
-function SplitButtonPropertyView({ note, property }: { note: FNote, property: SplitButtonProperty }) {
- const parentComponent = useContext(ParentComponent);
- const clickContext = parentComponent && {
- note,
- triggerCommand: parentComponent.triggerCommand.bind(parentComponent)
- };
-
- const ItemsComponent = property.items;
- return <SplitButton
- text={property.label}
- icon={property.icon}
- title={property.title}
- onClick={() => clickContext && property.onClick(clickContext)}
- >
- {parentComponent && <ItemsComponent note={note} parentComponent={parentComponent} />}
- </SplitButton>;
-}
-
-function CheckboxPropertyView({ note, property }: { note: FNote, property: CheckBoxProperty }) {
- const [ value, setValue ] = useNoteLabelBoolean(note, property.bindToLabel);
-
- return (
- <FormCheckbox
- label={property.label}
- currentValue={value} onChange={setValue}
- />
- );
-}
-
-function NumberPropertyView({ note, property }: { note: FNote, property: NumberProperty }) {
- //@ts-expect-error Interop with text box which takes in string values even for numbers.
- const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
- const disabled = property.disabled?.(note);
-
- return (
- <LabelledEntry label={property.label}>
- <FormTextBox
- type="number"
- currentValue={value ?? ""} onChange={setValue}
- style={{ width: (property.width ?? 100) }}
- min={property.min ?? 0}
- disabled={disabled}
- />
- </LabelledEntry>
- );
-}
-
-function ComboBoxPropertyView({ note, property }: { note: FNote, property: ComboBoxProperty }) {
- const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
-
- return (
- <LabelledEntry label={property.label}>
- <FormSelectWithGroups
- values={property.options.filter(i => !("type" in i)) as (ComboBoxItem | ComboBoxGroup)[]}
- keyProperty="value" titleProperty="label"
- currentValue={value ?? property.defaultValue} onChange={setValue}
- />
- </LabelledEntry>
- );
-}
-
-function OptionGroupPropertyView({ note, property }: { note: FNote, property: OptionGroupProperty }) {
- const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
-
- return (
- <LabelledEntry label={property.label}>
- <FormSelectWithGroups
- values={property.options}
- keyProperty="value" titleProperty="label"
- currentValue={value ?? property.defaultValue} onChange={setValue}
- />
- </LabelledEntry>
- );
-}
-
-function LabelledEntry({ label, children }: { label: string, children: ComponentChildren }) {
- return (
- <>
- <label>
- {label}
- &nbsp;&nbsp;
- {children}
- </label>
- </>
- );
-}
diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
index c50b2bac09..f5cf96a9f2 100644
--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts
+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
@@ -1,7 +1,6 @@
import { t } from "../../services/i18n";
import options from "../../services/options";
import BasicPropertiesTab from "./BasicPropertiesTab";
-import CollectionPropertiesTab from "./CollectionPropertiesTab";
import EditedNotesTab from "./EditedNotesTab";
import FilePropertiesTab from "./FilePropertiesTab";
import FormattingToolbar, { showFormattingToolbar } from "./FormattingToolbar";
@@ -50,13 +49,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
show: ({ note }) => note?.hasOwnedLabel("dateNote"),
activate: () => options.is("editedNotesOpenInRibbon")
},
- {
- title: t("book_properties.book_properties"),
- icon: "bx bx-book",
- content: CollectionPropertiesTab,
- show: ({ note }) => (note?.type === "book" || note?.type === "search"),
- toggleCommand: "toggleRibbonTabBookProperties"
- },
{
title: t("note_properties.info"),
icon: "bx bx-info-square",