Files
buzz/desktop/src/features/agents/ui/personaImportUpdateState.ts
Taylor Ho 41d343bb35 feat(desktop): team & persona import/edit flows (#288)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 07:17:19 -10:00

37 lines
984 B
TypeScript

import type { PersonaImportFieldChange } from "./personaImportPlan";
export function getFieldSecondaryText(
shouldUpdate: boolean,
importedPreview: string,
currentPreview: string,
): string {
return shouldUpdate ? importedPreview : currentPreview;
}
export function getFieldPreview(
value: string,
emptyFallback: string,
maxLength = 240,
): string {
const normalized = value.replace(/\r\n/g, "\n").trim();
if (normalized.length === 0) {
return emptyFallback;
}
const firstNonEmptyLine =
normalized
.split("\n")
.map((line) => line.trim())
.find((line) => line.length > 0) ?? normalized;
if (firstNonEmptyLine.length <= maxLength) {
return firstNonEmptyLine;
}
return `${firstNonEmptyLine.slice(0, maxLength).trimEnd()}…`;
}
export function getSelectedFieldCount(
fields: PersonaImportFieldChange[],
selectedFields: Set<string>,
): number {
return fields.filter((field) => selectedFields.has(field.field)).length;
}