This commit is contained in:
ditiqi 2025-02-25 22:04:19 +08:00
parent 6b699a4092
commit 3499231119
1 changed files with 30 additions and 20 deletions

View File

@ -72,7 +72,7 @@ export default function TermSelect({
throw error; throw error;
} }
}, },
[utils] [utils, value]
); );
const fetchTerms = useCallback(async () => { const fetchTerms = useCallback(async () => {
@ -139,15 +139,18 @@ export default function TermSelect({
} }
}; };
const handleExpand = async (keys: React.Key[]) => { const handleExpand = useCallback(
async (keys: React.Key[]) => {
try { try {
const allKeyIds = const allKeyIds =
keys.map((key) => key.toString()).filter(Boolean) || []; keys.map((key) => key.toString()).filter(Boolean) || [];
const expandedNodes = await utils.term.getChildSimpleTree.fetch({ const expandedNodes = await utils.term.getChildSimpleTree.fetch(
{
termIds: allKeyIds, termIds: allKeyIds,
taxonomyId, taxonomyId,
domainId, domainId,
}); }
);
const flattenedNodes = expandedNodes.flat(); const flattenedNodes = expandedNodes.flat();
const newItems = getUniqueItems( const newItems = getUniqueItems(
[...listTreeData, ...flattenedNodes], [...listTreeData, ...flattenedNodes],
@ -155,9 +158,16 @@ export default function TermSelect({
); );
setListTreeData(newItems); setListTreeData(newItems);
} catch (error) { } catch (error) {
console.error("Error expanding nodes with keys", keys, ":", error); console.error(
"Error expanding nodes with keys",
keys,
":",
error
);
} }
}; },
[value]
);
const handleDropdownVisibleChange = async (open: boolean) => { const handleDropdownVisibleChange = async (open: boolean) => {
if (open) { if (open) {
// This will attempt to expand all nodes and fetch their children when the dropdown opens // This will attempt to expand all nodes and fetch their children when the dropdown opens