mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
feat(skill-editor): render flat search result list in file tree
Replace the tree-filtered search with a flat list that shows icon + name on the left and parent path on the right, matching the Figma design. Clicking a file opens its tab; clicking a folder clears the search and reveals the folder in the tree.
This commit is contained in:
@ -199,6 +199,37 @@ function insertDraftNodeAtParent(
|
||||
return { nodes: inserted ? nextNodes : nodes, inserted }
|
||||
}
|
||||
|
||||
export type FlatSearchResult = {
|
||||
node: AppAssetTreeView
|
||||
parentPath: string
|
||||
}
|
||||
|
||||
export function flattenMatchingNodes(
|
||||
nodes: AppAssetTreeView[],
|
||||
searchTerm: string,
|
||||
): FlatSearchResult[] {
|
||||
if (!searchTerm)
|
||||
return []
|
||||
|
||||
const results: FlatSearchResult[] = []
|
||||
const lowerTerm = searchTerm.toLowerCase()
|
||||
|
||||
function traverse(nodeList: AppAssetTreeView[]): void {
|
||||
for (const node of nodeList) {
|
||||
if (node.name.toLowerCase().includes(lowerTerm)) {
|
||||
const lastSlash = node.path.lastIndexOf('/')
|
||||
const parentPath = lastSlash > 0 ? node.path.slice(1, lastSlash) : ''
|
||||
results.push({ node, parentPath })
|
||||
}
|
||||
if (node.children && node.children.length > 0)
|
||||
traverse(node.children)
|
||||
}
|
||||
}
|
||||
|
||||
traverse(nodes)
|
||||
return results
|
||||
}
|
||||
|
||||
export function insertDraftTreeNode(
|
||||
nodes: AppAssetTreeView[],
|
||||
parentId: string | null,
|
||||
|
||||
Reference in New Issue
Block a user