(props: React.HTMLProps<HTMLDivElement>)
| 12 | import "./FileTree.css"; |
| 13 | |
| 14 | const FileTree = (props: React.HTMLProps<HTMLDivElement>) => { |
| 15 | const { |
| 16 | db, |
| 17 | initialized, |
| 18 | importedSqliteFilePath, |
| 19 | currentPath, |
| 20 | startProcessing, |
| 21 | endProcessing, |
| 22 | updateCurrentPath, |
| 23 | } = useWorkbenchDB(); |
| 24 | |
| 25 | const [treeData, setTreeData] = useState<FileDataNode[] | null>(null); |
| 26 | const [expandedKeys, setExpandedKeys] = useState<Key[]>([]); |
| 27 | |
| 28 | useEffect(() => { |
| 29 | if (currentPath.length === 0) return; |
| 30 | |
| 31 | // Show working indicator while the FileTree Node is being rendered and focused |
| 32 | startProcessing(); |
| 33 | |
| 34 | setExpandedKeys((keys) => { |
| 35 | return [...keys, currentPath.substring(0, currentPath.lastIndexOf("/"))]; |
| 36 | }); |
| 37 | |
| 38 | // Scroll to selected filetree node |
| 39 | // Hide working indicator after the FileTree Node is focused |
| 40 | const clearThrottledScroll = throttledScroller( |
| 41 | `[data-tree-node-id="${currentPath}"]`, |
| 42 | () => endProcessing() |
| 43 | ); |
| 44 | |
| 45 | return () => { |
| 46 | // Clear any pending scroll timeout |
| 47 | clearThrottledScroll(); |
| 48 | }; |
| 49 | }, [currentPath]); |
| 50 | |
| 51 | useEffect(() => { |
| 52 | if (!initialized || !db || !importedSqliteFilePath) { |
| 53 | setTreeData(null); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | db.findAllJSTree().then((treeData) => { |
| 58 | // Wrap with react-scroll wrapper |
| 59 | function wrapNode(node: FileDataNode) { |
| 60 | const key = String(node.key); |
| 61 | node.title = ( |
| 62 | <Element |
| 63 | key={key} |
| 64 | name={key} |
| 65 | className="filetree-node-wrapper" |
| 66 | data-tree-node-id={key} |
| 67 | > |
| 68 | <span>{String(node.title)}</span> |
| 69 | </Element> |
| 70 | ); |
| 71 | node.children?.forEach(wrapNode); |
nothing calls this directly
no test coverage detected