feat(views/table): proper storage of relations

This commit is contained in:
Elian Doran 2025-07-04 15:07:40 +03:00
parent a4664576fe
commit 45ac70b78f
No known key found for this signature in database
2 changed files with 13 additions and 6 deletions

View File

@ -50,7 +50,7 @@ function removeOwnedLabelByName(note: FNote, labelName: string) {
* @param name the name of the attribute to set. * @param name the name of the attribute to set.
* @param value the value 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) { if (value) {
// Create or update the attribute. // Create or update the attribute.
await server.put(`notes/${note.noteId}/set-attribute`, { type, name, value }); await server.put(`notes/${note.noteId}/set-attribute`, { type, name, value });

View File

@ -1,6 +1,6 @@
import froca from "../../../services/froca.js"; import froca from "../../../services/froca.js";
import ViewMode, { type ViewModeArgs } from "../view_mode.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 getPromotedAttributeInformation, { buildColumnDefinitions, buildData, buildRowDefinitions, TableData } from "./data.js";
import server from "../../../services/server.js"; import server from "../../../services/server.js";
import SpacedUpdate from "../../../services/spaced_update.js"; import SpacedUpdate from "../../../services/spaced_update.js";
@ -120,7 +120,7 @@ export default class TableView extends ViewMode<StateInfo> {
} }
private setupEditing() { private setupEditing() {
this.api!.on("cellEdited", (cell) => { this.api!.on("cellEdited", async (cell) => {
const noteId = cell.getRow().getData().noteId; const noteId = cell.getRow().getData().noteId;
const field = cell.getField(); const field = cell.getField();
const newValue = cell.getValue(); const newValue = cell.getValue();
@ -130,9 +130,16 @@ export default class TableView extends ViewMode<StateInfo> {
return; return;
} }
if (field.startsWith("labels.")) { if (field.includes(".")) {
const labelName = field.split(".", 2)[1]; const [ type, name ] = field.split(".", 2);
setLabel(noteId, labelName, newValue); if (type === "labels") {
setLabel(noteId, name, newValue);
} else if (type === "relations") {
const note = await froca.getNote(noteId);
if (note) {
setAttribute(note, "relation", name, newValue);
}
}
} }
}); });
} }