From 99dc2606aaed66b3ee7c1c105d5084b6be205e14 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 28 Aug 2025 18:16:30 +0200 Subject: [PATCH] Improved input validation for the single input dialog (#541) --- .../Assistants/I18N/allTexts.lua | 9 +++++ .../Components/Workspaces.razor.cs | 36 +++++++++++-------- .../Dialogs/SingleInputDialog.razor | 4 ++- .../Dialogs/SingleInputDialog.razor.cs | 27 ++++++++++++-- .../plugin.lua | 9 +++++ .../plugin.lua | 9 +++++ .../wwwroot/changelog/v0.9.51.md | 1 + 7 files changed, 77 insertions(+), 18 deletions(-) diff --git a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua index 816357ba..212ee492 100644 --- a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua +++ b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua @@ -2155,6 +2155,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2237618267"] = "Are you sure -- Delete Chat UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2244038752"] = "Delete Chat" +-- Please enter a chat name. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2301651387"] = "Please enter a chat name." + -- Move to workspace UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2509305748"] = "Move to workspace" @@ -2167,6 +2170,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3045856778"] = "Move Chat to -- Please enter a new or edit the name for your workspace '{0}': UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T323280982"] = "Please enter a new or edit the name for your workspace '{0}':" +-- Please enter a workspace name. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3288132732"] = "Please enter a workspace name." + -- Unnamed chat UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3310482275"] = "Unnamed chat" @@ -4135,6 +4141,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGWRITINGEMAILS::T4004 -- Chat name UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T1746586282"] = "Chat name" +-- Please enter a value. +UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T3576780391"] = "Please enter a value." + -- Cancel UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T900713019"] = "Cancel" diff --git a/app/MindWork AI Studio/Components/Workspaces.razor.cs b/app/MindWork AI Studio/Components/Workspaces.razor.cs index beb10a24..1f86dd3c 100644 --- a/app/MindWork AI Studio/Components/Workspaces.razor.cs +++ b/app/MindWork AI Studio/Components/Workspaces.razor.cs @@ -396,12 +396,14 @@ public partial class Workspaces : MSGComponentBase if (chat is null) return; - var dialogParameters = new DialogParameters + var dialogParameters = new DialogParameters { - { "Message", string.Format(T("Please enter a new or edit the name for your chat '{0}':"), chat.Name) }, - { "UserInput", chat.Name }, - { "ConfirmText", T("Rename") }, - { "ConfirmColor", Color.Info }, + { x => x.Message, string.Format(T("Please enter a new or edit the name for your chat '{0}':"), chat.Name) }, + { x => x.UserInput, chat.Name }, + { x => x.ConfirmText, T("Rename") }, + { x => x.ConfirmColor, Color.Info }, + { x => x.AllowEmptyInput, false }, + { x => x.EmptyInputErrorMessage, T("Please enter a chat name.") }, }; var dialogReference = await this.DialogService.ShowAsync(T("Rename Chat"), dialogParameters, DialogOptions.FULLSCREEN); @@ -428,12 +430,14 @@ public partial class Workspaces : MSGComponentBase var workspaceId = Guid.Parse(Path.GetFileName(workspacePath)); var workspaceName = await WorkspaceBehaviour.LoadWorkspaceName(workspaceId); - var dialogParameters = new DialogParameters + var dialogParameters = new DialogParameters { - { "Message", string.Format(T("Please enter a new or edit the name for your workspace '{0}':"), workspaceName) }, - { "UserInput", workspaceName }, - { "ConfirmText", T("Rename") }, - { "ConfirmColor", Color.Info }, + { x => x.Message, string.Format(T("Please enter a new or edit the name for your workspace '{0}':"), workspaceName) }, + { x => x.UserInput, workspaceName }, + { x => x.ConfirmText, T("Rename") }, + { x => x.ConfirmColor, Color.Info }, + { x => x.AllowEmptyInput, false }, + { x => x.EmptyInputErrorMessage, T("Please enter a workspace name.") }, }; var dialogReference = await this.DialogService.ShowAsync(T("Rename Workspace"), dialogParameters, DialogOptions.FULLSCREEN); @@ -449,12 +453,14 @@ public partial class Workspaces : MSGComponentBase private async Task AddWorkspace() { - var dialogParameters = new DialogParameters + var dialogParameters = new DialogParameters { - { "Message", T("Please name your workspace:") }, - { "UserInput", string.Empty }, - { "ConfirmText", T("Add workspace") }, - { "ConfirmColor", Color.Info }, + { x => x.Message, T("Please name your workspace:") }, + { x => x.UserInput, string.Empty }, + { x => x.ConfirmText, T("Add workspace") }, + { x => x.ConfirmColor, Color.Info }, + { x => x.AllowEmptyInput, false }, + { x => x.EmptyInputErrorMessage, T("Please enter a workspace name.") }, }; var dialogReference = await this.DialogService.ShowAsync(T("Add Workspace"), dialogParameters, DialogOptions.FULLSCREEN); diff --git a/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor b/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor index 1583fc04..5e4bb80c 100644 --- a/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor +++ b/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor @@ -4,7 +4,9 @@ @this.Message - + + + diff --git a/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor.cs b/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor.cs index c4686571..08d3d94d 100644 --- a/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/SingleInputDialog.razor.cs @@ -20,9 +20,17 @@ public partial class SingleInputDialog : MSGComponentBase [Parameter] public Color ConfirmColor { get; set; } = Color.Error; - + + [Parameter] + public bool AllowEmptyInput { get; set; } + + [Parameter] + public string EmptyInputErrorMessage { get; set; } = string.Empty; + private static readonly Dictionary USER_INPUT_ATTRIBUTES = new(); + private MudForm form = null!; + #region Overrides of ComponentBase protected override async Task OnInitializedAsync() @@ -34,7 +42,22 @@ public partial class SingleInputDialog : MSGComponentBase #endregion + private string? ValidateUserInput(string? value) + { + if (!this.AllowEmptyInput && string.IsNullOrWhiteSpace(value)) + return string.IsNullOrWhiteSpace(this.EmptyInputErrorMessage) ? T("Please enter a value.") : this.EmptyInputErrorMessage; + + return null; + } + private void Cancel() => this.MudDialog.Cancel(); - private void Confirm() => this.MudDialog.Close(DialogResult.Ok(this.UserInput)); + private async Task Confirm() + { + await this.form.Validate(); + if(!this.form.IsValid) + return; + + this.MudDialog.Close(DialogResult.Ok(this.UserInput)); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua b/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua index 948e6972..bab0ac14 100644 --- a/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua +++ b/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua @@ -2157,6 +2157,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2237618267"] = "Möchten Sie -- Delete Chat UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2244038752"] = "Chat löschen" +-- Please enter a chat name. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2301651387"] = "Bitte geben Sie einen Namen für diesen Chat ein." + -- Move to workspace UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2509305748"] = "In einen Arbeitsbereich verschieben" @@ -2169,6 +2172,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3045856778"] = "Chat in den -- Please enter a new or edit the name for your workspace '{0}': UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T323280982"] = "Bitte geben Sie einen neuen Namen für ihren Arbeitsbereich „{0}“ ein oder bearbeiten Sie ihn:" +-- Please enter a workspace name. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3288132732"] = "Bitte geben Sie einen Namen für diesen Arbeitsbereich ein." + -- Unnamed chat UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3310482275"] = "Unbenannter Chat" @@ -4137,6 +4143,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGWRITINGEMAILS::T4004 -- Chat name UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T1746586282"] = "Chat-Name" +-- Please enter a value. +UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T3576780391"] = "Bitte geben Sie einen Wert ein." + -- Cancel UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T900713019"] = "Abbrechen" diff --git a/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua b/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua index 017b5e0c..75575e12 100644 --- a/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua +++ b/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua @@ -2157,6 +2157,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2237618267"] = "Are you sure -- Delete Chat UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2244038752"] = "Delete Chat" +-- Please enter a chat name. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2301651387"] = "Please enter a chat name." + -- Move to workspace UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T2509305748"] = "Move to workspace" @@ -2169,6 +2172,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3045856778"] = "Move Chat to -- Please enter a new or edit the name for your workspace '{0}': UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T323280982"] = "Please enter a new or edit the name for your workspace '{0}':" +-- Please enter a workspace name. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3288132732"] = "Please enter a workspace name." + -- Unnamed chat UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::WORKSPACES::T3310482275"] = "Unnamed chat" @@ -4137,6 +4143,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGWRITINGEMAILS::T4004 -- Chat name UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T1746586282"] = "Chat name" +-- Please enter a value. +UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T3576780391"] = "Please enter a value." + -- Cancel UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SINGLEINPUTDIALOG::T900713019"] = "Cancel" diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md b/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md index 63b7c673..0155d75c 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md @@ -4,6 +4,7 @@ - Added the ability to control the update installation behavior by configuration plugins. - Improved memory usage in several areas of the app. - Improved plugin management for configuration plugins so that hot reload detects when a provider or chat template has been removed. +- Improved the dialog for naming chats and workspaces to ensure valid inputs are entered. - Changed the configuration plugin setting name for how often to check for updates from `UpdateBehavior` to `UpdateInterval`. - Fixed a bug in various assistants where some text fields were not reset when resetting. - Fixed a rare chat-related bug that could occur when a workspace was not created correctly. Thank you, Naomi, for reporting this issue. \ No newline at end of file