Skip to content

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

:sparkles: Support opening database rows from relation selector https://github.com/siyuan-note/siyuan/issues/13645

Danielc169a18a1887
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index 670cc2058b..f5de00b427 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -1897,6 +1897,10 @@ img.av__cellassetimg {
.av__relation-table-primary {
box-shadow: inset 0 0 0 9999px var(--b3-list-hover);
}
+
+ .av__relation-row-open {
+ opacity: 1;
+ }
}
&[data-relation-type="selected"],
@@ -1910,7 +1914,7 @@ img.av__cellassetimg {
}
}
- .av__relation-table-cell > :not(.fn__grab),
+ .av__relation-table-cell > :not(.fn__grab):not(.av__relation-row-open),
.av__relation-table-check > * {
pointer-events: none;
}
@@ -1953,6 +1957,39 @@ img.av__cellassetimg {
margin: 0 6px 0 0;
width: 14px;
}
+
+ .b3-menu__label {
+ flex: 1;
+ min-width: 0;
+ }
+ }
+
+ .av__relation-row-open {
+ align-items: center;
+ background-color: transparent;
+ border: 0;
+ border-radius: var(--b3-border-radius);
+ color: var(--b3-theme-on-surface);
+ cursor: pointer;
+ display: flex;
+ flex: 0 0 auto;
+ height: 26px;
+ justify-content: center;
+ margin-left: 4px;
+ opacity: .54;
+ padding: 5px;
+ width: 26px;
+
+ &:hover,
+ &:focus-visible {
+ background-color: var(--b3-list-hover);
+ opacity: 1;
+ }
+
+ svg {
+ height: 14px;
+ width: 14px;
+ }
}
.av__relation-table-cell {
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index bebc9455e7..6a2871669c 100644
--- a/app/src/protyle/render/av/openMenuPanel.ts
+++ b/app/src/protyle/render/av/openMenuPanel.ts
@@ -263,6 +263,7 @@ export const openMenuPanel = (options: {
const ghostElement = primaryElement.cloneNode(true) as HTMLElement;
ghostElement.className = "av__relation-drag-ghost";
ghostElement.removeAttribute("style");
+ ghostElement.querySelector(".av__relation-row-open")?.remove();
document.body.append(ghostElement);
event.dataTransfer.setDragImage(ghostElement, 16, 17);
setTimeout(() => {
diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.ts
index e9b116fbd7..61d5fb2bfc 100644
--- a/app/src/protyle/render/av/relation.ts
+++ b/app/src/protyle/render/av/relation.ts
@@ -1,5 +1,5 @@
import {Menu} from "../../../plugin/Menu";
-import {hasClosestByClassName, hasTopClosestByClassName} from "../../util/hasClosest";
+import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName} from "../../util/hasClosest";
import {UDLRHint, upDownHint} from "../../../util/upDownHint";
import {fetchPost} from "../../../util/fetch";
import {escapeAttr, escapeHtml, escapeLessThans} from "../../../util/escape";
@@ -16,6 +16,7 @@ import {isMobile} from "../../../util/functions";
import {showMessage} from "../../../dialog/message";
import {writeText} from "../../util/compatibility";
import {Constants} from "../../../constants";
+import {openDatabaseRowByData} from "./openDatabaseRow";
interface IAVItem {
avID: string;
@@ -308,11 +309,14 @@ style="grid-template-columns:${gridTemplate}">
if (index === 0) {
const isDetached = primaryValue.isDetached;
html += `<span class="av__relation-table-cell av__relation-table-primary" data-row-id="${escapeAttr(row.id)}"
+data-value-id="${escapeAttr(primaryCell.id || "")}"
style="${primaryCell.bgColor ? `background-color:${primaryCell.bgColor};` : ""}${primaryCell.color ? `color:${primaryCell.color};` : ""}">
${selected ? '<svg class="b3-menu__icon fn__grab"><use xlink:href="#iconDrag"></use></svg>' : ""}
<span class="b3-menu__label fn__ellipsis${isDetached ? "" : " popover__block"}"
${isDetached ? "" : 'style="color:var(--b3-protyle-inline-blockref-color)"'}
data-id="${escapeAttr(primaryValue.block?.id || "")}">${Lute.EscapeHTMLStr(primaryValue.block?.content || window.siyuan.languages.untitled)}</span>
+ ${primaryCell.id ? `<button type="button" class="av__relation-row-open ariaLabel" data-type="openRelationRow" draggable="false"
+ data-position="north" aria-label="${window.siyuan.languages.openBy}"><svg><use xlink:href="#iconOpen"></use></svg></button>` : ""}
</span>`;
} else {
html += `<span class="av__relation-table-cell"
@@ -528,6 +532,9 @@ ${genRelationLoaderHTML(state.loading)}`;
const databaseName = inputElement.parentElement.parentElement.querySelector(".popover__block");
databaseName.textContent = response.data.name;
databaseName.setAttribute("data-id", response.data.blockIDs?.[0] || "");
+ const relationElement = options.menuElement.firstElementChild as HTMLElement;
+ relationElement.dataset.databaseBlockId = response.data.blockIDs?.[0] || "";
+ relationElement.dataset.notebookId = response.data.notebookID || "";
const columns = response.data.columns as IAVColumn[] || [];
const selectedRowsByID = new Map<string, IAVRow>((response.data.selectedRows as IAVRow[] || []).
map((row) => [row.id, row]));
@@ -618,6 +625,31 @@ ${genRelationLoaderHTML(state.loading)}`;
event.stopPropagation();
search();
});
+ listElement.addEventListener("click", (event) => {
+ const openElement = hasClosestByAttribute(event.target as HTMLElement, "data-type", "openRelationRow");
+ if (!openElement || !listElement.contains(openElement)) {
+ return;
+ }
+ const rowElement = hasClosestByClassName(openElement, "av__relation-table-row") as HTMLElement;
+ const primaryElement = rowElement?.querySelector(".av__relation-table-primary") as HTMLElement;
+ const blockElement = primaryElement?.querySelector(".b3-menu__label") as HTMLElement;
+ const relationElement = options.menuElement.firstElementChild as HTMLElement;
+ if (!rowElement || !primaryElement || !blockElement || !relationElement.dataset.databaseBlockId) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ openDatabaseRowByData(options.protyle, {
+ avID: relationElement.dataset.avId,
+ databaseBlockID: relationElement.dataset.databaseBlockId,
+ notebookID: relationElement.dataset.notebookId,
+ itemID: rowElement.dataset.rowId,
+ valueID: primaryElement.dataset.valueId,
+ title: blockElement.textContent,
+ boundBlockID: blockElement.dataset.id,
+ isDetached: !blockElement.classList.contains("popover__block"),
+ });
+ });
listElement.addEventListener("scroll", () => {
if (!state.loading && hasMore() && listElement.scrollHeight - listElement.scrollTop - listElement.clientHeight <= 30) {
loadPage(false);
diff --git a/docs/API.ja.md b/docs/API.ja.md
index aaf5094a92..04113c19fc 100644
--- a/docs/API.ja.md
+++ b/docs/API.ja.md
@@ -1932,48 +1932,6 @@
* `data.blockIDs`: このデータベースを参照する全データベースブロック(ミラー)の ID
* `data.total`: フィルタリング後、ページング前の主キー値の数
-### リレーション候補アイテムを取得
-
-* `/api/av/getAttributeViewRelationCandidates`
-* パラメータ
-
- ```json
- {
- "id": "20240118120204-kwyzf77",
- "keyword": "",
- "page": 1,
- "pageSize": 16,
- "selectedBlockIDs": ["20240118203831-fkfvvtx"]
- }
- ```
-
- * `id`:データベース ID
- * `keyword`:任意の検索テキスト。空白で区切られたキーワードは同じフィールド内にすべて含まれる必要があり、すべてのフィールドが検索対象になります
- * `page`:候補アイテムのページ番号。`1` から始まり、既定値は `1` です
- * `pageSize`:1 ページあたりの候補アイテム数。`-1` または省略時は `16` です
- * `selectedBlockIDs`:任意の選択済みアイテムの行 ID。`selectedRows` では指定した順序が維持されます
-* 戻り値
-
- ```json
- {
- "code": 0,
- "msg": "",
- "data": {
- "name": "データベース",
- "blockIDs": ["20240118120201-kldj15t"],
- "columns": [],
- "selectedRows": [],
- "rows": [],
- "total": 0
- }
- }
- ```
-
- * `columns`:行番号を除くデータベースの全フィールド。主キーが先頭です
- * `selectedRows`:`selectedBlockIDs` に対応する完全なレンダリング済み行。`keyword` とページングの影響を受けません
- * `rows`:`keyword` に一致する候補行。作成日時の降順で並びます
- * `total`:ページング前に `keyword` と一致した候補行の総数
-
### 検索
* `/api/av/searchAttributeView`
diff --git a/docs/API.md b/docs/API.md
index 5d660f9e92..561d7d6c5c 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -1943,48 +1943,6 @@ The field types (`keyType`) are:
* `data.blockIDs`: IDs of all database blocks (mirrors) that reference this database
* `data.total`: Number of primary-key values after filtering and before pagination
-### Get relation candidates
-
-* `/api/av/getAttributeViewRelationCandidates`
-* Parameters
-
- ```json
- {
- "id": "20240118120204-kwyzf77",
- "keyword": "",
- "page": 1,
- "pageSize": 16,
- "selectedBlockIDs": ["20240118203831-fkfvvtx"]
- }
- ```
-
- * `id`: Database ID
- * `keyword`: Optional search text. Space-separated terms must all occur in the same field; all fields are searched
- * `page`: Candidate page number, 1-based. Defaults to `1`
- * `pageSize`: Candidates per page. `-1` or omitted means `16`
- * `selectedBlockIDs`: Optional row IDs of selected items. Their order is preserved in `selectedRows`
-* Return value
-
- ```json
- {
- "code": 0,
- "msg": "",
- "data": {
- "name": "Database",
- "blockIDs": ["20240118120201-kldj15t"],
- "columns": [],
- "selectedRows": [],
- "rows": [],
- "total": 0
- }
- }
- ```
-
- * `columns`: All database fields except line numbers, with the primary key first
- * `selectedRows`: Complete rendered rows matching `selectedBlockIDs`; not affected by `keyword` or pagination
- * `rows`: Candidate rows matching `keyword`, sorted by creation time descending
- * `total`: Total number of candidate rows matching `keyword` before pagination
-
### Search
* `/api/av/searchAttributeView`
diff --git a/docs/API.zh-CN.md b/docs/API.zh-CN.md
index 5ce6f832a0..8c15e4cf7c 100644
--- a/docs/API.zh-CN.md
+++ b/docs/API.zh-CN.md
@@ -1932,48 +1932,6 @@
* `data.blockIDs`: 引用该数据库的所有数据库块(镜像)ID
* `data.total`: 过滤后、分页前的主键值数量
-### 获取关系候选条目
-
-* `/api/av/getAttributeViewRelationCandidates`
-* 参数
-
- ```json
- {
- "id": "20240118120204-kwyzf77",
- "keyword": "",
- "page": 1,
- "pageSize": 16,
- "selectedBlockIDs": ["20240118203831-fkfvvtx"]
- }
- ```
-
- * `id`:数据库 ID
- * `keyword`:可选搜索文本。以空格分隔的关键词必须同时出现在同一个字段中,搜索范围为全部字段
- * `page`:候选条目页码,从 `1` 开始,默认为 `1`
- * `pageSize`:每页候选条目数,传入 `-1` 或省略时默认为 `16`
- * `selectedBlockIDs`:可选的已选条目行 ID,`selectedRows` 会保留其顺序
-* 返回值
-
- ```json
- {
- "code": 0,
- "msg": "",
- "data": {
- "name": "数据库",
- "blockIDs": ["20240118120201-kldj15t"],
- "columns": [],
- "selectedRows": [],
- "rows": [],
- "total": 0
- }
- }
- ```
-
- * `columns`:数据库的全部字段,不包含行号,主键位于第一列
- * `selectedRows`:与 `selectedBlockIDs` 对应的完整渲染行,不受 `keyword` 和分页影响
- * `rows`:与 `keyword` 匹配的候选行,按创建时间降序排列
- * `total`:分页前与 `keyword` 匹配的候选行总数
-
### 搜索
* `/api/av/searchAttributeView`
diff --git a/kernel/api/av.go b/kernel/api/av.go
index ba794e2228..718e6878c7 100644
--- a/kernel/api/av.go
+++ b/kernel/api/av.go
@@ -491,9 +491,16 @@ func getAttributeViewRelationCandidates(c *gin.Context) {
ret.Msg = err.Error()
return
}
+ notebookID := ""
+ if 0 < len(blockIDs) {
+ if blockTree := treenode.GetBlockTree(blockIDs[0]); nil != blockTree {
+ notebookID = blockTree.BoxID
+ }
+ }
ret.Data = map[string]any{
"name": name,
"blockIDs": blockIDs,
+ "notebookID": notebookID,
"columns": columns,
"selectedRows": selectedRows,
"rows": rows,