fix(data): 清理旧数据并保护服务端写入
This commit is contained in:
@@ -17,6 +17,80 @@ export interface SourceTarget {
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export function parseSourceTargetSelection(value?: string | null): string[] {
|
||||
if (!value) return [];
|
||||
return uniqueNonEmptyNames(value.split(/[、,,]/));
|
||||
}
|
||||
|
||||
export function formatSourceTargetSelection(names: string[]): string {
|
||||
return uniqueNonEmptyNames(names).join('、');
|
||||
}
|
||||
|
||||
export function filterSourceTargetsByKeyword(
|
||||
targets: SourceTarget[],
|
||||
sourceType: SourceType,
|
||||
keyword: string,
|
||||
): SourceTarget[] {
|
||||
const query = keyword.trim().toLowerCase();
|
||||
return targets.filter((target) => {
|
||||
if (target.sourceType !== sourceType) return false;
|
||||
if (!query) return true;
|
||||
return target.name.toLowerCase().includes(query);
|
||||
});
|
||||
}
|
||||
|
||||
export interface RequirementProjectOption {
|
||||
id: string;
|
||||
name: string;
|
||||
productId: string;
|
||||
}
|
||||
|
||||
export interface RequirementVersionOption {
|
||||
id: string;
|
||||
name: string;
|
||||
projectId: string;
|
||||
}
|
||||
|
||||
export function filterRequirementProjectOptions(
|
||||
projects: RequirementProjectOption[],
|
||||
productId: string,
|
||||
keyword: string,
|
||||
): RequirementProjectOption[] {
|
||||
if (!productId) return [];
|
||||
const query = keyword.trim().toLowerCase();
|
||||
return projects.filter((project) => {
|
||||
if (project.productId !== productId) return false;
|
||||
if (!query) return true;
|
||||
return project.name.toLowerCase().includes(query);
|
||||
});
|
||||
}
|
||||
|
||||
export function filterRequirementVersionOptions(
|
||||
versions: RequirementVersionOption[],
|
||||
projectId: string,
|
||||
keyword: string,
|
||||
): RequirementVersionOption[] {
|
||||
if (!projectId) return [];
|
||||
const query = keyword.trim().toLowerCase();
|
||||
return versions.filter((version) => {
|
||||
if (version.projectId !== projectId) return false;
|
||||
if (!query) return true;
|
||||
return version.name.toLowerCase().includes(query);
|
||||
});
|
||||
}
|
||||
|
||||
function uniqueNonEmptyNames(names: string[]): string[] {
|
||||
const seen = new Set<string>();
|
||||
const out: string[] = [];
|
||||
for (const name of names) {
|
||||
const trimmed = name.trim();
|
||||
if (!trimmed || seen.has(trimmed)) continue;
|
||||
seen.add(trimmed);
|
||||
out.push(trimmed);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export interface Requirement {
|
||||
id: string;
|
||||
code: string;
|
||||
|
||||
Reference in New Issue
Block a user