mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 15:13:04 +02:00
Flattened the sidebar tree
This commit is contained in:
@@ -2,10 +2,11 @@ import type { DragMoveEvent } from '@dnd-kit/core';
|
||||
import { jotaiStore } from '../../../lib/jotai';
|
||||
import { selectedIdsFamily } from './atoms';
|
||||
|
||||
export interface TreeNode<T extends { id: string }> {
|
||||
export interface TreeNode<T extends { id: string } > {
|
||||
children?: TreeNode<T>[];
|
||||
item: T;
|
||||
parent: TreeNode<T> | null;
|
||||
depth: number;
|
||||
}
|
||||
|
||||
export interface SelectableTreeNode<T extends { id: string }> {
|
||||
@@ -41,9 +42,10 @@ export function equalSubtree<T extends { id: string }>(
|
||||
}
|
||||
|
||||
export function hasAncestor<T extends { id: string }>(node: TreeNode<T>, ancestorId: string) {
|
||||
// Check parents recursively
|
||||
if (node.parent == null) return false;
|
||||
if (node.parent.item.id === ancestorId) return true;
|
||||
|
||||
// Check parents recursively
|
||||
return hasAncestor(node.parent, ancestorId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user