From a182cc438a5d7834bb391cb0d96ecbaf205f7bac Mon Sep 17 00:00:00 2001 From: nilsk Date: Fri, 13 Mar 2026 01:14:03 +0100 Subject: [PATCH] improved dropdown component and fixed some bugs with it --- .../Assistants/Dynamic/AssistantDynamic.razor | 13 ++++- .../Dynamic/AssistantDynamic.razor.cs | 2 +- .../Components/DynamicAssistantDropdown.razor | 16 ++++-- .../DynamicAssistantDropdown.razor.cs | 27 +++++++--- .../Plugins/assistants/README.md | 20 +++++++ .../Plugins/assistants/plugin.lua | 17 ++++-- .../DataModel/AssistantComponentPropHelper.cs | 2 + .../Assistants/DataModel/AssistantDropdown.cs | 54 +++++++++++++++++++ .../DataModel/AssistantDropdownItem.cs | 4 +- .../DataModel/ComponentPropSpecs.cs | 5 +- 10 files changed, 138 insertions(+), 22 deletions(-) diff --git a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor index 5ac6359a..d014a3c0 100644 --- a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor +++ b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor @@ -91,9 +91,18 @@ @bind-Value="@this.dropdownFields[assistantDropdown.Name]" Default="@assistantDropdown.Default" Label="@assistantDropdown.Label" - Icon="@Icons.Material.Filled.Translate" + HelperText="@assistantDropdown.HelperText" + OpenIcon="@AssistantComponentPropHelper.GetIconSvg(assistantDropdown.OpenIcon)" + CloseIcon="@AssistantComponentPropHelper.GetIconSvg(assistantDropdown.CloseIcon)" + IconColor="@AssistantComponentPropHelper.GetColor(assistantDropdown.IconColor, Color.Default)" + IconPosition="@AssistantComponentPropHelper.GetAdornment(assistantDropdown.IconPositon, Adornment.End)" + Variant="@AssistantComponentPropHelper.GetVariant(assistantDropdown.Variant, Variant.Outlined)" + IsMultiselect="@assistantDropdown.IsMultiselect" + HasSelectAll="@assistantDropdown.HasSelectAll" + SelectAllText="@assistantDropdown.SelectAllText" Class="@assistantDropdown.Class" - Style="@assistantDropdown.Style" /> + Style="@this.GetOptionalStyle(assistantDropdown.Style)" + /> } break; case AssistantComponentType.BUTTON: diff --git a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs index f3abcd7f..cc68282d 100644 --- a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs +++ b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs @@ -288,7 +288,7 @@ public partial class AssistantDynamic : AssistantBaseCore break; case AssistantComponentType.DROPDOWN: if (component is AssistantDropdown dropdown && !this.dropdownFields.ContainsKey(dropdown.Name)) - this.dropdownFields.Add(dropdown.Name, dropdown.Default.Value); + this.dropdownFields.Add(dropdown.Name, dropdown.Default.Display); break; case AssistantComponentType.SWITCH: if (component is AssistantSwitch switchComponent && !this.switchFields.ContainsKey(switchComponent.Name)) diff --git a/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor b/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor index 0c209c11..9ad8880a 100644 --- a/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor +++ b/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor @@ -1,15 +1,21 @@ +@using AIStudio.Tools.PluginSystem.Assistants.DataModel @foreach (var item in Items) { diff --git a/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor.cs b/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor.cs index cde6cdfd..22896792 100644 --- a/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor.cs +++ b/app/MindWork AI Studio/Components/DynamicAssistantDropdown.razor.cs @@ -18,13 +18,29 @@ namespace AIStudio.Components [Parameter] public EventCallback ValueChanged { get; set; } [Parameter] public string Label { get; set; } = string.Empty; + + [Parameter] public string HelperText { get; set; } = string.Empty; [Parameter] public Func ValidateSelection { get; set; } = _ => null; - [Parameter] public string Icon { get; set; } = Icons.Material.Filled.ArrowDropDown; + [Parameter] public string OpenIcon { get; set; } = Icons.Material.Filled.ArrowDropDown; + + [Parameter] public string CloseIcon { get; set; } = Icons.Material.Filled.ArrowDropUp; + + [Parameter] public Color IconColor { get; set; } = Color.Default; + + [Parameter] public Adornment IconPosition { get; set; } = Adornment.End; + + [Parameter] public Variant Variant { get; set; } = Variant.Outlined; + + [Parameter] public bool IsMultiselect { get; set; } + + [Parameter] public bool HasSelectAll { get; set; } + + [Parameter] public string SelectAllText { get; set; } = string.Empty; [Parameter] public string Class { get; set; } = string.Empty; - + [Parameter] public string Style { get; set; } = string.Empty; private async Task OnValueChanged(string newValue) @@ -36,17 +52,14 @@ namespace AIStudio.Components } } - internal string MergeClasses(string custom, string fallback) + private string MergeClasses(string custom, string fallback) { var trimmedCustom = custom?.Trim() ?? string.Empty; var trimmedFallback = fallback?.Trim() ?? string.Empty; if (string.IsNullOrEmpty(trimmedCustom)) return trimmedFallback; - if (string.IsNullOrEmpty(trimmedFallback)) - return trimmedCustom; - - return $"{trimmedCustom} {trimmedFallback}"; + return string.IsNullOrEmpty(trimmedFallback) ? trimmedCustom : $"{trimmedCustom} {trimmedFallback}"; } } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Plugins/assistants/README.md b/app/MindWork AI Studio/Plugins/assistants/README.md index 546dab2a..4e810c29 100644 --- a/app/MindWork AI Studio/Plugins/assistants/README.md +++ b/app/MindWork AI Studio/Plugins/assistants/README.md @@ -7,6 +7,7 @@ This folder keeps the Lua manifest (`plugin.lua`) that defines a custom assistan - [How to Use This Documentation](#how-to-use-this-documentation) - [Directory Structure](#directory-structure) - [Structure](#structure) + - [Minimal Requirements Assistant Table](#example-minimal-requirements-assistant-table) - [Supported types (matching the Blazor UI components):](#supported-types-matching-the-blazor-ui-components) - [Component References](#component-references) - [`TEXT_AREA` reference](#text_area-reference) @@ -64,6 +65,24 @@ Each assistant plugin lives in its own directory under the assistants plugin roo - `UI.Type` is always `"FORM"` and `UI.Children` is a list of component tables. - Each component table declares `Type`, an optional `Children` array, and a `Props` table that feeds the component’s parameters. +### Example: Minimal Requirements Assistant Table +```lua +ASSISTANT = { + ["Title"] = "", + ["Description"] = "", + ["SystemPrompt"] = "", + ["SubmitText"] = "", + ["AllowProfiles"] = true, + ["UI"] = { + ["Type"] = "FORM", + ["Children"] = { + -- Components + } + }, +} +``` + + #### Supported types (matching the Blazor UI components): - `TEXT_AREA`: user input field based on `MudTextField`; requires `Name`, `Label`, and may include `HelperText`, `HelperTextOnFocus`, `Adornment`, `AdornmentIcon`, `AdornmentText`, `AdornmentColor`, `Counter`, `MaxLength`, `IsImmediate`, `UserPrompt`, `PrefillText`, `IsSingleLine`, `ReadOnly`, `Class`, `Style`. @@ -692,5 +711,6 @@ LogInfo(dt.day .. "." .. dt.month .. "." .. dt.year) ## Useful Resources - [plugin.lua - Lua Manifest](https://github.com/MindWorkAI/AI-Studio/tree/main/app/MindWork%20AI%20Studio/Plugins/assistants/plugin.lua) +- [AI Studio Repository](https://github.com/MindWorkAI/AI-Studio/) - [Lua 5.2 Reference Manual](https://www.lua.org/manual/5.2/manual.html) - [MudBlazor Documentation](https://www.mudblazor.com/docs/overview) diff --git a/app/MindWork AI Studio/Plugins/assistants/plugin.lua b/app/MindWork AI Studio/Plugins/assistants/plugin.lua index 49028340..0bba5df3 100644 --- a/app/MindWork AI Studio/Plugins/assistants/plugin.lua +++ b/app/MindWork AI Studio/Plugins/assistants/plugin.lua @@ -70,7 +70,7 @@ ASSISTANT = { ["Props"] = { ["Name"] = "", -- required ["Label"] = "", -- required - ["Adornment"] = "", -- location of the `AdornmentIcon` OR `AdornmentText`; CASE SENSITIV + ["Adornment"] = "", -- location of the `AdornmentIcon` OR `AdornmentText`; CASE SENSITIVE ["AdornmentIcon"] = "Icons.Material.Filled.AppSettingsAlt", -- The Mudblazor icon displayed for the adornment ["AdornmentText"] = "", -- The text displayed for the adornment ["AdornmentColor"] = "", -- the color of AdornmentText or AdornmentIcon; CASE SENSITIVE @@ -90,10 +90,19 @@ ASSISTANT = { { ["Type"] = "DROPDOWN", -- required ["Props"] = { - ["Name"] = "", -- required - ["Label"] = "", -- required + ["Name"] = "", -- required + ["Label"] = "", -- required ["UserPrompt"] = "", - ["ValueType"] = "", -- required + ["IsMultiselect"] = false, + ["HasSelectAll"] = false, + ["SelectAllText"] = "