Skip to content

Build your personal knowledge base with Trilium Notes

feat(views/table): proper storage of relations

Elian Doran45ac70b78ff2
diff --git a/apps/client/src/services/attributes.ts b/apps/client/src/services/attributes.ts
index 95fb757269..52ea8967af 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 5a06384cb8..41f6fa39a2 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<StateInfo> {
}
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<StateInfo> {
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);
+ }
+ }
}
});
}