e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
// Auto-naming for connection profiles.
|
|
//
|
|
// A new profile is created already named after its provider (see `addProfile`
|
|
// in SettingsContext). As long as the user hasn't typed a custom name, we want
|
|
// the name to keep tracking the provider when they switch it — so a profile
|
|
// created as "Brave" becomes "Jina" when the provider changes to Jina, but a
|
|
// profile the user renamed to "My search" is left untouched.
|
|
//
|
|
// The heuristic is deliberately stateless (no extra persisted field): the name
|
|
// is considered "auto" when it is empty or still equals the previous provider's
|
|
// label. Once it diverges, it is treated as user-owned and never overwritten.
|
|
|
|
export function nextProfileName(
|
|
currentName: string,
|
|
previousProviderLabel: string,
|
|
nextProviderLabel: string,
|
|
): string {
|
|
// Never overwrite with an empty label (e.g. "Select provider…").
|
|
if (!nextProviderLabel) return currentName;
|
|
const trimmed = (currentName ?? "").trim();
|
|
if (trimmed === "" || trimmed === (previousProviderLabel ?? "").trim()) {
|
|
return nextProviderLabel;
|
|
}
|
|
return currentName;
|
|
}
|