Skip to content

Commit

Permalink
fix(table): fix onChange calls twice (#2046)
Browse files Browse the repository at this point in the history
* fix(table): fix onChange calls twice

* fix(table): add span wrapper for expand icon

Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed May 26, 2022
1 parent 3c00371 commit 677f0b6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
37 changes: 19 additions & 18 deletions src/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,24 @@ export function Table<RecordType>(
const expandIcon: RenderExpandIcon<RecordType> = (expandProps) => {
const { expanded, onExpand, record, expandable: expandableProp } = expandProps;
if (expandableProp) {
return expanded ? (
<ArrowDownOutlined
size="12px"
className={`${prefixCls}-expanded-icon`}
onClick={(event) => {
isFunction(onExpand) && onExpand(record, event as React.MouseEvent<HTMLElement, MouseEvent>);
}}
/>
) : (
<ArrowRightOutlined
size="12px"
className={`${prefixCls}-to_expand-icon`}
onClick={(event) => {
isFunction(onExpand) && onExpand(record, event as React.MouseEvent<HTMLElement, MouseEvent>);
}}
/>
return (
<span className={expanded ? `${prefixCls}-expanded-icon` : `${prefixCls}-to_expand-icon`}>
{expanded ? (
<ArrowDownOutlined
size="12px"
onClick={(event) => {
isFunction(onExpand) && onExpand(record, event as React.MouseEvent<HTMLElement, MouseEvent>);
}}
/>
) : (
<ArrowRightOutlined
size="12px"
onClick={(event) => {
isFunction(onExpand) && onExpand(record, event as React.MouseEvent<HTMLElement, MouseEvent>);
}}
/>
)}
</span>
);
}
return <div className={`${prefixCls}-expanded-placeholder`} />;
Expand Down Expand Up @@ -197,7 +199,6 @@ export function Table<RecordType>(
column={column}
updateSorterStates={updateSorterStates}
updateFilterStates={updateFilterStates}
onTriggerStateUpdate={onTriggerStateUpdate}
columnKey={columnKey}
/>
),
Expand All @@ -213,7 +214,7 @@ export function Table<RecordType>(
});
}
return renderTitle(columns);
}, [columns, sortStates, filterStates, prefixCls, updateSorterStates, updateFilterStates, onTriggerStateUpdate]);
}, [columns, sortStates, filterStates, prefixCls, updateSorterStates, updateFilterStates]);

const composedColumns = compose(transformSelectionPipeline, transformShowIndexPipeline)(transformColumnTitle);

Expand Down
4 changes: 2 additions & 2 deletions src/table/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getNextSortDirection = (sortDirections: SortOrder[], current: SortOrder):
current === null ? sortDirections[0] : sortDirections[sortDirections.indexOf(current) + 1];

const Title = <RecordType,>(props: TitleProps<RecordType>): React.ReactElement => {
const { prefixCls, column, onTriggerStateUpdate, sorterState, updateSorterStates, columnKey } = props;
const { prefixCls, column, sorterState, updateSorterStates, columnKey } = props;

const { align, sorter, sortDirections = defaultSortDirections, sortPriorityOrder } = column;

Expand Down Expand Up @@ -66,7 +66,7 @@ const Title = <RecordType,>(props: TitleProps<RecordType>): React.ReactElement =
}
const { filteredKeys, filters } = filterState;
const handleFilterPopoverClick = (newFilteredKeys: Key[]): void => {
onTriggerStateUpdate({ filterStates: updateFilterStates({ ...filterState, filteredKeys: newFilteredKeys }) });
updateFilterStates({ ...filterState, filteredKeys: newFilteredKeys });
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/table/demos/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const Filtering = () => {
[]
);

return <Table<DataSourceType> columns={columns} rowKey="id" dataSource={dataSource} />;
return <Table<DataSourceType> columns={columns} rowKey="id" onChange={action('filter')} dataSource={dataSource} />;
};

// ----------------------- Filtering -----------------------//
Expand Down
1 change: 0 additions & 1 deletion src/table/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ interface TitleProps<RecordType> {
column: ColumnType<RecordType>;
updateSorterStates: (sortState: SortState<RecordType>) => SortState<RecordType>;
updateFilterStates: (filterState: FilterState<RecordType>) => Record<string, string[]>;
onTriggerStateUpdate: (onTriggerStateUpdateProps?: OnTriggerStateUpdateProps<RecordType>) => void;
columnKey: Key;
}

Expand Down

1 comment on commit 677f0b6

@vercel
Copy link

@vercel vercel bot commented on 677f0b6 May 26, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

gio-design – ./

gio-design-growingio.vercel.app
gio-design-git-master-growingio.vercel.app
gio-design.vercel.app

Please sign in to comment.