diff --git a/web/src/components/TreeFilterDropdown/TreeFilterDropdown.tsx b/web/src/components/TreeFilterDropdown/TreeFilterDropdown.tsx index 76ab446..a6e1619 100644 --- a/web/src/components/TreeFilterDropdown/TreeFilterDropdown.tsx +++ b/web/src/components/TreeFilterDropdown/TreeFilterDropdown.tsx @@ -34,10 +34,6 @@ export const TreeFilterDropdown: React.FC = ({ const [checkedKeys, setCheckedKeys] = useState(selectedKeys); const [expandedKeys, setExpandedKeys] = useState([]); - useEffect(() => { - setCheckedKeys(selectedKeys); - }, [selectedKeys]); - const filteredTreeData = useMemo(() => { if (!query) return treeData; @@ -51,7 +47,11 @@ export const TreeFilterDropdown: React.FC = ({ } if (isMatch || filteredChildren.length > 0) { - return { ...node, children: filteredChildren.length > 0 ? filteredChildren : undefined }; + return { + ...node, + // ВАЖНО: мы оставляем родителя, но обрезаем его детей до найденных + children: filteredChildren.length > 0 ? filteredChildren : undefined, + }; } return null; }; @@ -98,8 +98,68 @@ export const TreeFilterDropdown: React.FC = ({ onClose(); }; + function checkHandler(keys: string[], info: { node: OptionType; checked: boolean }) { + const newKeys = new Set([...keys, ...selectedKeys]); + + const getAllDescendants = (node: OptionType): string[] => { + let res: string[] = []; + if (node?.children) { + node.children.forEach((child) => { + res.push(child.key); + res = [...res, ...getAllDescendants(child)]; + }); + } + return res; + }; + const findNodeByKey = (nodes: OptionType[], key: string): OptionType | undefined => { + for (const node of nodes) { + if (node.key === key) return node; + if (node.children) { + const found = findNodeByKey(node.children, key); + if (found) return found; + } + } + return undefined; + }; + function findParentByKey(nodes: OptionType[], targetKey: string, parent: OptionType | null = null): OptionType | undefined { + for (const node of nodes) { + if (node.key === targetKey) { + return parent || undefined; + } + + if (node.children) { + const foundParent = findParentByKey(node.children, targetKey, node); + if (foundParent) { + return foundParent; + } + } + } + return undefined; + } + const node = findNodeByKey(treeData, info.node.key); + const childrens = getAllDescendants(node as OptionType); + if (node?.key) { + if (info.checked) { + newKeys.add(node.key); + childrens?.forEach((elem) => newKeys.add(elem)); + } else { + const parentNode = findParentByKey(treeData, node.key); + if (parentNode?.key) { + newKeys.delete(parentNode?.key); + } + newKeys.delete(node.key); + childrens?.forEach((elem) => newKeys.delete(elem)); + } + } + + setCheckedKeys(Array.from(newKeys)); + } + useEffect(() => { + setCheckedKeys(selectedKeys); + }, [selectedKeys]); + return ( -
+
{title}
{warningBlock}
Поиск
@@ -122,16 +182,7 @@ export const TreeFilterDropdown: React.FC = ({ selectable={false} treeData={filteredTreeData} checkedKeys={visibleCheckedKeys} - onCheck={(keys) => { - const newChecked = Array.isArray(keys) ? keys : keys.checked; - - const allVisibleKeys = getAllNodeKeys(filteredTreeData); - const hiddenKeys = checkedKeys.filter((k) => !allVisibleKeys.includes(k)); - - const finalKeys = Array.from(new Set([...newChecked.map(String), ...hiddenKeys])); - - setCheckedKeys(finalKeys); - }} + onCheck={(keys, test) => checkHandler(keys as string[], test)} expandedKeys={expandedKeys} onExpand={(keys) => setExpandedKeys(keys as string[])} /> diff --git a/web/src/widgets/ConsolidationChessResTable/ConsolidatedChessResTable.css b/web/src/widgets/ConsolidationChessResTable/ConsolidatedChessResTable.css index 3a279ef..eb37592 100644 --- a/web/src/widgets/ConsolidationChessResTable/ConsolidatedChessResTable.css +++ b/web/src/widgets/ConsolidationChessResTable/ConsolidatedChessResTable.css @@ -6,6 +6,6 @@ .chessTable .ant-table-cell-fix { background-color: #f8fafc !important; } -.resRow { +.chessTable .resRow { background-color: #e6f4ea !important ; } diff --git a/web/src/widgets/ConsolidationChessTable/ConsolidatedChessTable.css b/web/src/widgets/ConsolidationChessTable/ConsolidatedChessTable.css index 2362af1..0bfdefa 100644 --- a/web/src/widgets/ConsolidationChessTable/ConsolidatedChessTable.css +++ b/web/src/widgets/ConsolidationChessTable/ConsolidatedChessTable.css @@ -1,4 +1,4 @@ -.empty-cell { +.chessTable .empty-cell { background-color: #f2f4f7; } .chessTable .ant-table-tbody > tr:hover > td.empty-cell { diff --git a/web/src/widgets/ConsolidationChessTableFilter/ConsolidationChessTableFilter.tsx b/web/src/widgets/ConsolidationChessTableFilter/ConsolidationChessTableFilter.tsx index a87908b..2a3e24b 100644 --- a/web/src/widgets/ConsolidationChessTableFilter/ConsolidationChessTableFilter.tsx +++ b/web/src/widgets/ConsolidationChessTableFilter/ConsolidationChessTableFilter.tsx @@ -151,6 +151,7 @@ export const ConsolidationChessTableFilter: React.FC ( ( (