Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Keep relation list height stable while sorting https://github.com/siyuan-note/siyuan/issues/19904

Daniel2a979b2a964c
diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.ts
index 0c16ea90f4..863e189901 100644
--- a/app/src/protyle/render/av/relation.ts
+++ b/app/src/protyle/render/av/relation.ts
@@ -677,7 +677,7 @@ export const bindRelationEvent = (options: {
<div class="av__relation-table-selected" data-relation-type="selectedRows">${selectedHTML}</div>
<div class="b3-menu__separator" data-relation-type="separator"></div>
<div class="av__relation-table-candidates" data-relation-type="candidateRows">${candidateHTML}</div>
-${genRelationLoaderHTML(state.loading, state.loaderVisible)}`;
+${genRelationLoaderHTML(false)}`;
} else {
candidateHTML = genRelationRowsHTML(data.rows || [], state.columns, "candidate", gridTemplate, excludedIDs);
if (candidateHTML) {
@@ -713,7 +713,8 @@ ${genRelationLoaderHTML(state.loading, state.loaderVisible)}`;
const selectedItems = getSelectedItems();
state.controller = controller;
state.loading = true;
- setLoading(true, initialLoad && reset, controller);
+ // 已有条目刷新时保留列表尺寸,首次加载和追加分页显示底部加载提示。
+ setLoading(initialLoad || !reset, initialLoad && reset, controller);
let succeeded = false;
fetchPost("/api/av/getAttributeViewRelationCandidates", {
avID: relationElement.getAttribute("data-source-av-id"),
diff --git a/app/src/protyle/render/av/relationSort.test.ts b/app/src/protyle/render/av/relationSort.test.ts
index f83ae7aba1..8533bd6b63 100644
--- a/app/src/protyle/render/av/relationSort.test.ts
+++ b/app/src/protyle/render/av/relationSort.test.ts
@@ -4,6 +4,32 @@ import {readFileSync} from "node:fs";
import {join} from "node:path";
import {transpileModule, ScriptTarget} from "typescript";
+it("keeps the footer loader hidden while refreshing existing candidates", () => {
+ const source = readFileSync(join(__dirname, "relation.ts"), "utf8");
+ const start = source.indexOf(" const loadPage = (reset: boolean) => {");
+ const end = source.indexOf(' listElement.addEventListener("mousedown"', start);
+ assert.ok(start > 0 && end > start);
+ for (const test of [{initial: true, reset: true, loader: true},
+ {initial: false, reset: true, loader: false}, {initial: false, reset: false, loader: true}]) {
+ const loading: boolean[] = [];
+ const dependencies = {
+ state: {loading: false, page: 1, total: 32, keyword: "", controller: undefined as AbortController | undefined},
+ initialLoad: test.initial,
+ hasMore: () => true,
+ getSelectedItems: (): {id: string}[] => [],
+ setLoading: (show: boolean) => loading.push(show),
+ relationElement: {getAttribute: () => "database"},
+ RELATION_PAGE_SIZE: 16,
+ fetchPost: () => ({finally() {}}),
+ };
+ const loadPage = new Function(...Object.keys(dependencies), transpileModule(source.slice(start, end), {
+ compilerOptions: {target: ScriptTarget.ES2021},
+ }).outputText + "\nreturn loadPage;")(...Object.values(dependencies));
+ loadPage(test.reset);
+ assert.deepEqual(loading, [test.loader]);
+ }
+});
+
it("toggles one candidate sort, resets paging, and ignores width dragging", () => {
const source = readFileSync(join(__dirname, "relation.ts"), "utf8");
const start = source.indexOf(' listElement.addEventListener("click", event => {');