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;
}
},
[utils]
[utils, value]
);
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 {
const allKeyIds =
keys.map((key) => key.toString()).filter(Boolean) || [];
const expandedNodes = await utils.term.getChildSimpleTree.fetch({
const expandedNodes = await utils.term.getChildSimpleTree.fetch(
{
termIds: allKeyIds,
taxonomyId,
domainId,
});
}
);
const flattenedNodes = expandedNodes.flat();
const newItems = getUniqueItems(
[...listTreeData, ...flattenedNodes],
@ -155,9 +158,16 @@ export default function TermSelect({
);
setListTreeData(newItems);
} 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) => {
if (open) {
// This will attempt to expand all nodes and fetch their children when the dropdown opens