From cba46cc29caab55d0dba783369ecc59c38833665 Mon Sep 17 00:00:00 2001 From: sealday Date: Mon, 25 Mar 2024 20:40:08 +0800 Subject: [PATCH] fix: association cascader can not filter --- .../AssociationCascader.tsx | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx index d9737762e..1dace2bc0 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx @@ -40,8 +40,41 @@ const AssociationCascader = connect((props) => { })); return options; }, [associationField, joinTitleField, titleField, data?.data]); - return ; + return ; }); +const SingleValueCascader = (props) => { + const { value, options, onChange, fieldNames } = props; + const arrayValue = value && options ? [] : undefined; + if (arrayValue) { + for (const option of options) { + if (option[fieldNames.value] === value) { + arrayValue.push(option[fieldNames.value]); + break; + } + for (const subOption of option.children) { + if (subOption[fieldNames.value] === value) { + arrayValue.push(option[fieldNames.value]); + arrayValue.push(subOption[fieldNames.value]); + break; + } + } + } + } + const newProps = { + ...props, + value: arrayValue, + onChange: (v) => { + if (v) { + onChange(v[v.length - 1]); + } else { + onChange(v); + } + }, + }; + return ; +}; + +SingleValueCascader.displayName = 'SingleValueCascader'; AssociationCascader.displayName = 'AssociationCascader'; export default AssociationCascader;