Added validation to the directory selection component

This commit is contained in:
tsommer committed 2025-01-07 20:52:17 +01:00
1 parent a75020fb9b
commit 6a31b1bfa7
4 files changed
+16 -1

No files matched your search

@@ -346,4 +346,4 @@ else
</MudText> </MudText>
<MudTextSwitch Label="Should we write the generated code to the file system?" Disabled="@this.IsNoneERIServerSelected" @bind-Value="@this.writeToFilesystem" LabelOn="Yes, please write or update all generated code to the file system" LabelOff="No, just show me the code" /> <MudTextSwitch Label="Should we write the generated code to the file system?" Disabled="@this.IsNoneERIServerSelected" @bind-Value="@this.writeToFilesystem" LabelOn="Yes, please write or update all generated code to the file system" LabelOff="No, just show me the code" />
<SelectDirectory Label="Base directory where to write the code" @bind-Directory="@this.baseDirectory" Disabled="@(this.IsNoneERIServerSelected || !this.writeToFilesystem)" DirectoryDialogTitle="Select the target directory for the ERI server"/> <SelectDirectory Label="Base directory where to write the code" @bind-Directory="@this.baseDirectory" Disabled="@(this.IsNoneERIServerSelected || !this.writeToFilesystem)" DirectoryDialogTitle="Select the target directory for the ERI server" Validation="@this.ValidateDirectory" />
@@ -739,6 +739,17 @@ public partial class AssistantERI : AssistantBaseCore
return null; return null;
} }
private string? ValidateDirectory(string path)
{
if(!this.writeToFilesystem)
return null;
if(string.IsNullOrWhiteSpace(path))
return "Please provide a base directory for the ERI server to write files to.";
return null;
}
private string GetMultiSelectionAuthText(List<Auth> selectedValues) private string GetMultiSelectionAuthText(List<Auth> selectedValues)
{ {
@@ -4,6 +4,7 @@
Text="@this.Directory" Text="@this.Directory"
Label="@this.Label" Label="@this.Label"
ReadOnly="@true" ReadOnly="@true"
Validation="@this.Validation"
Adornment="Adornment.Start" Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Folder" AdornmentIcon="@Icons.Material.Filled.Folder"
UserAttributes="@SPELLCHECK_ATTRIBUTES" UserAttributes="@SPELLCHECK_ATTRIBUTES"
@@ -21,6 +21,9 @@ public partial class SelectDirectory : ComponentBase
[Parameter] [Parameter]
public string DirectoryDialogTitle { get; set; } = "Select Directory"; public string DirectoryDialogTitle { get; set; } = "Select Directory";
[Parameter]
public Func<string, string?> Validation { get; set; } = _ => null;
[Inject] [Inject]
private SettingsManager SettingsManager { get; init; } = null!; private SettingsManager SettingsManager { get; init; } = null!;