jskim-node #396

Merged
kjs merged 44 commits from jskim-node into main 2026-02-28 14:37:11 +09:00
1 changed files with 27 additions and 8 deletions
Showing only changes of commit 1a6d78df43 - Show all commits

View File

@ -937,19 +937,38 @@ export function BomItemEditorComponent({
setItemSearchOpen(true); setItemSearchOpen(true);
}, []); }, []);
// 이미 추가된 품목 ID 목록 (중복 방지용) // 같은 레벨(형제) 품목 ID 목록 (동일 레벨 중복 방지, 하위 레벨은 허용)
const existingItemIds = useMemo(() => { const existingItemIds = useMemo(() => {
const ids = new Set<string>(); const ids = new Set<string>();
const collect = (nodes: BomItemNode[]) => { const fkField = cfg.dataSource?.foreignKey || "child_item_id";
for (const n of nodes) {
const fk = n.data[cfg.dataSource?.foreignKey || "child_item_id"]; if (addTargetParentId === null) {
// 루트 레벨 추가: 루트 노드의 형제들만 체크
for (const n of treeData) {
const fk = n.data[fkField];
if (fk) ids.add(fk); if (fk) ids.add(fk);
collect(n.children);
} }
} else {
// 하위 추가: 해당 부모의 직속 자식들만 체크
const findParent = (nodes: BomItemNode[]): BomItemNode | null => {
for (const n of nodes) {
if (n.tempId === addTargetParentId) return n;
const found = findParent(n.children);
if (found) return found;
}
return null;
}; };
collect(treeData); const parent = findParent(treeData);
if (parent) {
for (const child of parent.children) {
const fk = child.data[fkField];
if (fk) ids.add(fk);
}
}
}
return ids; return ids;
}, [treeData, cfg]); }, [treeData, cfg, addTargetParentId]);
// 루트 품목 추가 시작 // 루트 품목 추가 시작
const handleAddRoot = useCallback(() => { const handleAddRoot = useCallback(() => {