Skip to content

Commit

Permalink
fix(table, pagination): 替换新组件及样式 (#1463)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed Nov 15, 2021
1 parent f591968 commit 4681bdc
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/pagination/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import './index.less';

import '../../button/style';
import '../../input/style';
import '../../legacy/select/style';
import '../../select/style';
26 changes: 12 additions & 14 deletions src/table/FilterList.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import React from 'react';
import { without, concat } from 'lodash';
import List from '../legacy/list';
import Checkbox from '../checkbox';
import List from '../list';
import { Key } from './interface';

interface FilterListProps {
prefixCls: string;
value: Key[];
onChange: (value: Key[]) => void;
dataSource: {
key: string;
value: string;
label: string;
}[];
}

const FilterList = ({ prefixCls, value, onChange, dataSource }: FilterListProps) => (
<List className={`${prefixCls}-filter-list`}>
<List
className={`${prefixCls}-filter-list`}
value={value}
isMultiple
onChange={(changedKeys) => {
onChange(Array.isArray(changedKeys) ? changedKeys : [changedKeys]);
}}
>
{dataSource.map((item) => (
<List.Item
key={item.key}
className={`${prefixCls}-filter-list-item`}
onClick={() => {
onChange(value.includes(item.key) ? without(value, item.key) : concat(value, item.key));
}}
>
<Checkbox checked={value.includes(item.key)} />
{item.value}
<List.Item key={`${item.label}-${item.value}`} value={item.value}>
{item.label}
</List.Item>
))}
</List>
Expand Down
14 changes: 7 additions & 7 deletions src/table/FilterPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import defaultLocale from './locales/zh-CN';
interface FilterPopoverProps {
prefixCls: string;
children: React.ReactElement;
onClick: (newFilterState: string[]) => void;
onClick: (newFilterState: Key[]) => void;
filters?: FilterType[];
values: Key[];
/**
Expand All @@ -30,13 +30,13 @@ const FilterPopover = (props: FilterPopoverProps): React.ReactElement => {

const { children, onClick, filters = [], values, prefixCls, placeholder = searchText } = props;
const [searchValue, setSearchValue] = useState<string>('');
const [selectFilterKeys, setSelectFilterKeys] = useState<string[]>(values.map((value) => `${value}`));
const [selectFilterKeys, setSelectFilterKeys] = useState<Key[]>(values);
const [visible, setVisible] = useState<boolean>(false);
const { tableRef } = useContext(TableContext);

useEffect(() => {
if (visible) {
setSelectFilterKeys(values.map((value) => `${value}`));
setSelectFilterKeys(values);
}
}, [values, visible]);

Expand All @@ -50,7 +50,7 @@ const FilterPopover = (props: FilterPopoverProps): React.ReactElement => {
setVisible(_visible);
if (_visible === false) {
setSearchValue('');
setSelectFilterKeys(values.map((value) => `${value}`));
setSelectFilterKeys(values);
}
}}
placement="bottomLeft"
Expand All @@ -69,7 +69,7 @@ const FilterPopover = (props: FilterPopoverProps): React.ReactElement => {
prefixCls={prefixCls}
value={selectFilterKeys}
onChange={(keys) => {
setSelectFilterKeys(keys.map((key) => `${key}`));
setSelectFilterKeys(keys);
}}
dataSource={filters
.filter((item) => {
Expand All @@ -80,9 +80,9 @@ const FilterPopover = (props: FilterPopoverProps): React.ReactElement => {
})
.map((item) => {
if (isObject(item)) {
return { key: item.value, value: item.label };
return { value: item.value, label: item.label };
}
return { key: item.toString(), value: item.toString() };
return { value: item.toString(), label: item.toString() };
})}
/>
<div className={`${prefixCls}-filter-popover-footer`}>
Expand Down
2 changes: 1 addition & 1 deletion src/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function Table<RecordType>(props: TableProps<RecordType>, ref: React.ForwardedRe

const emptyElement = (
<div className={`${prefixCls}-empty`}>
<Page description={emptyText} size="small" {...empty} />
<Page description={emptyText} size="normal" type="noData" {...empty} />
</div>
);

Expand Down
4 changes: 2 additions & 2 deletions src/table/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isEmpty, isUndefined } from 'lodash';
import Button from '../button';
import Tooltip from '../tooltip';
import FilterPopover from './FilterPopover';
import { SortOrder, TitleProps } from './interface';
import { Key, SortOrder, TitleProps } from './interface';

export const getNextSortDirection = (sortDirections: SortOrder[], current: SortOrder): SortOrder =>
current === null ? sortDirections[0] : sortDirections[sortDirections.indexOf(current) + 1];
Expand Down Expand Up @@ -52,7 +52,7 @@ const Title = <RecordType,>(props: TitleProps<RecordType>): React.ReactElement =
return null;
}
const { filteredKeys, filters } = filterState;
const handleFilterPopoverClick = (newFilteredKeys: string[]): void => {
const handleFilterPopoverClick = (newFilteredKeys: Key[]): void => {
onTriggerStateUpdate({ filterStates: updateFilterStates({ ...filterState, filteredKeys: newFilteredKeys }) });
};

Expand Down
6 changes: 3 additions & 3 deletions src/table/demos/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,13 @@ export const Empty = () => {

return (
<Table.ResizableTable<DataSourceType>
title="无数据,参考 Empty 组件"
title="表格无数据时的展示页面,请参考 Page 组件"
columns={columns}
rowKey="id"
pagination={false}
empty={{
image: 'no-data',
description: 'description',
description: '无数据',
type: 'noData',
}}
/>
);
Expand Down
66 changes: 35 additions & 31 deletions src/table/hook/useSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import React, { useMemo, useCallback } from 'react';
import { get, intersection, isUndefined, difference, union, isFunction, isString, flatten, flattenDeep } from 'lodash';
import { ColumnsType, RowSelection, ColumnType, TableProps, Key } from '../interface';

import Checkbox from '../../checkbox';
import Tooltip from '../../legacy/tooltip';
import Tooltip from '../../tooltip';
import useControlledState from '../../utils/hooks/useControlledState';

// 拿到row及其children 所有的key
Expand Down Expand Up @@ -156,35 +155,40 @@ const useSelection = <RecordType,>(
const key = getRowKey(rest[1], rowKey);
const thisCheckboxProps = getCheckboxProps?.(rest[1]) || {};
const { tooltipProps, disabled, ...restCheckboxProps } = thisCheckboxProps;
return (
<Tooltip placement="topLeft" arrowPointAtCenter disabled={!disabled} {...tooltipProps}>
<div>
<Checkbox
{...restCheckboxProps}
disabled={disabled || isParentDisabled(key) || isChildDisabled(key)}
indeterminate={!isRowAllSelected(key) && isRowPartSelected(key)}
checked={
Array.isArray(key)
? key.some((keyItem) => localSelectedRowKeys.includes(keyItem))
: localSelectedRowKeys.includes(key)
}
onClick={(e) => e.stopPropagation()}
onChange={(e) => {
getAllDisabledKey(data);
const latestLocalSelectedRowKeys = e.target.checked
? flattenDeep(difference(union(localSelectedRowKeys, flattenDeep([key])), allDisabledKey))
: flattenDeep(difference(localSelectedRowKeys, flattenDeep([key]), allDisabledKey));
setLocalSelectedRowKeys(latestLocalSelectedRowKeys);

const updatedSelectedRowKeys = updateParentCheck(latestLocalSelectedRowKeys, key);
setLocalSelectedRowKeys(updatedSelectedRowKeys);

onChange?.(updatedSelectedRowKeys, getSelectRows(updatedSelectedRowKeys));
}}
>
{disabled ? null : undefined}
</Checkbox>
</div>
const contentNode = (
<div>
<Checkbox
{...restCheckboxProps}
disabled={disabled || isParentDisabled(key) || isChildDisabled(key)}
indeterminate={!isRowAllSelected(key) && isRowPartSelected(key)}
checked={
Array.isArray(key)
? key.some((keyItem) => localSelectedRowKeys.includes(keyItem))
: localSelectedRowKeys.includes(key)
}
onClick={(e) => e.stopPropagation()}
onChange={(e) => {
getAllDisabledKey(data);
const latestLocalSelectedRowKeys = e.target.checked
? flattenDeep(difference(union(localSelectedRowKeys, flattenDeep([key])), allDisabledKey))
: flattenDeep(difference(localSelectedRowKeys, flattenDeep([key]), allDisabledKey));
setLocalSelectedRowKeys(latestLocalSelectedRowKeys);

const updatedSelectedRowKeys = updateParentCheck(latestLocalSelectedRowKeys, key);
setLocalSelectedRowKeys(updatedSelectedRowKeys);

onChange?.(updatedSelectedRowKeys, getSelectRows(updatedSelectedRowKeys));
}}
>
{disabled ? null : undefined}
</Checkbox>
</div>
);
return disabled ? (
contentNode
) : (
<Tooltip placement="topLeft" arrowPointAtCenter {...tooltipProps}>
{contentNode}
</Tooltip>
);
},
Expand Down
4 changes: 4 additions & 0 deletions src/table/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ interface TableProps<RecordType> extends Omit<GioTableProps<RecordType>, 'title'
* 表格数据为空时的占位内容
*/
emptyText?: React.ReactNode;

/**
* 自定义表格数据为空时的页面,请参考 Page 组件
*/
empty?: PageProps;
/**
* 分页/排序/筛选变化时触发
Expand Down
7 changes: 1 addition & 6 deletions src/table/style/index.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
@import '../../stylesheet/variables/index.less';
@import (reference) '../../checkbox/style/index.less';
@import (reference) '../../popover/style/index.less';
@import (reference) '../../legacy/empty/style/index.less';

@table-prefix-cls: ~'@{component-prefix}-table-new';

Expand Down Expand Up @@ -47,9 +44,6 @@
display: none;
}
}
.@{checkbox-wrapper-cls} + .@{table-prefix-cls}-resizable-handle {
display: none;
}

&:hover {
.@{table-prefix-cls}-resizable-handle {
Expand Down Expand Up @@ -354,6 +348,7 @@

&-filter-list {
height: 160px;
margin-top: 4px;
}

&-search-bar {
Expand Down
7 changes: 4 additions & 3 deletions src/table/style/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import './index.less';
import '../../legacy/list/style';
import '../../legacy/empty/style';
import '../../checkbox/style';
import '../../list/style';
import '../../page/style';
import '../../tooltip/style';
import '../../button/style';
import '../../popover/style';
import '../../search-bar/style';
import '../../pagination/style';

1 comment on commit 4681bdc

@vercel
Copy link

@vercel vercel bot commented on 4681bdc Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.