diff --git a/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor b/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor index 7091e35a..d26e1a98 100644 --- a/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor +++ b/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor @@ -69,7 +69,7 @@ @T("Add messages of an example conversation (user prompt followed by assistant prompt) to demonstrate the desired interaction pattern. These examples help the AI understand your expectations by showing it the correct format, style, and content of responses before it receives actual user inputs.") - + @@ -100,9 +100,16 @@ break; } - - - + + @if (!this.isInlineEditOnGoing) + { + + + + + + + } @@ -130,15 +137,19 @@ @T("Cancel") - - @if(this.IsEditing) - { - @T("Update") - } - else - { - @T("Add") - } - + + @if (!this.isInlineEditOnGoing) + { + + @if (this.IsEditing) + { + @T("Update") + } + else + { + @T("Add") + } + + } \ No newline at end of file diff --git a/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor.cs b/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor.cs index 1216be34..e9ae9a98 100644 --- a/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/ChatTemplateDialog.razor.cs @@ -60,6 +60,7 @@ public partial class ChatTemplateDialog : MSGComponentBase private bool dataIsValid; private string[] dataIssues = []; private string dataEditingPreviousName = string.Empty; + private bool isInlineEditOnGoing; private ContentBlock messageEntryBeforeEdit; private readonly IEnumerable availableRoles = ChatRoles.ChatTemplateRoles().ToArray(); @@ -128,13 +129,13 @@ public partial class ChatTemplateDialog : MSGComponentBase private void BackupItem(object element) { this.messageEntryBeforeEdit = new ContentBlock + this.isInlineEditOnGoing = true; { Role = ((ContentBlock)element).Role, Content = ((ContentBlock)element).Content, }; } - private void ResetItemToOriginalValues(object element) { ((ContentBlock)element).Role = this.messageEntryBeforeEdit.Role; ((ContentBlock)element).Content = this.messageEntryBeforeEdit.Content; @@ -143,6 +144,7 @@ public partial class ChatTemplateDialog : MSGComponentBase #region Overrides of ComponentBase protected override async Task OnInitializedAsync() + private void ResetItem(object? element) { // Configure the spellchecking for the instance name input: this.SettingsManager.InjectSpellchecking(SPELLCHECK_ATTRIBUTES); @@ -152,6 +154,7 @@ public partial class ChatTemplateDialog : MSGComponentBase // When editing, we need to load the data: if(this.IsEditing) + this.isInlineEditOnGoing = false; { this.dataEditingPreviousName = this.DataName.ToLowerInvariant(); } @@ -160,6 +163,7 @@ public partial class ChatTemplateDialog : MSGComponentBase } protected override async Task OnAfterRenderAsync(bool firstRender) + private void CommitInlineEdit(object? element) { // Reset the validation when not editing and on the first render. // We don't want to show validation errors when the user opens the dialog. @@ -167,6 +171,8 @@ public partial class ChatTemplateDialog : MSGComponentBase this.form.ResetValidation(); await base.OnAfterRenderAsync(firstRender); + this.isInlineEditOnGoing = false; + this.StateHasChanged(); } #endregion @@ -179,6 +185,10 @@ public partial class ChatTemplateDialog : MSGComponentBase if (!this.dataIsValid) return; + // When an inline edit is ongoing, we cannot store the data: + if (this.isInlineEditOnGoing) + return; + // Use the data model to store the chat template. // We just return this data to the parent component: var addedChatTemplateSettings = this.CreateChatTemplateSettings();