fix: avoid o2o, o2m can select the data already selected (#1462)
* fix: avoid o2o, o2m can select the data already selected * fix: o2m
This commit is contained in:
parent
1beb25da70
commit
92185ec57c
@ -81,12 +81,12 @@ const InternalAssociationSelect = connect(
|
||||
mapReadPretty(ReadPretty),
|
||||
);
|
||||
|
||||
interface RemoteSelectInterface {
|
||||
interface AssociationSelectInterface {
|
||||
(props: any): React.ReactElement;
|
||||
Designer: React.FC;
|
||||
}
|
||||
|
||||
export const AssociationSelect = InternalAssociationSelect as unknown as RemoteSelectInterface;
|
||||
export const AssociationSelect = InternalAssociationSelect as unknown as AssociationSelectInterface;
|
||||
|
||||
AssociationSelect.Designer = () => {
|
||||
const { getCollectionFields, getInterface, getCollectionJoinField } = useCollectionManager();
|
||||
|
@ -1,20 +1,51 @@
|
||||
import { useFieldSchema } from '@formily/react';
|
||||
import { useMemo } from 'react';
|
||||
import { useCollection } from '../../../collection-manager';
|
||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||
import { useRecord } from '../../../record-provider';
|
||||
|
||||
export default function useServiceOptions(props) {
|
||||
const { action = 'list', service } = props;
|
||||
const { action = 'list', service, params, value } = props;
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { getField } = useCollection();
|
||||
const { getCollectionFields } = useCollectionManager();
|
||||
const record = useRecord();
|
||||
|
||||
const collectionField = useMemo(() => {
|
||||
return getField(fieldSchema.name);
|
||||
}, [fieldSchema.name]);
|
||||
|
||||
const filter = useMemo(() => {
|
||||
if (!collectionField) return params?.filter;
|
||||
let extraFilter = {};
|
||||
if (['oho', 'o2m'].includes(collectionField.interface)) {
|
||||
const eqValue = record?.[collectionField.sourceKey];
|
||||
extraFilter = {
|
||||
$or: [
|
||||
{
|
||||
[collectionField.foreignKey]: {
|
||||
$is: null,
|
||||
},
|
||||
},
|
||||
eqValue !== undefined && eqValue !== null
|
||||
? {
|
||||
[collectionField.foreignKey]: {
|
||||
$eq: eqValue,
|
||||
},
|
||||
}
|
||||
: null,
|
||||
].filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
return params?.filter ? { $and: [extraFilter, params?.filter] } : extraFilter;
|
||||
}, [params?.filter, getCollectionFields, collectionField]);
|
||||
|
||||
return useMemo(() => {
|
||||
return {
|
||||
resource: collectionField?.target,
|
||||
action,
|
||||
...service,
|
||||
params: { ...service?.params, filter },
|
||||
};
|
||||
}, [collectionField?.target, action, service]);
|
||||
}, [collectionField?.target, action, filter, service]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user