fix: association field (select) displaying N/A when exposing related collection fields (#6582)

* fix: association field (select) displaying N/A when exposing related collection fields

* fix: cascade issue: 'The value of xxx cannot be in array format' when deleting and re-selecting

* fix: bug
This commit is contained in:
Katherine 2025-03-31 14:42:16 +08:00 committed by GitHub
parent febaef9cf9
commit a7775c25db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ import {
SchemaComponentContext,
useAPIClient,
useCollectionRecordData,
useCollectionManager_deprecated,
} from '../../../';
import { VariablePopupRecordProvider } from '../../../modules/variable/variablesProvider/VariablePopupRecordProvider';
import { isVariable } from '../../../variables/utils/isVariable';
@ -31,6 +32,11 @@ import { Action } from '../action';
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
import useServiceOptions, { useAssociationFieldContext } from './hooks';
const removeIfKeyEmpty = (obj, filterTargetKey) => {
if (!obj || typeof obj !== 'object' || !filterTargetKey) return obj;
return !obj[filterTargetKey] ? null : obj;
};
export const AssociationFieldAddNewer = (props) => {
const schemaComponentCtxValue = useContext(SchemaComponentContext);
return (
@ -93,6 +99,9 @@ const InternalAssociationSelect = observer(
const resource = api.resource(collectionField.target);
const recordData = useCollectionRecordData();
const schemaComponentCtxValue = useContext(SchemaComponentContext);
const { getCollection } = useCollectionManager_deprecated();
const associationCollection = getCollection(collectionField.target);
const { filterTargetKey } = associationCollection;
useEffect(() => {
const initValue = isVariable(field.value) ? undefined : field.value;
@ -167,7 +176,7 @@ const InternalAssociationSelect = observer(
{...rest}
size={'middle'}
objectValue={objectValue}
value={value || innerValue}
value={removeIfKeyEmpty(value || innerValue, filterTargetKey)}
service={service}
onChange={(value) => {
const val = value?.length !== 0 ? value : null;