mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 13:37:52 +08:00
refactor: solve circular reference of Table (#42813)
* refactor: solve circular reference of Table * Update index.tsx * chore: add export
This commit is contained in:
parent
875a221c62
commit
7dc74b1da9
@ -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);
|
||||
}
|
||||
|
@ -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<RecordType> {
|
||||
column: ColumnType<RecordType>;
|
||||
@ -129,17 +128,6 @@ function injectFilter<RecordType>(
|
||||
});
|
||||
}
|
||||
|
||||
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<RecordType>(filterStates: FilterState<RecordType>[]) {
|
||||
const currentFilters: Record<string, FilterValue | null> = {};
|
||||
|
||||
@ -292,4 +280,6 @@ function useFilter<RecordType>({
|
||||
return [transformColumns, mergedFilterStates, filters];
|
||||
}
|
||||
|
||||
export { flattenKeys };
|
||||
|
||||
export default useFilter;
|
||||
|
Loading…
Reference in New Issue
Block a user