Optimize local folder file tree lazy loading
This commit is contained in:
@@ -108,13 +108,9 @@ fn render_filetree_row(
|
||||
create_action_html = create_action_html,
|
||||
title = escape_html(&row.title),
|
||||
));
|
||||
if row.expandable {
|
||||
if row.expandable && row.expanded {
|
||||
if let Some(children) = children_by_parent.get(&Some(row.node_id.clone())) {
|
||||
html.push_str(if row.expanded {
|
||||
r#"<ul class="tree-children">"#
|
||||
} else {
|
||||
r#"<ul class="tree-children tree-children--collapsed">"#
|
||||
});
|
||||
html.push_str(r#"<ul class="tree-children">"#);
|
||||
for child in children {
|
||||
render_filetree_row(html, child, children_by_parent);
|
||||
}
|
||||
@@ -221,4 +217,47 @@ mod tests {
|
||||
assert!(html.contains("title=\"思维导图.json\""));
|
||||
assert!(html.contains("data-selected=\"true\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_shell_filetree_renderer_does_not_ssr_collapsed_descendants() {
|
||||
let html = render_initial_filetree_html(&FileTreeInitialRenderInput {
|
||||
rows: vec![
|
||||
FileTreeRenderRow {
|
||||
row_id: "local:folder:docs".into(),
|
||||
row_kind: "folder".into(),
|
||||
node_id: "local:node:docs".into(),
|
||||
parent_node_id: None,
|
||||
title: "docs".into(),
|
||||
depth: 0,
|
||||
expandable: true,
|
||||
expanded: false,
|
||||
icon_kind: "folder".into(),
|
||||
document_id: None,
|
||||
asset_id: None,
|
||||
object_identity: None,
|
||||
selected: false,
|
||||
},
|
||||
FileTreeRenderRow {
|
||||
row_id: "local:markdown:docs/README.md".into(),
|
||||
row_kind: "markdown".into(),
|
||||
node_id: "local:node:docs/README.md".into(),
|
||||
parent_node_id: Some("local:node:docs".into()),
|
||||
title: "README.md".into(),
|
||||
depth: 1,
|
||||
expandable: false,
|
||||
expanded: false,
|
||||
icon_kind: "file".into(),
|
||||
document_id: Some("local-md:docs~2FREADME.md".into()),
|
||||
asset_id: None,
|
||||
object_identity: None,
|
||||
selected: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
assert!(html.contains("data-row-id=\"local:folder:docs\""));
|
||||
assert!(!html.contains("data-row-id=\"local:markdown:docs/README.md\""));
|
||||
assert!(!html.contains("README.md"));
|
||||
assert!(!html.contains("tree-children--collapsed"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user