mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-20 09:52:14 +00:00
added display value of dropdowns to the state
This commit is contained in:
parent
d494fe4bc7
commit
ff32f8f184
@ -121,6 +121,26 @@ internal sealed class AssistantDropdown : StatefulAssistantComponentBase
|
||||
|
||||
#endregion
|
||||
|
||||
internal string ResolveDisplayText(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return this.Default.Display;
|
||||
|
||||
var item = this.GetRenderedItems().FirstOrDefault(item => string.Equals(item.Value, value, StringComparison.Ordinal));
|
||||
return item?.Display ?? value;
|
||||
}
|
||||
|
||||
private List<AssistantDropdownItem> GetRenderedItems()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(this.Default.Value))
|
||||
return this.Items;
|
||||
|
||||
if (this.Items.Any(item => string.Equals(item.Value, this.Default.Value, StringComparison.Ordinal)))
|
||||
return this.Items;
|
||||
|
||||
return [this.Default, .. this.Items];
|
||||
}
|
||||
|
||||
public IEnumerable<object> GetParsedDropdownValues()
|
||||
{
|
||||
foreach (var item in this.Items)
|
||||
|
||||
@ -156,12 +156,17 @@ public sealed class AssistantState
|
||||
{
|
||||
if (component is INamedAssistantComponent named)
|
||||
{
|
||||
target[named.Name] = new LuaTable
|
||||
var componentEntry = new LuaTable
|
||||
{
|
||||
["Type"] = Enum.GetName(component.Type) ?? string.Empty,
|
||||
["Value"] = component is IStatefulAssistantComponent ? this.ReadValueForLua(named.Name) : LuaValue.Nil,
|
||||
["Props"] = this.CreatePropsTable(component),
|
||||
};
|
||||
|
||||
if (component is AssistantDropdown dropdown)
|
||||
this.AddDropdownDisplay(componentEntry, dropdown, named.Name);
|
||||
|
||||
target[named.Name] = componentEntry;
|
||||
}
|
||||
|
||||
if (component.Children.Count > 0)
|
||||
@ -218,6 +223,27 @@ public sealed class AssistantState
|
||||
return table;
|
||||
}
|
||||
|
||||
private void AddDropdownDisplay(LuaTable componentEntry, AssistantDropdown dropdown, string name)
|
||||
{
|
||||
if (dropdown.IsMultiselect)
|
||||
{
|
||||
if (!this.MultiSelect.TryGetValue(name, out var selectedValues))
|
||||
return;
|
||||
|
||||
componentEntry["Display"] = AssistantLuaConversion.CreateLuaArray(
|
||||
selectedValues
|
||||
.OrderBy(static value => value, StringComparer.Ordinal)
|
||||
.Select(dropdown.ResolveDisplayText));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.SingleSelect.TryGetValue(name, out var selectedValue))
|
||||
return;
|
||||
|
||||
componentEntry["Display"] = dropdown.ResolveDisplayText(selectedValue);
|
||||
}
|
||||
|
||||
private static HashSet<string> ReadStringValues(LuaTable values)
|
||||
{
|
||||
var parsedValues = new HashSet<string>(StringComparer.Ordinal);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user