From 39962edc79e544180f484c195a0b525f64de129f Mon Sep 17 00:00:00 2001 From: IgniKSJ <124532891+IgniKSJ@users.noreply.github.com> Date: Sun, 23 Mar 2025 13:56:10 +0100 Subject: [PATCH 1/2] Fix: Bidirectional relationships not updating on remote ddbb when creating a new note from the RelationEditor --- src/components/cellTypes/Editor/RelationEditor.tsx | 9 ++++++++- src/services/RelationalService.ts | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/cellTypes/Editor/RelationEditor.tsx b/src/components/cellTypes/Editor/RelationEditor.tsx index e7d3ddaa..a4b2394e 100644 --- a/src/components/cellTypes/Editor/RelationEditor.tsx +++ b/src/components/cellTypes/Editor/RelationEditor.tsx @@ -33,10 +33,17 @@ const RelationEditor = (props: RelationEditorComponentProps) => { ) => { switch (actionMeta.action) { case "create-option": - await RelationalService.createNoteIntoRelation( + const newNotePath = await RelationalService.createNoteIntoRelation( tableColumn.config.related_note_path, actionMeta.option.value ); + // Once the note is created, we need to update the value of the new option + const newOption = newValue.find( + (option) => option.value === actionMeta.option.value + ); + if (newOption) { + newOption.value = newNotePath; + } break; default: // Do nothing diff --git a/src/services/RelationalService.ts b/src/services/RelationalService.ts index d51e2e09..2574fe44 100644 --- a/src/services/RelationalService.ts +++ b/src/services/RelationalService.ts @@ -3,7 +3,7 @@ import { TableColumn } from "cdm/FolderModel"; import { LocalSettings } from "cdm/SettingsModel"; import { obtainColumnsFromFolder, obtainColumnsFromRows } from "components/Columns"; import { DatabaseCore, DEFAULT_SETTINGS } from "helpers/Constants"; -import { resolve_tfile } from "helpers/FileManagement"; +import { destination_folder, resolve_tfile } from "helpers/FileManagement"; import { adapterTFilesToRows } from "helpers/VaultManagement"; import { SMarkdownPage } from "obsidian-dataview"; import { dataApiBuilder } from "views/DataApiBuilder"; @@ -87,6 +87,9 @@ class RelationalServiceInstance { const relatedColumns = await obtainColumnsFromFolder(ddbbInfo.yaml.columns); await dataApi.create(newFilename, relatedColumns, ddbbInfo.yaml.config); LOGGER.info(`<-- createNoteIntoRelation. Note ${newFilename} created into relation ${ddbbPath}`); + const dest_folder = destination_folder(ddbbFile, ddbbInfo.yaml.config); + const newNotePath = `${dest_folder}/${newFilename}.md`; + return newNotePath; } /** From 08d111336bbdfa5d53c862a97b3d7a05cfa401de Mon Sep 17 00:00:00 2001 From: IgniKSJ <124532891+IgniKSJ@users.noreply.github.com> Date: Sun, 23 Mar 2025 14:04:22 +0100 Subject: [PATCH 2/2] changed createNoteIntoRelation return type definition to string --- src/services/RelationalService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/RelationalService.ts b/src/services/RelationalService.ts index 2574fe44..9c647680 100644 --- a/src/services/RelationalService.ts +++ b/src/services/RelationalService.ts @@ -79,7 +79,7 @@ class RelationalServiceInstance { * @param ddbbPath * @param content */ - public async createNoteIntoRelation(ddbbPath: string, newFilename: string): Promise { + public async createNoteIntoRelation(ddbbPath: string, newFilename: string): Promise { LOGGER.info(`--> createNoteIntoRelation. Creating note ${newFilename} into relation ${ddbbPath}`); const ddbbFile = resolve_tfile(ddbbPath); const ddbbInfo = await new DatabaseInfo(ddbbFile, DEFAULT_SETTINGS.local_settings).build();