From 0fb0be4ffceee423e7a9ec3549569b452f5cb581 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 27 Jun 2025 22:43:29 +0300 Subject: [PATCH] feat(views/table): actually add attributes --- apps/client/src/components/component.ts | 6 +----- apps/client/src/services/attributes.ts | 5 +++-- apps/client/src/widgets/note_list.ts | 9 ++++++++ .../widgets/view_widgets/table_view/index.ts | 21 +++++++++++++------ apps/server/src/routes/api/attributes.ts | 3 ++- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/apps/client/src/components/component.ts b/apps/client/src/components/component.ts index e2897d1f3..8686a7bb9 100644 --- a/apps/client/src/components/component.ts +++ b/apps/client/src/components/component.ts @@ -93,11 +93,7 @@ export class TypedComponent> { 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.ts index 315dc2c15..95fb75726 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.ts index 81a818bdb..150c4933e 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(name: K, data?: CommandMappings[K]): Promise | 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.ts index 0b6641612..7ec559a85 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*/`
@@ -53,6 +54,7 @@ export default class TableView extends ViewMode { 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 { 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.ts index 7d542ac16..fa106180b 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 }); }