Skip to content

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

:sparkles: https://github.com/siyuan-note/siyuan/issues/8664

Vanessa25728e356426
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index 7a24a246af..935d6627ef 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -2,6 +2,55 @@ import {transaction} from "../../wysiwyg/transaction";
import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
import {openMenuPanel} from "./openMenuPanel";
+export const genCellValue = (colType: TAVCol, value: string | {
+ content: string,
+ color: string
+}[]) => {
+ let cellValue: IAVCellValue;
+ if (typeof value === "string") {
+ if (colType === "number") {
+ if (value) {
+ cellValue = {
+ type: colType,
+ number: {
+ content: parseFloat(value),
+ isNotEmpty: true
+ }
+ };
+ } else {
+ cellValue = {
+ type: colType,
+ number: {
+ isNotEmpty: false
+ }
+ };
+ }
+ } else if (colType === "text") {
+ cellValue = {
+ type: colType,
+ text: {
+ content: value
+ }
+ };
+ } else if (colType === "mSelect" || colType === "select") {
+ return cellValue = {
+ type: colType,
+ mSelect: [{
+ content: value,
+ color: ""
+ }]
+ };
+ }
+ return cellValue;
+ }
+ if (colType === "mSelect" || colType === "select") {
+ return cellValue = {
+ type: colType,
+ mSelect: value
+ };
+ }
+};
+
export const popTextCell = (protyle: IProtyle, cellElement: HTMLElement) => {
const type = cellElement.parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElement.getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol;
const cellRect = cellElement.getBoundingClientRect();
diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts
index e14b1a0589..9c1426e0e4 100644
--- a/app/src/protyle/render/av/col.ts
+++ b/app/src/protyle/render/av/col.ts
@@ -2,7 +2,8 @@ import {hasClosestBlock} from "../../util/hasClosest";
import {Menu} from "../../../plugin/Menu";
import {transaction} from "../../wysiwyg/transaction";
import {fetchPost} from "../../../util/fetch";
-import {genCellValue, setFilter} from "./filter";
+import {getDefaultOperatorByType, setFilter} from "./filter";
+import {genCellValue} from "./cell";
export const getColIconByType = (type: TAVCol) => {
switch (type) {
@@ -155,7 +156,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
if (!filter) {
filter = {
column: colId,
- operator: "Contains",
+ operator: getDefaultOperatorByType(type),
value: genCellValue(type, "")
};
avData.view.filters.push(filter);
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index be0e6352e9..4d8ab8b630 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -4,53 +4,14 @@ import {hasClosestByClassName} from "../../util/hasClosest";
import {getColIconByType} from "./col";
import {setPosition} from "../../../util/setPosition";
import {objEquals} from "../../../util/functions";
+import {genCellValue} from "./cell";
-export const genCellValue = (colType: TAVCol, value: string | {
- content: string,
- color: string
-}[]) => {
- let cellValue: IAVCellValue;
- if (typeof value === "string") {
- if (colType === "number") {
- if (value) {
- cellValue = {
- type: colType,
- number: {
- content: parseFloat(value),
- isNotEmpty: true
- }
- };
- } else {
- cellValue = {
- type: colType,
- number: {
- isNotEmpty: false
- }
- };
- }
- } else if (colType === "text") {
- cellValue = {
- type: colType,
- text: {
- content: value
- }
- };
- } else if (colType === "mSelect" || colType === "select") {
- return cellValue = {
- type: colType,
- mSelect: [{
- content: value,
- color: ""
- }]
- };
- }
- return cellValue;
+export const getDefaultOperatorByType = (type: TAVCol) => {
+ if (type === "number" || type === "select") {
+ return "=";
}
- if (colType === "mSelect" || colType === "select") {
- return cellValue = {
- type: colType,
- mSelect: value
- };
+ if (type === "text" || type === "mSelect") {
+ return "Contains";
}
};
@@ -94,6 +55,9 @@ export const setFilter = (options: {
});
}
});
+ if (mSelect.length === 0) {
+ mSelect.push({color: "", content: ""});
+ }
cellValue = genCellValue(options.filter.value.type, mSelect);
}
const newFilter: IAVFilter = {
@@ -298,7 +262,7 @@ export const addFilter = (options: {
const cellValue = genCellValue(column.type, "");
options.data.view.filters.push({
column: column.id,
- operator: "Contains",
+ operator: getDefaultOperatorByType(column.type),
value: cellValue,
});
transaction(options.protyle, [{
@@ -315,7 +279,7 @@ export const addFilter = (options: {
const filterElement = options.menuElement.querySelector(`[data-id="${column.id}"] .b3-chip`) as HTMLElement;
setFilter({
filter: {
- operator: "Contains",
+ operator: getDefaultOperatorByType(column.type),
column: column.id,
value: cellValue
},
diff --git a/app/src/protyle/render/av/select.ts b/app/src/protyle/render/av/select.ts
index 3d7511bfec..3df4a65e81 100644
--- a/app/src/protyle/render/av/select.ts
+++ b/app/src/protyle/render/av/select.ts
@@ -3,7 +3,7 @@ import {transaction} from "../../wysiwyg/transaction";
import {hasClosestByClassName} from "../../util/hasClosest";
import {confirmDialog} from "../../../dialog/confirmDialog";
import {upDownHint} from "../../../util/upDownHint";
-import {genCellValue} from "./filter";
+import {genCellValue} from "./cell";
const filterSelectHTML = (key: string, options: { name: string, color: string }[]) => {
let html = "";