From bb5134ce24a22c6e3f73d29f3854d186bc9d750a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 24 Dec 2023 21:25:48 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/9888 --- app/src/protyle/render/av/relation.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.ts index b3312d79b..0839841b7 100644 --- a/app/src/protyle/render/av/relation.ts +++ b/app/src/protyle/render/av/relation.ts @@ -104,15 +104,28 @@ export const updateRelation = (options: { avID: string, avElement: Element }) => { + const inputElement = options.avElement.querySelector('input[data-type="colName"]') as HTMLInputElement; + const goSearchAVElement = options.avElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement; + const oldValue = JSON.parse(goSearchAVElement.dataset.oldValue) as IAVCellRelationValue; + const newAVId = goSearchAVElement.getAttribute("data-av-id") + const colId = options.avElement.querySelector(".b3-menu__item").getAttribute("data-col-id") transaction(options.protyle, [{ action: "updateAttrViewColRelation", avID: options.avID, - id: options.avElement.querySelector('.b3-menu__item[data-type="goSearchAV"]').getAttribute("data-av-id"), - keyID: options.avElement.querySelector(".b3-menu__item").getAttribute("data-col-id"), // 源 av 关联列 ID - backRelationKeyID: Lute.NewNodeID(), // 双向关联的目标关联列 ID + keyID: colId, + id: newAVId, + backRelationKeyID: oldValue.avID === newAVId ? oldValue.backKeyID : Lute.NewNodeID(), isTwoWay: (options.avElement.querySelector(".b3-switch") as HTMLInputElement).checked, - name: (options.avElement.querySelector('input[data-type="colName"]') as HTMLInputElement).value, - }], []); + name: inputElement.value, + }], [{ + action: "updateAttrViewColRelation", + avID: options.avID, + keyID: colId, + id: oldValue.avID, + backRelationKeyID: oldValue.backKeyID, + isTwoWay: oldValue.isTwoWay, + name: inputElement.dataset.oldValue + }]); options.avElement.remove(); }