From 963272e47fb8261e8de9ee53507cdaf8b5bd776a Mon Sep 17 00:00:00 2001 From: yxh01132861 Date: Fri, 22 Dec 2023 10:10:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/widgets/FilterControl/Component/DateItem.tsx | 6 +++--- .../src/widgets/FilterControl/Component/NumberItem.tsx | 8 ++++---- .../src/widgets/FilterControl/Component/StringItem.tsx | 6 +++--- .../src/widgets/FilterControl/Component/index.tsx | 6 ++++-- .../FilterModal/FilterContent/DateItem/index.tsx | 2 +- .../FilterModal/FilterContent/NumberItem/index.tsx | 8 ++++---- .../FilterModal/FilterContent/StringItem/index.tsx | 6 +++--- .../Formily/FilterConfiguration/FilterModal/helper.ts | 8 ++++---- .../src/components/Formily/FilterConfiguration/type.ts | 8 ++++---- packages/li-p2/src/components/Formily/index.ts | 7 ++++++- 10 files changed, 36 insertions(+), 29 deletions(-) diff --git a/packages/li-analysis-assets/src/widgets/FilterControl/Component/DateItem.tsx b/packages/li-analysis-assets/src/widgets/FilterControl/Component/DateItem.tsx index 842734f0..d8578a7c 100644 --- a/packages/li-analysis-assets/src/widgets/FilterControl/Component/DateItem.tsx +++ b/packages/li-analysis-assets/src/widgets/FilterControl/Component/DateItem.tsx @@ -1,10 +1,10 @@ -import type { DateConfig } from '@antv/li-p2'; +import type { FilterDateConfigType } from '@antv/li-p2'; import React from 'react'; import { FilterDateConfig } from '@antv/li-p2'; export interface DateItemProps { - value: DateConfig; - onChange: (value: DateConfig) => void; + value: FilterDateConfigType; + onChange: (value: FilterDateConfigType) => void; } const DateItem: React.FC = (props) => { diff --git a/packages/li-analysis-assets/src/widgets/FilterControl/Component/NumberItem.tsx b/packages/li-analysis-assets/src/widgets/FilterControl/Component/NumberItem.tsx index 763b7199..1d29f0d4 100644 --- a/packages/li-analysis-assets/src/widgets/FilterControl/Component/NumberItem.tsx +++ b/packages/li-analysis-assets/src/widgets/FilterControl/Component/NumberItem.tsx @@ -1,13 +1,13 @@ import { DownOutlined } from '@ant-design/icons'; -import type { NumberConfig } from '@antv/li-p2'; +import type { FilterNumberConfigType } from '@antv/li-p2'; import { FilterNumberConfig } from '@antv/li-p2'; import { Button, Popover } from 'antd'; import React, { useState } from 'react'; import useStyle from './style'; export interface NumberItemProps { - value: NumberConfig; - onChange: (value: NumberConfig) => void; + value: FilterNumberConfigType; + onChange: (value: FilterNumberConfigType) => void; } const NumberItem: React.FC = (props) => { @@ -29,7 +29,7 @@ const NumberItem: React.FC = (props) => { }; const onSubmit = () => { - const numberNode = { ...defaluValue, ...valAndOperator } as NumberConfig; + const numberNode = { ...defaluValue, ...valAndOperator } as FilterNumberConfigType; onChange(numberNode); setOpen(false); }; diff --git a/packages/li-analysis-assets/src/widgets/FilterControl/Component/StringItem.tsx b/packages/li-analysis-assets/src/widgets/FilterControl/Component/StringItem.tsx index 14c1093f..22632868 100644 --- a/packages/li-analysis-assets/src/widgets/FilterControl/Component/StringItem.tsx +++ b/packages/li-analysis-assets/src/widgets/FilterControl/Component/StringItem.tsx @@ -1,13 +1,13 @@ -import type { StringConfig } from '@antv/li-p2'; +import type { FilterStringConfigType } from '@antv/li-p2'; import { FilterStringConfig } from '@antv/li-p2'; import { uniq } from 'lodash-es'; import React, { useMemo } from 'react'; export interface StringItemProps { - value: StringConfig; + value: FilterStringConfigType; field: string; data: Record[]; - onChange: (value: StringConfig) => void; + onChange: (value: FilterStringConfigType) => void; } const StringItem: React.FC = (props) => { diff --git a/packages/li-analysis-assets/src/widgets/FilterControl/Component/index.tsx b/packages/li-analysis-assets/src/widgets/FilterControl/Component/index.tsx index 6c419b74..51b2602d 100644 --- a/packages/li-analysis-assets/src/widgets/FilterControl/Component/index.tsx +++ b/packages/li-analysis-assets/src/widgets/FilterControl/Component/index.tsx @@ -26,7 +26,7 @@ const LIFilterControl: React.FC = (props) => { const { data: tableData = [] } = dataset || {}; const [filterList, setFilterList] = useState(defaultFilters); // 筛选数据 - const [_, { addFilterNode, updateFilter }] = useDatasetFilter(datasetId); + const [_, { addFilterNode, updateFilterNode, updateFilter }] = useDatasetFilter(datasetId); const firstMountRef = useRef(false); // 首次挂载 @@ -55,7 +55,9 @@ const LIFilterControl: React.FC = (props) => { }); setFilterList(_filterList); - updateFilter({ relation: 'AND', children: getFilterNodes(_filterList) }); + + const filterNode = getFilterNodes([val])[0]; + updateFilterNode(val.id, filterNode); }; if (!defaultFilters.length) { diff --git a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/DateItem/index.tsx b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/DateItem/index.tsx index 9f9c55c8..68a0ad4a 100644 --- a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/DateItem/index.tsx +++ b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/DateItem/index.tsx @@ -6,7 +6,7 @@ import { FilterDateSetting } from '../../../components'; import { DEFAULT_OPTIONS } from '../../../components/FilterDateConfig/contents'; import { getTimeFormat } from '../../../components/FilterDateConfig/helper'; import type { GranularityItem } from '../../../components/FilterDateConfig/type'; -import type { DateConfig as FilterDateType } from '../../../type'; +import type { FilterDateConfigType as FilterDateType } from '../../../type'; import { getOptions } from './helper'; import useStyle from './style'; export interface DateItemProps { diff --git a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/NumberItem/index.tsx b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/NumberItem/index.tsx index 4f60b1f5..d7c6f2a2 100644 --- a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/NumberItem/index.tsx +++ b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/NumberItem/index.tsx @@ -1,16 +1,16 @@ import { usePrefixCls } from '@formily/antd-v5/esm/__builtins__'; import cls from 'classnames'; import React from 'react'; -import type { NumberConfig } from '../../../type'; +import type { FilterNumberConfigType } from '../../../type'; import { FilterNumberConfig } from '../../../components'; import useStyle from './style'; export interface NumberItemProps { - value: NumberConfig; + value: FilterNumberConfigType; /** * 选择发生改变时 */ - onChange: (value: NumberConfig) => void; + onChange: (value: FilterNumberConfigType) => void; } const NumberItem: React.FC = (props) => { @@ -24,7 +24,7 @@ const NumberItem: React.FC = (props) => { ...defaultValue, value: val, operator, - } as NumberConfig; + } as FilterNumberConfigType; onChange(_value); }; diff --git a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/StringItem/index.tsx b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/StringItem/index.tsx index 806d23a2..4257bab7 100644 --- a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/StringItem/index.tsx +++ b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/FilterContent/StringItem/index.tsx @@ -3,12 +3,12 @@ import { Radio } from 'antd'; import cls from 'classnames'; import React from 'react'; import { FilterStringConfig } from '../../../components'; -import type { StringConfig } from '../../../type'; +import type { FilterStringConfigType } from '../../../type'; import useStyle from './style'; export interface StringItemProps { - value: StringConfig; + value: FilterStringConfigType; options: string[]; - onChange: (value: StringConfig) => void; + onChange: (value: FilterStringConfigType) => void; } const StringItem: React.FC = (props) => { diff --git a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/helper.ts b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/helper.ts index bc837bd0..fc57497e 100644 --- a/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/helper.ts +++ b/packages/li-p2/src/components/Formily/FilterConfiguration/FilterModal/helper.ts @@ -1,8 +1,8 @@ -import type { DateConfig, NumberConfig, StringConfig, OptionType } from '../type'; +import type { FilterDateConfigType, FilterNumberConfigType, FilterStringConfigType, OptionType } from '../type'; export const getDefaultValue = (field: OptionType, id: string) => { if (field.type === 'string') { - const _filter: StringConfig = { + const _filter: FilterStringConfigType = { id, title: field.value, field: field.value, @@ -17,7 +17,7 @@ export const getDefaultValue = (field: OptionType, id: string) => { } if (field.type === 'date') { - const _filter: DateConfig = { + const _filter: FilterDateConfigType = { id, title: field.value, field: field.value, @@ -32,7 +32,7 @@ export const getDefaultValue = (field: OptionType, id: string) => { return _filter; } - const _filter: NumberConfig = { + const _filter: FilterNumberConfigType = { id, title: field.value, field: field.value, diff --git a/packages/li-p2/src/components/Formily/FilterConfiguration/type.ts b/packages/li-p2/src/components/Formily/FilterConfiguration/type.ts index abdc7c49..f2a590a8 100644 --- a/packages/li-p2/src/components/Formily/FilterConfiguration/type.ts +++ b/packages/li-p2/src/components/Formily/FilterConfiguration/type.ts @@ -42,7 +42,7 @@ type FilterConfigBase = { field: string; }; -export type StringConfig = FilterConfigBase & { +export type FilterStringConfigType = FilterConfigBase & { type: 'string'; operator: 'IN'; value?: string[]; @@ -52,7 +52,7 @@ export type StringConfig = FilterConfigBase & { }; }; -export type DateConfig = FilterConfigBase & { +export type FilterDateConfigType = FilterConfigBase & { type: 'date'; /** 日期粒度 */ granularity: Granularity; @@ -66,7 +66,7 @@ export type DateConfig = FilterConfigBase & { }; }; -export type NumberConfig = FilterConfigBase & +export type FilterNumberConfigType = FilterConfigBase & ( | { type: 'number'; @@ -80,4 +80,4 @@ export type NumberConfig = FilterConfigBase & } ); -export type FilterConfig = DateConfig | NumberConfig | StringConfig; +export type FilterConfig = FilterDateConfigType | FilterNumberConfigType | FilterStringConfigType; diff --git a/packages/li-p2/src/components/Formily/index.ts b/packages/li-p2/src/components/Formily/index.ts index b6771f6a..fe76a11c 100644 --- a/packages/li-p2/src/components/Formily/index.ts +++ b/packages/li-p2/src/components/Formily/index.ts @@ -11,7 +11,12 @@ export { default as Slider } from './Slider'; export { default as SliderRange } from './SliderRange'; export { default as TimeGranularitySelect } from './TimeGranularitySelect'; export { default as FilterConfiguration } from './FilterConfiguration'; -export type { FilterConfig, DateConfig, NumberConfig, StringConfig } from './FilterConfiguration/type'; +export type { + FilterConfig, + FilterDateConfigType, + FilterNumberConfigType, + FilterStringConfigType, +} from './FilterConfiguration/type'; export { default as FilterDateConfig } from './FilterConfiguration/components/FilterDateConfig'; export { default as FilterStringConfig } from './FilterConfiguration/components/FilterStringConfig'; export { default as FilterNumberConfig } from './FilterConfiguration/components/FilterNumberConfig';