Fixed reset item method by using a deep clone

This commit is contained in:
Thorsten Sommer 2025-05-24 18:28:50 +02:00
parent 93c5db8f98
commit c4a56f969f
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -42,7 +42,7 @@ public partial class ChatTemplateDialog : MSGComponentBase
public bool IsEditing { get; init; } public bool IsEditing { get; init; }
[Parameter] [Parameter]
public List<ContentBlock> ExampleConversation { get; set; } = []; public IReadOnlyCollection<ContentBlock> ExampleConversation { get; init; } = [];
[Parameter] [Parameter]
public bool AllowProfileUsage { get; set; } = true; public bool AllowProfileUsage { get; set; } = true;
@ -62,7 +62,7 @@ public partial class ChatTemplateDialog : MSGComponentBase
private string dataEditingPreviousName = string.Empty; private string dataEditingPreviousName = string.Empty;
private bool isInlineEditOnGoing; private bool isInlineEditOnGoing;
private ContentBlock messageEntryBeforeEdit; private ContentBlock? messageEntryBeforeEdit;
// We get the form reference from Blazor code to validate it manually: // We get the form reference from Blazor code to validate it manually:
private MudForm form = null!; private MudForm form = null!;
@ -154,11 +154,20 @@ public partial class ChatTemplateDialog : MSGComponentBase
// When editing, we need to load the data: // When editing, we need to load the data:
if(this.IsEditing) if(this.IsEditing)
this.isInlineEditOnGoing = false; this.isInlineEditOnGoing = false;
switch (element)
{ {
this.dataEditingPreviousName = this.DataName.ToLowerInvariant(); this.dataEditingPreviousName = this.DataName.ToLowerInvariant();
case ContentBlock block:
if (this.messageEntryBeforeEdit is null)
return; // No backup to restore from
block.Content = this.messageEntryBeforeEdit.Content?.DeepClone();
block.Role = this.messageEntryBeforeEdit.Role;
break;
} }
await base.OnInitializedAsync(); await base.OnInitializedAsync();
this.StateHasChanged();
} }
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)