Skip to content

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

:art: Improve database context filter interaction https://github.com/siyuan-note/siyuan/issues/19121

Danielbeffaaeb3a22
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
index cf89b88d04..0f1544514f 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
@@ -7,7 +7,7 @@
"id": "20240208172514-9dsv6na",
"title": "Database",
"type": "doc",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -45,7 +45,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20251224101749-zybcbjk",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -984,7 +984,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260613171129-edm1pru",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1013,7 +1013,7 @@
"HeadingLevel": 4,
"Properties": {
"id": "20260613171129-5zjv62o",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1042,7 +1042,7 @@
"ListData": {},
"Properties": {
"id": "20260613171129-438l9c3",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1327,7 +1327,7 @@
},
"Properties": {
"id": "20260904022100-t3p2t45",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1335,7 +1335,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260904022100-h1drat7",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1345,7 +1345,16 @@
},
{
"Type": "NodeText",
- "Data": ": Use the database block’s “Context filter” to select a configured Relation field. It applies “Contains any item - Current document” to every view in this database block, resolving the containing document to its item in the related database. Ordinary view filters remain view-specific and are combined with the context filter using AND. Change the selected field or disable the context filter from the same panel"
+ "Data": ": Open "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Context filter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " from the database block toolbar and select a configured Relation field. The panel lists all configured Relation fields in the database, but only one can be enabled at a time. Select another field to switch to it; select the checked field again to turn off the context filter. Once enabled, the fixed condition “Contains any item - Current document” applies to every view in this database block. Each view’s ordinary filters remain independent and are combined with the context filter using AND. When you add an item from this database block, the current document is automatically added to the selected Relation field. For filtering and adding items to work, the current document must already be bound to an item in the selected Relation field’s target database; otherwise, no matching items are shown and you cannot add items from this database block."
}
]
}
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
index 83a655e324..2f06d0fd97 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
@@ -7,7 +7,7 @@
"id": "20240208113259-nykkvaq",
"title": "数据库",
"type": "doc",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -45,7 +45,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20240208115136-9g2b46l",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -984,7 +984,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260613170258-y3mj135",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1013,7 +1013,7 @@
"HeadingLevel": 4,
"Properties": {
"id": "20260613170258-kfaoevw",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1042,7 +1042,7 @@
"ListData": {},
"Properties": {
"id": "20260613170258-stvvay1",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1327,7 +1327,7 @@
},
"Properties": {
"id": "20260904022100-u8yv871",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1335,7 +1335,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260904022100-k06aj5m",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1345,7 +1345,16 @@
},
{
"Type": "NodeText",
- "Data": ":在数据库块工具栏的“上下文筛选”中选择已配置的关联字段。系统会对该数据库块的所有视图应用“包含任一 - 当前文档”,把数据库块所在文档解析为目标数据库中的对应条目。普通视图筛选仍只属于各自视图,并与上下文筛选通过“且”组合。可在同一面板中更换字段或禁用上下文筛选"
+ "Data": ":从数据库块工具栏打开 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "上下文筛选"
+ },
+ {
+ "Type": "NodeText",
+ "Data": ",并选择一个已配置的关联字段。面板会列出数据库中所有已配置的关联字段,但同时只能启用一个。点击其他字段可切换;再次点击当前已勾选字段可关闭上下文筛选。启用后,系统会对该数据库块的所有视图应用固定条件“包含任一 - 当前文档”;各视图原有筛选仍保持独立,并与上下文筛选按“且”组合。从该数据库块新增条目时,系统会自动将当前文档填入所选关联字段。要正常筛选和新增条目,当前文档必须已经绑定为所选关联字段目标数据库中的条目;否则不会显示匹配项,也无法从该数据库块新增条目。"
}
]
}
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
index 42c145a6ee..6106dbd9a8 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
@@ -7,7 +7,7 @@
"id": "20240208171522-y7dxcno",
"title": "資料庫",
"type": "doc",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -45,7 +45,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20251224101729-yhz5zrt",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -984,7 +984,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260613171246-whfdkq8",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1013,7 +1013,7 @@
"HeadingLevel": 4,
"Properties": {
"id": "20260613171246-qovn46w",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1042,7 +1042,7 @@
"ListData": {},
"Properties": {
"id": "20260613171246-frygk48",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1327,7 +1327,7 @@
},
"Properties": {
"id": "20260904022100-5x68nm2",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1335,7 +1335,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260904022100-ivb080o",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1345,7 +1345,16 @@
},
{
"Type": "NodeText",
- "Data": ":在資料庫區塊工具列的「情境篩選」中選擇已設定的關聯欄位。系統會對此資料庫區塊的所有檢視套用「包含任一項 - 目前文件」,將資料庫區塊所在文件解析為目標資料庫中的對應項目。一般檢視篩選仍只屬於各自檢視,並與情境篩選以且組合。可在同一面板中更換欄位或停用情境篩選"
+ "Data": ":從資料庫區塊工具列開啟 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "情境篩選"
+ },
+ {
+ "Type": "NodeText",
+ "Data": ",並選取一個已設定的關聯欄位。面板會列出資料庫中所有已設定的關聯欄位,但一次只能啟用一個。選取其他欄位即可切換;再次選取目前已勾選的欄位即可關閉情境篩選。啟用後,固定條件「包含任一項 - 目前文件」會套用於此資料庫區塊的所有檢視;各檢視原有篩選仍保持獨立,並與情境篩選以「且」組合。從此資料庫區塊新增項目時,系統會自動將目前文件加入所選的關聯欄位。若要正常篩選與新增項目,目前文件必須已綁定為所選關聯欄位所指向之資料庫中的項目;否則不會顯示相符項目,也無法從此資料庫區塊新增項目。"
}
]
}
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
index f446663bc4..2b624b2e3e 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
@@ -8,7 +8,7 @@
"id": "20240530101000-3eaevtp",
"title": "データベース",
"type": "doc",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -46,7 +46,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20251224101829-lva3op2",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -985,7 +985,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260613171234-4oam4x1",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1014,7 +1014,7 @@
"HeadingLevel": 4,
"Properties": {
"id": "20260613171234-x40bu7m",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1043,7 +1043,7 @@
"ListData": {},
"Properties": {
"id": "20260613171234-lbxo0ro",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1328,7 +1328,7 @@
},
"Properties": {
"id": "20260904022100-hzqmv7b",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1336,7 +1336,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260904022100-mif3i0m",
- "updated": "20260904091600"
+ "updated": "20260904115016"
},
"Children": [
{
@@ -1346,7 +1346,16 @@
},
{
"Type": "NodeText",
- "Data": ":「コンテキストフィルター」で設定済みのリレーションフィールドを選択します。「いずれかを含む - 現在の文書」がこのデータベースブロックのすべてのビューに適用され、ブロックを含む文書を関連先データベース内の対応する項目として解決します。通常のビューフィルターは各ビュー専用のままで、コンテキストフィルターとは AND で組み合わせます。同じパネルでフィールドの変更やコンテキストフィルターの無効化ができます"
+ "Data": ":データベースブロックのツールバーから "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "コンテキストフィルター"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " を開き、設定済みのリレーションフィールドを1つ選択します。パネルにはデータベース内の設定済みリレーションフィールドがすべて表示されますが、一度に有効にできるのは1つだけです。別のフィールドを選択すると切り替わり、チェック済みのフィールドをもう一度選択するとコンテキストフィルターが無効になります。有効にすると、固定条件「いずれかを含む - 現在の文書」がこのデータベースブロックのすべてのビューに適用されます。通常のビューフィルターは各ビューで独立したままで、コンテキストフィルターとは AND で組み合わせられます。このデータベースブロックから項目を追加すると、現在の文書が選択中のリレーションフィールドに自動的に追加されます。フィルターと項目追加を正しく機能させるには、現在の文書が、選択するリレーションフィールドの関連先データベース内の項目としてあらかじめ紐付けられている必要があります。紐付けられていない場合、一致する項目は表示されず、このデータベースブロックから項目を追加することもできません。"
}
]
}
diff --git a/app/src/protyle/render/av/contextFilter.ts b/app/src/protyle/render/av/contextFilter.ts
index c1507c677d..6878c9a6ac 100644
--- a/app/src/protyle/render/av/contextFilter.ts
+++ b/app/src/protyle/render/av/contextFilter.ts
@@ -4,6 +4,7 @@ import {
createContextFilter,
getContextFilterFields,
getContextFilterKeyID,
+ toggleContextFilterKeyID,
} from "./contextFilterState";
import {unicode2Emoji} from "../../../emoji";
@@ -25,14 +26,9 @@ export const getContextFilterHTML = (data: IAV) => {
</button>
<button class="b3-menu__separator"></button>
<div class="b3-menu__item b3-menu__item--readonly">
- <span class="b3-menu__label ft__on-surface">${window.siyuan.languages.contextFilterTip}</span>
+ <span class="b3-menu__label ft__on-surface fn__flex"><span class="fn__flex-center">${window.siyuan.languages.contextFilterTip}</span></span>
</div>
-${optionsHTML || `<div class="b3-menu__item b3-menu__item--readonly"><span class="b3-menu__label ft__on-surface">${window.siyuan.languages.contextFilterNoRelation}</span></div>`}
-<button class="b3-menu__separator${selectedKeyID ? "" : " fn__none"}"></button>
-<button class="b3-menu__item b3-menu__item--warning${selectedKeyID ? "" : " fn__none"}" data-type="disableContextFilter">
- <svg class="b3-menu__icon"><use xlink:href="#iconTrashcan"></use></svg>
- <span class="b3-menu__label">${window.siyuan.languages.disable}</span>
-</button>
+${optionsHTML || `<div class="b3-menu__item b3-menu__item--readonly"><span class="b3-menu__label ft__on-surface fn__flex"><span class="fn__flex-center">${window.siyuan.languages.contextFilterNoRelation}</span></span></div>`}
</div>`;
};
@@ -46,17 +42,11 @@ export const bindContextFilterEvent = (options: {
options.menuElement.addEventListener("click", (event: MouseEvent) => {
const target = event.target as HTMLElement;
const fieldElement = target.closest('[data-type="contextFilterField"]') as HTMLElement;
- const disableElement = target.closest('[data-type="disableContextFilter"]') as HTMLElement;
- if (!fieldElement && !disableElement) {
+ if (!fieldElement) {
return;
}
const oldKeyID = getContextFilterKeyID(options.data.contextFilter);
- const keyID = disableElement ? "" : fieldElement.dataset.id || "";
- if (keyID === oldKeyID) {
- event.preventDefault();
- event.stopPropagation();
- return;
- }
+ const keyID = toggleContextFilterKeyID(oldKeyID, fieldElement.dataset.id || "");
const operation = (operationKeyID: string): IOperation => ({
action: "setAttrViewContextFilter",
avID: options.avID,
diff --git a/app/src/protyle/render/av/contextFilterState.test.ts b/app/src/protyle/render/av/contextFilterState.test.ts
index 52744e4fae..d7791cfbfe 100644
--- a/app/src/protyle/render/av/contextFilterState.test.ts
+++ b/app/src/protyle/render/av/contextFilterState.test.ts
@@ -4,6 +4,7 @@ import {
createContextFilter,
getContextFilterFields,
getContextFilterKeyID,
+ toggleContextFilterKeyID,
} from "./contextFilterState";
describe("database block context filter", () => {
@@ -31,4 +32,10 @@ describe("database block context filter", () => {
assert.deepEqual(createContextFilter("relation-a"), {spec: 1, keyID: "relation-a"});
assert.equal(createContextFilter(""), null);
});
+
+ it("toggles the selected relation field", () => {
+ assert.equal(toggleContextFilterKeyID("", "relation-a"), "relation-a");
+ assert.equal(toggleContextFilterKeyID("relation-a", "relation-a"), "");
+ assert.equal(toggleContextFilterKeyID("relation-a", "relation-b"), "relation-b");
+ });
});
diff --git a/app/src/protyle/render/av/contextFilterState.ts b/app/src/protyle/render/av/contextFilterState.ts
index 4950e3d179..acf79e3214 100644
--- a/app/src/protyle/render/av/contextFilterState.ts
+++ b/app/src/protyle/render/av/contextFilterState.ts
@@ -9,3 +9,7 @@ export const getContextFilterFields = (fields?: IAVContextFilterField[]) => {
export const createContextFilter = (keyID: string): IAVContextFilter | null => {
return keyID ? {spec: 1, keyID} : null;
};
+
+export const toggleContextFilterKeyID = (currentKeyID: string, targetKeyID: string) => {
+ return currentKeyID === targetKeyID ? "" : targetKeyID;
+};