Skip to content

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

:art: Support database filter composition https://github.com/siyuan-note/siyuan/issues/10550

Daniel92af7709296a
diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts
index 483407aa01..933ba158f6 100644
--- a/app/src/protyle/render/av/col.ts
+++ b/app/src/protyle/render/av/col.ts
@@ -847,42 +847,26 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
id: avID,
}, (response) => {
const avData = response.data as IAV;
- let filter: IAVFilter;
- // 递归在过滤树中查找该列已存在的叶子
- const findFilter = (nodes: IAVFilter[]): IAVFilter => {
- for (const n of nodes) {
- if (n.filters) {
- const found = findFilter(n.filters);
- if (found) return found;
- } else if (n.column === colId && n.value.type === type) {
- return n;
- }
- }
- return undefined;
+ // 始终新建一个占位条件(允许同列多条件,支持“主键包含111 OR 主键包含222”等组合)
+ const filter: IAVFilter = {
+ column: colId,
+ operator: getDefaultOperatorByType(type),
+ value: genCellValue(type, ""),
};
- filter = findFilter(getEditableFilters(avData));
- if (!filter) {
- // 新建占位条件并保存,随后打开筛选面板 inline 编辑
- filter = {
- column: colId,
- operator: getDefaultOperatorByType(type),
- value: genCellValue(type, ""),
- };
- // 深拷贝旧值用于 undo,撤销时恢复完整筛选状态而非清空全部
- const oldFilters = JSON.parse(JSON.stringify(avData.view.filters));
- getEditableFilters(avData).push(filter);
- transaction(protyle, [{
- action: "setAttrViewFilters",
- avID,
- data: avData.view.filters,
- blockID: blockElement.getAttribute("data-node-id")
- }], [{
- action: "setAttrViewFilters",
- avID,
- data: oldFilters,
- blockID: blockElement.getAttribute("data-node-id")
- }]);
- }
+ // 深拷贝旧值用于 undo,撤销时恢复完整筛选状态而非清空全部
+ const oldFilters = JSON.parse(JSON.stringify(avData.view.filters));
+ getEditableFilters(avData).push(filter);
+ transaction(protyle, [{
+ action: "setAttrViewFilters",
+ avID,
+ data: avData.view.filters,
+ blockID: blockElement.getAttribute("data-node-id")
+ }], [{
+ action: "setAttrViewFilters",
+ avID,
+ data: oldFilters,
+ blockID: blockElement.getAttribute("data-node-id")
+ }]);
// 打开筛选面板,用户在内联控件中编辑(替代原 setFilter 弹层)
openMenuPanel({
protyle,
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index cd204d9234..65a582ceba 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -150,7 +150,7 @@ export const addFilter = (options: {
parentPath?: string
}) => {
const menu = new Menu(Constants.MENU_AV_ADD_FILTER);
- // 仅在目标分组内查重:同一分组内不重复添加同列叶子,但不同分组允许同列(嵌套的核心价值,如 状态=完成 OR 状态=进行中)
+ // 定位目标分组:支持向指定分组内追加,同分组允许同列多条件(如 状态=完成 OR 状态=进行中)
let targetGroupFilters: IAVFilter[];
if (options.parentPath && options.parentPath !== "") {
const node = getFilterByPath(getRootFilters(options.data), options.parentPath);
@@ -158,15 +158,9 @@ export const addFilter = (options: {
} else {
targetGroupFilters = getEditableFilters(options.data);
}
- const usedColumns = new Set<string>();
- targetGroupFilters.forEach(n => {
- if (!n.filters && n.column) {
- usedColumns.add(n.column);
- }
- });
getFieldsByData(options.data).forEach((column) => {
- // 该列是行号类型列,或目标分组内已有该列叶子,则不重复添加
- if (column.type !== "lineNumber" && !usedColumns.has(column.id)) {
+ // 行号类型列不可筛选
+ if (column.type !== "lineNumber") {
menu.addItem({
label: column.name,
iconHTML: column.icon ? unicode2Emoji(column.icon, "b3-menu__icon", true) : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(column.type)}"></use></svg>`,