Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup dataeditor js code and hooks #2095

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion reflex/.templates/web/utils/helpers/dataeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,21 @@ export function formatCell(value, column) {
readonly: !editable,
}
default:
console.log("Warning: column.type is undefined for column.title=" + column.title)
return {
kind: GridCellKind.Text,
data: value,
displayData: "type not specified in column definition"
displayData: column.type
}
};
};

export function formatDataEditorCells(col, row, columns, data) {
if (row < data.length && col < columns.length) {
const column = getDEColumn(columns, col);
const rowData = getDERow(data, row);
const cellData = locateCell(rowData, column);
return formatCell(cellData, column);
}
return { kind: GridCellKind.Loading };
}
21 changes: 7 additions & 14 deletions reflex/components/datadisplay/dataeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@ def _get_imports(self):
},
self.library: {ImportVar(tag="GridCellKind")},
"/utils/helpers/dataeditor.js": {
ImportVar(tag=f"getDEColumn", is_default=False, install=False),
ImportVar(tag=f"getDERow", is_default=False, install=False),
ImportVar(tag=f"locateCell", is_default=False, install=False),
ImportVar(tag=f"formatCell", is_default=False, install=False),
ImportVar(tag=f"onEditCell", is_default=False, install=False),
ImportVar(
tag=f"formatDataEditorCells", is_default=False, install=False
),
},
},
)
Expand Down Expand Up @@ -258,21 +256,16 @@ def _get_hooks(self) -> str | None:

code = [f"function {data_callback}([col, row])" "{"]

columns_path = f"{self.columns._var_full_name}"
data_path = f"{self.data._var_full_name}"

code.extend(
[
f" if (row < {self.data._var_full_name}.length && col < {self.columns._var_full_name}.length)"
" {",
f" const column = getDEColumn({self.columns._var_full_name}, col);",
f" const rowData = getDERow({self.data._var_full_name}, row);",
f" const cellData = locateCell(rowData, column);",
" return formatCell(cellData, column);",
f" return formatDataEditorCells(col, row, {columns_path}, {data_path});",
" }",
" return { kind: GridCellKind.Loading};",
]
)

code.append("}")

return "\n".join(code)

@classmethod
Expand Down
Loading