fix(center-table): size fixed actions responsively

This commit is contained in:
zhanjunhao
2026-11-16 23:01:35 +08:00
parent 93128a77d3
commit 931c4dec66
25 changed files with 590 additions and 41 deletions
+1
View File
@@ -48,6 +48,7 @@ const ui = await loadFrontendModule(
'../../hooks/common/useIsMobile': { useIsMobile: () => false },
'../console/ConsoleContext': context,
'../console/consoleTableAdapter': {},
'./CenterActionTable': Ant.Table,
'../console/ConsolePrimitives': {},
},
);
+114
View File
@@ -0,0 +1,114 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import assert from 'node:assert/strict';
import test from 'node:test';
import i18next from 'i18next';
import {
isActionColumn,
isCenterTableScope,
prepareCenterColumns,
} from '../../src/components/ui/centerTablePolicy.js';
test('center operation policy includes system settings and excludes unrelated routes', () => {
for (const path of [
'/user-center/usage-record',
'/org/tokens',
'/console/user',
'/console/setting',
'/console/setting/theme',
])
assert.equal(isCenterTableScope(path), true);
for (const path of ['/market', '/organization'])
assert.equal(isCenterTableScope(path), false);
});
test('pins operations and detail callbacks without changing data, renderers or input columns', () => {
const render = () => null;
const columns = [
{ key: 'name', width: 240, fixed: 'left' },
{ title: '类型', dataIndex: 'action', render },
{ title: '操作', key: 'actions', width: 160, render },
];
const result = prepareCenterColumns(columns, 1200);
assert.deepEqual(result[0], columns[0]);
assert.deepEqual(result[1], columns[1]);
assert.equal(result[2].fixed, 'right');
assert.equal(result[2].render, render);
assert.equal(columns[2].fixed, undefined);
assert.equal(isActionColumn(columns[1]), false);
assert.equal(
isActionColumn({ key: 'fail_reason', title: '详情', render }),
true,
);
assert.equal(isActionColumn({ title: '详情', dataIndex: 'detail' }), false);
assert.equal(
isActionColumn({ title: '操作人', dataIndex: 'operator' }),
false,
);
});
test('narrow containers release colliding left columns and bound the operation area', () => {
const columns = [
{ key: 'name', width: 240, fixed: 'left' },
{ title: '说明', width: 300, fixed: 'right' },
{ key: 'result', width: 300, render: () => null },
];
const result = prepareCenterColumns(columns, 300);
assert.equal(result[0].fixed, 'right');
assert.equal(result[1].fixed, 'right');
assert.equal(result[2].fixed, 'right');
assert.equal(result[2].width, 300);
assert.equal(columns[0].fixed, 'left');
});
test('renames interactive detail headers and sizes action columns from controls', () => {
const renderDetail = function renderDetail() {
return { onClick: true, Button: true };
};
const result = prepareCenterColumns(
[
{ key: 'name', width: 180 },
{ title: '详情', dataIndex: 'detail', render: renderDetail },
],
900,
);
assert.equal(result[1].title, '操作');
assert.equal(result[1].fixed, 'right');
assert.ok(result[1].width >= 120);
});
test('supports grouped headers and keeps ordinary tables intact', () => {
const render = () => null;
const grouped = [{ title: '记录', children: [{ title: '操作', render }] }];
assert.equal(
prepareCenterColumns(grouped, 800)[0].children[0].fixed,
'right',
);
const ordinary = [{ title: '金额', dataIndex: 'amount' }];
assert.deepEqual(prepareCenterColumns(ordinary, 300), ordinary);
});
test('recognizes translated operation headers without requiring a key', async () => {
await i18next.init({
lng: 'en',
resources: { en: { translation: { 操作: 'Actions' } } },
});
assert.equal(isActionColumn({ title: 'Actions', render: () => null }), true);
});
+103
View File
@@ -0,0 +1,103 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import assert from 'node:assert/strict';
import test from 'node:test';
import React from 'react';
import { loadFrontendModule } from './helpers/frontendModule.js';
async function search(query, filters = {}) {
const models = [
{
model_name: 'GPT-4o',
vendor_name: 'OpenAI',
description: '聊天模型',
tags: '热门',
enable_groups: ['default'],
},
{
model_name: 'Claude-Sonnet',
vendor_name: 'GPT',
description: 'GPT-4o',
tags: 'GPT',
enable_groups: ['vip'],
},
{
model_name: '中文模型-Pro',
vendor_name: 'other',
enable_groups: ['default'],
},
{ model_name: null, description: 'GPT', enable_groups: [] },
];
let index = 0;
const state = {
0: query,
7: filters.group || 'all',
10: filters.vendor || 'all',
17: models,
};
const react = {
...React,
useState: (initial) => [
Object.hasOwn(state, index) ? state[index++] : (++index, initial),
() => {},
],
useMemo: (fn) => fn(),
useEffect: () => {},
useRef: (initial) => ({ current: initial }),
useContext: () => [{}],
};
const { useModelPricingData: runHook } = await loadFrontendModule(
new URL(
'../../src/hooks/model-pricing/useModelPricingData.jsx',
import.meta.url,
),
{
react,
'../common/useEffectEvent': { useEffectEvent: (callback) => callback },
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
'../../helpers': {
API: { get: assert.fail },
copy: assert.fail,
getCurrencySymbol: () => '$',
showError: assert.fail,
showInfo: assert.fail,
showSuccess: assert.fail,
},
'@/components/ui': { Modal: {} },
'../../context/User': { UserContext: {} },
'../../context/Status': { StatusContext: {} },
},
);
return runHook().filteredModels.map((model) => model.model_name);
}
test('model search matches names only, ignoring case and surrounding spaces', async () => {
assert.deepEqual(await search(' gPt-4 '), ['GPT-4o']);
assert.deepEqual(await search('OpenAI'), []);
assert.deepEqual(await search('热门'), []);
assert.deepEqual(await search('模型'), ['中文模型-Pro']);
});
test('blank and missing names are safe; search still intersects existing filters', async () => {
assert.equal((await search(' ')).length, 4);
assert.deepEqual(await search('gpt', { vendor: 'GPT' }), []);
assert.deepEqual(await search('gpt', { group: 'vip' }), []);
assert.deepEqual(await search('son', { group: 'vip' }), ['Claude-Sonnet']);
});
+1
View File
@@ -163,6 +163,7 @@ async function modelTestFixture() {
),
Typography: { Text: 'Text' },
},
'../../../ui/CenterActionTable': 'Table',
'lucide-react': { Search: 'Search' },
'./model-test-modal.css': {},
'../../../../helpers': {},
+1
View File
@@ -416,6 +416,7 @@ const modules = {
'./form': {},
'./chat': {},
'../console/ConsoleContext': { useConsolePage: () => null },
'./CenterActionTable': Ant.Table,
'../console/ConsolePrimitives': {},
'../console/consoleTableAdapter': {},
};
+1
View File
@@ -51,6 +51,7 @@ const mocks = {
theme: { useToken: () => ({ token }) },
},
'react-i18next': {},
'../ui/CenterActionTable': 'table',
'../common/table/TableEmpty': () => null,
'./ConsoleContext': { useConsolePage: () => ({ page: { key: pageKey } }) },
};