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

Daniel2675c5036cad
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index c8fcd767b3..f7c310cd42 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -185,7 +185,7 @@ export const addFilter = (options: {
transaction(options.protyle, [{
action: "setAttrViewFilters",
avID: options.avId,
- data: options.data.view.filters,
+ data: JSON.parse(JSON.stringify(options.data.view.filters)),
blockID
}], [{
action: "setAttrViewFilters",
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index 8f80604df7..31227c98f7 100644
--- a/app/src/protyle/render/av/openMenuPanel.ts
+++ b/app/src/protyle/render/av/openMenuPanel.ts
@@ -645,17 +645,18 @@ export const openMenuPanel = (options: {
window.siyuan.menus.menu.remove();
const rmNode = getFilterByPath(getEditableFilters(data), btnPath);
const doRemove = () => {
- const oldFilters = JSON.parse(JSON.stringify(data.view.filters));
+ const cloneBefore = JSON.parse(JSON.stringify(data.view.filters));
removeFilterByPath(getEditableFilters(data), btnPath);
+ const cloneAfter = JSON.parse(JSON.stringify(data.view.filters));
transaction(options.protyle, [{
action: "setAttrViewFilters",
avID,
- data: JSON.parse(JSON.stringify(data.view.filters)),
+ data: cloneAfter,
blockID
}], [{
action: "setAttrViewFilters",
avID,
- data: oldFilters,
+ data: cloneBefore,
blockID
}]);
menuElement.innerHTML = getFiltersHTML(data);
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 61153c42c5..840955a5b5 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -3536,9 +3536,11 @@ func SetAttrViewFilters(avID, blockID string, data []any) (err error) {
return
}
- if err = gulu.JSON.UnmarshalJSON(jsonData, &view.Filters); err != nil {
+ var newFilters []*av.ViewFilter
+ if err = gulu.JSON.UnmarshalJSON(jsonData, &newFilters); err != nil {
return
}
+ view.Filters = newFilters
// 归一化为单一根组:spec 5 起顶层应为一个根组。
// 兜底旧前端/异常数据发来的扁平叶子数组,在内存里包成 AND 根组后再持久化。
@@ -3581,9 +3583,11 @@ func SetAttrViewSorts(avID, blockID string, data []any) (err error) {
return
}
- if err = gulu.JSON.UnmarshalJSON(jsonData, &view.Sorts); err != nil {
+ var newSorts []*av.ViewSort
+ if err = gulu.JSON.UnmarshalJSON(jsonData, &newSorts); err != nil {
return
}
+ view.Sorts = newSorts
err = av.SaveAttributeView(attrView)
return