feat(FN-800): auto-generate model preset IDs and remove manual ID editing
- Add slugify and generatePresetId utilities with collision handling for unique preset IDs - Remove manual ID input field from preset editor UI in SettingsModal - Auto-generate preset IDs server-side from name on creation - Simplify Header tests by removing ID-related test cases - Deduplicate tablet header controls tests by importing from shared Header tests - Remove unused CSS rules for removed ID input field - Update reviewer to pass through preset ID generation logic
This commit is contained in:
@@ -45,3 +45,26 @@ export function generatePresetId(name: string): string {
|
||||
|
||||
return slug || "preset";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique preset ID derived from the preset name, avoiding collisions
|
||||
* with existing preset IDs. If the base slug is already taken, appends `-1`,
|
||||
* `-2`, etc. until a unique ID is found.
|
||||
*/
|
||||
export function generateUniquePresetId(name: string, existingPresets: ModelPreset[]): string {
|
||||
const baseId = generatePresetId(name);
|
||||
const takenIds = new Set(existingPresets.map((p) => p.id));
|
||||
|
||||
if (!takenIds.has(baseId)) return baseId;
|
||||
|
||||
// Leave room for the numeric suffix (-N)
|
||||
const maxBase = 30;
|
||||
let candidate = baseId;
|
||||
let idx = 1;
|
||||
while (takenIds.has(candidate) && idx < 100) {
|
||||
const suffix = `-${idx}`;
|
||||
candidate = `${baseId.slice(0, maxBase - suffix.length)}${suffix}`;
|
||||
idx++;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user