fix: obo table selector (#613)

Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
金昶 2022-07-11 18:11:27 +08:00 committed by GitHub
parent 2282ec1a2d
commit ef0d60b683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -47,7 +47,7 @@ const recursiveParent = (schema: Schema, component) => {
export const TableSelectorProvider = (props) => { export const TableSelectorProvider = (props) => {
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const ctx = useFormBlockContext() const ctx = useFormBlockContext()
const { getCollectionJoinField } = useCollectionManager(); const { getCollectionJoinField, getCollectionFields } = useCollectionManager();
const record = useRecord(); const record = useRecord();
const collectionFieldSchema = recursiveParent(fieldSchema, 'CollectionField'); const collectionFieldSchema = recursiveParent(fieldSchema, 'CollectionField');
@ -63,7 +63,6 @@ export const TableSelectorProvider = (props) => {
if (appends?.length) { if (appends?.length) {
params['appends'] = appends; params['appends'] = appends;
} }
console.log('record', record);
if (collectionField) { if (collectionField) {
if (['oho', 'o2m'].includes(collectionField.interface)) { if (['oho', 'o2m'].includes(collectionField.interface)) {
if (record?.[collectionField.sourceKey]) { if (record?.[collectionField.sourceKey]) {
@ -86,8 +85,31 @@ export const TableSelectorProvider = (props) => {
} }
} }
} }
// if (['obo'].includes(collectionField.interface)) { if (['obo'].includes(collectionField.interface)) {
// } const fields = getCollectionFields(collectionField.target);
const targetField = fields.find(f => f.foreignKey && f.foreignKey === collectionField.foreignKey);
if (targetField) {
if (record?.[collectionField.foreignKey]) {
params['filter'] = {
$or: [{
[`${targetField.name}.${targetField.foreignKey}`]: {
$is: null,
}
}, {
[`${targetField.name}.${targetField.foreignKey}`]: {
$eq: record?.[collectionField.foreignKey],
}
}]
}
} else {
params['filter'] = {
[`${targetField.name}.${targetField.foreignKey}`]: {
$is: null,
}
}
}
}
}
} }
return ( return (
<BlockProvider {...props} params={params}> <BlockProvider {...props} params={params}>

View File

@ -37,6 +37,7 @@ const useTableColumns = () => {
} }
}, []); }, []);
const dataIndex = collectionFields?.length > 0 ? collectionFields[0].name : s.name; const dataIndex = collectionFields?.length > 0 ? collectionFields[0].name : s.name;
return { return {
title: <RecursionField name={s.name} schema={s} onlyRenderSelf />, title: <RecursionField name={s.name} schema={s} onlyRenderSelf />,
dataIndex, dataIndex,