Finding small errors

This commit is contained in:
Peer Hogeterp committed 2026-09-25 12:41:55 +02:00
1 parent ad6b700978
commit 73f48e7bcd
8 files changed
+627 -62

No files matched your search

@@ -10,23 +10,6 @@
{
<MudAlert Severity="Severity.Warning" Class="mb-2">@this.importReferenceIssue</MudAlert>
}
@if (!string.IsNullOrWhiteSpace(this.relinkIssue))
{
<MudAlert Severity="Severity.Error" Class="mb-2">@this.relinkIssue</MudAlert>
}
@for (var index = 0; index < this.attachmentsToRelink.Count; index++)
{
var currentIndex = index;
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2">
<MudTextField T="string" Value="@this.attachmentsToRelink[index].ReplacementPath"
ValueChanged="@(value => this.UpdateRelinkPath(currentIndex, value))"
Label="@string.Format(T("Relink attachment: {0}"), this.attachmentsToRelink[index].OriginalPath)"
HelperText="@T("Enter an absolute path to an existing local file, or remove this attachment.")" Variant="Variant.Outlined" />
<MudTooltip Text="@T("Remove this attachment")">
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="@(() => this.RemoveAttachmentToRelink(currentIndex))" />
</MudTooltip>
</MudStack>
}
}
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
@* The name for the drop state is given although nobody uses it: the messages of this dialog
@@ -118,6 +101,33 @@
<MudJustifiedText Class="mb-3" Typo="Typo.body1">
@T("You can attach files that will be automatically included when using this chat template. These files will be added to the first message sent in any chat using this template.")
</MudJustifiedText>
@if (!this.IsEditing && !this.IsReadOnly)
{
@if (this.HasUnresolvedAttachments)
{
<MudAlert Severity="Severity.Warning" Variant="Variant.Filled" Icon="@Icons.Material.Filled.WarningAmber" Class="mb-3">
@T("Some attachments in this chat template are missing. Relink or remove them before adding the template.")
</MudAlert>
}
@if (!string.IsNullOrWhiteSpace(this.relinkIssue))
{
<MudAlert Severity="Severity.Error" Class="mb-2">@this.relinkIssue</MudAlert>
}
@for (var index = 0; index < this.attachmentsToRelink.Count; index++)
{
var currentIndex = index;
var attachment = this.attachmentsToRelink[index];
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2">
<MudTextField T="string" Value="@attachment.ReplacementPath"
ValueChanged="@(value => this.UpdateRelinkPath(currentIndex, value))"
Label="@string.Format(T("Relink attachment: {0}"), attachment.OriginalPath)"
HelperText="@T("Enter an absolute path to an existing local file, or remove this attachment.")" Variant="Variant.Outlined" Immediate="@true" />
<MudTooltip Text="@T("Remove this attachment")">
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="@(() => this.RemoveAttachmentToRelink(currentIndex))" />
</MudTooltip>
</MudStack>
}
}
<AttachDocuments
Name="ChatTemplateFileAttachments"
@bind-DocumentPaths="@this.fileAttachments"
@@ -276,7 +286,7 @@
@if (!this.isInlineEditOnGoing)
{
<MudButton OnClick="@this.Store" Variant="Variant.Filled" Color="Color.Primary">
<MudButton OnClick="@this.Store" Variant="Variant.Filled" Color="Color.Primary" Disabled="@this.HasUnresolvedAttachments">
@if (this.IsEditing)
{
@T("Update")
@@ -103,6 +103,7 @@ public partial class ChatTemplateDialog : MSGComponentBase
private HashSet<FileAttachment> fileAttachments = [];
private List<(string OriginalPath, string ReplacementPath)> attachmentsToRelink = [];
private string relinkIssue = string.Empty;
private bool HasUnresolvedAttachments => this.attachmentsToRelink.Any(attachment => !ConfigurationImportFields.IsExistingLocalFile(attachment.ReplacementPath));
private string importReferenceIssue = string.Empty;
private bool preselectTools;
private HashSet<string> selectedToolIds = new(StringComparer.Ordinal);
@@ -156,6 +157,9 @@ public partial class ChatTemplateDialog : MSGComponentBase
this.DataName = this.ExistingChatThread.Name;
}
if (this.ImportedConfiguration is not null && this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("CHAT_TEMPLATES"))
await this.ImportConfiguration(this.ImportedConfiguration);
await base.OnInitializedAsync();
}
@@ -166,14 +170,9 @@ public partial class ChatTemplateDialog : MSGComponentBase
if(!this.IsEditing && firstRender)
this.form.ResetValidation();
if (firstRender && this.ImportedConfiguration is not null)
{
if (!this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("CHAT_TEMPLATES"))
this.MudDialog.Cancel();
else
await this.ImportConfiguration(this.ImportedConfiguration);
this.StateHasChanged();
}
if (firstRender && this.ImportedConfiguration is not null &&
!this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("CHAT_TEMPLATES"))
this.MudDialog.Cancel();
await base.OnAfterRenderAsync(firstRender);
}
@@ -226,7 +225,6 @@ public partial class ChatTemplateDialog : MSGComponentBase
this.preselectDataSources = template.DataSourceOptions is not null;
this.templateDataSourceOptions = template.DataSourceOptions?.CreateCopy() ?? new DataSourceOptions { DisableDataSources = false };
this.importReferenceIssue = await this.BuildImportReferenceIssue();
this.form.ResetValidation();
}
private async Task<string> BuildImportReferenceIssue()
@@ -241,12 +239,17 @@ public partial class ChatTemplateDialog : MSGComponentBase
return ConfigurationImportFields.UnavailableReferencesIssue(missing);
}
private void UpdateRelinkPath(int index, string path) => this.attachmentsToRelink[index] = (this.attachmentsToRelink[index].OriginalPath, path);
private void UpdateRelinkPath(int index, string? path)
{
this.attachmentsToRelink[index] = (this.attachmentsToRelink[index].OriginalPath, path ?? string.Empty);
if (!this.HasUnresolvedAttachments)
this.relinkIssue = string.Empty;
}
private void RemoveAttachmentToRelink(int index)
{
this.attachmentsToRelink.RemoveAt(index);
if (this.attachmentsToRelink.Count == 0)
if (!this.HasUnresolvedAttachments)
this.relinkIssue = string.Empty;
}