diff --git a/apps/client/src/services/attributes.ts b/apps/client/src/services/attributes.ts index 95fb75726..52ea8967a 100644 --- a/apps/client/src/services/attributes.ts +++ b/apps/client/src/services/attributes.ts @@ -50,7 +50,7 @@ function removeOwnedLabelByName(note: FNote, labelName: string) { * @param name the name of the attribute to set. * @param value the value of the attribute to set. */ -async function setAttribute(note: FNote, type: "label" | "relation", name: string, value: string | null | undefined) { +export async function setAttribute(note: FNote, type: "label" | "relation", name: string, value: string | null | undefined) { if (value) { // Create or update the attribute. await server.put(`notes/${note.noteId}/set-attribute`, { type, name, value }); 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 5a06384cb..41f6fa39a 100644 --- a/apps/client/src/widgets/view_widgets/table_view/index.ts +++ b/apps/client/src/widgets/view_widgets/table_view/index.ts @@ -1,6 +1,6 @@ import froca from "../../../services/froca.js"; import ViewMode, { type ViewModeArgs } from "../view_mode.js"; -import attributes, { setLabel } from "../../../services/attributes.js"; +import attributes, { setAttribute, setLabel } from "../../../services/attributes.js"; import getPromotedAttributeInformation, { buildColumnDefinitions, buildData, buildRowDefinitions, TableData } from "./data.js"; import server from "../../../services/server.js"; import SpacedUpdate from "../../../services/spaced_update.js"; @@ -120,7 +120,7 @@ export default class TableView extends ViewMode { } private setupEditing() { - this.api!.on("cellEdited", (cell) => { + this.api!.on("cellEdited", async (cell) => { const noteId = cell.getRow().getData().noteId; const field = cell.getField(); const newValue = cell.getValue(); @@ -130,9 +130,16 @@ export default class TableView extends ViewMode { return; } - if (field.startsWith("labels.")) { - const labelName = field.split(".", 2)[1]; - setLabel(noteId, labelName, newValue); + if (field.includes(".")) { + const [ type, name ] = field.split(".", 2); + if (type === "labels") { + setLabel(noteId, name, newValue); + } else if (type === "relations") { + const note = await froca.getNote(noteId); + if (note) { + setAttribute(note, "relation", name, newValue); + } + } } }); }