feat(版本): 优化概览与只读状态
关键改动: - 增加需求排序和版本只读状态规则及测试 - 完善版本概览阶段耗时、项目页和工作台展示 - 优化小宝预警请求节流、建议状态和风险过滤 Co-Authored-By: Codex GPT-5 <codex@openai.com>
This commit is contained in:
39
apps/web/lib/requirement-sort.ts
Normal file
39
apps/web/lib/requirement-sort.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { Requirement } from './requirement';
|
||||
|
||||
export type RequirementDateSort = 'desc' | 'asc';
|
||||
|
||||
export function sortRequirementsByCreatedAt(
|
||||
requirements: Requirement[],
|
||||
direction: RequirementDateSort = 'desc',
|
||||
): Requirement[] {
|
||||
const multiplier = direction === 'asc' ? 1 : -1;
|
||||
return [...requirements].sort((a, b) => compareRequirementCreatedAt(a, b) * multiplier);
|
||||
}
|
||||
|
||||
function compareRequirementCreatedAt(a: Requirement, b: Requirement): number {
|
||||
const createdAtDiff = toTimestamp(a.createdAt) - toTimestamp(b.createdAt);
|
||||
if (createdAtDiff !== 0) return createdAtDiff;
|
||||
|
||||
const idDiff = trailingNumber(a.id) - trailingNumber(b.id);
|
||||
if (idDiff !== 0) return idDiff;
|
||||
|
||||
const codeDiff = trailingNumber(a.code) - trailingNumber(b.code);
|
||||
if (codeDiff !== 0) return codeDiff;
|
||||
|
||||
const codeTextDiff = a.code.localeCompare(b.code);
|
||||
if (codeTextDiff !== 0) return codeTextDiff;
|
||||
|
||||
return a.id.localeCompare(b.id);
|
||||
}
|
||||
|
||||
function toTimestamp(value: string): number {
|
||||
const timestamp = new Date(value).getTime();
|
||||
return Number.isFinite(timestamp) ? timestamp : 0;
|
||||
}
|
||||
|
||||
function trailingNumber(value: string): number {
|
||||
const matches = value.match(/\d+/g);
|
||||
if (!matches) return 0;
|
||||
const numericValue = Number(matches[matches.length - 1]);
|
||||
return Number.isFinite(numericValue) ? numericValue : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user