diff --git a/apps/client/src/widgets/react/FormSelect.tsx b/apps/client/src/widgets/react/FormSelect.tsx index 3f11c3f98..639cd5bde 100644 --- a/apps/client/src/widgets/react/FormSelect.tsx +++ b/apps/client/src/widgets/react/FormSelect.tsx @@ -39,15 +39,22 @@ export default function FormSelect({ name, id, onChange, style, ...restProps /** * Similar to {@link FormSelect}, but the top-level elements are actually groups. */ -export function FormSelectWithGroups({ name, id, values, keyProperty, titleProperty, currentValue, onChange }: FormSelectProps>) { +export function FormSelectWithGroups({ name, id, values, keyProperty, titleProperty, currentValue, onChange }: FormSelectProps | T>) { return ( - {values.map(({ title, items }) => { - return ( - - - - ); + {values.map((item) => { + if (!item) return <>; + if (typeof item === "object" && "items" in item) { + return ( + + + + ); + } else { + return ( + + ) + } })} ) diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx index 04f6ba3ff..77853e617 100644 --- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx +++ b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx @@ -1,11 +1,11 @@ import { useContext, useMemo } from "preact/hooks"; import { t } from "../../services/i18n"; import { ViewTypeOptions } from "../../services/note_list_renderer"; -import FormSelect from "../react/FormSelect"; +import FormSelect, { FormSelectWithGroups } from "../react/FormSelect"; import { TabContext } from "./ribbon-interface"; import { mapToKeyValueArray } from "../../services/utils"; import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks"; -import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, NumberProperty } from "../ribbon_widgets/book_properties_config"; +import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxGroup, ComboBoxProperty, NumberProperty } from "../ribbon_widgets/book_properties_config"; import Button from "../react/Button"; import { ParentComponent } from "../react/react_utils"; import FNote from "../../entities/fnote"; @@ -69,6 +69,8 @@ function mapPropertyView({ note, property }: { note: FNote, property: BookProper return case "number": return + case "combobox": + return } } @@ -117,4 +119,22 @@ function NumberPropertyView({ note, property }: { note: FNote, property: NumberP ) +} + +function ComboBoxPropertyView({ note, property }: { note: FNote, property: ComboBoxProperty }) { + const [ value, setValue ] = useNoteLabel(note, property.bindToLabel); + + return ( + <> + + + ) } \ No newline at end of file diff --git a/apps/client/src/widgets/ribbon_widgets/book_properties.ts b/apps/client/src/widgets/ribbon_widgets/book_properties.ts deleted file mode 100644 index fb99477dd..000000000 --- a/apps/client/src/widgets/ribbon_widgets/book_properties.ts +++ /dev/null @@ -1,105 +0,0 @@ -import NoteContextAwareWidget from "../note_context_aware_widget.js"; -import attributeService from "../../services/attributes.js"; -import { t } from "../../services/i18n.js"; -import type FNote from "../../entities/fnote.js"; -import type { EventData } from "../../components/app_context.js"; -import { bookPropertiesConfig, BookProperty } from "./book_properties_config.js"; -import attributes from "../../services/attributes.js"; - -export default class BookPropertiesWidget extends NoteContextAwareWidget { - - private $viewTypeSelect!: JQuery; - private $propertiesContainer!: JQuery; - private labelsToWatch: string[] = []; - - doRender() { - - this.$viewTypeSelect = this.$widget.find(".view-type-select"); - this.$viewTypeSelect.on("change", () => this.toggleViewType(String(this.$viewTypeSelect.val()))); - - this.$propertiesContainer = this.$widget.find(".book-properties-container"); - } - - async refreshWithNote(note: FNote) { - if (!this.note) { - return; - } - - const viewType = this.note.getLabelValue("viewType") || "grid"; - - this.$viewTypeSelect.val(viewType); - - this.$propertiesContainer.empty(); - - const bookPropertiesData = bookPropertiesConfig[viewType]; - if (bookPropertiesData) { - for (const property of bookPropertiesData.properties) { - this.$propertiesContainer.append(this.renderBookProperty(property)); - this.labelsToWatch.push(property.bindToLabel); - } - } - } - - entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { - if (loadResults.getAttributeRows().find((attr) => - attr.noteId === this.noteId - && (attr.name === "viewType" || this.labelsToWatch.includes(attr.name ?? "")))) { - this.refresh(); - } - } - - renderBookProperty(property: BookProperty) { - const $container = $("
"); - $container.addClass(`type-${property.type}`); - const note = this.note; - if (!note) { - return $container; - } - switch (property.type) { - case "combobox": - const $select = $("