diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index 2e223fa93..26fb38b09 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -10,6 +10,7 @@ export const getCellValue = (colType: TAVCol, value: string) => {
if (colType === "number") {
if (value) {
cellValue = {
+ type: colType,
number: {
content: parseFloat(value),
isNotEmpty: true
@@ -17,6 +18,7 @@ export const getCellValue = (colType: TAVCol, value: string) => {
};
} else {
cellValue = {
+ type: colType,
number: {
isNotEmpty: false
}
@@ -24,12 +26,14 @@ export const getCellValue = (colType: TAVCol, value: string) => {
}
} else if (colType === "text") {
cellValue = {
+ type: colType,
text: {
content: value
}
};
} else if (colType === "mSelect" || colType === "select") {
cellValue = {
+ type: colType,
mSelect: [{
content: value,
color: ""
@@ -45,12 +49,11 @@ export const setFilter = (options: {
data: IAV,
target: HTMLElement,
}) => {
- const colType = Object.keys(options.filter.value)[0] as TAVCol;
const rectTarget = options.target.getBoundingClientRect();
const menu = new Menu("set-filter-" + options.filter.column, () => {
const oldFilters = JSON.parse(JSON.stringify(options.data.view.filters));
let hasMatch = false;
- const cellValue = getCellValue(colType, textElement?.value || "");
+ const cellValue = getCellValue(options.filter.value.type, textElement?.value || "");
const newFilter: IAVFilter = {
column: options.filter.column,
value: cellValue,
@@ -91,7 +94,7 @@ export const setFilter = (options: {
}
let selectHTML = "";
let colData: IAVColumn;
- switch (colType) {
+ switch (options.filter.value.type) {
case "text":
selectHTML = `
@@ -140,7 +143,7 @@ export const setFilter = (options: {
iconHTML: "",
label: ``
});
- if (colType === "mSelect") {
+ if (options.filter.value.type === "mSelect") {
// TODO
colData.options.forEach((option) => {
menu.addItem({
@@ -150,12 +153,12 @@ export const setFilter = (options: {
}
});
});
- } else if (colType === "text") {
+ } else if (options.filter.value.type === "text") {
menu.addItem({
iconHTML: "",
label: ``
});
- } else if (colType === "number") {
+ } else if (options.filter.value.type === "number") {
menu.addItem({
iconHTML: "",
label: ``
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index 0ca0f0c85..2f5407e58 100644
--- a/app/src/protyle/render/av/openMenuPanel.ts
+++ b/app/src/protyle/render/av/openMenuPanel.ts
@@ -484,7 +484,7 @@ export const openMenuPanel = (protyle: IProtyle,
event.stopPropagation();
break;
} else if (type === "removeSelectCell") {
- removeSelectCell(protyle, data.view, options, target.parentElement);
+ removeSelectCell(protyle, data, options, target.parentElement);
event.stopPropagation();
break;
}
diff --git a/app/src/protyle/render/av/select.ts b/app/src/protyle/render/av/select.ts
index f934e6941..603ff64a1 100644
--- a/app/src/protyle/render/av/select.ts
+++ b/app/src/protyle/render/av/select.ts
@@ -42,7 +42,7 @@ const filterSelectHTML = (key: string, options: { name: string, color: string }[
return html;
};
-export const removeSelectCell = (protyle: IProtyle, data: IAVTable, options: {
+export const removeSelectCell = (protyle: IProtyle, data: IAV, options: {
cellElement: HTMLElement
}, target: HTMLElement) => {
if (!target) {
@@ -52,7 +52,7 @@ export const removeSelectCell = (protyle: IProtyle, data: IAVTable, options: {
const colId = options.cellElement.dataset.colId;
const cellId = options.cellElement.dataset.id;
let colData: IAVColumn;
- data.columns.find((item: IAVColumn) => {
+ data.view.columns.find((item: IAVColumn) => {
if (item.id === colId) {
colData = item;
return;
@@ -62,7 +62,7 @@ export const removeSelectCell = (protyle: IProtyle, data: IAVTable, options: {
colData.options = [];
}
let cellData: IAVCell;
- data.rows.find(row => {
+ data.view.rows.find(row => {
if (row.id === rowID) {
row.cells.find(cell => {
if (cell.id === cellId) {
@@ -342,7 +342,9 @@ export const bindSelectEvent = (protyle: IProtyle, data: IAV, menuElement: HTMLE
}
addSelectColAndCell(protyle, data, options, currentElement, menuElement);
} else if (event.key === "Backspace" && inputElement.value === "") {
- removeSelectCell(protyle, data.view, options, inputElement.previousElementSibling as HTMLElement);
+ removeSelectCell(protyle, data, options, inputElement.previousElementSibling as HTMLElement);
+ } else if (event.key === "Escape") {
+ menuElement.parentElement.remove();
}
});
};
@@ -381,7 +383,7 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
if (!cellData) {
cellData = {
color: "",
- bgColor:"",
+ bgColor: "",
id: Lute.NewNodeID(),
value: {
mSelect: []
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index af44aec7d..f4c8babc3 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -912,6 +912,7 @@ interface IAVCell {
}
interface IAVCellValue {
+ type?: TAVCol,
text?: { content: string },
number?: { content?: number, isNotEmpty: boolean },
mSelect?: { content: string, color: string }[]