diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts index 51b612ffa..aa7a4440f 100644 --- a/app/src/protyle/render/av/filter.ts +++ b/app/src/protyle/render/av/filter.ts @@ -80,8 +80,9 @@ export const setFilter = async (options: { operator: selectElement.value as TAVFilterOperator }; let hasMatch = false; + let newValue; if (textElements.length > 0) { - if (["date", "updated", "created"].includes(filterType)) { + if (["date", "updated", "created"].includes(filterValue.type)) { const typeElement = menu.element.querySelector('.b3-select[data-type="dateType"]') as HTMLSelectElement; const directElements = menu.element.querySelectorAll('.b3-select[data-type="dataDirection"]') as NodeListOf; if (typeElement.value === "custom") { @@ -96,7 +97,7 @@ export const setFilter = async (options: { direction: parseInt(directElements[1].value) }; } else { - newFilter.value = genCellValue(filterType, { + newValue = genCellValue(filterValue.type, { isNotEmpty2: textElements[1].value !== "", isNotEmpty: textElements[0].value !== "", content: textElements[0].value ? new Date(textElements[0].value + " 00:00").getTime() : null, @@ -106,9 +107,9 @@ export const setFilter = async (options: { }); } } else { - newFilter.value = genCellValue(filterType, textElements[0].value); + newValue = genCellValue(filterValue.type, textElements[0].value); } - } else if (filterType === "select" || filterType === "mSelect") { + } else if (filterValue.type === "select" || filterValue.type === "mSelect") { const mSelect: { color: string, content: string @@ -122,15 +123,24 @@ export const setFilter = async (options: { }); } }); - newFilter.value = genCellValue(filterType, mSelect); - } else if (filterType === "checkbox") { - newFilter.value = genCellValue(filterType, { + newValue = genCellValue(filterValue.type, mSelect); + } else if (filterValue.type === "checkbox") { + newValue = genCellValue(filterValue.type, { checked: newFilter.operator === "Is true" }); } else { - newFilter.value = genCellValue(filterType, undefined); + newValue = genCellValue(filterValue.type, undefined); + } + if (options.filter.value.type === "rollup") { + newFilter.value = { + rollup: { + contents: [newValue], + }, + type: "rollup" + } + } else { + newFilter.value = newValue } - let isSame = false; options.data.view.filters.find((filter, index) => { if (filter.column === options.filter.column && filter.value.type === options.filter.value.type) { @@ -178,8 +188,8 @@ export const setFilter = async (options: { return true; } }); - let filterType = colData.type; - if (filterType === "rollup") { + let filterValue = JSON.parse(JSON.stringify(options.filter.value)); + if (colData.type === "rollup") { if (!colData.rollup || !colData.rollup.relationKeyID || !colData.rollup.keyID) { showMessage(window.siyuan.languages.plsChoose); openMenuPanel({ @@ -200,34 +210,33 @@ export const setFilter = async (options: { const response = await fetchSyncPost("/api/av/getAttributeView", {id: targetAVId}); response.data.av.keyValues.find((item: { key: { id: string, name: string, type: TAVCol } }) => { if (item.key.id === colData.rollup.keyID) { - filterType = item.key.type; + filterValue.type = item.key.type; return true; } }); options.data.view.filters.find(item => { if (item.column === colData.id && item.value.type === "rollup") { if (!item.value.rollup) { - item.value.rollup = { - contents: [{ - [filterType]: genCellValue(filterType, ""), - type: filterType - }] + filterValue = { + [filterValue.type]: genCellValue(filterValue.type, filterValue.type === "checkbox" ? {checked: undefined} : ""), + type: filterValue.type }; - item.operator = getDefaultOperatorByType(filterType) + } else { + filterValue = item.value.rollup.contents[0] } return true; } }); } let checkboxInit = false; - if (filterType === "checkbox") { - checkboxInit = typeof options.filter.value.checkbox.checked === "boolean"; + if (filterValue.type === "checkbox") { + checkboxInit = typeof filterValue.checkbox === "undefined" || typeof filterValue.checkbox.checked === "undefined"; } - switch (filterType) { + switch (filterValue.type) { case "checkbox": - selectHTML = ` -`; - if (!checkboxInit) { + selectHTML = ` +`; + if (checkboxInit) { selectHTML = `${selectHTML}`; } break; @@ -300,10 +309,10 @@ export const setFilter = async (options: { type: "readonly", label: `` }); - if (filterType === "select" || filterType === "mSelect") { + if (filterValue.type === "select" || filterValue.type === "mSelect") { colData.options?.forEach((option) => { let icon = "iconUncheck"; - options.filter.value?.mSelect?.find((optionItem) => { + filterValue?.mSelect?.find((optionItem: IAVCellSelectValue) => { if (optionItem.content === option.name) { icon = "iconCheck"; } @@ -325,13 +334,13 @@ export const setFilter = async (options: { } }); }); - } else if (["text", "url", "block", "email", "phone", "template", "relation"].includes(filterType)) { + } else if (["text", "url", "block", "email", "phone", "template", "relation"].includes(filterValue.type)) { let value = ""; - if (options.filter.value) { - if (filterType === "relation") { - value = options.filter.value.relation.contents[0] || ""; + if (filterValue) { + if (filterValue.type === "relation") { + value = filterValue.relation.contents[0] || ""; } else { - value = options.filter.value[filterType as "text"].content || ""; + value = filterValue[filterValue.type as "text"].content || ""; } } menu.addItem({ @@ -339,14 +348,14 @@ export const setFilter = async (options: { type: "readonly", label: `` }); - } else if (filterType === "number") { + } else if (filterValue.type === "number") { menu.addItem({ iconHTML: "", type: "readonly", - label: `` + label: `` }); - } else if (["date", "updated", "created"].includes(filterType)) { - const dateValue = options.filter.value ? options.filter.value[filterType as "date"] : null; + } else if (["date", "updated", "created"].includes(filterValue.type)) { + const dateValue = filterValue ? filterValue[filterValue.type as "date"] : null; const showToday = !options.filter.relativeDate?.direction; const showToday2 = !options.filter.relativeDate2?.direction; menu.addItem({ @@ -361,7 +370,7 @@ export const setFilter = async (options: {
- +