Require unique names for profiles
This commit is contained in:
parent
827fce4542
commit
739d0c95c3
|
@ -147,14 +147,19 @@ async function createConnectionProfile(forceName = null) {
|
||||||
|
|
||||||
const profileForDisplay = makeFancyProfile(profile);
|
const profileForDisplay = makeFancyProfile(profile);
|
||||||
const template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay });
|
const template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay });
|
||||||
const checkName = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
|
const isNameTaken = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
|
||||||
const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), checkName);
|
const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), isNameTaken);
|
||||||
const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 });
|
const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 });
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNameTaken(name)) {
|
||||||
|
toastr.error('A profile with the same name already exists.');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
profile.name = name;
|
profile.name = name;
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue