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
This commit is contained in:
katherinehhh 2023-09-24 20:02:34 +08:00 committed by GitHub
parent d83afc52ec
commit 51edb770bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -15,9 +15,9 @@ export type CollectionSelectProps = SelectProps<any, any> & {
function useOptions({ filter, isTableOid }: CollectionSelectProps) { function useOptions({ filter, isTableOid }: CollectionSelectProps) {
const compile = useCompile(); const compile = useCompile();
const field: any = useField(); const field: any = useField();
const ctx = useContext(FilterContext); const ctx: any = useContext(FilterContext);
const collection = useCollection(); 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 inheritCollections = useSelfAndChildrenCollections(targetCollection);
const { collections = [] } = useCollectionManager(); const { collections = [] } = useCollectionManager();
const currentCollections = field?.dataSource const currentCollections = field?.dataSource

View File

@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep';
import get from 'lodash/get'; import get from 'lodash/get';
import { useContext, useEffect } from 'react'; import { useContext, useEffect } from 'react';
import { FilterContext } from './context'; import { FilterContext } from './context';
import { useCollection, useCollectionManager } from '../../../collection-manager';
// import { useValues } from './useValues'; // import { useValues } from './useValues';
const findOption = (dataIndex = [], options) => { const findOption = (dataIndex = [], options) => {
@ -22,7 +23,10 @@ const findOption = (dataIndex = [], options) => {
export const useValues = () => { export const useValues = () => {
const field = useField<any>(); const field = useField<any>();
const { options } = useContext(FilterContext) || {}; const { name } = useCollection();
const { getCollectionJoinField } = useCollectionManager();
const ctx: any = useContext(FilterContext) || {};
const { options } = ctx;
const data2value = () => { const data2value = () => {
field.value = flat.unflatten({ field.value = flat.unflatten({
[`${field.data.dataIndex?.join('.')}.${field.data?.operator?.value}`]: field.data?.value, [`${field.data.dataIndex?.join('.')}.${field.data?.operator?.value}`]: field.data?.value,
@ -42,6 +46,14 @@ export const useValues = () => {
const operators = option?.operators; const operators = option?.operators;
const operator = operators?.find?.((item) => item.value === `$${operatorValue}`); const operator = operators?.find?.((item) => item.value === `$${operatorValue}`);
field.data.dataIndex = dataIndex; 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.operators = operators;
field.data.operator = operator; field.data.operator = operator;
field.data.schema = merge(option?.schema, operator?.schema); field.data.schema = merge(option?.schema, operator?.schema);
@ -61,6 +73,14 @@ export const useValues = () => {
const s2 = cloneDeep(operator?.schema); const s2 = cloneDeep(operator?.schema);
field.data.schema = merge(s1, s2); field.data.schema = merge(s1, s2);
field.data.dataIndex = dataIndex; 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; field.data.value = operator?.noValue ? operator.default || true : undefined;
data2value(); data2value();
}, },