阶段七:完成React feature依赖门禁与旧入口瘦身

This commit is contained in:
Christ committed 2026-08-15 02:31:07 +08:00
1 parent 448713735f
commit 22656c20f1
30 files changed
+1485 -1511

No files matched your search

+5 -7
View File
@@ -4,7 +4,10 @@ import {
GitCommitHorizontal, LogOut, MessageCircleMore, Settings, ShoppingBag, Users, Zap,
} from 'lucide-react';
import { YdisksBrandIcon } from './YdisksLogo';
import { getHealth } from '../app/features/system/api';
import type { BuildInfo } from '../app/features/system/types';
// SidebarProps 描述侧边栏所需的导航和会话回调。
interface SidebarProps {
activeTab: string;
isAdmin?: boolean;
@@ -14,20 +17,15 @@ interface SidebarProps {
onLogout: () => void;
}
interface BuildInfo {
version: string;
commit: string;
}
const Sidebar: React.FC<SidebarProps> = ({
activeTab, isAdmin = false, collapsed, onToggleCollapsed, onNavigate, onLogout,
}) => {
const [buildInfo, setBuildInfo] = useState<BuildInfo>({ version: 'dev', commit: 'unknown' });
useEffect(() => {
// controller 控制健康检查请求的取消。
const controller = new AbortController();
fetch('/health', { signal: controller.signal })
.then(response => response.ok ? response.json() : Promise.reject(new Error('health request failed')))
getHealth({ signal: controller.signal })
.then(data => setBuildInfo({
version: String(data.version || 'dev'),
commit: String(data.commit || 'unknown'),
-62
View File
@@ -1,62 +0,0 @@
import { expect, test } from 'vitest';
import { buildAccountLoginInfoUpdate } from './accountEdit';
test('buildAccountLoginInfoUpdate omits blank password while updating other login fields', () => {
const payload = buildAccountLoginInfoUpdate(
{ id: 'acc1', enabled: true, auto_confirm: true, username: 'old-user', show_browser: true },
{ username: 'new-user', login_password: '', show_browser: false },
);
expect(payload).toEqual({
username: 'new-user',
show_browser: false,
});
});
test('buildAccountLoginInfoUpdate includes password only when user entered one', () => {
const payload = buildAccountLoginInfoUpdate(
{ id: 'acc1', enabled: true, auto_confirm: true, username: 'old-user', show_browser: false },
{ username: 'old-user', login_password: 'new-secret', show_browser: false },
);
expect(payload).toEqual({
username: 'old-user',
login_password: 'new-secret',
show_browser: false,
});
});
test('buildAccountLoginInfoUpdate skips unchanged login info', () => {
const payload = buildAccountLoginInfoUpdate(
{ id: 'acc1', enabled: true, auto_confirm: true, username: 'old-user', show_browser: false },
{ username: 'old-user', login_password: '', show_browser: false },
);
expect(payload).toBeNull();
});
test('buildAccountLoginInfoUpdate sends explicit clear password flag', () => {
const payload = buildAccountLoginInfoUpdate(
{ id: 'acc1', enabled: true, auto_confirm: true, username: 'old-user', show_browser: false },
{ username: 'old-user', login_password: '', show_browser: false, clear_password: true },
);
expect(payload).toEqual({
username: 'old-user',
show_browser: false,
clear_password: true,
});
});
test('buildAccountLoginInfoUpdate prefers clear password over typed password', () => {
const payload = buildAccountLoginInfoUpdate(
{ id: 'acc1', enabled: true, auto_confirm: true, username: 'old-user', show_browser: false },
{ username: 'old-user', login_password: 'new-secret', show_browser: false, clear_password: true },
);
expect(payload).toEqual({
username: 'old-user',
show_browser: false,
clear_password: true,
});
});
-8
View File
@@ -1,8 +0,0 @@
// 旧目录保留兼容入口,实际登录字段构造逻辑已归入 accounts feature。
export {
buildAccountLoginInfoUpdate,
} from '../app/features/accounts/state';
export type {
AccountLoginEditFields as AccountLoginEditForm,
AccountLoginInfoPayload,
} from '../app/features/accounts/state';
-17
View File
@@ -1,17 +0,0 @@
import { describe, expect, it } from 'vitest';
import { shouldUpdateAccountPause } from './accountPause';
describe('shouldUpdateAccountPause', () => {
it('does not silently reapply the same duration after a pause has expired', () => {
expect(shouldUpdateAccountPause(60, { pause_duration: 60, paused: false })).toBe(false);
});
it('does not restart an active unchanged pause', () => {
expect(shouldUpdateAccountPause(60, { pause_duration: 60, paused: true })).toBe(false);
});
it('sends changed values including explicit resume', () => {
expect(shouldUpdateAccountPause(30, { pause_duration: 60, paused: true })).toBe(true);
expect(shouldUpdateAccountPause(0, { pause_duration: 60, paused: true })).toBe(true);
});
});
-2
View File
@@ -1,2 +0,0 @@
// 旧目录保留兼容入口,实际暂停时长门禁已归入 accounts feature。
export { shouldUpdateAccountPause } from '../app/features/accounts/state';
@@ -1,62 +0,0 @@
import { describe, expect, test } from 'vitest';
import type { AccountDetail } from '../types';
import { mergeAccountRuntimeStatuses } from './accountRuntimeState';
const account = (overrides: Partial<AccountDetail> = {}): AccountDetail => ({
id: 'account-1',
cookie: 'cookie',
enabled: true,
auto_confirm: false,
...overrides,
});
describe('mergeAccountRuntimeStatuses', () => {
test('用最新在线状态替换风控恢复中的旧提示', () => {
const result = mergeAccountRuntimeStatuses([
account({
runtime_state: 'connecting',
runtime_message: 'token 风控验证已处理,正在重新获取登录凭证',
runtime_updated_at: '2026-07-13T13:16:00+08:00',
}),
], {
'account-1': {
state: 'online',
message: '消息服务连接正常',
connected: true,
failures: 0,
updated_at: '2026-07-13T13:16:02+08:00',
},
});
expect(result[0]).toMatchObject({
runtime_state: 'online',
runtime_message: '消息服务连接正常',
runtime_connected: true,
runtime_updated_at: '2026-07-13T13:16:02+08:00',
});
});
test('忽略晚到达的旧状态响应', () => {
const current = account({
runtime_state: 'online',
runtime_message: '消息服务连接正常',
runtime_updated_at: '2026-07-13T13:16:02+08:00',
});
const result = mergeAccountRuntimeStatuses([current], {
'account-1': {
state: 'connecting',
message: 'token 风控验证已处理,正在重新获取登录凭证',
connected: false,
failures: 0,
updated_at: '2026-07-13T13:16:00+08:00',
},
});
expect(result[0]).toBe(current);
});
test('缺少对应运行时状态时保留账号对象', () => {
const current = account();
expect(mergeAccountRuntimeStatuses([current], {})[0]).toBe(current);
});
});
@@ -1,2 +0,0 @@
// 旧目录保留兼容入口,实际运行状态合并逻辑已归入 accounts feature。
export { mergeAccountRuntimeStatuses } from '../app/features/accounts/runtime';
@@ -1,43 +0,0 @@
import { expect, test } from 'vitest';
import type { AutomationRunIssue } from '../services/api';
import { canResolveAutomationIssue, filterAutomationIssues, loadAutomationPageData } from './automationIssueState';
const issue = (cookieID: string, allowed: AutomationRunIssue['allowed_resolutions']): AutomationRunIssue => ({
id: cookieID === 'a' ? 1 : 2,
cookie_id: cookieID,
order_id: 'o',
trigger_type: 'buyer_reviewed',
error_message: 'error',
issue_kind: 'invalid_snapshot',
allowed_resolutions: allowed,
action_cursor: 0,
sent_count: 0,
updated_at: '',
});
test('automation issue actions follow the backend policy', () => {
const invalid = issue('a', ['cancel']);
expect(canResolveAutomationIssue(invalid, 'cancel')).toBe(true);
expect(canResolveAutomationIssue(invalid, 'continue')).toBe(false);
expect(canResolveAutomationIssue(invalid, 'retry')).toBe(false);
});
test('automation issues are filtered before deciding whether to show the panel', () => {
const visible = filterAutomationIssues({ runs: [issue('a', ['cancel']), issue('b', ['retry', 'cancel'])], pending_tasks: [] }, 'missing');
expect(visible.runs).toEqual([]);
expect(visible.pending_tasks).toEqual([]);
});
test('automation rules still load when the diagnostic issue request fails', async () => {
const receivedRules: string[][] = [];
const errors: unknown[] = [];
await loadAutomationPageData({
loadRules: async () => ['rule'],
loadIssues: async () => { throw new Error('issues unavailable'); },
onRules: rules => receivedRules.push(rules),
onIssues: () => { throw new Error('must not receive issues'); },
onIssuesError: error => errors.push(error),
});
expect(receivedRules).toEqual([['rule']]);
expect(errors).toHaveLength(1);
});
@@ -1,8 +0,0 @@
// 旧目录保留兼容入口,实际实现统一归属 Rules feature。
export {
automationIssueKindLabel,
canResolveAutomationIssue,
filterAutomationIssues,
loadAutomationPageData,
} from '../app/features/rules/issueState';
export type { AutomationResolution } from '../app/features/rules/issueState';
-19
View File
@@ -1,19 +0,0 @@
import { describe, expect, test } from 'vitest';
import type { Card } from '../types';
import { filterCards } from './cardListState';
const cards = [
{ id: 1, name: '年终总结 PPT', type: 'text' },
{ id: 2, name: '年终总结兑换码', type: 'data' },
{ id: 3, name: '产品介绍 PPT', type: 'text' },
] as Card[];
describe('filterCards', () => {
test('combines type and name filters with AND semantics', () => {
expect(filterCards(cards, 'text', '年终')).toEqual([cards[0]]);
});
test('matches names case-insensitively and ignores surrounding whitespace', () => {
expect(filterCards(cards, '', ' ppt ')).toEqual([cards[0], cards[2]]);
});
});
-7
View File
@@ -1,7 +0,0 @@
// 旧目录保留兼容入口,实际卡密筛选和批量状态逻辑已归入 cards feature。
export {
canSubmitAppend,
filterCards,
isCurrentCardRequest,
previewAppendContent,
} from '../app/features/cards/batchState';
@@ -1,10 +0,0 @@
import { expect, test } from 'vitest';
import { selectActivePublishBatch } from './itemPublishBatchState';
test('completed history does not replace the new batch upload flow', () => {
expect(selectActivePublishBatch([{ id: 'done', status: 'completed' }])).toBeUndefined();
expect(selectActivePublishBatch([
{ id: 'done', status: 'completed' },
{ id: 'active', status: 'running' },
])?.id).toBe('active');
});
@@ -1,3 +0,0 @@
// 旧目录保留兼容入口,实际批量状态模型统一归属 ItemList feature。
export { selectActivePublishBatch } from '../app/features/items/batchState';
export type { PublishBatchSummary } from '../app/features/items/batchState';
-8
View File
@@ -1,8 +0,0 @@
export {
failedOrderImportRows,
normalizeOrderImportResult,
} from '../app/features/orders/state';
export type {
OrderImportResult,
OrderImportRowResult,
} from '../app/features/orders/types';