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(views/table): actually add attributes
Elian Doran0fb0be4ffcee
diff --git a/apps/client/src/components/component.ts b/apps/client/src/components/component.tsindex e2897d1f37..8686a7bb96 100644--- a/apps/client/src/components/component.ts+++ b/apps/client/src/components/component.ts@@ -93,11 +93,7 @@ export class TypedComponent<ChildT extends TypedComponent<ChildT>> {if (fun) {return this.callMethod(fun, data);- } else {- if (!this.parent) {- throw new Error(`Component "${this.componentId}" does not have a parent attached to propagate a command.`);- }-+ } else if (this.parent) {return this.parent.triggerCommand(name, data);}}diff --git a/apps/client/src/services/attributes.ts b/apps/client/src/services/attributes.tsindex 315dc2c15a..95fb757269 100644--- a/apps/client/src/services/attributes.ts+++ b/apps/client/src/services/attributes.ts@@ -3,11 +3,12 @@ import froca from "./froca.js";import type FNote from "../entities/fnote.js";import type { AttributeRow } from "./load_results.js";-async function addLabel(noteId: string, name: string, value: string = "") {+async function addLabel(noteId: string, name: string, value: string = "", isInheritable = false) {await server.put(`notes/${noteId}/attribute`, {type: "label",name: name,- value: value+ value: value,+ isInheritable});}diff --git a/apps/client/src/widgets/note_list.ts b/apps/client/src/widgets/note_list.tsindex 81a818bdbc..150c4933ea 100644--- a/apps/client/src/widgets/note_list.ts+++ b/apps/client/src/widgets/note_list.ts@@ -166,4 +166,13 @@ export default class NoteListWidget extends NoteContextAwareWidget {}}+ triggerCommand<K extends CommandNames>(name: K, data?: CommandMappings[K]): Promise<unknown> | undefined | null {+ // Pass the commands to the view mode, which is not actually attached to the hierarchy.+ if (this.viewMode?.triggerCommand(name, data)) {+ return;+ }++ return super.triggerCommand(name, data);+ }+}diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.tsindex 0b66416126..7ec559a85c 100644--- a/apps/client/src/widgets/view_widgets/table_view/index.ts+++ b/apps/client/src/widgets/view_widgets/table_view/index.ts@@ -1,7 +1,7 @@import froca from "../../../services/froca.js";import ViewMode, { type ViewModeArgs } from "../view_mode.js";import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";-import { setLabel } from "../../../services/attributes.js";+import attributes, { setLabel } from "../../../services/attributes.js";import getPromotedAttributeInformation, { buildData, TableData } from "./data.js";import applyHeaderCustomization from "./header-customization.js";import server from "../../../services/server.js";@@ -9,6 +9,7 @@ import type { GridApi, GridState } from "ag-grid-community";import SpacedUpdate from "../../../services/spaced_update.js";import branches from "../../../services/branches.js";import type { CommandListenerData } from "../../../components/app_context.js";+import type { Attribute } from "../../../services/attribute_parser.js";const TPL = /*html*/`<div class="table-view">@@ -53,6 +54,7 @@ export default class TableView extends ViewMode<StateInfo> {private args: ViewModeArgs;private spacedUpdate: SpacedUpdate;private api?: GridApi;+ private newAttribute?: Attribute;constructor(args: ViewModeArgs) {super(args, "table");@@ -164,16 +166,23 @@ export default class TableView extends ViewMode<StateInfo> {return config;}- async saveAttributesCommand() {- console.log("Save attributes");- }-async reloadAttributesCommand() {console.log("Reload attributes");}async updateAttributeListCommand({ attributes }: CommandListenerData<"updateAttributeList">) {- console.log("Update attributes", { attributes });+ this.newAttribute = attributes[0];+ }++ async saveAttributesCommand() {+ if (!this.newAttribute) {+ return;+ }++ const { name, value } = this.newAttribute;+ attributes.addLabel(this.parentNote.noteId, name, value, true);+ console.log("Save attributes", this.newAttribute);}+}diff --git a/apps/server/src/routes/api/attributes.ts b/apps/server/src/routes/api/attributes.tsindex 7d542ac16d..fa106180b2 100644--- a/apps/server/src/routes/api/attributes.ts+++ b/apps/server/src/routes/api/attributes.ts@@ -48,7 +48,8 @@ function updateNoteAttribute(req: Request) {attribute = new BAttribute({noteId: noteId,name: body.name,- type: body.type+ type: body.type,+ isInheritable: body.isInheritable});}