using AIStudio.Settings; using AIStudio.Tools; using Microsoft.AspNetCore.Components; namespace AIStudio.Components.Blocks; /// /// Configuration component for selecting a value from a list. /// /// The type of the value to select. public partial class ConfigurationSelect : ConfigurationBase, IMessageBusReceiver { /// /// The data to select from. /// [Parameter] public IEnumerable> Data { get; set; } = []; /// /// The selected value. /// [Parameter] public Func SelectedValue { get; set; } = () => default!; /// /// An action that is called when the selection changes. /// [Parameter] public Action SelectionUpdate { get; set; } = _ => { }; /// /// Is the selection component disabled? /// [Parameter] public Func Disabled { get; set; } = () => false; #region Overrides of ComponentBase protected override async Task OnInitializedAsync() { // Register this component with the message bus: this.MessageBus.RegisterComponent(this); this.MessageBus.ApplyFilters(this, [], [ Event.CONFIGURATION_CHANGED ]); await base.OnInitializedAsync(); } #endregion private async Task OptionChanged(T updatedValue) { this.SelectionUpdate(updatedValue); await this.SettingsManager.StoreSettings(); await this.InformAboutChange(); } private static string GetClass => $"{MARGIN_CLASS} rounded-lg"; #region Implementation of IMessageBusReceiver public Task ProcessMessage(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data) { switch (triggeredEvent) { case Event.CONFIGURATION_CHANGED: this.StateHasChanged(); break; } return Task.CompletedTask; } public Task ProcessMessageWithResult(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) { return Task.FromResult(default); } #endregion }