fix(table): 统一筛选交互并补齐移动视口覆盖

This commit is contained in:
zhanjunhao
2026-11-24 20:14:10 +08:00
parent 471d7843de
commit 2cbbf0839b
83 changed files with 2094 additions and 1355 deletions
+41 -12
View File
@@ -11,8 +11,7 @@ async function fixture(kind) {
{ length: 24 },
(_, i) => 'aa-' + String(i + 1).padStart(2, '0'),
);
const states =
kind === 'Missing' ? [5, false, models, 'AA', 2] : [5, {}, 2, 'AA'];
const states = kind === 'Missing' ? [5, false, models, 2] : [5, {}, 2];
let cursor = 0;
const react = {
...React,
@@ -51,6 +50,22 @@ async function fixture(kind) {
react,
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
'@/components/ui': ui,
'@/hooks/common/useLocalTableFilters': {
useLocalTableFilters: () => ({
draft: { searchKeyword: 'AA' },
applied: { searchKeyword: 'AA' },
changeFilters: ({ searchKeyword }) =>
calls.push(['search', searchKeyword]),
submitSearch: () => {},
resetFilters: () => {},
}),
},
'@/hooks/common/useFilteredTableRows': {
useFilteredTableRows: (rows, matches) => rows.filter(matches),
},
'@/hooks/common/useEffectEvent': {
useEffectEvent: (callback) => callback,
},
'../../../../hooks/common/useEffectEvent': {
useEffectEvent: (callback) => callback,
},
@@ -105,11 +120,12 @@ for (const kind of ['Missing', 'Upstream']) {
assert.equal(table.pagination.total, 24);
assert.equal(table.pagination.pageSize, 5);
assert.equal(table.pagination.currentPage, 2);
assert.equal(table.pagination.preservePage, true);
},
);
test(
kind +
': search and size changes reset the current page without network calls',
': search retains the page and size changes reset it without network calls',
async () => {
const { calls, table, input } = await fixture(kind);
table.pagination.onPageSizeChange(20);
@@ -117,8 +133,7 @@ for (const kind of ['Missing', 'Upstream']) {
assert.ok(calls.some(([, value]) => value === 20));
calls.length = 0;
input.onChange('aa-24');
assert.ok(calls.some(([, value]) => value === 'aa-24'));
assert.ok(calls.some(([, value]) => value === 1));
assert.deepEqual(calls, [['search', 'aa-24']]);
},
);
}
@@ -135,6 +150,24 @@ async function modelTestFixture() {
react: {
...React,
useState: () => [5, (value) => calls.push(['size', value])],
useEffect: () => {},
useMemo: (fn) => fn(),
useCallback: (fn) => fn,
},
'@/hooks/common/useEffectEvent': {
useEffectEvent: (callback) => callback,
},
'@/hooks/common/useLocalTableFilters': {
useLocalTableFilters: () => ({
draft: { keyword: 'AA' },
applied: { keyword: 'AA' },
changeFilters: ({ keyword }) => calls.push(['search', keyword]),
submitSearch: () => {},
resetFilters: () => {},
}),
},
'@/hooks/common/useFilteredTableRows': {
useFilteredTableRows: (rows, matches) => rows.filter(matches),
},
antd: {
...Object.fromEntries(
@@ -154,13 +187,11 @@ async function modelTestFixture() {
);
const tree = Component({
currentTestChannel: { id: 7, name: 'channel', models: models.join(',') },
modelSearchKeyword: 'AA',
modelTablePage: 2,
selectedModelKeys: [],
modelTestResults: {},
testingModels: new Set(),
setModelTablePage: (value) => calls.push(['page', value]),
setModelSearchKeyword: (value) => calls.push(['search', value]),
t: (key) => key,
});
const find = (type, node = tree) =>
@@ -187,6 +218,7 @@ test('Model test dialog passes the complete filtered list to local table paginat
models,
);
assert.equal(table.pagination.total, undefined);
assert.equal(table.pagination.preservePage, true);
assert.equal(table.pagination.current, 2);
assert.equal(table.pagination.pageSize, 5);
const html = renderToStaticMarkup(React.createElement(AntTable, table));
@@ -197,7 +229,7 @@ test('Model test dialog passes the complete filtered list to local table paginat
);
});
test('Model test dialog preserves page changes and resets after search or size changes', async () => {
test('Model test dialog retains the page after search and resets after size changes', async () => {
const { calls, table, input } = await modelTestFixture();
table.pagination.onChange(3, 5);
assert.deepEqual(calls.splice(0), [
@@ -210,8 +242,5 @@ test('Model test dialog preserves page changes and resets after search or size c
['size', 20],
]);
input.onChange({ target: { value: 'aa-24' } });
assert.deepEqual(calls, [
['search', 'aa-24'],
['page', 1],
]);
assert.deepEqual(calls, [['search', 'aa-24']]);
});