From 51edb770bb9b50a2c6d8b4c6848c545cca75bac0 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Sun, 24 Sep 2023 20:02:34 +0800 Subject: [PATCH] fix: tableoid options value of association field in filter is incorrect (#2705) * fix: tableoid option value of association field in filter is incorrect * fix: the saving method of the association field creation button is not effective * refactor: code improve * refactor: code improve * refactor: code improve --- .../collection-select/CollectionSelect.tsx | 4 ++-- .../schema-component/antd/filter/useValues.ts | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/collection-select/CollectionSelect.tsx b/packages/core/client/src/schema-component/antd/collection-select/CollectionSelect.tsx index 86a7c7343..049876011 100644 --- a/packages/core/client/src/schema-component/antd/collection-select/CollectionSelect.tsx +++ b/packages/core/client/src/schema-component/antd/collection-select/CollectionSelect.tsx @@ -15,9 +15,9 @@ export type CollectionSelectProps = SelectProps & { function useOptions({ filter, isTableOid }: CollectionSelectProps) { const compile = useCompile(); const field: any = useField(); - const ctx = useContext(FilterContext); + const ctx: any = useContext(FilterContext); const collection = useCollection(); - const targetCollection = isTableOid && (ctx?.collectionName || collection.name); + const targetCollection = isTableOid && (ctx?.collectionName || ctx.field?.collectionName || collection.name); const inheritCollections = useSelfAndChildrenCollections(targetCollection); const { collections = [] } = useCollectionManager(); const currentCollections = field?.dataSource diff --git a/packages/core/client/src/schema-component/antd/filter/useValues.ts b/packages/core/client/src/schema-component/antd/filter/useValues.ts index a1deb7382..a8343fe10 100644 --- a/packages/core/client/src/schema-component/antd/filter/useValues.ts +++ b/packages/core/client/src/schema-component/antd/filter/useValues.ts @@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep'; import get from 'lodash/get'; import { useContext, useEffect } from 'react'; import { FilterContext } from './context'; +import { useCollection, useCollectionManager } from '../../../collection-manager'; // import { useValues } from './useValues'; const findOption = (dataIndex = [], options) => { @@ -22,7 +23,10 @@ const findOption = (dataIndex = [], options) => { export const useValues = () => { const field = useField(); - const { options } = useContext(FilterContext) || {}; + const { name } = useCollection(); + const { getCollectionJoinField } = useCollectionManager(); + const ctx: any = useContext(FilterContext) || {}; + const { options } = ctx; const data2value = () => { field.value = flat.unflatten({ [`${field.data.dataIndex?.join('.')}.${field.data?.operator?.value}`]: field.data?.value, @@ -42,6 +46,14 @@ export const useValues = () => { const operators = option?.operators; const operator = operators?.find?.((item) => item.value === `$${operatorValue}`); field.data.dataIndex = dataIndex; + if (dataIndex?.length > 1) { + const fieldNames = dataIndex.concat(); + fieldNames.pop(); + const targetField = getCollectionJoinField(`${name}.${fieldNames.join('.')}`); + ctx.field.collectionName = targetField?.target; + } else { + ctx.field.collectionName = null; + } field.data.operators = operators; field.data.operator = operator; field.data.schema = merge(option?.schema, operator?.schema); @@ -61,6 +73,14 @@ export const useValues = () => { const s2 = cloneDeep(operator?.schema); field.data.schema = merge(s1, s2); field.data.dataIndex = dataIndex; + if (dataIndex?.length > 1) { + const fieldNames = dataIndex.concat(); + fieldNames.pop(); + const targetField = getCollectionJoinField(`${name}.${fieldNames.join('.')}`); + ctx.field.collectionName = targetField?.target; + } else { + ctx.field.collectionName = null; + } field.data.value = operator?.noValue ? operator.default || true : undefined; data2value(); },