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: Auto-dismiss invalid document drag messages after seven seconds https://github.com/siyuan-note/siyuan/issues/19548
Daniel381d10bba12e
diff --git a/app/src/layout/dock/Files.drop.test.ts b/app/src/layout/dock/Files.drop.test.tsindex 661318fb09..8a6ad4078f 100644--- a/app/src/layout/dock/Files.drop.test.ts+++ b/app/src/layout/dock/Files.drop.test.ts@@ -44,7 +44,7 @@ test("dropping a document into itself or descendants reports an invalid target wfor (const target of ["/parent.sy", "/parent/child.sy", "/parent/child/grandchild.sy"]) {for (const sources of [["/parent.sy"], ["/other.sy", "/parent.sy"]]) {const result = dropDocuments(sources, target);- assert.deepEqual(result.messages, [{message: "Cannot move to this location", timeout: 0, type: "error"}]);+ assert.deepEqual(result.messages, [{message: "Cannot move to this location", timeout: 7000, type: "error"}]);assert.equal(result.requests.length, 0);assert.equal(result.classes.size, 0);}diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex b88b7eac52..4362bb6030 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -881,7 +881,7 @@ export class Files extends Model {}});if (invalidMoveTarget) {- showMessage(window.siyuan.languages._kernel[87], 0, "error");+ showMessage(window.siyuan.languages._kernel[87], 7000, "error");newElement.classList.remove("dragover", "dragover__bottom", "dragover__top");return;}diff --git a/app/src/util/fileTreeReorder.test.ts b/app/src/util/fileTreeReorder.test.tsindex deb615304d..51ae8a4ae1 100644--- a/app/src/util/fileTreeReorder.test.ts+++ b/app/src/util/fileTreeReorder.test.ts@@ -10,20 +10,26 @@ const compiled = transpileModule(readFileSync("src/util/fileTreeReorder.ts", "utconst fixture = (responses: any[], accept = false) => {const requests: any[] = [];+ const messages: unknown[][] = [];+ const processed: unknown[] = [];let confirmations = 0;const exports: any = {};runInNewContext(compiled, {exports,- window: {siyuan: {languages: {removeSorts: "Sort", fileTreeDragRemoveSorts: "Confirm"}}},+ window: {siyuan: {languages: {removeSorts: "Sort", fileTreeDragRemoveSorts: "Confirm",+ _kernel: {87: "Cannot move to this location"}}}},require: () => ({getRelativeReorderRequest: (sourceIDs: string[], targetID: string, after: boolean) => ({sourceIDs, targetID, position: after ? "after" : "before",}),- fetchSyncPost: async (_url: string, data: any) => {+ fetchSyncPost: async (_url: string, data: any, _headers: unknown, process: boolean) => {+ assert.equal(process, false);requests.push(data);assert.ok(responses.length > 0);return responses.shift();},+ showMessage: (...args: unknown[]) => messages.push(args),+ processMessage: (response: unknown) => processed.push(response),confirmDialog: (_title: string, _text: string, confirm: () => void, cancel: () => void) => {confirmations++;assert.equal(requests[requests.length - 1].preview, true);@@ -33,6 +39,8 @@ const fixture = (responses: any[], accept = false) => {});return {requests,+ messages,+ processed,confirmations: () => confirmations,sort: () => exports.reorderSortedFileTree(["a", "b"], "c", false),};@@ -41,6 +49,24 @@ const fixture = (responses: any[], accept = false) => {const preview = (conflict: boolean) => ({code: 0, data: {changed: true, conflict}});const applied = {code: 0, data: {notebook: "notebook", parentPath: "/"}};+test("invalid move targets close automatically after seven seconds in preview and execution", async () => {+ const failure: {code: number, msg: string, data: null} = {code: -1, msg: "Cannot move to this location", data: null};+ for (const responses of [[failure], [preview(false), failure]]) {+ const f = fixture(responses);+ assert.equal(await f.sort(), undefined);+ assert.deepEqual(f.messages, [[failure.msg, 7000, "error"]]);+ assert.ok(!f.processed.includes(failure));+ }+});++test("other reorder errors retain standard message processing", async () => {+ const failure: {code: number, msg: string, data: null} = {code: -1, msg: "Other error", data: null};+ const f = fixture([failure]);+ await f.sort();+ assert.deepEqual(f.messages, []);+ assert.deepEqual(f.processed, [failure]);+});+test("canceling or closing a conflict dialog does not move documents", async () => {const f = fixture([preview(true)]);assert.equal(await f.sort(), undefined);diff --git a/app/src/util/fileTreeReorder.ts b/app/src/util/fileTreeReorder.tsindex c09bbd5828..6df53a8b02 100644--- a/app/src/util/fileTreeReorder.ts+++ b/app/src/util/fileTreeReorder.ts@@ -1,12 +1,23 @@import {confirmDialog} from "../dialog/confirmDialog";import {fetchSyncPost} from "./fetch";import {getRelativeReorderRequest} from "./fileTreeMove";+import {showMessage} from "../dialog/message";+import {processMessage} from "./processMessage";++const processReorderMessage = (response: IWebSocketData) => {+ if (response.code === -1 && response.msg === window.siyuan.languages._kernel[87]) {+ showMessage(response.msg, 7000, "error");+ return;+ }+ processMessage(response);+};// 确认前只请求预览,取消或关闭对话框不会移动文档。export const reorderSortedFileTree = async (sourceIDs: string[], targetID: string, after: boolean):Promise<{notebook: string, parentPath: string} | undefined> => {const request = {...getRelativeReorderRequest(sourceIDs, targetID, after), respectSort: true};- const preview = await fetchSyncPost("/api/filetree/reorderDocs", {...request, preview: true});+ const preview = await fetchSyncPost("/api/filetree/reorderDocs", {...request, preview: true}, undefined, false);+ processReorderMessage(preview);if (preview.code !== 0 || !preview.data?.changed) {return;}@@ -20,7 +31,8 @@ export const reorderSortedFileTree = async (sourceIDs: string[], targetID: strinreturn;}}- const response = await fetchSyncPost("/api/filetree/reorderDocs", {...request, removeSorts});+ const response = await fetchSyncPost("/api/filetree/reorderDocs", {...request, removeSorts}, undefined, false);+ processReorderMessage(response);if (response.code !== 0) {return;}