fix: table column 快捷操作同时支持 sortable 和一个非 sortable 的操作组合 (#5341)

This commit is contained in:
meerkat 2022-09-15 20:00:01 +08:00 committed by GitHub
parent 54641d2e80
commit 9da3c98330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 7 deletions

View File

@ -865,3 +865,50 @@ test('Renderer:crud group', async () => {
).getAttribute('rowSpan')
).toBe('2');
});
test('Renderer: crud searchable sortable filterable', async () => {
const mockFetcher = jest.fn(fetcher);
const {container, debug, getByText} = render(
amisRender(
{
type: 'page',
body: {
type: 'crud',
api: '/api/mock2/sample',
syncLocation: false,
columns: [
{
name: '__id',
label: 'ID'
},
{
name: 'engine',
label: 'Rendering engine',
quickEdit: true,
sortable: true,
searchable: true,
options: ['1', '2', '3']
}
]
}
},
{},
makeEnv({fetcher: mockFetcher})
)
);
await waitFor(() => {
expect(container.querySelectorAll('tbody>tr').length > 5).toBeTruthy();
});
expect(container.querySelector('[icon="filter"]')).not.toBeInTheDocument();
fireEvent.click(container.querySelector('[icon="search"]')!);
await waitFor(() => {
expect(container.querySelector('.cxd-PopOver')).toBeInTheDocument();
});
// 弹窗中没有 排序
expect(container.querySelectorAll('[data-role="form-item"]').length).toBe(1);
});

View File

@ -1893,16 +1893,16 @@ export default class Table extends React.Component<TableProps, object> {
);
}
let affix = null;
let affix = [];
if (column.searchable && column.name && !autoGenerateFilter) {
affix = (
affix.push(
<HeadCellSearchDropDown
{...this.props}
onQuery={onQuery}
name={column.name}
searchable={column.searchable}
sortable={column.sortable}
sortable={false}
type={column.type}
data={query}
orderBy={store.orderBy}
@ -1910,8 +1910,9 @@ export default class Table extends React.Component<TableProps, object> {
popOverContainer={this.getPopOverContainer}
/>
);
} else if (column.sortable && column.name) {
affix = (
}
if (column.sortable && column.name) {
affix.push(
<span
className={cx('TableCell-sortBtn')}
onClick={async () => {
@ -1979,8 +1980,9 @@ export default class Table extends React.Component<TableProps, object> {
</i>
</span>
);
} else if (column.filterable && column.name) {
affix = (
}
if (!column.searchable && column.filterable && column.name) {
affix.push(
<HeadCellFilterDropDown
{...this.props}
onQuery={onQuery}