mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
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:
parent
febaef9cf9
commit
a7775c25db
@ -23,6 +23,7 @@ import {
|
|||||||
SchemaComponentContext,
|
SchemaComponentContext,
|
||||||
useAPIClient,
|
useAPIClient,
|
||||||
useCollectionRecordData,
|
useCollectionRecordData,
|
||||||
|
useCollectionManager_deprecated,
|
||||||
} from '../../../';
|
} from '../../../';
|
||||||
import { VariablePopupRecordProvider } from '../../../modules/variable/variablesProvider/VariablePopupRecordProvider';
|
import { VariablePopupRecordProvider } from '../../../modules/variable/variablesProvider/VariablePopupRecordProvider';
|
||||||
import { isVariable } from '../../../variables/utils/isVariable';
|
import { isVariable } from '../../../variables/utils/isVariable';
|
||||||
@ -31,6 +32,11 @@ import { Action } from '../action';
|
|||||||
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
|
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
|
||||||
import useServiceOptions, { useAssociationFieldContext } from './hooks';
|
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) => {
|
export const AssociationFieldAddNewer = (props) => {
|
||||||
const schemaComponentCtxValue = useContext(SchemaComponentContext);
|
const schemaComponentCtxValue = useContext(SchemaComponentContext);
|
||||||
return (
|
return (
|
||||||
@ -93,6 +99,9 @@ const InternalAssociationSelect = observer(
|
|||||||
const resource = api.resource(collectionField.target);
|
const resource = api.resource(collectionField.target);
|
||||||
const recordData = useCollectionRecordData();
|
const recordData = useCollectionRecordData();
|
||||||
const schemaComponentCtxValue = useContext(SchemaComponentContext);
|
const schemaComponentCtxValue = useContext(SchemaComponentContext);
|
||||||
|
const { getCollection } = useCollectionManager_deprecated();
|
||||||
|
const associationCollection = getCollection(collectionField.target);
|
||||||
|
const { filterTargetKey } = associationCollection;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initValue = isVariable(field.value) ? undefined : field.value;
|
const initValue = isVariable(field.value) ? undefined : field.value;
|
||||||
@ -167,7 +176,7 @@ const InternalAssociationSelect = observer(
|
|||||||
{...rest}
|
{...rest}
|
||||||
size={'middle'}
|
size={'middle'}
|
||||||
objectValue={objectValue}
|
objectValue={objectValue}
|
||||||
value={value || innerValue}
|
value={removeIfKeyEmpty(value || innerValue, filterTargetKey)}
|
||||||
service={service}
|
service={service}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
const val = value?.length !== 0 ? value : null;
|
const val = value?.length !== 0 ? value : null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user