opti: style improve of sidebar and topbar #572;

This commit is contained in:
mitsuhatu
2022-07-27 17:40:42 +08:00
parent 9f0064978d
commit 7820fd7b34
11 changed files with 90 additions and 33 deletions
@@ -0,0 +1,25 @@
import { TreeItem, TreeItems } from './../workspace-sidebar/page-tree';
const pickPath = (treeItems: TreeItem | TreeItems, targetId: string) => {
const pick = (tree: TreeItem, result: TreeItem[] = []) => {
if (tree.id === targetId) {
result.push(tree);
return result;
}
for (const child of tree?.children || []) {
if (pick(child, result).length) {
result.unshift(tree);
break;
}
}
return result;
};
return (Array.isArray(treeItems) ? treeItems : [treeItems]).map(treeItem =>
pick(treeItem)
);
};
export { pickPath };