refactor: extract filetree projection helpers
This commit is contained in:
@@ -2142,6 +2142,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function readProjection(value) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('readProjection');
|
||||
if (runtimeFn) return runtimeFn(value);
|
||||
if (!value || typeof value !== 'object') return null;
|
||||
if (value.result && typeof value.result === 'object') return value.result;
|
||||
if (value.snapshot && value.snapshot.tree) return value.snapshot.tree;
|
||||
@@ -2151,6 +2153,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function readSidebarDataset(value) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('readSidebarDataset');
|
||||
if (runtimeFn) return runtimeFn(value);
|
||||
if (!value || typeof value !== 'object') return null;
|
||||
if (value.snapshot && value.snapshot.dataset && typeof value.snapshot.dataset === 'object') return value.snapshot.dataset;
|
||||
if (value.data && value.data.dataset && typeof value.data.dataset === 'object') return value.data.dataset;
|
||||
@@ -2160,6 +2164,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function readDatasetProjection(value, snakeCaseKey, camelCaseKey) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('readDatasetProjection');
|
||||
if (runtimeFn) return runtimeFn(value, snakeCaseKey, camelCaseKey);
|
||||
var dataset = readSidebarDataset(value);
|
||||
if (!dataset || typeof dataset !== 'object') return null;
|
||||
if (dataset[snakeCaseKey] && typeof dataset[snakeCaseKey] === 'object') return dataset[snakeCaseKey];
|
||||
@@ -2172,32 +2178,46 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function projectionItems(projection) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('projectionItems');
|
||||
if (runtimeFn) return runtimeFn(projection);
|
||||
var resolved = readProjection(projection);
|
||||
return resolved && Array.isArray(resolved.items) ? resolved.items : [];
|
||||
}
|
||||
|
||||
function hasProjectionItems(projection) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('hasProjectionItems');
|
||||
if (runtimeFn) return runtimeFn(projection);
|
||||
var resolved = readProjection(projection);
|
||||
return Boolean(resolved && Array.isArray(resolved.items));
|
||||
}
|
||||
|
||||
function nodeIdOf(item) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('nodeIdOf');
|
||||
if (runtimeFn) return runtimeFn(item);
|
||||
return String(item && (item.nodeId || item.id || item.documentId) || '').trim();
|
||||
}
|
||||
|
||||
function rowIdOf(item) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('rowIdOf');
|
||||
if (runtimeFn) return runtimeFn(item);
|
||||
return String(item && (item.rowId || item.nodeId || item.id) || '').trim();
|
||||
}
|
||||
|
||||
function parentIdOf(item) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('parentIdOf');
|
||||
if (runtimeFn) return runtimeFn(item);
|
||||
return String(item && (item.parentNodeId || item.parentId || '') || '').trim();
|
||||
}
|
||||
|
||||
function titleOf(item) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('titleOf');
|
||||
if (runtimeFn) return runtimeFn(item);
|
||||
return String(item && item.title || '无标题').trim() || '无标题';
|
||||
}
|
||||
|
||||
function fileWorkspaceRelativePath(item) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('fileWorkspaceRelativePath');
|
||||
if (runtimeFn) return runtimeFn(item);
|
||||
var meta = item && item.resourceMeta && typeof item.resourceMeta === 'object' ? item.resourceMeta : {};
|
||||
var workspacePath = meta.workspacePath && typeof meta.workspacePath === 'object' ? meta.workspacePath : {};
|
||||
var fromWorkspacePath = String(workspacePath.relativePath || '').trim();
|
||||
@@ -2210,6 +2230,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function groupRowsByParent(rows) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('groupRowsByParent');
|
||||
if (runtimeFn) return runtimeFn(rows);
|
||||
var ids = new Set(rows.map(nodeIdOf).filter(Boolean));
|
||||
var grouped = new Map();
|
||||
rows.forEach(function(item) {
|
||||
@@ -11054,6 +11076,17 @@ mod tests {
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('revealFileTreeAssetRow')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('appendUploadedAssetRow')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeUploadTargetFallback')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('readProjection')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('readSidebarDataset')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('readDatasetProjection')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('projectionItems')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('hasProjectionItems')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('nodeIdOf')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('rowIdOf')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('parentIdOf')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('titleOf')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileWorkspaceRelativePath')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('groupRowsByParent')"));
|
||||
let document_id_body = js_function_body(SIDEBAR_TREE_JS, "fileTreeRowDocumentId");
|
||||
assert!(
|
||||
document_id_body.contains("data-document-id")
|
||||
@@ -11077,7 +11110,19 @@ mod tests {
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function revealFileTreeAssetRow"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function appendUploadedAssetRow"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeUploadTargetFallback"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function readProjection"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function readSidebarDataset"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function readDatasetProjection"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function projectionItems"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function hasProjectionItems"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function nodeIdOf"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function rowIdOf"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function parentIdOf"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function titleOf"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileWorkspaceRelativePath"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function groupRowsByParent"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("appendUploadedAssetRow: appendUploadedAssetRow"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("groupRowsByParent: groupRowsByParent"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
.contains("uploadIntent: String(detail.uploadIntent || 'filetree.folder.drop')"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
|
||||
Reference in New Issue
Block a user