feat(views/table): actually add attributes

This commit is contained in:
Elian Doran
2025-06-27 22:43:29 +03:00
parent fe1dbb4cbf
commit 0fb0be4ffc
5 changed files with 30 additions and 14 deletions

View File

@@ -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);
}
}

View File

@@ -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
});
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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
});
}