An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Refresh database attribute panels after block binding changes https://github.com/siyuan-note/siyuan/issues/20777
Daniela0ffbb82f664
diff --git a/app/src/protyle/render/av/attributePanel.test.ts b/app/src/protyle/render/av/attributePanel.test.tsnew file mode 100644index 0000000000..cbe04332eb--- /dev/null+++ b/app/src/protyle/render/av/attributePanel.test.ts@@ -0,0 +1,47 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import {test} from "node:test";+import {runInNewContext} from "node:vm";+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";++const exports = {} as typeof import("./attributePanel");+runInNewContext(transpileModule(readFileSync("src/protyle/render/av/attributePanel.ts", "utf8"), {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},+}).outputText, {exports, require: () => ({})});++const setup = (database = "", item = "") => {+ const panel = Object.create(exports.AVAttributePanel.prototype);+ let refreshed = 0;+ Object.assign(panel, {+ targetID: "document",+ hasDatabase: (id: string) => id === database,+ hasItem: (id: string) => !!id && id === item,+ refresh: () => { refreshed++; },+ });+ return {panel, refreshed: () => refreshed};+};++test("binding refreshes a newly bound document even before its database panel exists", () => {+ const {panel, refreshed} = setup();+ panel.refreshForOperation({action: "replaceAttrViewBlock", avID: "database", previousID: "item",+ nextID: "document", isDetached: false});+ assert.equal(refreshed(), 1);+});++test("rebinding, detaching and undo refresh the existing database and item panels", () => {+ for (const [database, item] of [["database", ""], ["", "item"]]) {+ const {panel, refreshed} = setup(database, item);+ for (const [nextID, isDetached] of [["other-document", false], ["", true], ["document", false]]) {+ panel.refreshForOperation({action: "replaceAttrViewBlock", avID: "database", previousID: "item",+ nextID, isDetached});+ }+ assert.equal(refreshed(), 3);+ }+});++test("binding transactions do not refresh unrelated panels or operations without a database", () => {+ const {panel, refreshed} = setup("other-database", "other-item");+ panel.refreshForOperation({action: "replaceAttrViewBlock", avID: "database", previousID: "item", nextID: "other"});+ panel.refreshForOperation({action: "replaceAttrViewBlock", previousID: "other-item", nextID: "document"});+ assert.equal(refreshed(), 0);+});diff --git a/app/src/protyle/render/av/attributePanel.ts b/app/src/protyle/render/av/attributePanel.tsindex 62082c857f..6d4c581127 100644--- a/app/src/protyle/render/av/attributePanel.ts+++ b/app/src/protyle/render/av/attributePanel.ts@@ -229,6 +229,11 @@ export class AVAttributePanel {if (!avID) {return;}+ if (operation.action === "replaceAttrViewBlock" &&+ (this.hasDatabase(avID) || this.hasItem(operation.previousID) || operation.nextID === this.targetID)) {+ this.refresh();+ return;+ }if (operation.action === "insertAttrViewBlock" && operation.srcs?.some(item => item.id === this.targetID)) {this.refresh();return;