fix: filter-condition-update-incorrectly(switch "and"、"or") (#1737)

This commit is contained in:
black 2023-04-21 11:04:46 +08:00 committed by GitHub
parent 5d2724583c
commit 9c4f1a8d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,13 +4,13 @@ import flat from 'flat';
import cloneDeep from 'lodash/cloneDeep'; 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, FilterLogicContext } from './context'; import { FilterContext } from './context';
// import { useValues } from './useValues'; // import { useValues } from './useValues';
const findOption = (dataIndex = [], options) => { const findOption = (dataIndex = [], options) => {
let items = options; let items = options;
let option; let option;
dataIndex?.forEach?.((name, index) => { dataIndex?.forEach?.((name) => {
const item = items.find((item) => item.name === name); const item = items.find((item) => item.name === name);
if (item) { if (item) {
option = item; option = item;
@ -22,7 +22,6 @@ const findOption = (dataIndex = [], options) => {
export const useValues = () => { export const useValues = () => {
const field = useField<any>(); const field = useField<any>();
const logic = useContext(FilterLogicContext);
const { options } = useContext(FilterContext); const { options } = useContext(FilterContext);
const data2value = () => { const data2value = () => {
field.value = flat.unflatten({ field.value = flat.unflatten({
@ -48,7 +47,7 @@ export const useValues = () => {
field.data.schema = merge(option?.schema, operator?.schema); field.data.schema = merge(option?.schema, operator?.schema);
field.data.value = get(field.value, `${fieldPath}.$${operatorValue}`); field.data.value = get(field.value, `${fieldPath}.$${operatorValue}`);
}; };
useEffect(value2data, [logic]); useEffect(value2data, [field.path.entire]);
return { return {
fields: options, fields: options,
...field.data, ...field.data,