From 7dc74b1da9790cdf0e64b9b25e8c003992b3a196 Mon Sep 17 00:00:00 2001 From: Zack Chang <73225408+jrr997@users.noreply.github.com> Date: Sun, 25 Jun 2023 12:17:44 +0800 Subject: [PATCH] refactor: solve circular reference of Table (#42813) * refactor: solve circular reference of Table * Update index.tsx * chore: add export --- .../table/hooks/useFilter/FilterDropdown.tsx | 21 ++++++++++++++----- components/table/hooks/useFilter/index.tsx | 16 +++----------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index 7c7358a3a0..3532ecbf30 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -1,34 +1,34 @@ import FilterFilled from '@ant-design/icons/FilterFilled'; import classNames from 'classnames'; -import isEqual from 'rc-util/lib/isEqual'; import type { FieldDataNode } from 'rc-tree'; +import isEqual from 'rc-util/lib/isEqual'; import * as React from 'react'; -import type { MenuProps } from '../../../menu'; import type { FilterState } from '.'; -import { flattenKeys } from '.'; +import useSyncState from '../../../_util/hooks/useSyncState'; +import warning from '../../../_util/warning'; import Button from '../../../button'; import type { CheckboxChangeEvent } from '../../../checkbox'; import Checkbox from '../../../checkbox'; import { ConfigContext } from '../../../config-provider/context'; import Dropdown from '../../../dropdown'; import Empty from '../../../empty'; +import type { MenuProps } from '../../../menu'; import Menu from '../../../menu'; import { OverrideProvider } from '../../../menu/OverrideContext'; import Radio from '../../../radio'; import type { EventDataNode } from '../../../tree'; import Tree from '../../../tree'; -import useSyncState from '../../../_util/hooks/useSyncState'; import type { ColumnFilterItem, ColumnType, FilterSearchType, + FilterValue, GetPopupContainer, Key, TableLocale, } from '../../interface'; import FilterSearch from './FilterSearch'; import FilterDropdownMenuWrapper from './FilterWrapper'; -import warning from '../../../_util/warning'; type FilterTreeDataNode = FieldDataNode<{ title: React.ReactNode; key: React.Key }>; @@ -37,6 +37,17 @@ interface FilterRestProps { closeDropdown?: Boolean; } +export function flattenKeys(filters?: ColumnFilterItem[]) { + let keys: FilterValue = []; + (filters || []).forEach(({ value, children }) => { + keys.push(value); + if (children) { + keys = [...keys, ...flattenKeys(children)]; + } + }); + return keys; +} + function hasSubMenu(filters: ColumnFilterItem[]) { return filters.some(({ children }) => children); } diff --git a/components/table/hooks/useFilter/index.tsx b/components/table/hooks/useFilter/index.tsx index ae58ffe464..c721916fe2 100644 --- a/components/table/hooks/useFilter/index.tsx +++ b/components/table/hooks/useFilter/index.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import warning from '../../../_util/warning'; import type { - ColumnFilterItem, ColumnsType, ColumnTitleProps, ColumnType, @@ -13,7 +12,7 @@ import type { TransformColumns, } from '../../interface'; import { getColumnKey, getColumnPos, renderColumnTitle } from '../../util'; -import FilterDropdown from './FilterDropdown'; +import FilterDropdown, { flattenKeys } from './FilterDropdown'; export interface FilterState { column: ColumnType; @@ -129,17 +128,6 @@ function injectFilter( }); } -export function flattenKeys(filters?: ColumnFilterItem[]) { - let keys: FilterValue = []; - (filters || []).forEach(({ value, children }) => { - keys.push(value); - if (children) { - keys = [...keys, ...flattenKeys(children)]; - } - }); - return keys; -} - function generateFilterInfo(filterStates: FilterState[]) { const currentFilters: Record = {}; @@ -292,4 +280,6 @@ function useFilter({ return [transformColumns, mergedFilterStates, filters]; } +export { flattenKeys }; + export default useFilter;